예제 #1
0
  /** Initializes the Graphics */
  public Graphics(
      FBCore fbCore,
      String userToken,
      String userEmail,
      String nickName,
      String playerRating,
      String playerRD) {
    initWidget(uiBinder.createAndBindUi(this));

    treasureGridN = new Grid(1, 1);
    treasureGridN.setHeight(TREASURE_CHEST_HEIGHT + PADDING * 2 + "px");
    treasureGridN.setCellPadding(PADDING);

    treasureGridS = new Grid(1, 1);
    treasureGridS.setHeight(TREASURE_CHEST_HEIGHT + PADDING * 2 + "px");
    treasureGridS.setCellPadding(PADDING);

    AbsolutePanel treasurePanelN = new AbsolutePanel();
    treasurePanelN.setSize(TREASURE_CHEST_WIDTH + "px", TREASURE_CHEST_HEIGHT + "px");
    treasureGridN.setWidget(0, 0, treasurePanelN);

    AbsolutePanel treasurePanelS = new AbsolutePanel();
    treasurePanelS.setSize(TREASURE_CHEST_WIDTH + "px", TREASURE_CHEST_HEIGHT + "px");
    treasureGridS.setWidget(0, 0, treasurePanelS);

    gameGrid = new Grid(2, 6);
    gameGrid.resize(2, 6);
    for (int row = 0; row < 2; row++) {
      for (int col = 0; col < 6; col++) {
        AbsolutePanel pitPanel = new AbsolutePanel();
        pitPanel.setSize(PIT_WIDTH + "px", PIT_HEIGHT + "px");

        addSeeds(pitPanel, 0);

        if (row == 0) {
          handlerRegs[row][col] =
              pitPanel.addDomHandler(
                  new ClickHandler() {
                    @Override
                    public void onClick(ClickEvent event) {
                      // presenter.makeMove(colB);
                    }
                  },
                  ClickEvent.getType());

          gameGrid.setWidget(row, 5 - col, pitPanel);
          // setPitEnabled(PlayerColor.NORTH, col, false);
        } else {
          handlerRegs[row][col] =
              pitPanel.addDomHandler(
                  new ClickHandler() {
                    @Override
                    public void onClick(ClickEvent event) {
                      // presenter.makeMove(colB);
                    }
                  },
                  ClickEvent.getType());

          gameGrid.setWidget(row, col, pitPanel);
          // setPitEnabled(PlayerColor.SOUTH, col, true);
        }
      }
    }

    gameGrid.setCellPadding(20);

    gameAbsolutePanel.add(treasureGridN);
    gameAbsolutePanel.add(gameGrid, TREASURE_CHEST_WIDTH + 2 * PADDING, 0);
    gameAbsolutePanel.add(
        treasureGridS, TREASURE_CHEST_WIDTH + 14 * PADDING + PIT_WIDTH * 6 + 6 * 2, 0);
    gameAbsolutePanel.setSize(
        12 + TREASURE_CHEST_WIDTH * 2 + 16 * PADDING + PIT_WIDTH * 6 + "px",
        4 + 4 * PADDING + 2 * PIT_HEIGHT + "px");
    gameAbsolutePanel.getElement().getStyle().setProperty("margin", "auto");

    DOM.setStyleAttribute(gameAbsolutePanel.getElement(), "backgroundColor", "#b0c4de");
    Image bgImg = new Image();
    bgImg.setResource(gameImages.board());

    DOM.setStyleAttribute(
        gameAbsolutePanel.getElement(), "backgroundImage", "url(" + bgImg.getUrl() + ")");

    // Create a CellList.
    ContactCell contactCell = new ContactCell();

    // Set a key provider that provides a unique key for each contact. If key is used to identify
    // contacts when fields (such as
    // the name and address) change.
    cellList = new CellList<ContactInfo>(contactCell, ContactInfo.KEY_PROVIDER);

    cellList.setPageSize(30);
    cellList.setKeyboardPagingPolicy(KeyboardPagingPolicy.INCREASE_RANGE);
    cellList.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.BOUND_TO_SELECTION);

    // Add a selection model so we can select cells.
    final SingleSelectionModel<ContactInfo> selectionModel =
        new SingleSelectionModel<ContactInfo>(ContactInfo.KEY_PROVIDER);
    cellList.setSelectionModel(selectionModel);
    selectionModel.addSelectionChangeHandler(
        new SelectionChangeEvent.Handler() {
          public void onSelectionChange(SelectionChangeEvent event) {
            showPlayGameElements(selectionModel.getSelectedObject());
          }
        });

    // Set the cellList as the display of the pagers. This example has two pagers. pagerPanel is a
    // scrollable pager that extends
    // the range when the user scrolls to the bottom. rangeLabelPager is a pager that displays the
    // current range, but does not
    // have any controls to change the range.
    contactsPanel.setDisplay(cellList);
    // rangeLabelPager.setDisplay(cellList);

    presenter = new Presenter(this, fbCore, userEmail.toLowerCase(), userToken);

    turnLabel.setHorizontalAlignment(Label.ALIGN_CENTER);
    warnLabel.setHorizontalAlignment(Label.ALIGN_CENTER);
    aiMovesLabel.setHorizontalAlignment(Label.ALIGN_CENTER);
    hideStartGameElements();

    initializeAudios();
    initializeHandlers();

    // presenter.setState(Presenter.deserializeState(stateStr));

    setUserNameLabelText("Name: " + nickName + " (" + playerRating + "|" + playerRD + ")");
    initializeUILanguage();
  }