use of gaiasky.event.Event in project gaiasky by langurmonkey.
the class SearchDialog method build.
public void build() {
candidates = new Table(skin);
candidates.setBackground("table-bg");
candidates.setFillParent(false);
// Info message
searchInput = new OwnTextField("", skin);
searchInput.setWidth(480f);
searchInput.setMessageText(I18n.txt("gui.objects.search"));
searchInput.addListener(event -> {
if (event instanceof InputEvent) {
InputEvent ie = (InputEvent) event;
int matchingSize = matching.size();
int code = ie.getKeyCode();
if (ie.getType() == Type.keyUp) {
if (code == Keys.ESCAPE || code == Keys.ENTER) {
if (cIdx >= 0) {
checkString(searchInput.getText(), sg);
}
removeCandidates();
me.remove();
return true;
} else if (code == Keys.UP && matchingSize > 0) {
cIdx = cIdx - 1 < 0 ? matchingSize - 1 : cIdx - 1;
selectMatch();
} else if (code == Keys.DOWN && matchingSize > 0) {
cIdx = (cIdx + 1) % matchingSize;
selectMatch();
} else if (!searchInput.getText().equals(currentInputText) && !searchInput.getText().isBlank()) {
// Process only if text changed
if (suggestions) {
currentInputText = searchInput.getText();
String name = currentInputText.toLowerCase().trim();
// New task
Task task = new Task() {
public void run() {
synchronized (matching) {
matchingNodes(name, sg);
if (!matching.isEmpty()) {
cIdx = -1;
candidates.clear();
int n = matching.size();
matching.stream().forEach(match -> {
OwnLabel m = new OwnLabel(match, skin);
m.addListener((evt) -> {
if (evt instanceof InputEvent) {
InputEvent iEvt = (InputEvent) evt;
if (iEvt.getType() == Type.touchDown) {
checkString(match, sg);
searchInput.setText(match);
accept();
return true;
}
}
return false;
});
matchingLabels.add(m);
m.setWidth(searchInput.getWidth());
Cell<?> c = candidates.add(m).left().padBottom(pad5);
c.row();
});
candidates.pack();
searchInput.localToStageCoordinates(aux.set(0, 0));
candidates.setPosition(aux.x, aux.y, Align.topLeft);
stage.addActor(candidates);
} else {
removeCandidates();
}
}
}
};
// Cancel others
cancelTasks();
tasks.add(task);
// Schedule with delay
Timer.schedule(task, 0.5f);
// Actually check and select
if (!checkString(name, sg)) {
if (name.matches("[0-9]+")) {
// Check with 'HIP '
if (checkString("hip " + name, sg)) {
cancelTasks();
removeCandidates();
}
} else if (name.matches("hip [0-9]+") || name.matches("HIP [0-9]+")) {
// Check without 'HIP '
if (checkString(name.substring(4), sg)) {
cancelTasks();
removeCandidates();
}
}
} else {
cancelTasks();
removeCandidates();
}
}
} else {
removeCandidates();
}
if (GaiaSky.instance.getICamera() instanceof NaturalCamera)
((NaturalCamera) GaiaSky.instance.getICamera()).getCurrentMouseKbdListener().removePressedKey(ie.getKeyCode());
}
}
return false;
});
// Info message
infoMessage = new OwnLabel("", skin, "default-blue");
content.add(searchInput).top().left().expand().row();
infoCell = content.add();
infoCell.top().left().padTop(pad5).expand().row();
}
use of gaiasky.event.Event in project gaiasky by langurmonkey.
the class ExternalInformationUpdater method update.
public void update(final IFocus focus) {
GaiaSky.postRunnable(() -> {
if (focus != null) {
logger.debug("Looking up network resources for '" + focus.getName() + "'");
infoCell = table.add().left();
gaiaCell = table.add().left();
simbadCell = table.add().left();
// Add table
if (focus instanceof IStarFocus) {
EventManager.publish(Event.UPDATE_ARCHIVE_VIEW_ACTION, this, focus);
if (gaiaButton != null)
gaiaButton.remove();
gaiaButton = new OwnTextButton(I18n.txt("gui.focusinfo.archive"), skin);
gaiaButton.pad(pad / 3f, pad, pad / 3f, pad);
gaiaButton.addListener(new GaiaButtonListener((IStarFocus) focus));
gaiaButton.addListener(new OwnTextTooltip(I18n.txt("gui.tooltip.gaiaarchive"), skin));
gaiaCell.setActor(gaiaButton).padRight(pad);
} else {
gaiaCell.padRight(0);
}
String wikiname = focus.getName().replace(' ', '_');
setWikiLink(wikiname, focus, new LinkListener() {
@Override
public void ok(String link) {
if (infoCell != null) {
try {
String actualWikiname = link.substring(Constants.URL_WIKIPEDIA.length());
EventManager.publish(Event.UPDATE_WIKI_INFO_ACTION, this, actualWikiname);
if (infoButton != null)
infoButton.remove();
infoButton = new OwnTextButton(I18n.txt("gui.focusinfo.moreinfo"), skin);
infoButton.addListener(new OwnTextTooltip(I18n.txt("gui.tooltip.wiki"), skin));
infoButton.pad(pad / 3f, pad, pad / 3f, pad);
infoButton.addListener((event) -> {
if (event instanceof ChangeEvent) {
EventManager.publish(Event.SHOW_WIKI_INFO_ACTION, this, actualWikiname);
return true;
}
return false;
});
infoCell.setActor(infoButton).padRight(pad);
} catch (Exception ignored) {
}
}
}
@Override
public void ko(String link) {
if (infoCell != null)
infoCell.padRight(0);
}
});
setSimbadLink(focus, new LinkListener() {
@Override
public void ok(String link) {
if (simbadCell != null) {
try {
if (simbadLink != null) {
simbadLink.remove();
}
simbadLink = new Link(I18n.txt("gui.focusinfo.simbad"), linkStyle, "");
simbadLink.addListener(new OwnTextTooltip(I18n.txt("gui.tooltip.simbad"), skin));
simbadLink.setLinkURL(link);
simbadCell.setActor(simbadLink);
} catch (Exception ignored) {
}
}
}
@Override
public void ko(String link) {
}
});
}
});
}
use of gaiasky.event.Event in project gaiasky by langurmonkey.
the class EventScriptingInterface method runCameraPath.
@Override
public void runCameraPath(String file, boolean sync) {
em.post(Event.PLAY_CAMERA_CMD, this, file);
// Wait if needed
if (sync) {
Object monitor = new Object();
IObserver watcher = (event, source, data) -> {
switch(event) {
case CAMERA_PLAY_INFO:
Boolean status = (Boolean) data[0];
if (!status) {
synchronized (monitor) {
monitor.notify();
}
}
break;
default:
break;
}
};
em.subscribe(watcher, Event.CAMERA_PLAY_INFO);
// Wait for camera to finish
synchronized (monitor) {
try {
monitor.wait();
} catch (InterruptedException e) {
logger.error(e, "Error waiting for camera file to finish");
}
}
}
}
use of gaiasky.event.Event in project gaiasky by langurmonkey.
the class GaiaSkyContextMenu method build.
private void build() {
Drawable rulerDwb = skin.getDrawable("icon-elem-ruler");
if (candidate != null) {
MenuItem select = new MenuItem(I18n.txt("context.select", candidateNameShort), skin, skin.getDrawable("highlight-off"));
select.addListener(event -> {
if (event instanceof ChangeEvent) {
EventManager.publish(Event.CAMERA_MODE_CMD, select, CameraMode.FOCUS_MODE);
EventManager.publish(Event.FOCUS_CHANGE_CMD, select, candidate);
}
return false;
});
addItem(select);
MenuItem go = new MenuItem(I18n.txt("context.goto", candidateNameShort), skin, skin.getDrawable("go-to"));
go.addListener(event -> {
if (event instanceof ChangeEvent) {
candidate.makeFocus();
EventManager.publish(Event.NAVIGATE_TO_OBJECT, go, candidate);
}
return false;
});
addItem(go);
addSeparator();
// Tracking object
MenuItem track = new MenuItem(I18n.txt("context.track", candidateNameShort), skin, skin.getDrawable("highlight-on"));
track.addListener(event -> {
if (event instanceof ChangeEvent) {
EventManager.publish(Event.CAMERA_TRACKING_OBJECT_CMD, track, candidate, candidateName);
}
return false;
});
addItem(track);
MenuItem noTrack = new MenuItem(I18n.txt("context.notrack", candidateNameShort), skin, skin.getDrawable("iconic-delete"));
noTrack.addListener(event -> {
if (event instanceof ChangeEvent) {
EventManager.publish(Event.CAMERA_TRACKING_OBJECT_CMD, noTrack, (Object) null, (Object) null);
}
return false;
});
addItem(noTrack);
addSeparator();
// Add bounding shape at object position
MenuItem addShape = new MenuItem(I18n.txt("context.shape.new", candidateNameShort), skin, skin.getDrawable("icon-elem-grids"));
addShape.addListener(event -> {
if (event instanceof ChangeEvent) {
AddShapeDialog dialog = new AddShapeDialog(I18n.txt("context.shape.new", candidateNameShort), candidate, candidateName, skin, getStage());
dialog.setAcceptRunnable(() -> {
double size = dialog.units.getSelected().toKm(dialog.size.getDoubleValue(1)) * 2.0;
float[] color = dialog.color.getPickedColor();
String shape = dialog.shape.getSelected().toString().toLowerCase(Locale.ROOT);
String primitive = dialog.primitive.getSelected().toString();
boolean showLabel = dialog.showLabel.isChecked();
boolean trackObj = dialog.track.isChecked();
GaiaSky.instance.scripting().addShapeAroundObject(dialog.name.getText().trim(), shape, primitive, size, candidateName, color[0], color[1], color[2], color[3], showLabel, trackObj);
});
dialog.show(getStage());
return true;
}
return false;
});
addItem(addShape);
MenuItem removeShapesObj = new MenuItem(I18n.txt("context.shape.remove", candidateNameShort), skin, skin.getDrawable("iconic-delete"));
removeShapesObj.addListener(event -> {
if (event instanceof ChangeEvent) {
ISceneGraph sg = GaiaSky.instance.sceneGraph;
Array<SceneGraphNode> l = new Array<>();
sg.getRoot().getChildrenByType(ShapeObject.class, l);
GaiaSky.postRunnable(() -> {
for (SceneGraphNode n : l) {
ShapeObject shapeObject = (ShapeObject) n;
IFocus tr = shapeObject.getTrack();
String trName = shapeObject.getTrackName();
if (tr != null && tr == candidate) {
EventManager.publish(Event.SCENE_GRAPH_REMOVE_OBJECT_CMD, removeShapesObj, candidate, false);
} else if (trName != null && trName.equalsIgnoreCase(candidateName)) {
EventManager.publish(Event.SCENE_GRAPH_REMOVE_OBJECT_CMD, removeShapesObj, candidate, false);
}
}
});
}
return false;
});
addItem(removeShapesObj);
MenuItem removeShapesAll = new MenuItem(I18n.txt("context.shape.remove.all"), skin, skin.getDrawable("iconic-delete"));
removeShapesAll.addListener(event -> {
if (event instanceof ChangeEvent) {
ISceneGraph sg = GaiaSky.instance.sceneGraph;
Array<SceneGraphNode> l = new Array<>();
sg.getRoot().getChildrenByType(ShapeObject.class, l);
GaiaSky.postRunnable(() -> {
for (SceneGraphNode n : l) {
EventManager.publish(Event.SCENE_GRAPH_REMOVE_OBJECT_CMD, removeShapesAll, n, false);
}
});
}
return false;
});
addItem(removeShapesAll);
if (candidate instanceof Planet) {
addSeparator();
MenuItem landOn = new MenuItem(I18n.txt("context.landon", candidateNameShort), skin, skin.getDrawable("land-on"));
landOn.addListener(event -> {
if (event instanceof ChangeEvent) {
EventManager.publish(Event.LAND_ON_OBJECT, landOn, candidate);
return true;
}
return false;
});
addItem(landOn);
double[] lonlat = new double[2];
boolean ok = CameraUtils.getLonLat((Planet) candidate, GaiaSky.instance.getICamera(), Gdx.input.getX(), Gdx.input.getY(), new Vector3(), new Vector3(), new Vector3(), new Vector3(), new Vector3d(), new Vector3d(), new Matrix4(), lonlat);
if (ok) {
final Double pointerLon = lonlat[0];
final Double pointerLat = lonlat[1];
// Add mouse pointer
MenuItem landOnPointer = new MenuItem(I18n.txt("context.landatpointer", candidateNameShort), skin, skin.getDrawable("land-on"));
landOnPointer.addListener(event -> {
if (event instanceof ChangeEvent) {
EventManager.publish(Event.LAND_AT_LOCATION_OF_OBJECT, landOnPointer, candidate, pointerLon, pointerLat);
return true;
}
return false;
});
addItem(landOnPointer);
}
MenuItem landOnCoord = new MenuItem(I18n.txt("context.landatcoord", candidateNameShort), skin, skin.getDrawable("land-at"));
landOnCoord.addListener(event -> {
if (event instanceof ChangeEvent) {
EventManager.publish(Event.SHOW_LAND_AT_LOCATION_ACTION, landOnCoord, candidate);
return true;
}
return false;
});
addItem(landOnCoord);
addSeparator();
MenuItem proceduralSurface = new MenuItem(I18n.txt("context.proceduralmenu", candidateNameShort), skin, skin.getDrawable("iconic-infinity"));
proceduralSurface.addListener(event -> {
if (event instanceof ChangeEvent) {
EventManager.publish(Event.SHOW_PROCEDURAL_GEN_ACTION, proceduralSurface, candidate);
return true;
}
return false;
});
addItem(proceduralSurface);
}
if (candidate instanceof IStarFocus && uncertainties) {
boolean sep = false;
if (UncertaintiesHandler.getInstance().containsStar(candidate.getCandidateId())) {
addSeparator();
sep = true;
MenuItem showUncertainties = new MenuItem(I18n.txt("context.showuncertainties"), skin, "default");
showUncertainties.addListener(event -> {
if (event instanceof ChangeEvent) {
EventManager.publish(Event.SHOW_UNCERTAINTIES, showUncertainties, candidate);
return true;
}
return false;
});
addItem(showUncertainties);
}
if (UncertaintiesHandler.getInstance().containsUncertainties()) {
if (!sep)
addSeparator();
MenuItem hideUncertainties = new MenuItem(I18n.txt("context.hideuncertainties"), skin, "default");
hideUncertainties.addListener(event -> {
if (event instanceof ChangeEvent) {
EventManager.publish(Event.HIDE_UNCERTAINTIES, hideUncertainties, candidate);
return true;
}
return false;
});
addItem(hideUncertainties);
}
}
addSeparator();
// Cosmic ruler
CosmicRuler cr = (CosmicRuler) sg.getNode("Cosmicruler");
if (cr == null) {
sg.insert((cr = new CosmicRuler()), true);
}
MenuItem rulerAttach0 = null, rulerAttach1 = null;
if (!cr.hasObject0() && !cr.hasObject1()) {
// No objects attached
rulerAttach0 = new MenuItem(I18n.txt("context.ruler.attach", "0", candidateNameShort), skin, rulerDwb);
final MenuItem ra = rulerAttach0;
rulerAttach0.addListener((ev) -> {
if (ev instanceof ChangeEvent) {
EventManager.publish(Event.RULER_ATTACH_0, ra, candidateName);
return true;
}
return false;
});
} else if (cr.hasObject0() && !cr.hasObject1()) {
// Only 0 is attached
rulerAttach1 = new MenuItem(I18n.txt("context.ruler.attach", "1", candidateNameShort), skin, rulerDwb);
final MenuItem ra = rulerAttach1;
rulerAttach1.addListener((ev) -> {
if (ev instanceof ChangeEvent) {
EventManager.publish(Event.RULER_ATTACH_1, ra, candidateName);
return true;
}
return false;
});
} else {
// All attached, show both
rulerAttach0 = new MenuItem(I18n.txt("context.ruler.attach", "0", candidateNameShort), skin, rulerDwb);
final MenuItem ra0 = rulerAttach0;
rulerAttach0.addListener((ev) -> {
if (ev instanceof ChangeEvent) {
GaiaSky.postRunnable(() -> {
EventManager.publish(Event.RULER_ATTACH_0, ra0, candidateName);
});
return true;
}
return false;
});
rulerAttach1 = new MenuItem(I18n.txt("context.ruler.attach", "1", candidateNameShort), skin, rulerDwb);
final MenuItem ra1 = rulerAttach1;
rulerAttach1.addListener((ev) -> {
if (ev instanceof ChangeEvent) {
GaiaSky.postRunnable(() -> {
EventManager.publish(Event.RULER_ATTACH_1, ra1, candidateName);
});
return true;
}
return false;
});
}
if (rulerAttach0 != null)
addItem(rulerAttach0);
if (rulerAttach1 != null)
addItem(rulerAttach1);
}
// Clear ruler
CosmicRuler cr = (CosmicRuler) sg.getNode("Cosmicruler");
if (cr == null) {
sg.insert((cr = new CosmicRuler()), true);
}
if (cr.rulerOk() || cr.hasAttached()) {
MenuItem clearRuler = new MenuItem(I18n.txt("context.ruler.clear"), skin, rulerDwb);
clearRuler.addListener((evt) -> {
if (evt instanceof ChangeEvent) {
GaiaSky.postRunnable(() -> {
EventManager.publish(Event.RULER_CLEAR, clearRuler);
});
return true;
}
return false;
});
addItem(clearRuler);
}
// Load
MenuItem dsLoad = new MenuItem(I18n.txt("context.dataset.load"), skin, skin.getDrawable("open-icon"));
dsLoad.addListener(event -> {
if (event instanceof ChangeEvent) {
EventManager.publish(Event.SHOW_LOAD_CATALOG_ACTION, dsLoad);
return true;
}
return false;
});
addItem(dsLoad);
// Dataset highlight
Collection<CatalogInfo> cis = catalogManager.getCatalogInfos();
if (cis != null && cis.size() > 0) {
MenuItem dsHighlight = new MenuItem(I18n.txt("context.dataset.highlight"), skin, skin.getDrawable("highlight-on"));
ContextMenu dsHighlightSubmenu = new ContextMenu(skin, "default");
for (CatalogInfo ci : cis) {
if (ci.isVisible()) {
MenuItem cim = new MenuItem(ci.name, skin, "default");
cim.align(Align.right);
OwnCheckBox cb = new OwnCheckBox(null, skin, pad);
cb.setChecked(ci.highlighted);
cim.add(cb).right().expand();
cim.addListener(event -> {
if (event instanceof ChangeEvent) {
EventManager.publish(Event.CATALOG_HIGHLIGHT, cim, ci, !ci.highlighted);
return true;
}
return false;
});
dsHighlightSubmenu.addItem(cim);
}
}
dsHighlight.setSubMenu(dsHighlightSubmenu);
addItem(dsHighlight);
}
// Dataset visibility
if (cis != null && cis.size() > 0) {
MenuItem dsVisibility = new MenuItem(I18n.txt("context.dataset.visibility"), skin, skin.getDrawable("eye-icon"));
ContextMenu dsVisibilitySubmenu = new ContextMenu(skin, "default");
for (CatalogInfo ci : cis) {
MenuItem cim = new MenuItem(ci.name, skin, "default");
cim.align(Align.right);
Drawable icon = ci.isVisible(true) ? skin.getDrawable("eye-icon") : skin.getDrawable("eye-closed-icon");
OwnImage img = new OwnImage(icon);
cim.add(img).right().padRight(pad).expand();
cim.addListener(event -> {
if (event instanceof ChangeEvent) {
EventManager.publish(Event.CATALOG_VISIBLE, cim, ci.name, !ci.isVisible(true));
return true;
}
return false;
});
dsVisibilitySubmenu.addItem(cim);
}
dsVisibility.setSubMenu(dsVisibilitySubmenu);
addItem(dsVisibility);
}
if (relativisticEffects) {
// Spawn gravitational waves
MenuItem gravWaveStart = new MenuItem(I18n.txt("context.startgravwave"), skin, "default");
gravWaveStart.addListener(event -> {
if (event instanceof ChangeEvent) {
EventManager.publish(Event.GRAV_WAVE_START, gravWaveStart, screenX, screenY);
return true;
}
return false;
});
addItem(gravWaveStart);
if (RelativisticEffectsManager.getInstance().gravWavesOn()) {
// Cancel gravitational waves
MenuItem gravWaveStop = new MenuItem(I18n.txt("context.stopgravwave"), skin, "default");
gravWaveStop.addListener(event -> {
if (event instanceof ChangeEvent) {
EventManager.publish(Event.GRAV_WAVE_STOP, gravWaveStop);
return true;
}
return false;
});
addItem(gravWaveStop);
}
}
if (nItems > 0) {
addSeparator();
}
// Quit
MenuItem quit = new MenuItem(I18n.txt("context.quit"), skin, skin.getDrawable("quit-icon"));
quit.addListener((event) -> {
if (event instanceof ChangeEvent) {
EventManager.publish(Event.SHOW_QUIT_ACTION, quit);
return true;
}
return false;
});
addItem(quit);
}
use of gaiasky.event.Event in project gaiasky by langurmonkey.
the class WelcomeGui method initialize.
@Override
public void initialize(AssetManager assetManager, SpriteBatch sb) {
// User interface
ScreenViewport vp = new ScreenViewport();
vp.setUnitsPerPixel(unitsPerPixel);
ui = new Stage(vp, sb);
popupInterface = new PopupNotificationsInterface(skin);
popupInterface.top().right();
popupInterface.setFillParent(true);
if (vrStatus.vrInitFailed()) {
if (vrStatus.equals(VRStatus.ERROR_NO_CONTEXT))
GaiaSky.postRunnable(() -> GuiUtils.addNoVRConnectionExit(skin, ui));
else if (vrStatus.equals(VRStatus.ERROR_RENDERMODEL))
GaiaSky.postRunnable(() -> GuiUtils.addNoVRDataExit(skin, ui));
} else if (Settings.settings.program.net.slave.active || GaiaSky.instance.isHeadless()) {
// If slave or headless, data load can start
gaiaSky();
} else {
// Otherwise, check for updates, etc.
clearGui();
dataDescriptor = Gdx.files.absolute(SysUtils.getTempDir(Settings.settings.data.location) + "/gaiasky-data.json");
DownloadHelper.downloadFile(Settings.settings.program.url.dataDescriptor, dataDescriptor, null, null, (digest) -> GaiaSky.postRunnable(() -> {
// Data descriptor ok. Skip welcome screen only if flag and base data present
if (skipWelcome && baseDataPresent()) {
gaiaSky();
} else {
buildWelcomeUI();
}
}), () -> {
// Fail?
downloadError = true;
logger.error(I18n.txt("gui.welcome.error.nointernet"));
if (baseDataPresent()) {
// Go on all in
GaiaSky.postRunnable(() -> GuiUtils.addNoConnectionWindow(skin, ui, () -> buildWelcomeUI()));
} else {
// Error and exit
logger.error(I18n.txt("gui.welcome.error.nobasedata"));
GaiaSky.postRunnable(() -> GuiUtils.addNoConnectionExit(skin, ui));
}
}, null);
/* CAPTURE SCROLL FOCUS */
ui.addListener(event -> {
if (event instanceof InputEvent) {
InputEvent ie = (InputEvent) event;
if (ie.getType() == Type.keyUp) {
if (ie.getKeyCode() == Input.Keys.ESCAPE) {
Gdx.app.exit();
} else if (ie.getKeyCode() == Input.Keys.ENTER) {
if (baseDataPresent()) {
gaiaSky();
} else {
addDatasetManagerWindow(serverDatasets);
}
}
}
}
return false;
});
}
}
Aggregations