use of gaiasky.util.comp.CelestialBodyComparator 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;
}
Aggregations