public RobonoboFrame(RobonoboController control, String[] args) {
    this.control = control;
    this.cmdLineArgs = args;

    setTitle("robonobo");
    setIconImage(GUIUtils.getImage("/icon/robonobo-64x64.png"));
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    addWindowListener(new CloseListener());

    menuBar = Platform.getPlatform().getMenuBar(this);
    setJMenuBar(menuBar);

    JPanel contentPane = new JPanel();
    double[][] cellSizen = {{5, 200, 5, TableLayout.FILL, 5}, {3, TableLayout.FILL, 5}};
    contentPane.setLayout(new TableLayout(cellSizen));
    setContentPane(contentPane);
    leftSidebar = new LeftSidebar(this);
    contentPane.add(leftSidebar, "1,1");
    mainPanel = new MainPanel(this);
    contentPane.add(mainPanel, "3,1");
    setPreferredSize(new Dimension(1024, 723));
    pack();
    leftSidebar.selectMyMusic();
    guiConfig = (GuiConfig) control.getConfig("gui");
    addListeners();
  }
Esempio n. 2
0
  public WorldPanel(LD33Client client, int worldWidth, int worldHeight) {
    this.client = client;
    world = new World(worldWidth, worldHeight);
    cameraX = 0;
    cameraY = 0;
    addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent event) {
            if (isRightMouseButton(event)) {
              client.sendPacket(
                  new UnitMoveServerBoundPacket(
                      getSelectedUnit(),
                      (cameraX + event.getX()) / 64,
                      (cameraY + event.getY()) / 64));
              Tile tile =
                  getWorld()
                      .getTileAt((cameraX + event.getX()) / 64, (cameraY + event.getY()) / 64);
              if (tile != null) {
                if (tile.getUnit() != null) {
                  if (!tile.getUnit()
                      .getPlayerUUID()
                      .toString()
                      .equals(client.getPlayer().getUUID().toString())) {
                    new Thread(
                            () ->
                                client
                                    .getSoundPlayer()
                                    .play(getClass().getResourceAsStream("/burn.ogg")))
                        .start();
                  }
                }
              }
            } else if (isLeftMouseButton(event)) {
              ShopItem selectedShopItem = client.getShopPanel().getSelectedItem();
              if (selectedShopItem != null) {
                selectedShopItem.buy(
                    getWorld()
                        .getTileAt((cameraX + event.getX()) / 64, (cameraY + event.getY()) / 64));
                client.getShopPanel().setSelectedItem(null);
                client.getShopPanel().repaint();
              }
            }
          }

          @Override
          public void mousePressed(MouseEvent event) {
            mousePoint = event.getPoint();
          }
        });
    addMouseMotionListener(
        new MouseMotionAdapter() {
          @Override
          public void mouseDragged(MouseEvent event) {
            if (isMiddleMouseButton(event)) {
              int dx = event.getX() - (int) mousePoint.getX();
              int dy = event.getY() - (int) mousePoint.getY();
              cameraX -= dx;
              cameraY -= dy;
              mousePoint = event.getPoint();
            }
          }

          @Override
          public void mouseMoved(MouseEvent event) {
            Tile tile =
                getWorld().getTileAt((cameraX + event.getX()) / 64, (cameraY + event.getY()) / 64);
            if (tile != null) {
              Unit unit = tile.getUnit();
              if (unit != null) {
                try {
                  Player player = unit.getPlayer();
                  if (player != null) {
                    setToolTipText(
                        "Owner: "
                            + player.getName()
                            + " "
                            + "Health: "
                            + unit.getHealth()
                            + "/"
                            + unit.getMaxHealth()
                            + " "
                            + "Tile: "
                            + tile.getX()
                            + ", "
                            + tile.getY()
                            + (unit.getTimeToComplete() > 0
                                ? " Seconds till completion: " + (unit.getTimeToComplete() / 1000)
                                : ""));
                  } else {
                    setToolTipText("Could not retrieve player information for this unit.");
                  }
                } catch (SQLException exception) {
                  client.getLogger().log(SEVERE, "Failed to get player for unit", exception);
                }
              } else {
                setToolTipText(null);
              }
            } else {
              setToolTipText(null);
            }
          }
        });
    setDoubleBuffered(true);
    setMinimumSize(new Dimension(640, 480));
    setPreferredSize(new Dimension(640, 480));
  }