Search in sources :

Example 1 with EventManager

use of gaiasky.event.EventManager in project gaiasky by langurmonkey.

the class TimeComponent method initialize.

@Override
public void initialize() {
    float contentWidth = ControlsWindow.getContentWidth();
    KeyBindings kb = KeyBindings.instance;
    // Time
    date = new OwnLabel("date UT", skin);
    date.setName("label date");
    date.setWidth(170f);
    time = new OwnLabel("time UT", skin);
    time.setName("label time");
    time.setWidth(120f);
    dateEdit = new OwnTextIconButton("", skin, "edit");
    dateEdit.addListener(event -> {
        if (event instanceof ChangeEvent) {
            // Left button click
            if (dateDialog == null) {
                dateDialog = new DateDialog(stage, skin);
            }
            dateDialog.updateTime(GaiaSky.instance.time.getTime(), ZoneOffset.UTC);
            dateDialog.display();
        }
        return false;
    });
    dateEdit.addListener(new OwnTextTooltip(I18n.txt("gui.tooltip.dateedit"), skin));
    // Pace
    timeWarpVector = generateTimeWarpVector(warpSteps);
    warp = new OwnSliderPlus(I18n.txt("gui.warp"), -warpSteps, warpSteps, 1, skin, "big-horizontal-arrow");
    warp.setValueLabelTransform((value) -> TextUtils.getFormattedTimeWarp(timeWarpVector[value.intValue() + warpSteps]));
    warp.setValue(getWarpIndex(GaiaSky.instance.time.getWarpFactor()) - warpSteps);
    warp.setWidth(300f);
    warp.addListener((event) -> {
        if (event instanceof ChangeEvent && !warpGuard) {
            int index = (int) warp.getValue();
            double newWarp = timeWarpVector[index + warpSteps];
            EventManager.publish(Event.TIME_WARP_CMD, warp, newWarp);
        }
        return false;
    });
    plus = new OwnImageButton(skin, "plus");
    plus.setName("plus");
    plus.addListener(event -> {
        if (event instanceof ChangeEvent) {
            // Plus pressed
            EventManager.publish(Event.TIME_WARP_INCREASE_CMD, plus);
            return true;
        }
        return false;
    });
    plus.addListener(new OwnTextHotkeyTooltip(I18n.txt("gui.tooltip.timewarpplus"), kb.getStringKeys("action.doubletime"), skin));
    minus = new OwnImageButton(skin, "minus");
    minus.setName("minus");
    minus.addListener(event -> {
        if (event instanceof ChangeEvent) {
            // Minus pressed
            EventManager.publish(Event.TIME_WARP_DECREASE_CMD, minus);
            return true;
        }
        return false;
    });
    minus.addListener(new OwnTextHotkeyTooltip(I18n.txt("gui.tooltip.timewarpminus"), kb.getStringKeys("action.dividetime"), skin));
    /* Reset time */
    OwnTextIconButton resetTime = new OwnTextIconButton(I18n.txt("gui.resettime"), skin, "reset");
    resetTime.align(Align.center);
    resetTime.setWidth(contentWidth);
    resetTime.addListener(new OwnTextTooltip(I18n.txt("gui.resettime.tooltip"), skin));
    resetTime.addListener(event -> {
        if (event instanceof ChangeEvent) {
            // Events
            EventManager m = EventManager.instance;
            m.post(Event.TIME_CHANGE_CMD, resetTime, Instant.now());
            m.post(Event.TIME_WARP_CMD, resetTime, 1d);
            return true;
        }
        return false;
    });
    Table timeGroup = new Table(skin);
    // Date time
    Table dateGroup = new Table(skin);
    Table datetimeGroup = new Table(skin);
    datetimeGroup.add(date).left().padBottom(pad4).padRight(pad12);
    datetimeGroup.add(time).left().padBottom(pad4);
    dateGroup.add(datetimeGroup).left().padRight(pad12);
    dateGroup.add(dateEdit).right();
    // Pace
    Table paceGroup = new Table(skin);
    paceGroup.add(minus).left().padRight(pad1);
    paceGroup.add(warp).left().padRight(pad1);
    paceGroup.add(plus).left();
    // Add to table
    timeGroup.add(dateGroup).left().padBottom(pad12).row();
    timeGroup.add(paceGroup).left().padBottom(pad12).row();
    timeGroup.add(resetTime).center();
    timeGroup.pack();
    component = timeGroup;
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) EventManager(gaiasky.event.EventManager) ChangeEvent(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent) KeyBindings(gaiasky.interafce.KeyBindings) DateDialog(gaiasky.interafce.DateDialog)

Example 2 with EventManager

use of gaiasky.event.EventManager in project gaiasky by langurmonkey.

the class VisualEffectsComponent method initialize.

@SuppressWarnings("unchecked")
public void initialize() {
    float contentWidth = ControlsWindow.getContentWidth();
    /* Star brightness */
    starBrightness = new OwnSliderPlus(I18n.txt("gui.starbrightness"), Constants.MIN_SLIDER, Constants.MAX_SLIDER, Constants.SLIDER_STEP_TINY, Constants.MIN_STAR_BRIGHTNESS, Constants.MAX_STAR_BRIGHTNESS, skin);
    starBrightness.setName("star brightness");
    starBrightness.setWidth(contentWidth);
    starBrightness.setMappedValue(Settings.settings.scene.star.brightness);
    starBrightness.addListener(event -> {
        if (event instanceof ChangeEvent && hackProgrammaticChangeEvents) {
            EventManager.publish(Event.STAR_BRIGHTNESS_CMD, starBrightness, starBrightness.getMappedValue());
            return true;
        }
        return false;
    });
    /* Star brightness power */
    starBrightnessPower = new OwnSliderPlus(I18n.txt("gui.starbrightness.pow"), Constants.MIN_STAR_BRIGHTNESS_POW, Constants.MAX_STAR_BRIGHTNESS_POW, Constants.SLIDER_STEP_TINY, skin);
    starBrightnessPower.setName("star brightness power");
    starBrightnessPower.setWidth(contentWidth);
    starBrightnessPower.setMappedValue(Settings.settings.scene.star.power);
    starBrightnessPower.addListener(event -> {
        if (event instanceof ChangeEvent && hackProgrammaticChangeEvents) {
            EventManager.publish(Event.STAR_BRIGHTNESS_POW_CMD, starBrightnessPower, starBrightnessPower.getValue());
            return true;
        }
        return false;
    });
    /* Star size */
    starSize = new OwnSliderPlus(I18n.txt("gui.star.size"), Constants.MIN_STAR_POINT_SIZE, Constants.MAX_STAR_POINT_SIZE, Constants.SLIDER_STEP_TINY, skin);
    starSize.setName("star size");
    starSize.setWidth(contentWidth);
    starSize.setMappedValue(Settings.settings.scene.star.pointSize);
    starSize.addListener(event -> {
        if (flag && event instanceof ChangeEvent) {
            EventManager.publish(Event.STAR_POINT_SIZE_CMD, starSize, starSize.getMappedValue());
            return true;
        }
        return false;
    });
    /* Star min opacity */
    starMinOpacity = new OwnSliderPlus(I18n.txt("gui.star.opacity"), Constants.MIN_STAR_MIN_OPACITY, Constants.MAX_STAR_MIN_OPACITY, Constants.SLIDER_STEP_TINY, skin);
    starMinOpacity.setName("star min opacity");
    starMinOpacity.setWidth(contentWidth);
    starMinOpacity.setMappedValue(Settings.settings.scene.star.opacity[0]);
    starMinOpacity.addListener(event -> {
        if (event instanceof ChangeEvent && hackProgrammaticChangeEvents) {
            EventManager.publish(Event.STAR_MIN_OPACITY_CMD, starMinOpacity, starMinOpacity.getMappedValue());
            return true;
        }
        return false;
    });
    /* Ambient light */
    ambientLight = new OwnSliderPlus(I18n.txt("gui.light.ambient"), Constants.MIN_AMBIENT_LIGHT, Constants.MAX_AMBIENT_LIGHT, Constants.SLIDER_STEP_TINY, skin);
    ambientLight.setName("ambient light");
    ambientLight.setWidth(contentWidth);
    ambientLight.setMappedValue(Settings.settings.scene.renderer.ambient);
    ambientLight.addListener(event -> {
        if (event instanceof ChangeEvent) {
            EventManager.publish(Event.AMBIENT_LIGHT_CMD, ambientLight, ambientLight.getMappedValue());
            return true;
        }
        return false;
    });
    /* Label size */
    labelSize = new OwnSliderPlus(I18n.txt("gui.label.size"), Constants.MIN_LABEL_SIZE, Constants.MAX_LABEL_SIZE, Constants.SLIDER_STEP_TINY, skin);
    labelSize.setName("label size");
    labelSize.setWidth(contentWidth);
    labelSize.setMappedValue(Settings.settings.scene.label.size);
    labelSize.addListener(event -> {
        if (event instanceof ChangeEvent && hackProgrammaticChangeEvents) {
            float val = labelSize.getMappedValue();
            EventManager.publish(Event.LABEL_SIZE_CMD, labelSize, val);
            return true;
        }
        return false;
    });
    /* Line width */
    lineWidth = new OwnSliderPlus(I18n.txt("gui.line.width"), Constants.MIN_LINE_WIDTH, Constants.MAX_LINE_WIDTH, Constants.SLIDER_STEP_TINY, Constants.MIN_LINE_WIDTH, Constants.MAX_LINE_WIDTH, skin);
    lineWidth.setName("line width");
    lineWidth.setWidth(contentWidth);
    lineWidth.setMappedValue(Settings.settings.scene.lineWidth);
    lineWidth.addListener(event -> {
        if (event instanceof ChangeEvent && hackProgrammaticChangeEvents) {
            float val = lineWidth.getMappedValue();
            EventManager.publish(Event.LINE_WIDTH_CMD, lineWidth, val);
            return true;
        }
        return false;
    });
    /* Elevation multiplier */
    elevMult = new OwnSliderPlus(I18n.txt("gui.elevation.multiplier"), Constants.MIN_ELEVATION_MULT, Constants.MAX_ELEVATION_MULT, 0.1f, false, skin);
    elevMult.setName("elevation mult");
    elevMult.setWidth(contentWidth);
    elevMult.setValue((float) MathUtilsd.roundAvoid(Settings.settings.scene.renderer.elevation.multiplier, 1));
    elevMult.addListener(event -> {
        if (event instanceof ChangeEvent) {
            float val = elevMult.getValue();
            EventManager.publish(Event.ELEVATION_MULTIPLIER_CMD, elevMult, val);
            return true;
        }
        return false;
    });
    /* Reset defaults */
    OwnTextIconButton resetDefaults = new OwnTextIconButton(I18n.txt("gui.resetdefaults"), skin, "reset");
    resetDefaults.align(Align.center);
    resetDefaults.setWidth(contentWidth);
    resetDefaults.addListener(new OwnTextTooltip(I18n.txt("gui.resetdefaults.tooltip"), skin));
    resetDefaults.addListener(event -> {
        if (event instanceof ChangeEvent) {
            // Read defaults from internal settings file
            try {
                Path confFolder = Settings.settings.assetsPath("conf");
                Path internalFolderConfFile = confFolder.resolve(SettingsManager.getConfigFileName(Settings.settings.runtime.openVr));
                Yaml yaml = new Yaml();
                Map<Object, Object> conf = yaml.load(Files.newInputStream(internalFolderConfFile));
                float br = ((Double) ((Map<String, Object>) ((Map<String, Object>) conf.get("scene")).get("star")).get("brightness")).floatValue();
                float pow = ((Double) ((Map<String, Object>) ((Map<String, Object>) conf.get("scene")).get("star")).get("power")).floatValue();
                float ss = ((Double) ((Map<String, Object>) ((Map<String, Object>) conf.get("scene")).get("star")).get("pointSize")).floatValue();
                float pam = (((java.util.List<Double>) ((Map<String, Object>) ((Map<String, Object>) conf.get("scene")).get("star")).get("opacity")).get(0)).floatValue();
                float amb = ((Double) ((Map<String, Object>) ((Map<String, Object>) conf.get("scene")).get("renderer")).get("ambient")).floatValue();
                float ls = ((Double) ((Map<String, Object>) ((Map<String, Object>) conf.get("scene")).get("label")).get("size")).floatValue();
                float lw = ((Double) ((Map<String, Object>) conf.get("scene")).get("lineWidth")).floatValue();
                float em = ((Double) ((Map<String, Object>) ((Map<String, Object>) ((Map<Object, Object>) conf.get("scene")).get("renderer")).get("elevation")).get("multiplier")).floatValue();
                // Events
                EventManager m = EventManager.instance;
                m.post(Event.STAR_BRIGHTNESS_CMD, resetDefaults, br);
                m.post(Event.STAR_BRIGHTNESS_POW_CMD, resetDefaults, pow);
                m.post(Event.STAR_POINT_SIZE_CMD, resetDefaults, ss);
                m.post(Event.STAR_MIN_OPACITY_CMD, resetDefaults, pam);
                m.post(Event.AMBIENT_LIGHT_CMD, resetDefaults, amb);
                m.post(Event.LABEL_SIZE_CMD, resetDefaults, ls);
                m.post(Event.LINE_WIDTH_CMD, resetDefaults, lw);
                m.post(Event.ELEVATION_MULTIPLIER_CMD, resetDefaults, em);
            } catch (IOException e) {
                logger.error(e, "Error loading default configuration file");
            }
            return true;
        }
        return false;
    });
    /* Add to group */
    VerticalGroup lightingGroup = new VerticalGroup().align(Align.left).columnAlign(Align.left);
    lightingGroup.space(pad9);
    lightingGroup.addActor(starBrightness);
    lightingGroup.addActor(starBrightnessPower);
    lightingGroup.addActor(starSize);
    lightingGroup.addActor(starMinOpacity);
    lightingGroup.addActor(ambientLight);
    lightingGroup.addActor(lineWidth);
    lightingGroup.addActor(labelSize);
    lightingGroup.addActor(elevMult);
    lightingGroup.addActor(resetDefaults);
    component = lightingGroup;
    EventManager.instance.subscribe(this, Event.STAR_POINT_SIZE_CMD, Event.STAR_BRIGHTNESS_CMD, Event.STAR_BRIGHTNESS_POW_CMD, Event.STAR_MIN_OPACITY_CMD, Event.LABEL_SIZE_CMD, Event.LINE_WIDTH_CMD);
}
Also used : OwnTextIconButton(gaiasky.util.scene2d.OwnTextIconButton) Path(java.nio.file.Path) OwnTextTooltip(gaiasky.util.scene2d.OwnTextTooltip) EventManager(gaiasky.event.EventManager) OwnSliderPlus(gaiasky.util.scene2d.OwnSliderPlus) IOException(java.io.IOException) VerticalGroup(com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup) Yaml(org.yaml.snakeyaml.Yaml) ChangeEvent(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent) Map(java.util.Map)

Aggregations

ChangeEvent (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent)2 EventManager (gaiasky.event.EventManager)2 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)1 VerticalGroup (com.badlogic.gdx.scenes.scene2d.ui.VerticalGroup)1 DateDialog (gaiasky.interafce.DateDialog)1 KeyBindings (gaiasky.interafce.KeyBindings)1 OwnSliderPlus (gaiasky.util.scene2d.OwnSliderPlus)1 OwnTextIconButton (gaiasky.util.scene2d.OwnTextIconButton)1 OwnTextTooltip (gaiasky.util.scene2d.OwnTextTooltip)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Map (java.util.Map)1 Yaml (org.yaml.snakeyaml.Yaml)1