use of gaiasky.scenegraph.IFocus in project gaiasky by langurmonkey.
the class HiddenHelperUser method notify.
@Override
public void notify(final Event event, Object source, final Object... data) {
switch(event) {
case NAVIGATE_TO_OBJECT:
IFocus body;
if (data[0] instanceof String)
body = GaiaSky.instance.sceneGraph.findFocus((String) data[0]);
else
body = ((IFocus) data[0]);
GoToObjectTask gotoTask = new GoToObjectTask(body, currentTasks);
Thread gotoT = new Thread(gotoTask);
gotoT.start();
currentTasks.add(gotoTask);
lastCommandTime = TimeUtils.millis();
break;
case LAND_ON_OBJECT:
if (data[0] instanceof String)
body = GaiaSky.instance.sceneGraph.findFocus((String) data[0]);
else
body = ((CelestialBody) data[0]);
LandOnObjectTask landOnTask = new LandOnObjectTask(body, currentTasks);
Thread landonT = new Thread(landOnTask);
landonT.start();
currentTasks.add(landOnTask);
lastCommandTime = TimeUtils.millis();
break;
case LAND_AT_LOCATION_OF_OBJECT:
if (data[0] instanceof String)
body = GaiaSky.instance.sceneGraph.findFocus((String) data[0]);
else
body = ((CelestialBody) data[0]);
HelperTask landAtTask;
if (data[1] instanceof String) {
String locname = (String) data[1];
landAtTask = new LandAtLocationTask(body, locname, currentTasks);
} else {
Double lon = (Double) data[1];
Double lat = (Double) data[2];
landAtTask = new LandAtLocationTask(body, lon, lat, currentTasks);
}
Thread landAtLoc = new Thread(landAtTask);
landAtLoc.start();
currentTasks.add(landAtTask);
lastCommandTime = TimeUtils.millis();
break;
case INPUT_EVENT:
// stop
if (TimeUtils.millis() - lastCommandTime > 1000) {
// Stop all current threads
for (HelperTask tsk : currentTasks) {
tsk.stop();
}
currentTasks.clear();
}
break;
default:
break;
}
}
use of gaiasky.scenegraph.IFocus in project gaiasky by langurmonkey.
the class LocationLogManager method notify.
@Override
public void notify(Event event, Object source, Object... data) {
if (event == Event.CAMERA_NEW_CLOSEST) {
final IFocus closest = (IFocus) data[0];
this.addRecord(closest, GaiaSky.instance.getICamera(), GaiaSky.instance.time);
}
}
use of gaiasky.scenegraph.IFocus in project gaiasky by langurmonkey.
the class BookmarksComponent method initialize.
@Override
public void initialize() {
float contentWidth = ControlsWindow.getContentWidth();
searchBox = new OwnTextField("", skin);
searchBox.setName("search box");
searchBox.setWidth(contentWidth);
searchBox.setMessageText(I18n.txt("gui.objects.search"));
searchBox.addListener(event -> {
if (event instanceof InputEvent) {
InputEvent ie = (InputEvent) event;
if (ie.getType() == Type.keyUp && !searchBox.getText().isEmpty()) {
String text = searchBox.getText().toLowerCase().trim();
if (sg.containsNode(text)) {
SceneGraphNode node = sg.getNode(text);
if (node instanceof IFocus) {
IFocus focus = (IFocus) node;
boolean timeOverflow = focus.isCoordinatesTimeOverflow();
boolean ctOn = GaiaSky.instance.isOn(focus.getCt());
if (!timeOverflow && ctOn) {
GaiaSky.postRunnable(() -> {
EventManager.publish(Event.CAMERA_MODE_CMD, searchBox, CameraMode.FOCUS_MODE, true);
EventManager.publish(Event.FOCUS_CHANGE_CMD, searchBox, focus, true);
});
} else if (timeOverflow) {
info(I18n.txt("gui.objects.search.timerange.1", text), I18n.txt("gui.objects.search.timerange.2"));
} else {
info(I18n.txt("gui.objects.search.invisible.1", text), I18n.txt("gui.objects.search.invisible.2", focus.getCt().toString()));
}
}
} else {
info(null, null);
}
if (GaiaSky.instance.getICamera() instanceof NaturalCamera)
((NaturalCamera) GaiaSky.instance.getICamera()).getCurrentMouseKbdListener().removePressedKey(ie.getKeyCode());
if (ie.getKeyCode() == Keys.ESCAPE) {
// Lose focus
stage.setKeyboardFocus(null);
}
} else if (ie.getType() == Type.keyDown) {
if (ie.getKeyCode() == Keys.CONTROL_LEFT || ie.getKeyCode() == Keys.CONTROL_RIGHT) {
// Lose focus
stage.setKeyboardFocus(null);
}
}
return true;
}
return false;
});
// Info message
infoTable = new Table(skin);
infoCell1 = infoTable.add();
infoTable.row();
infoCell2 = infoTable.add();
infoMessage1 = new OwnLabel("", skin, "default-blue");
infoMessage2 = new OwnLabel("", skin, "default-blue");
/*
* OBJECTS
*/
bookmarksTree = new Tree<>(skin);
bookmarksTree.setName("bookmarks tree");
reloadBookmarksTree();
bookmarksTree.addListener(event -> {
if (events)
if (event instanceof ChangeEvent) {
ChangeEvent ce = (ChangeEvent) event;
Actor actor = ce.getTarget();
TreeNode selected = (TreeNode) ((Tree) actor).getSelectedNode();
if (selected != null && !selected.hasChildren()) {
String name = selected.getValue();
if (sg.containsNode(name)) {
SceneGraphNode node = sg.getNode(name);
if (node instanceof IFocus) {
IFocus focus = (IFocus) node;
boolean timeOverflow = focus.isCoordinatesTimeOverflow();
boolean ctOn = GaiaSky.instance.isOn(focus.getCt());
if (!timeOverflow && ctOn) {
GaiaSky.postRunnable(() -> {
EventManager.publish(Event.CAMERA_MODE_CMD, bookmarksTree, CameraMode.FOCUS_MODE, true);
EventManager.publish(Event.FOCUS_CHANGE_CMD, bookmarksTree, focus, true);
});
info(null, null);
} else if (timeOverflow) {
info(I18n.txt("gui.objects.search.timerange.1", name), I18n.txt("gui.objects.search.timerange.2"));
} else {
info(I18n.txt("gui.objects.search.invisible.1", name), I18n.txt("gui.objects.search.invisible.2", focus.getCt().toString()));
}
}
} else {
info(null, null);
}
}
return true;
} else if (event instanceof InputEvent) {
InputEvent ie = (InputEvent) event;
ie.toCoordinates(event.getListenerActor(), tmpCoords);
if (ie.getType() == Type.touchDown && ie.getButton() == Input.Buttons.RIGHT) {
TreeNode target = bookmarksTree.getNodeAt(tmpCoords.y);
// Context menu!
if (target != null) {
// selectBookmark(target.getValue(), true);
GaiaSky.postRunnable(() -> {
ContextMenu cm = new ContextMenu(skin, "default");
// New folder...
BookmarkNode parent = target.node.getFirstFolderAncestor();
String parentName = "/" + (parent == null ? "" : parent.path.toString());
MenuItem newDirectory = new MenuItem(I18n.txt("gui.bookmark.context.newfolder", parentName), skin);
newDirectory.addListener(evt -> {
if (evt instanceof ChangeEvent) {
NewBookmarkFolderDialog newBookmarkFolderDialog = new NewBookmarkFolderDialog(parent != null ? parent.path.toString() : "/", skin, stage);
newBookmarkFolderDialog.setAcceptRunnable(() -> {
String folderName = newBookmarkFolderDialog.input.getText();
EventManager.publish(Event.BOOKMARKS_ADD, newDirectory, parent != null ? parent.path.resolve(folderName).toString() : folderName, true);
reloadBookmarksTree();
});
newBookmarkFolderDialog.show(stage);
return true;
}
return false;
});
cm.addItem(newDirectory);
// Delete
MenuItem delete = new MenuItem(I18n.txt("gui.bookmark.context.delete", target.getValue()), skin);
delete.addListener(evt -> {
if (evt instanceof ChangeEvent) {
EventManager.publish(Event.BOOKMARKS_REMOVE, delete, target.node.path.toString());
reloadBookmarksTree();
return true;
}
return false;
});
cm.addItem(delete);
cm.addSeparator();
// Move up and down
MenuItem moveUp = new MenuItem(I18n.txt("gui.bookmark.context.move.up"), skin);
moveUp.addListener(evt -> {
if (evt instanceof ChangeEvent) {
EventManager.publish(Event.BOOKMARKS_MOVE_UP, moveUp, target.node);
reloadBookmarksTree();
return true;
}
return false;
});
cm.addItem(moveUp);
MenuItem moveDown = new MenuItem(I18n.txt("gui.bookmark.context.move.down"), skin);
moveDown.addListener(evt -> {
if (evt instanceof ChangeEvent) {
EventManager.publish(Event.BOOKMARKS_MOVE_DOWN, moveDown, target.node);
reloadBookmarksTree();
return true;
}
return false;
});
cm.addItem(moveDown);
// Move to...
if (target.node.parent != null) {
MenuItem move = new MenuItem(I18n.txt("gui.bookmark.context.move", target.getValue(), "/"), skin);
move.addListener(evt -> {
if (evt instanceof ChangeEvent) {
EventManager.publish(Event.BOOKMARKS_MOVE, move, target.node, null);
reloadBookmarksTree();
return true;
}
return false;
});
cm.addItem(move);
}
List<BookmarkNode> folders = GaiaSky.instance.getBookmarksManager().getFolders();
for (BookmarkNode folder : folders) {
if (!target.node.isDescendantOf(folder)) {
MenuItem mv = new MenuItem(I18n.txt("gui.bookmark.context.move", target.getValue(), "/" + folder.path.toString()), skin);
mv.addListener(evt -> {
if (evt instanceof ChangeEvent) {
EventManager.publish(Event.BOOKMARKS_MOVE, mv, target.node, folder);
reloadBookmarksTree();
return true;
}
return false;
});
cm.addItem(mv);
}
}
newMenu(cm);
cm.showMenu(stage, Gdx.input.getX(ie.getPointer()) / Settings.settings.program.ui.scale, stage.getHeight() - Gdx.input.getY(ie.getPointer()) / Settings.settings.program.ui.scale);
});
} else {
// New folder
GaiaSky.postRunnable(() -> {
ContextMenu cm = new ContextMenu(skin, "default");
// New folder...
String parentName = "/";
MenuItem newDirectory = new MenuItem(I18n.txt("gui.bookmark.context.newfolder", parentName), skin);
newDirectory.addListener(evt -> {
if (evt instanceof ChangeEvent) {
NewBookmarkFolderDialog nbfd = new NewBookmarkFolderDialog("/", skin, stage);
nbfd.setAcceptRunnable(() -> {
String folderName = nbfd.input.getText();
EventManager.publish(Event.BOOKMARKS_ADD, newDirectory, folderName, true);
reloadBookmarksTree();
});
nbfd.show(stage);
return true;
}
return false;
});
cm.addItem(newDirectory);
newMenu(cm);
cm.showMenu(stage, Gdx.input.getX(ie.getPointer()), Gdx.graphics.getHeight() - Gdx.input.getY(ie.getPointer()));
});
}
}
event.setBubbles(false);
return true;
}
return false;
});
bookmarksScrollPane = new OwnScrollPane(bookmarksTree, skin, "minimalist-nobg");
bookmarksScrollPane.setName("bookmarks scroll");
bookmarksScrollPane.setFadeScrollBars(false);
bookmarksScrollPane.setScrollingDisabled(true, false);
bookmarksScrollPane.setHeight(160f);
bookmarksScrollPane.setWidth(contentWidth);
/*
* ADD TO CONTENT
*/
VerticalGroup objectsGroup = new VerticalGroup().align(Align.left).columnAlign(Align.left).space(pad12);
objectsGroup.addActor(searchBox);
if (bookmarksScrollPane != null) {
objectsGroup.addActor(bookmarksScrollPane);
}
objectsGroup.addActor(infoTable);
component = objectsGroup;
}
use of gaiasky.scenegraph.IFocus in project gaiasky by langurmonkey.
the class ObjectsComponent method initialize.
@Override
public void initialize() {
float contentWidth = ControlsWindow.getContentWidth();
searchBox = new OwnTextField("", skin);
searchBox.setName("search box");
searchBox.setWidth(contentWidth);
searchBox.setMessageText(I18n.txt("gui.objects.search"));
searchBox.addListener(event -> {
if (event instanceof InputEvent) {
InputEvent ie = (InputEvent) event;
if (ie.getType() == Type.keyUp && !searchBox.getText().isEmpty()) {
String text = searchBox.getText().toLowerCase().trim();
if (sg.containsNode(text)) {
SceneGraphNode node = sg.getNode(text);
if (node instanceof IFocus) {
IFocus focus = (IFocus) node;
boolean timeOverflow = focus.isCoordinatesTimeOverflow();
boolean ctOn = GaiaSky.instance.isOn(focus.getCt());
if (!timeOverflow && ctOn) {
GaiaSky.postRunnable(() -> {
EventManager.publish(Event.CAMERA_MODE_CMD, this, CameraMode.FOCUS_MODE, true);
EventManager.publish(Event.FOCUS_CHANGE_CMD, this, focus, true);
});
} else if (timeOverflow) {
info(I18n.txt("gui.objects.search.timerange.1", text), I18n.txt("gui.objects.search.timerange.2"));
} else {
info(I18n.txt("gui.objects.search.invisible.1", text), I18n.txt("gui.objects.search.invisible.2", focus.getCt().toString()));
}
}
} else {
info(null, null);
}
if (GaiaSky.instance.getICamera() instanceof NaturalCamera)
((NaturalCamera) GaiaSky.instance.getICamera()).getCurrentMouseKbdListener().removePressedKey(ie.getKeyCode());
if (ie.getKeyCode() == Keys.ESCAPE) {
// Lose focus
stage.setKeyboardFocus(null);
}
} else if (ie.getType() == Type.keyDown) {
if (ie.getKeyCode() == Keys.CONTROL_LEFT || ie.getKeyCode() == Keys.CONTROL_RIGHT) {
// Lose focus
stage.setKeyboardFocus(null);
}
}
return true;
}
return false;
});
// Info message
infoTable = new Table(skin);
infoCell1 = infoTable.add();
infoTable.row();
infoCell2 = infoTable.add();
infoMessage1 = new OwnLabel("", skin, "default-blue");
infoMessage2 = new OwnLabel("", skin, "default-blue");
/*
* OBJECTS
*/
final com.badlogic.gdx.scenes.scene2d.ui.List<String> focusList = new com.badlogic.gdx.scenes.scene2d.ui.List<>(skin);
focusList.setName("objects list");
Array<IFocus> focusableObjects = sg.getFocusableObjects();
Array<String> names = new Array<>(false, focusableObjects.size);
for (IFocus focus : focusableObjects) {
// Omit stars with no proper names
if (focus.getName() != null && !GlobalResources.isNumeric(focus.getName())) {
names.add(focus.getName());
}
}
names.sort();
SceneGraphNode sol = sg.getNode("Sun");
if (sol != null) {
Array<IFocus> solChildren = new Array<>();
sol.addFocusableObjects(solChildren);
solChildren.sort(new CelestialBodyComparator());
for (IFocus cb : solChildren) names.insert(0, cb.getName());
}
focusList.setItems(names);
//
focusList.pack();
focusList.addListener(event -> {
if (event instanceof ChangeEvent) {
ChangeEvent ce = (ChangeEvent) event;
Actor actor = ce.getTarget();
@SuppressWarnings("unchecked") final String text = ((com.badlogic.gdx.scenes.scene2d.ui.List<String>) actor).getSelected().toLowerCase().trim();
if (sg.containsNode(text)) {
SceneGraphNode node = sg.getNode(text);
if (node instanceof IFocus) {
IFocus focus = (IFocus) node;
boolean timeOverflow = focus.isCoordinatesTimeOverflow();
boolean ctOn = GaiaSky.instance.isOn(focus.getCt());
if (!timeOverflow && ctOn) {
GaiaSky.postRunnable(() -> {
EventManager.publish(Event.CAMERA_MODE_CMD, this, CameraMode.FOCUS_MODE, true);
EventManager.publish(Event.FOCUS_CHANGE_CMD, this, focus, true);
});
} else if (timeOverflow) {
info(I18n.txt("gui.objects.search.timerange.1", text), I18n.txt("gui.objects.search.timerange.2"));
} else {
info(I18n.txt("gui.objects.search.invisible.1", text), I18n.txt("gui.objects.search.invisible.2", focus.getCt().toString()));
}
}
} else {
info(null, null);
}
return true;
}
return false;
});
objectsList = focusList;
focusListScrollPane = new OwnScrollPane(objectsList, skin, "minimalist-nobg");
focusListScrollPane.setName("objects list scroll");
focusListScrollPane.setFadeScrollBars(false);
focusListScrollPane.setScrollingDisabled(true, false);
focusListScrollPane.setHeight(160f);
focusListScrollPane.setWidth(contentWidth);
/*
* ADD TO CONTENT
*/
VerticalGroup objectsGroup = new VerticalGroup().align(Align.left).columnAlign(Align.left).space(pad12);
objectsGroup.addActor(searchBox);
if (focusListScrollPane != null) {
objectsGroup.addActor(focusListScrollPane);
}
objectsGroup.addActor(infoTable);
component = objectsGroup;
}
use of gaiasky.scenegraph.IFocus in project gaiasky by langurmonkey.
the class KeyframesWindow method clean.
private void clean(boolean cleanKeyframesList, boolean cleanModel) {
// Clean camera
IFocus focus = GaiaSky.instance.getICamera().getFocus();
if (focus instanceof Invisible && focus.getName().startsWith("Keyframe")) {
EventManager.publish(Event.FOCUS_CHANGE_CMD, this, Settings.settings.scene.homeObject);
EventManager.publish(Event.CAMERA_MODE_CMD, this, CameraManager.CameraMode.FREE_MODE);
}
if (cleanKeyframesList)
keyframes.clear();
notice.clearActor();
namesCells.clear();
secondsCells.clear();
keyframesTable.clearChildren();
nameInput.setText("");
secondsInput.setText("1.0");
if (cleanModel)
GaiaSky.postRunnable(() -> keyframesPathObject.clear());
}
Aggregations