Search in sources :

Example 1 with Event

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();
}
Also used : InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) CatalogInfo(gaiasky.util.CatalogInfo) GaiaSky(gaiasky.GaiaSky) CameraMode(gaiasky.scenegraph.camera.CameraManager.CameraMode) IFocus(gaiasky.scenegraph.IFocus) SortedSet(java.util.SortedSet) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Array(com.badlogic.gdx.utils.Array) Task(com.badlogic.gdx.utils.Timer.Task) ParticleGroup(gaiasky.scenegraph.ParticleGroup) Logger(gaiasky.util.Logger) Action(com.badlogic.gdx.scenes.scene2d.Action) TreeSet(java.util.TreeSet) I18n(gaiasky.util.I18n) Vector2(com.badlogic.gdx.math.Vector2) Cell(com.badlogic.gdx.scenes.scene2d.ui.Cell) OwnTextField(gaiasky.util.scene2d.OwnTextField) Stage(com.badlogic.gdx.scenes.scene2d.Stage) NaturalCamera(gaiasky.scenegraph.camera.NaturalCamera) Type(com.badlogic.gdx.scenes.scene2d.InputEvent.Type) Timer(com.badlogic.gdx.utils.Timer) ISceneGraph(gaiasky.scenegraph.ISceneGraph) Event(gaiasky.event.Event) Align(com.badlogic.gdx.utils.Align) Keys(com.badlogic.gdx.Input.Keys) Log(gaiasky.util.Logger.Log) OwnLabel(gaiasky.util.scene2d.OwnLabel) Optional(java.util.Optional) EventManager(gaiasky.event.EventManager) SceneGraphNode(gaiasky.scenegraph.SceneGraphNode) ColorUtils(gaiasky.util.color.ColorUtils) Task(com.badlogic.gdx.utils.Timer.Task) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) OwnTextField(gaiasky.util.scene2d.OwnTextField) NaturalCamera(gaiasky.scenegraph.camera.NaturalCamera) OwnLabel(gaiasky.util.scene2d.OwnLabel) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) Cell(com.badlogic.gdx.scenes.scene2d.ui.Cell)

Example 2 with Event

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) {
                }
            });
        }
    });
}
Also used : HttpRequest(com.badlogic.gdx.Net.HttpRequest) GaiaSky(gaiasky.GaiaSky) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Constants(gaiasky.util.Constants) Logger(gaiasky.util.Logger) HttpStatus(com.badlogic.gdx.net.HttpStatus) Event(gaiasky.event.Event) Gdx(com.badlogic.gdx.Gdx) HttpResponse(com.badlogic.gdx.Net.HttpResponse) gaiasky.scenegraph(gaiasky.scenegraph) Link(gaiasky.util.scene2d.Link) ChangeEvent(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent) I18n(gaiasky.util.I18n) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Cell(com.badlogic.gdx.scenes.scene2d.ui.Cell) OwnTextTooltip(gaiasky.util.scene2d.OwnTextTooltip) Log(gaiasky.util.Logger.Log) OwnTextButton(gaiasky.util.scene2d.OwnTextButton) EventManager(gaiasky.event.EventManager) HttpMethods(com.badlogic.gdx.Net.HttpMethods) LabelStyle(com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle) HttpResponseListener(com.badlogic.gdx.Net.HttpResponseListener) EventListener(com.badlogic.gdx.scenes.scene2d.EventListener) OwnTextButton(gaiasky.util.scene2d.OwnTextButton) OwnTextTooltip(gaiasky.util.scene2d.OwnTextTooltip) ChangeEvent(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent) Link(gaiasky.util.scene2d.Link)

Example 3 with Event

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");
            }
        }
    }
}
Also used : IGui(gaiasky.interafce.IGui) SysUtils(gaiasky.desktop.util.SysUtils) IAttribute(gaiasky.util.filter.attrib.IAttribute) GL20(com.badlogic.gdx.graphics.GL20) IObserver(gaiasky.event.IObserver) CubemapProjections(gaiasky.util.gdx.contrib.postprocess.effects.CubemapProjections) DatasetLoadType(gaiasky.data.group.DatasetOptions.DatasetLoadType) ComponentTypes(gaiasky.render.ComponentTypes) ZoneOffset(java.time.ZoneOffset) Shape(gaiasky.interafce.AddShapeDialog.Shape) Path(java.nio.file.Path) FileDataSource(uk.ac.starlink.util.FileDataSource) AssetManager(com.badlogic.gdx.assets.AssetManager) CatalogInfoSource(gaiasky.util.CatalogInfo.CatalogInfoSource) Coordinates(gaiasky.util.coord.Coordinates) StarClusterLoader(gaiasky.data.cluster.StarClusterLoader) Event(gaiasky.event.Event) AbstractOrbitCoordinates(gaiasky.util.coord.AbstractOrbitCoordinates) Instant(java.time.Instant) TimeFrame(gaiasky.event.EventManager.TimeFrame) InvocationTargetException(java.lang.reflect.InvocationTargetException) DatasetOptions(gaiasky.data.group.DatasetOptions) STILDataProvider(gaiasky.data.group.STILDataProvider) AttributeUCD(gaiasky.util.filter.attrib.AttributeUCD) Keys(com.badlogic.gdx.Input.Keys) EventManager(gaiasky.event.EventManager) GaiaSky(gaiasky.GaiaSky) ChronoField(java.time.temporal.ChronoField) Primitive(gaiasky.interafce.AddShapeDialog.Primitive) CameraMode(gaiasky.scenegraph.camera.CameraManager.CameraMode) java.util(java.util) Array(com.badlogic.gdx.utils.Array) LocalDateTime(java.time.LocalDateTime) DataSource(uk.ac.starlink.util.DataSource) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Gdx(com.badlogic.gdx.Gdx) ScreenshotSettings(gaiasky.util.Settings.ScreenshotSettings) Constructor(java.lang.reflect.Constructor) AtomicReference(java.util.concurrent.atomic.AtomicReference) Texture(com.badlogic.gdx.graphics.Texture) gaiasky.scenegraph(gaiasky.scenegraph) UCD(gaiasky.util.ucd.UCD) NaturalCamera(gaiasky.scenegraph.camera.NaturalCamera) TimeUtils(com.badlogic.gdx.utils.TimeUtils) gaiasky.util.math(gaiasky.util.math) Files(java.nio.file.Files) ComponentType(gaiasky.render.ComponentTypes.ComponentType) gaiasky.util(gaiasky.util) Group(com.badlogic.gdx.scenes.scene2d.Group) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ImageRenderer(gaiasky.screenshot.ImageRenderer) ITimeFrameProvider(gaiasky.util.time.ITimeFrameProvider) Paths(java.nio.file.Paths) Log(gaiasky.util.Logger.Log) ColormapPicker(gaiasky.interafce.ColormapPicker) IParticleRecord(gaiasky.scenegraph.particle.IParticleRecord) ColorUtils(gaiasky.util.color.ColorUtils) IObserver(gaiasky.event.IObserver) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 4 with Event

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);
}
Also used : CameraUtils(gaiasky.util.camera.CameraUtils) ContextMenu(gaiasky.util.scene2d.ContextMenu) GaiaSky(gaiasky.GaiaSky) CameraMode(gaiasky.scenegraph.camera.CameraManager.CameraMode) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) Array(com.badlogic.gdx.utils.Array) Vector3d(gaiasky.util.math.Vector3d) Collection(java.util.Collection) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) Event(gaiasky.event.Event) Gdx(com.badlogic.gdx.Gdx) gaiasky.util(gaiasky.util) Align(com.badlogic.gdx.utils.Align) gaiasky.scenegraph(gaiasky.scenegraph) ChangeEvent(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent) UncertaintiesHandler(gaiasky.data.stars.UncertaintiesHandler) OwnCheckBox(gaiasky.util.scene2d.OwnCheckBox) Vector3(com.badlogic.gdx.math.Vector3) Locale(java.util.Locale) MenuItem(gaiasky.util.scene2d.MenuItem) RelativisticEffectsManager(gaiasky.util.gravwaves.RelativisticEffectsManager) Matrix4(com.badlogic.gdx.math.Matrix4) EventManager(gaiasky.event.EventManager) OwnImage(gaiasky.util.scene2d.OwnImage) ContextMenu(gaiasky.util.scene2d.ContextMenu) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) MenuItem(gaiasky.util.scene2d.MenuItem) Vector3(com.badlogic.gdx.math.Vector3) Matrix4(com.badlogic.gdx.math.Matrix4) Array(com.badlogic.gdx.utils.Array) ChangeEvent(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent) Vector3d(gaiasky.util.math.Vector3d) OwnCheckBox(gaiasky.util.scene2d.OwnCheckBox) OwnImage(gaiasky.util.scene2d.OwnImage)

Example 5 with Event

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;
        });
    }
}
Also used : FileHandle(com.badlogic.gdx.files.FileHandle) GaiaSky(gaiasky.GaiaSky) SysUtils(gaiasky.desktop.util.SysUtils) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Array(com.badlogic.gdx.utils.Array) Drawable(com.badlogic.gdx.scenes.scene2d.utils.Drawable) Gdx(com.badlogic.gdx.Gdx) FileHandleResolver(com.badlogic.gdx.assets.loaders.FileHandleResolver) Texture(com.badlogic.gdx.graphics.Texture) HashSet(java.util.HashSet) SpriteDrawable(com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable) DataDescriptorUtils(gaiasky.util.datadesc.DataDescriptorUtils) DatasetDesc(gaiasky.util.datadesc.DatasetDesc) Input(com.badlogic.gdx.Input) Stage(com.badlogic.gdx.scenes.scene2d.Stage) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport) OwnTextIconButton(gaiasky.util.scene2d.OwnTextIconButton) Path(java.nio.file.Path) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener) Type(com.badlogic.gdx.scenes.scene2d.InputEvent.Type) Graphics(com.badlogic.gdx.Graphics) AssetManager(com.badlogic.gdx.assets.AssetManager) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) Files(java.nio.file.Files) SystemCursor(com.badlogic.gdx.graphics.Cursor.SystemCursor) HorizontalGroup(com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup) Set(java.util.Set) Event(gaiasky.event.Event) gaiasky.util(gaiasky.util) Align(com.badlogic.gdx.utils.Align) DataDescriptor(gaiasky.util.datadesc.DataDescriptor) ChangeEvent(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent) Paths(java.nio.file.Paths) VRStatus(gaiasky.vr.openvr.VRStatus) Log(gaiasky.util.Logger.Log) OwnLabel(gaiasky.util.scene2d.OwnLabel) Sprite(com.badlogic.gdx.graphics.g2d.Sprite) EventManager(gaiasky.event.EventManager) ColorUtils(gaiasky.util.color.ColorUtils) Stage(com.badlogic.gdx.scenes.scene2d.Stage) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent)

Aggregations

GaiaSky (gaiasky.GaiaSky)5 Event (gaiasky.event.Event)5 EventManager (gaiasky.event.EventManager)5 Gdx (com.badlogic.gdx.Gdx)4 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)4 Array (com.badlogic.gdx.utils.Array)4 Log (gaiasky.util.Logger.Log)4 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)3 ChangeEvent (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent)3 Align (com.badlogic.gdx.utils.Align)3 gaiasky.scenegraph (gaiasky.scenegraph)3 CameraMode (gaiasky.scenegraph.camera.CameraManager.CameraMode)3 gaiasky.util (gaiasky.util)3 ColorUtils (gaiasky.util.color.ColorUtils)3 Keys (com.badlogic.gdx.Input.Keys)2 AssetManager (com.badlogic.gdx.assets.AssetManager)2 Texture (com.badlogic.gdx.graphics.Texture)2 Drawable (com.badlogic.gdx.scenes.scene2d.utils.Drawable)2 SysUtils (gaiasky.desktop.util.SysUtils)2 Files (java.nio.file.Files)2