Search in sources :

Example 1 with KeyBindings

use of gaiasky.interafce.KeyBindings 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)

Aggregations

Table (com.badlogic.gdx.scenes.scene2d.ui.Table)1 ChangeEvent (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent)1 EventManager (gaiasky.event.EventManager)1 DateDialog (gaiasky.interafce.DateDialog)1 KeyBindings (gaiasky.interafce.KeyBindings)1