Search in sources :

Example 1 with PositionChangedEvent

use of com.playshogi.website.gwt.client.events.gametree.PositionChangedEvent in project playshogi by Tellmarch.

the class PositionEditingPanel method createPresetsList.

private ListBox createPresetsList() {
    final ListBox presets;
    presets = new ListBox();
    presets.addItem("Template", "");
    presets.addItem("----------------", "");
    presets.addItem("Empty board (One King)", "ONE_KING");
    presets.addItem("Empty board (Two Kings)", "TWO_KINGS");
    presets.addItem("----------------", "");
    presets.addItem("Initial position: even game", Handicap.EVEN.name());
    presets.addItem("Handicap: " + messages.handicapLance(), Handicap.LANCE.name());
    presets.addItem("Handicap: " + messages.handicapBishop(), Handicap.BISHOP.name());
    presets.addItem("Handicap: " + messages.handicapRook(), Handicap.ROOK.name());
    presets.addItem("Handicap: " + messages.handicapRookLance(), Handicap.ROOK_LANCE.name());
    presets.addItem("Handicap: " + messages.handicapTwoPieces(), Handicap.TWO_PIECES.name());
    presets.addItem("Handicap: " + messages.handicapFourPieces(), Handicap.FOUR_PIECES.name());
    presets.addItem("Handicap: " + messages.handicapSixPieces(), Handicap.SIX_PIECES.name());
    presets.addItem("Handicap: " + messages.handicapEightPieces(), Handicap.EIGHT_PIECES.name());
    presets.addItem("Handicap: " + messages.handicapNinePieces(), Handicap.NINE_PIECES.name());
    presets.addItem("Handicap: " + messages.handicapTenPieces(), Handicap.TEN_PIECES.name());
    presets.addItem("Handicap: " + messages.handicapThreePawns(), Handicap.THREE_PAWNS.name());
    presets.addItem("Handicap: " + messages.handicapNakedKing(), Handicap.NAKED_KING.name());
    presets.setVisibleItemCount(1);
    presets.addChangeHandler(changeEvent -> {
        String value = presets.getSelectedValue();
        GWT.log(value);
        if ("ONE_KING".equals(value)) {
            eventBus.fireEvent(new PositionChangedEvent(ShogiInitialPositionFactory.createEmptyTsumePosition(false), true));
        } else if ("TWO_KINGS".equals(value)) {
            eventBus.fireEvent(new PositionChangedEvent(ShogiInitialPositionFactory.createEmptyTsumePosition(true), true));
        } else if (!value.isEmpty()) {
            eventBus.fireEvent(new PositionChangedEvent(ShogiInitialPositionFactory.createInitialPosition(Handicap.valueOf(value)), true));
        }
    });
    return presets;
}
Also used : PositionChangedEvent(com.playshogi.website.gwt.client.events.gametree.PositionChangedEvent) ListBox(com.google.gwt.user.client.ui.ListBox)

Example 2 with PositionChangedEvent

use of com.playshogi.website.gwt.client.events.gametree.PositionChangedEvent in project playshogi by Tellmarch.

the class ImportPositionPanel method importPositionFromText.

private void importPositionFromText() {
    GWT.log("Importing position...");
    ShogiPosition position = null;
    if (sfenButton.getValue()) {
        GWT.log("Will parse as SFEN position");
        position = SfenConverter.fromSFEN(textArea.getText());
    } else if (kifButton.getValue()) {
        GWT.log("Will parse as KIF position");
        position = KifFormat.INSTANCE.readPosition(textArea.getText());
    } else if (ussButton.getValue()) {
        GWT.log("Will parse as USS position");
        position = UssConverter.fromUSS(textArea.getText());
    }
    if (position != null) {
        GWT.log("Firing position changed event...");
        eventBus.fireEvent(new PositionChangedEvent(position, true));
    }
    dialogBox.hide();
}
Also used : PositionChangedEvent(com.playshogi.website.gwt.client.events.gametree.PositionChangedEvent) ShogiPosition(com.playshogi.library.shogi.models.position.ShogiPosition)

Example 3 with PositionChangedEvent

use of com.playshogi.website.gwt.client.events.gametree.PositionChangedEvent in project playshogi by Tellmarch.

the class OpeningsActivity method start.

@Override
public void start(final AcceptsOneWidget containerWidget, final EventBus eventBus) {
    this.eventBus = eventBus;
    GWT.log("Starting openings activity");
    eventBinder.bindEventHandlers(this, eventBus);
    final ShogiPosition position = SfenConverter.fromSFEN(sfen);
    openingsView.activate(position, eventBus);
    containerWidget.setWidget(openingsView.asWidget());
    kifuService.getPositionDetails(SfenConverter.toSFEN(position), gameSetId, new AsyncCallback<PositionDetails>() {

        @Override
        public void onSuccess(final PositionDetails result) {
            GWT.log("OPENINGS - GOT POSITION DETAILS " + result);
            eventBus.fireEvent(new PositionStatisticsEvent(result, position, gameSetId));
        }

        @Override
        public void onFailure(final Throwable caught) {
            GWT.log("OPENINGS - ERROR GETTING POSITION STATS");
        }
    });
    Scheduler.get().scheduleDeferred(() -> eventBus.fireEvent(new PositionChangedEvent(position, false)));
}
Also used : PositionChangedEvent(com.playshogi.website.gwt.client.events.gametree.PositionChangedEvent) PositionStatisticsEvent(com.playshogi.website.gwt.client.events.kifu.PositionStatisticsEvent) PositionDetails(com.playshogi.website.gwt.shared.models.PositionDetails) ShogiPosition(com.playshogi.library.shogi.models.position.ShogiPosition)

Example 4 with PositionChangedEvent

use of com.playshogi.website.gwt.client.events.gametree.PositionChangedEvent in project playshogi by Tellmarch.

the class KifuEditorView method onSwitchPlayerToPlay.

@EventHandler
public void onSwitchPlayerToPlay(final SwitchPlayerToPlayEvent event) {
    GWT.log("Problem editor: handle SwitchPlayerToPlayEvent");
    shogiBoard.getPosition().setPlayerToMove(shogiBoard.getPosition().getPlayerToMove().opposite());
    eventBus.fireEvent(new PositionChangedEvent(shogiBoard.getPosition(), true));
}
Also used : PositionChangedEvent(com.playshogi.website.gwt.client.events.gametree.PositionChangedEvent) EventHandler(com.google.web.bindery.event.shared.binder.EventHandler)

Example 5 with PositionChangedEvent

use of com.playshogi.website.gwt.client.events.gametree.PositionChangedEvent in project playshogi by Tellmarch.

the class KifuEditorView method resetForNewProblem.

private void resetForNewProblem() {
    Scheduler.get().scheduleDeferred(() -> {
        loadGameRecord(new GameRecord());
        kifuEditorLeftBarPanel.resetToProblemMode();
        eventBus.fireEvent(new PositionChangedEvent(ShogiInitialPositionFactory.createEmptyTsumePosition(false), true));
    });
}
Also used : PositionChangedEvent(com.playshogi.website.gwt.client.events.gametree.PositionChangedEvent)

Aggregations

PositionChangedEvent (com.playshogi.website.gwt.client.events.gametree.PositionChangedEvent)5 ShogiPosition (com.playshogi.library.shogi.models.position.ShogiPosition)2 ListBox (com.google.gwt.user.client.ui.ListBox)1 EventHandler (com.google.web.bindery.event.shared.binder.EventHandler)1 PositionStatisticsEvent (com.playshogi.website.gwt.client.events.kifu.PositionStatisticsEvent)1 PositionDetails (com.playshogi.website.gwt.shared.models.PositionDetails)1