use of gaiasky.util.scene2d.OwnCheckBox 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.util.scene2d.OwnCheckBox in project gaiasky by langurmonkey.
the class LandAtWindow method build.
@Override
protected void build() {
latlonCb = new OwnCheckBox(I18n.txt("context.lonlat"), skin, "radio", pad10);
latlonCb.setChecked(false);
latlonCb.addListener(new EventListener() {
@Override
public boolean handle(com.badlogic.gdx.scenes.scene2d.Event event) {
if (event instanceof ChangeEvent) {
if (latlonCb.isChecked()) {
enableComponents(false, location);
enableComponents(true, longitude, latitude);
stage.setKeyboardFocus(longitude);
}
return true;
}
return false;
}
});
longitude = new OwnTextField("", skin, new FloatValidator(0, 360));
latitude = new OwnTextField("", skin, new FloatValidator(-90, 90));
locationCb = new OwnCheckBox(I18n.txt("context.location"), skin, "radio", pad10);
locationCb.setChecked(true);
locationCb.addListener(new EventListener() {
@Override
public boolean handle(com.badlogic.gdx.scenes.scene2d.Event event) {
if (event instanceof ChangeEvent) {
if (locationCb.isChecked()) {
enableComponents(true, location);
enableComponents(false, longitude, latitude);
stage.setKeyboardFocus(location);
}
return true;
}
return false;
}
});
location = new OwnTextField("", skin, new ExistingLocationValidator(target));
new ButtonGroup<CheckBox>(latlonCb, locationCb);
content.add(locationCb).left().top().padBottom(pad10).colspan(4).row();
content.add(new OwnLabel(I18n.txt("context.location"), skin)).left().top().padRight(pad10);
content.add(location).left().top().padBottom(pad10 * 2).row();
content.add(latlonCb).left().top().padBottom(pad10).colspan(4).row();
content.add(new OwnLabel(I18n.txt("context.longitude"), skin)).left().top().padRight(pad10);
content.add(longitude).left().top().padRight(pad10 * 2);
content.add(new OwnLabel(I18n.txt("context.latitude"), skin)).left().top().padRight(pad10);
content.add(latitude).left().top();
}
use of gaiasky.util.scene2d.OwnCheckBox in project gaiasky by langurmonkey.
the class AddShapeDialog method build.
@Override
protected void build() {
content.clear();
OwnLabel info = new OwnLabel(I18n.txt("gui.shape.info", object.getName()), skin, "hud-subheader");
content.add(info).left().padBottom(pad15).row();
// Name
addName(content, "1 AU from " + objectName);
// Size
FloatValidator val = new FloatValidator(0f, Float.MAX_VALUE);
size = new OwnTextField("1.0", skin, val);
size.setWidth(fieldWidth * 0.6f);
size.addListener((event) -> {
if (event instanceof ChangeEvent) {
recomputeObjectName();
}
return true;
});
units = new OwnSelectBox<>(skin);
units.setWidth(fieldWidth * 0.3f);
units.setItems(Units.values());
units.setSelected(Units.AU);
units.addListener((event) -> {
if (event instanceof ChangeEvent) {
recomputeObjectName();
}
return true;
});
HorizontalGroup sizeGroup = new HorizontalGroup();
sizeGroup.space(15f);
sizeGroup.addActor(size);
sizeGroup.addActor(units);
content.add(new OwnLabel(I18n.txt("gui.shape.size"), skin, titleWidth)).left().padRight(pad10).padBottom(pad10);
content.add(sizeGroup).left().padBottom(pad10).row();
// Show label
showLabel = new OwnCheckBox(I18n.txt("gui.shape.label"), skin, pad5);
showLabel.setChecked(true);
content.add(showLabel).left().colspan(2).padRight(pad10).padBottom(pad10).row();
// Track
track = new OwnCheckBox(I18n.txt("gui.shape.track"), skin, pad5);
track.setChecked(true);
content.add(track).left().colspan(2).padRight(pad10).padBottom(pad5);
// Separator
addSeparator(2);
// Shape
shape = new OwnSelectBox<>(skin);
shape.setWidth(fieldWidth);
shape.setItems(Shape.values());
shape.setSelected(Shape.SPHERE);
content.add(new OwnLabel(I18n.txt("gui.shape.shape"), skin, titleWidth)).left().padRight(pad10).padBottom(pad10);
content.add(shape).left().padBottom(pad10).row();
// Color
addColor(content);
// Primitive
primitive = new OwnSelectBox<>(skin);
primitive.setWidth(fieldWidth);
primitive.setItems(Primitive.values());
primitive.setSelected(Primitive.LINES);
content.add(new OwnLabel(I18n.txt("gui.shape.primitive"), skin, titleWidth)).left().padRight(pad10).padBottom(pad10);
content.add(primitive).left().padBottom(pad10).row();
}
use of gaiasky.util.scene2d.OwnCheckBox in project gaiasky by langurmonkey.
the class QuitWindow method build.
@Override
protected void build() {
content.clear();
content.add(new OwnLabel(I18n.txt("gui.quit.sure"), skin)).left().padBottom(pad10 * 2f).row();
doNotAsk = new OwnCheckBox(I18n.txt("gui.donotask"), skin, pad5);
doNotAsk.setChecked(false);
bottom.add(doNotAsk).right().row();
}
Aggregations