コード例 #1
0
ファイル: GenericScreen.java プロジェクト: martynd/Spoutcraft
 public GenericScreen() {
   ScaledResolution resolution =
       new ScaledResolution(
           SpoutClient.getHandle().gameSettings,
           SpoutClient.getHandle().displayWidth,
           SpoutClient.getHandle().displayHeight);
   screenWidth = resolution.getScaledWidth();
   screenHeight = resolution.getScaledHeight();
 }
コード例 #2
0
 public void run(int PlayerId) {
   if (name != null) {
     if (name.equals("[resetall]")) {
       SpoutClient.getInstance().getItemManager().reset();
     } else if (name.equals("[reset]")) {
       SpoutClient.getInstance().getItemManager().resetName(id, data);
     } else {
       SpoutClient.getInstance().getItemManager().setItemName(id, data, name);
     }
   }
 }
コード例 #3
0
ファイル: GenericScreen.java プロジェクト: martynd/Spoutcraft
 @Override
 public void onTick() {
   for (Widget widget : widgets) {
     widget.onTick();
   }
   ScaledResolution resolution =
       new ScaledResolution(
           SpoutClient.getHandle().gameSettings,
           SpoutClient.getHandle().displayWidth,
           SpoutClient.getHandle().displayHeight);
   screenWidth = resolution.getScaledWidth();
   screenHeight = resolution.getScaledHeight();
 }
コード例 #4
0
ファイル: GuiFavorites.java プロジェクト: NuclearW/Spoutcraft
 public void doQuickJoin() {
   try {
     String adress = textQuickJoin.getText();
     if (!adress.isEmpty()) {
       String split[] = adress.split(":");
       String ip = split[0];
       int port = split.length > 1 ? Integer.parseInt(split[1]) : 25565;
       SpoutClient.getHandle().gameSettings.lastServer = adress.replace(":", "_");
       SpoutClient.getHandle().gameSettings.saveOptions();
       SpoutClient.getInstance().getServerManager().join(ip, port, this, "Favorites");
     }
   } catch (Exception e) {
   }
 }
コード例 #5
0
ファイル: PacketSky.java プロジェクト: martynd/Spoutcraft
  @Override
  public void run(int PlayerId) {
    if (cloudY != 0) {
      SpoutClient.getInstance().getSkyManager().setCloudHeight(cloudY);
    }
    if (stars != 0) {
      SpoutClient.getInstance().getSkyManager().setStarFrequency(stars);
    }
    if (sunPercent != 0) {
      SpoutClient.getInstance().getSkyManager().setSunSizePercent(sunPercent);
    }
    if (moonPercent != 0) {
      SpoutClient.getInstance().getSkyManager().setMoonSizePercent(moonPercent);
    }
    if (sun != null) {
      if (sun.equals("[reset]")) {
        SpoutClient.getInstance().getSkyManager().setSunTextureUrl(null);
      } else if (sun.length() > 5) {
        SpoutClient.getInstance().getSkyManager().setSunTextureUrl(sun);
      }
    }
    if (moon != null) {
      if (moon.equals("[reset]")) {
        SpoutClient.getInstance().getSkyManager().setMoonTextureUrl(null);
      } else if (moon.length() > 5) {
        SpoutClient.getInstance().getSkyManager().setMoonTextureUrl(moon);
      }
    }
    SkyManager sky = SpoutClient.getInstance().getSkyManager();

    // Sky
    if (skyColor.isOverride()) {
      sky.setSkyColor(null);
    } else if (!skyColor.isInvalid()) {
      sky.setSkyColor(skyColor);
    }

    // Fog
    if (fogColor.isOverride()) {
      sky.setFogColor(null);
    } else if (!fogColor.isInvalid()) {
      sky.setFogColor(fogColor);
    }

    // Cloud
    if (cloudColor.isOverride()) {
      sky.setCloudColor(null);
    } else if (!cloudColor.isInvalid()) {
      sky.setCloudColor(cloudColor);
    }
  }
コード例 #6
0
 @Override
 public void run(int PlayerId) {
   if (texture.equals("[reset]")) {
     texture = null;
   }
   EntityManager manager = SpoutClient.getInstance().getEntityManager();
   if (isMainTexture) {
     manager.setTexture(entityId, texture);
   } else {
     manager.setAlternateTexture(entityId, texture);
   }
 }
コード例 #7
0
 public void run() {
   TexturePackCustom pack = new TexturePackCustom(texturePackFile);
   Minecraft game = SpoutClient.getHandle();
   if (game.renderEngine.oldPack == null) {
     game.renderEngine.oldPack = game.renderEngine.texturePack.selectedTexturePack;
   }
   game.renderEngine.texturePack.setTexturePack(pack);
   game.renderEngine.refreshTextures();
   if (game.renderGlobal != null && game.renderGlobal.worldRenderers != null) {
     WorldRenderer[] renderers = game.renderGlobal.worldRenderers;
     for (int i = 0; i < renderers.length; i++) {
       renderers[i].markDirty();
     }
   }
 }
コード例 #8
0
 protected void passSpecialRender(EntityLiving var1, double var2, double var4, double var6) {
   // Spout Start
   if (Minecraft.isDebugInfoEnabled() && SpoutClient.getInstance().isEntityLabelCheat()) {
     this.renderLivingLabel(var1, Integer.toString(var1.entityId), var2, var4, var6, 64);
   } else {
     String title = var1.displayName;
     if (title != null && !title.equals("[hide]")) {
       String lines[] = title.split("\\n");
       for (int i = 0; i < lines.length; i++) {
         renderLivingLabel(
             var1, lines[i], var2, var4 + (0.275D * (lines.length - i - 1)), var6, 64);
       }
     }
   }
   // Spout End
 }
コード例 #9
0
  public void handleFlying(Packet10Flying var1) {
    EntityPlayerSP var2 = this.mc.thePlayer;
    double var3 = var2.posX;
    double var5 = var2.posY;
    double var7 = var2.posZ;
    float var9 = var2.rotationYaw;
    float var10 = var2.rotationPitch;
    if (var1.moving) {
      var3 = var1.xPosition;
      var5 = var1.yPosition;
      var7 = var1.zPosition;
    }

    if (var1.rotating) {
      var9 = var1.yaw;
      var10 = var1.pitch;
    }

    var2.ySize = 0.0F;
    var2.motionX = var2.motionY = var2.motionZ = 0.0D;
    var2.setPositionAndRotation(var3, var5, var7, var9, var10);
    var1.xPosition = var2.posX;
    var1.yPosition = var2.boundingBox.minY;
    var1.zPosition = var2.posZ;
    var1.stance = var2.posY;

    this.netManager.addToSendQueue(var1);
    if (!this.field_1210_g) {
      this.mc.thePlayer.prevPosX = this.mc.thePlayer.posX;
      this.mc.thePlayer.prevPosY = this.mc.thePlayer.posY;
      this.mc.thePlayer.prevPosZ = this.mc.thePlayer.posZ;
      this.field_1210_g = true;

      // Spout Start
      if (SpoutClient.getInstance().isSpoutEnabled()) {
        if (FileDownloadThread.preCacheCompleted.get() == 0L) {
          return;
        }
      }
      // Spout End
      this.mc.displayGuiScreen((GuiScreen) null);
    }
  }
コード例 #10
0
ファイル: GuiIngame.java プロジェクト: Killili/Spoutcraft
  public void renderGameOverlay(float var1, boolean var2, int var3, int var4) {
    // Spout Start
    SpoutClient.getInstance().onTick();
    InGameHUD mainScreen = SpoutClient.getInstance().getActivePlayer().getMainScreen();
    // Spout End
    ScaledResolution var5 =
        new ScaledResolution(this.mc.gameSettings, this.mc.displayWidth, this.mc.displayHeight);
    int var6 = var5.getScaledWidth();
    int var7 = var5.getScaledHeight();
    FontRenderer var8 = this.mc.fontRenderer;
    this.mc.entityRenderer.func_905_b();
    GL11.glEnable(3042 /*GL_BLEND*/);
    if (Minecraft.isFancyGraphicsEnabled()) {
      this.renderVignette(this.mc.thePlayer.getEntityBrightness(var1), var6, var7);
    }

    ItemStack var9 = this.mc.thePlayer.inventory.armorItemInSlot(3);
    if (!this.mc.gameSettings.thirdPersonView
        && var9 != null
        && var9.itemID == Block.pumpkin.blockID) {
      this.renderPumpkinBlur(var6, var7);
    }

    float var10 =
        this.mc.thePlayer.prevTimeInPortal
            + (this.mc.thePlayer.timeInPortal - this.mc.thePlayer.prevTimeInPortal) * var1;
    if (var10 > 0.0F) {
      this.renderPortalOverlay(var10, var6, var7);
    }

    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    GL11.glBindTexture(3553 /*GL_TEXTURE_2D*/, this.mc.renderEngine.getTexture("/gui/gui.png"));
    InventoryPlayer var11 = this.mc.thePlayer.inventory;
    this.zLevel = -90.0F;
    this.drawTexturedModalRect(var6 / 2 - 91, var7 - 22, 0, 0, 182, 22);
    this.drawTexturedModalRect(
        var6 / 2 - 91 - 1 + var11.currentItem * 20, var7 - 22 - 1, 0, 22, 24, 22);
    GL11.glBindTexture(3553 /*GL_TEXTURE_2D*/, this.mc.renderEngine.getTexture("/gui/icons.png"));
    GL11.glEnable(3042 /*GL_BLEND*/);
    GL11.glBlendFunc(775, 769);
    this.drawTexturedModalRect(var6 / 2 - 7, var7 / 2 - 7, 0, 0, 16, 16);
    GL11.glDisable(3042 /*GL_BLEND*/);
    boolean var12 = this.mc.thePlayer.heartsLife / 3 % 2 == 1;
    if (this.mc.thePlayer.heartsLife < 10) {
      var12 = false;
    }

    int var13 = this.mc.thePlayer.health;
    int var14 = this.mc.thePlayer.prevHealth;
    this.rand.setSeed((long) (this.updateCounter * 312871));
    int var15;
    int var17;
    int var16;
    if (this.mc.playerController.shouldDrawHUD()) {
      var15 = this.mc.thePlayer.getPlayerArmorValue();

      int var18;
      for (var16 = 0; var16 < 10; ++var16) {
        var17 = var7 - 32;
        // Spout Start
        if (mainScreen.getArmorBar().isVisible()) {
          if (var15 > 0) {
            var18 = var6 / 2 + 91 - var16 * 8 - 9;
            if (var16 * 2 + 1 < var15) {
              this.drawTexturedModalRect(var18, var17, 34, 9, 9, 9);
            }

            if (var16 * 2 + 1 == var15) {
              this.drawTexturedModalRect(var18, var17, 25, 9, 9, 9);
            }

            if (var16 * 2 + 1 > var15) {
              this.drawTexturedModalRect(var18, var17, 16, 9, 9, 9);
            }
          }
        }
        // Spout End
        byte var31 = 0;
        if (var12) {
          var31 = 1;
        }

        int var19 = var6 / 2 - 91 + var16 * 8;
        if (var13 <= 4) {
          var17 += this.rand.nextInt(2);
        }
        // Spout Start
        if (mainScreen.getHealthBar().isVisible()) {
          this.drawTexturedModalRect(var19, var17, 16 + var31 * 9, 0, 9, 9);
          if (var12) {
            if (var16 * 2 + 1 < var14) {
              this.drawTexturedModalRect(var19, var17, 70, 0, 9, 9);
            }
            if (var16 * 2 + 1 == var14) {
              this.drawTexturedModalRect(var19, var17, 79, 0, 9, 9);
            }
          }

          if (var16 * 2 + 1 < var13) {
            this.drawTexturedModalRect(var19, var17, 52, 0, 9, 9);
          }

          if (var16 * 2 + 1 == var13) {
            this.drawTexturedModalRect(var19, var17, 61, 0, 9, 9);
          }
        }
        // Spout End
      }

      if (this.mc.thePlayer.isInsideOfMaterial(Material.water)) {
        // Spout Start
        var16 =
            (int) Math.ceil(((double) (mc.thePlayer.air - 2) * 10D) / (mc.thePlayer.maxAir * 1D));
        var17 =
            (int) Math.ceil(((double) mc.thePlayer.air * 10D) / (mc.thePlayer.maxAir * 1D)) - var16;
        if (mainScreen.getBubbleBar().isVisible()) {
          for (var18 = 0; var18 < var16 + var17; ++var18) {
            if (var18 < var16) {
              this.drawTexturedModalRect(var6 / 2 - 91 + var18 * 8, var7 - 32 - 9, 16, 18, 9, 9);
            } else {
              this.drawTexturedModalRect(var6 / 2 - 91 + var18 * 8, var7 - 32 - 9, 25, 18, 9, 9);
            }
          }
        }
        // Spout End
      }
    }

    GL11.glDisable(3042 /*GL_BLEND*/);
    GL11.glEnable('\u803a');
    GL11.glPushMatrix();
    GL11.glRotatef(120.0F, 1.0F, 0.0F, 0.0F);
    RenderHelper.enableStandardItemLighting();
    GL11.glPopMatrix();

    for (var15 = 0; var15 < 9; ++var15) {
      var16 = var6 / 2 - 90 + var15 * 20 + 2;
      var17 = var7 - 16 - 3;
      this.renderInventorySlot(var15, var16, var17, var1);
    }

    RenderHelper.disableStandardItemLighting();
    GL11.glDisable('\u803a');
    if (this.mc.thePlayer.func_22060_M() > 0) {
      GL11.glDisable(2929 /*GL_DEPTH_TEST*/);
      GL11.glDisable(3008 /*GL_ALPHA_TEST*/);
      var15 = this.mc.thePlayer.func_22060_M();
      float var26 = (float) var15 / 100.0F;
      if (var26 > 1.0F) {
        var26 = 1.0F - (float) (var15 - 100) / 10.0F;
      }

      var17 = (int) (220.0F * var26) << 24 | 1052704;
      this.drawRect(0, 0, var6, var7, var17);
      GL11.glEnable(3008 /*GL_ALPHA_TEST*/);
      GL11.glEnable(2929 /*GL_DEPTH_TEST*/);
    }
    // Spout Start
    mainScreen.render();
    // Spout End
    String var23;
    if (this.mc.gameSettings.showDebugInfo) {
      GL11.glPushMatrix();
      if (Minecraft.hasPaidCheckTime > 0L) {
        GL11.glTranslatef(0.0F, 32.0F, 0.0F);
      }

      var8.drawStringWithShadow("Minecraft Beta 1.7.3 (" + this.mc.debug + ")", 2, 2, 16777215);
      var8.drawStringWithShadow(this.mc.func_6241_m(), 2, 12, 16777215);
      var8.drawStringWithShadow(this.mc.func_6262_n(), 2, 22, 16777215);
      var8.drawStringWithShadow(this.mc.func_6245_o(), 2, 32, 16777215);
      var8.drawStringWithShadow(this.mc.func_21002_o(), 2, 42, 16777215);
      long var25 = Runtime.getRuntime().maxMemory();
      long var30 = Runtime.getRuntime().totalMemory();
      long var29 = Runtime.getRuntime().freeMemory();
      long var21 = var30 - var29;
      var23 =
          "Used memory: "
              + var21 * 100L / var25
              + "% ("
              + var21 / 1024L / 1024L
              + "MB) of "
              + var25 / 1024L / 1024L
              + "MB";
      this.drawString(var8, var23, var6 - var8.getStringWidth(var23) - 2, 2, 14737632);
      var23 = "Allocated memory: " + var30 * 100L / var25 + "% (" + var30 / 1024L / 1024L + "MB)";
      this.drawString(var8, var23, var6 - var8.getStringWidth(var23) - 2, 12, 14737632);
      // Spout Start
      // No Cheating!
      if (SpoutClient.getInstance().isCheatMode()) {
        this.drawString(var8, "x: " + this.mc.thePlayer.posX, 2, 64, 14737632);
        this.drawString(var8, "y: " + this.mc.thePlayer.posY, 2, 72, 14737632);
        this.drawString(var8, "z: " + this.mc.thePlayer.posZ, 2, 80, 14737632);
        this.drawString(
            var8,
            "f: "
                + (MathHelper.floor_double(
                        (double) (this.mc.thePlayer.rotationYaw * 4.0F / 360.0F) + 0.5D)
                    & 3),
            2,
            88,
            14737632);
      }
      // Spout End
      // Spout Start
      this.drawString(var8, "Map Data Info", 2, 64, 14737632);
      this.drawString(
          var8,
          "Average packet size: " + ChunkCache.averageChunkSize.get() + " bytes",
          2,
          72,
          14737632);
      this.drawString(
          var8, "Cache hit percent: " + ChunkCache.hitPercentage.get(), 2, 80, 14737632);
      // Spout end
      GL11.glPopMatrix();
    }

    if (this.recordPlayingUpFor > 0) {
      float var24 = (float) this.recordPlayingUpFor - var1;
      var16 = (int) (var24 * 256.0F / 20.0F);
      if (var16 > 255) {
        var16 = 255;
      }

      if (var16 > 0) {
        GL11.glPushMatrix();
        GL11.glTranslatef((float) (var6 / 2), (float) (var7 - 48), 0.0F);
        GL11.glEnable(3042 /*GL_BLEND*/);
        GL11.glBlendFunc(770, 771);
        var17 = 16777215;
        if (this.field_22065_l) {
          var17 = Color.HSBtoRGB(var24 / 50.0F, 0.7F, 0.6F) & 16777215;
        }

        var8.drawString(
            this.recordPlaying,
            -var8.getStringWidth(this.recordPlaying) / 2,
            -4,
            var17 + (var16 << 24));
        GL11.glDisable(3042 /*GL_BLEND*/);
        GL11.glPopMatrix();
      }
    }

    byte var27 = 10;
    boolean var28 = false;
    // Spout Start
    if (mainScreen.getChatBar().isVisible()) {
      if (mc.currentScreen instanceof GuiChat) {
        var27 = 20;
        var28 = true;
      }
    }
    boolean chatOpen = var28;
    int lines =
        chatOpen
            ? mainScreen.getChatTextBox().getNumVisibleChatLines()
            : mainScreen.getChatTextBox().getNumVisibleLines();
    // Spout End

    GL11.glEnable(3042 /*GL_BLEND*/);
    GL11.glBlendFunc(770, 771);
    GL11.glDisable(3008 /*GL_ALPHA_TEST*/);
    GL11.glPushMatrix();
    GL11.glTranslatef(0.0F, (float) (var7 - 48), 0.0F);

    // Spout Start

    if (mainScreen.getChatTextBox().isVisible()) {
      Math.max(
          0,
          chatMessageList.size()
              - SpoutClient.getInstance().getChatManager().chatScroll
              - 1
              - var27);
      int viewedLine = 0;

      for (int line = SpoutClient.getInstance().getChatManager().chatScroll;
          line
              < Math.min(
                  chatMessageList.size() - 1,
                  (lines + SpoutClient.getInstance().getChatManager().chatScroll));
          line++) {
        if (chatOpen || chatMessageList.get(line).updateCounter < 250) {
          double opacity = 1.0D - chatMessageList.get(line).updateCounter / 250D;
          opacity *= 10D;
          if (opacity < 0.0D) {
            opacity = 0.0D;
          }
          if (opacity > 1.0D) {
            opacity = 1.0D;
          }
          opacity *= opacity;
          int color = chatOpen ? 255 : (int) (255D * opacity);
          if (color > 0) {
            int height = 2;
            int width = -viewedLine * 9;
            String chat = chatMessageList.get(line).message;
            chat = SpoutClient.getInstance().getChatManager().formatChatColors(chat);
            chat = ChatManager.formatUrl(chat);
            // TODO add support for opening URL in browser if clicked?
            drawRect(height, width - 1, height + 320, width + 8, color / 2 << 24);
            GL11.glEnable(3042 /*GL_BLEND*/);
            var8.drawStringWithShadow(chat, height, width, 0xffffff + (color << 24));
          }
          viewedLine++;
        }
      }
    }
    // Spout End

    GL11.glPopMatrix();
    GL11.glEnable(3008 /*GL_ALPHA_TEST*/);
    GL11.glDisable(3042 /*GL_BLEND*/);
  }
コード例 #11
0
ファイル: GuiFavorites.java プロジェクト: NuclearW/Spoutcraft
  @Override
  public void initGui() {
    Addon spoutcraft = SpoutClient.getInstance().getAddonManager().getAddon("spoutcraft");

    title = new GenericLabel("Favorite Servers");
    title.setX(
        width / 2 - SpoutClient.getHandle().fontRenderer.getStringWidth(title.getText()) / 2);
    title.setY(12);
    title
        .setHeight(15)
        .setWidth(SpoutClient.getHandle().fontRenderer.getStringWidth(title.getText()) / 2);
    getScreen().attachWidget(spoutcraft, title);

    buttonMoveUp = new GenericButton("/\\");
    buttonMoveUp.setTooltip("Move Item Up");
    buttonMoveUp.setX(5).setY(5);
    buttonMoveUp.setHeight(20).setWidth(20);
    getScreen().attachWidget(spoutcraft, buttonMoveUp);

    buttonMoveDown = new GenericButton("\\/");
    buttonMoveDown.setTooltip("Move Item Down");
    buttonMoveDown.setX(25).setY(5);
    buttonMoveDown.setHeight(20).setWidth(20);
    getScreen().attachWidget(spoutcraft, buttonMoveDown);

    buttonRefresh = new GenericButton("Refresh");
    buttonRefresh.setHeight(20).setWidth(100).setX(width - 105).setY(5);
    getScreen().attachWidget(spoutcraft, buttonRefresh);

    view = new GenericListView(model);
    view.setX(5).setY(30).setWidth(width - 10).setHeight(height - 110);
    getScreen().attachWidget(spoutcraft, view);

    int top = (int) (view.getY() + view.getHeight() + 5);

    int totalWidth = Math.min(width - 9, 200 * 3 + 10);
    int cellWidth = (totalWidth - 10) / 3;
    int left = width / 2 - totalWidth / 2;
    int center = left + cellWidth + 5;
    int right = center + cellWidth + 5;

    String text = SpoutClient.getHandle().gameSettings.lastServer.replace("_", ":");
    if (textQuickJoin != null) text = textQuickJoin.getText();
    textQuickJoin = new GenericTextField();
    textQuickJoin.setX(left + 2).setY(top + 2).setHeight(16).setWidth(cellWidth * 2 + 5 - 4);
    textQuickJoin.setMaximumCharacters(0);
    textQuickJoin.setText(text);
    getScreen().attachWidget(spoutcraft, textQuickJoin);

    buttonQuickJoin = new GenericButton("Quick Join");
    buttonQuickJoin.setX(right).setY(top).setWidth(cellWidth).setHeight(20);
    getScreen().attachWidget(spoutcraft, buttonQuickJoin);

    top += 25;

    buttonJoin = new GenericButton("Join Server");
    buttonJoin.setX(right).setY(top).setWidth(cellWidth).setHeight(20);
    getScreen().attachWidget(spoutcraft, buttonJoin);

    buttonAdd = new GenericButton("Add Favorite");
    buttonAdd.setX(center).setY(top).setWidth(cellWidth).setHeight(20);
    getScreen().attachWidget(spoutcraft, buttonAdd);

    buttonEdit = new GenericButton("Edit");
    buttonEdit.setX(left).setY(top).setWidth(cellWidth).setHeight(20);
    getScreen().attachWidget(spoutcraft, buttonEdit);

    top += 25;

    buttonDelete = new GenericButton("Delete");
    buttonDelete.setX(left).setY(top).setWidth(cellWidth).setHeight(20);
    getScreen().attachWidget(spoutcraft, buttonDelete);

    buttonServerList = new GenericButton("Server List");
    buttonServerList.setX(center).setY(top).setWidth(cellWidth).setHeight(20);
    getScreen().attachWidget(spoutcraft, buttonServerList);

    buttonMainMenu = new GenericButton("Main Menu");
    buttonMainMenu.setX(right).setY(top).setWidth(cellWidth).setHeight(20);
    getScreen().attachWidget(spoutcraft, buttonMainMenu);

    updateButtons();
  }
コード例 #12
0
ファイル: GuiFavorites.java プロジェクト: NuclearW/Spoutcraft
public class GuiFavorites extends GuiScreen {
  @SuppressWarnings("unused")
  private GuiScreen parent;

  // GUI stuff
  private Button buttonJoin,
      buttonAdd,
      buttonDelete,
      buttonEdit,
      buttonMainMenu,
      buttonServerList,
      buttonQuickJoin,
      buttonMoveUp,
      buttonMoveDown,
      buttonRefresh;
  private TextField textQuickJoin;
  private GenericListView view;
  private Label title;
  public FavoritesModel model = SpoutClient.getInstance().getServerManager().getFavorites();
  private long confirmationTimeout = 0;

  public GuiFavorites(GuiScreen parent) {
    model.setCurrentGUI(this);
    this.parent = parent;
  }

  @Override
  public void initGui() {
    Addon spoutcraft = SpoutClient.getInstance().getAddonManager().getAddon("spoutcraft");

    title = new GenericLabel("Favorite Servers");
    title.setX(
        width / 2 - SpoutClient.getHandle().fontRenderer.getStringWidth(title.getText()) / 2);
    title.setY(12);
    title
        .setHeight(15)
        .setWidth(SpoutClient.getHandle().fontRenderer.getStringWidth(title.getText()) / 2);
    getScreen().attachWidget(spoutcraft, title);

    buttonMoveUp = new GenericButton("/\\");
    buttonMoveUp.setTooltip("Move Item Up");
    buttonMoveUp.setX(5).setY(5);
    buttonMoveUp.setHeight(20).setWidth(20);
    getScreen().attachWidget(spoutcraft, buttonMoveUp);

    buttonMoveDown = new GenericButton("\\/");
    buttonMoveDown.setTooltip("Move Item Down");
    buttonMoveDown.setX(25).setY(5);
    buttonMoveDown.setHeight(20).setWidth(20);
    getScreen().attachWidget(spoutcraft, buttonMoveDown);

    buttonRefresh = new GenericButton("Refresh");
    buttonRefresh.setHeight(20).setWidth(100).setX(width - 105).setY(5);
    getScreen().attachWidget(spoutcraft, buttonRefresh);

    view = new GenericListView(model);
    view.setX(5).setY(30).setWidth(width - 10).setHeight(height - 110);
    getScreen().attachWidget(spoutcraft, view);

    int top = (int) (view.getY() + view.getHeight() + 5);

    int totalWidth = Math.min(width - 9, 200 * 3 + 10);
    int cellWidth = (totalWidth - 10) / 3;
    int left = width / 2 - totalWidth / 2;
    int center = left + cellWidth + 5;
    int right = center + cellWidth + 5;

    String text = SpoutClient.getHandle().gameSettings.lastServer.replace("_", ":");
    if (textQuickJoin != null) text = textQuickJoin.getText();
    textQuickJoin = new GenericTextField();
    textQuickJoin.setX(left + 2).setY(top + 2).setHeight(16).setWidth(cellWidth * 2 + 5 - 4);
    textQuickJoin.setMaximumCharacters(0);
    textQuickJoin.setText(text);
    getScreen().attachWidget(spoutcraft, textQuickJoin);

    buttonQuickJoin = new GenericButton("Quick Join");
    buttonQuickJoin.setX(right).setY(top).setWidth(cellWidth).setHeight(20);
    getScreen().attachWidget(spoutcraft, buttonQuickJoin);

    top += 25;

    buttonJoin = new GenericButton("Join Server");
    buttonJoin.setX(right).setY(top).setWidth(cellWidth).setHeight(20);
    getScreen().attachWidget(spoutcraft, buttonJoin);

    buttonAdd = new GenericButton("Add Favorite");
    buttonAdd.setX(center).setY(top).setWidth(cellWidth).setHeight(20);
    getScreen().attachWidget(spoutcraft, buttonAdd);

    buttonEdit = new GenericButton("Edit");
    buttonEdit.setX(left).setY(top).setWidth(cellWidth).setHeight(20);
    getScreen().attachWidget(spoutcraft, buttonEdit);

    top += 25;

    buttonDelete = new GenericButton("Delete");
    buttonDelete.setX(left).setY(top).setWidth(cellWidth).setHeight(20);
    getScreen().attachWidget(spoutcraft, buttonDelete);

    buttonServerList = new GenericButton("Server List");
    buttonServerList.setX(center).setY(top).setWidth(cellWidth).setHeight(20);
    getScreen().attachWidget(spoutcraft, buttonServerList);

    buttonMainMenu = new GenericButton("Main Menu");
    buttonMainMenu.setX(right).setY(top).setWidth(cellWidth).setHeight(20);
    getScreen().attachWidget(spoutcraft, buttonMainMenu);

    updateButtons();
  }

  @Override
  public void drawScreen(int var1, int var2, float var3) {
    drawDefaultBackground();

    // TODO: Draw the refresh button thingie
  }

  @Override
  public void buttonClicked(Button btn) {
    if (btn.equals(buttonMainMenu)) {
      SpoutClient.getHandle().displayGuiScreen(new GuiMainMenu());
    }
    if (btn.equals(buttonServerList)) {
      SpoutClient.getHandle().displayGuiScreen(new GuiServerList());
    }
    if (btn.equals(buttonQuickJoin)) {
      doQuickJoin();
    }
    if (btn.equals(buttonAdd)) {
      SpoutClient.getHandle().displayGuiScreen(new GuiAddFavorite(this));
    }
    if (btn.equals(buttonEdit)) {
      ServerItem item = (ServerItem) view.getSelectedItem();
      // Produces a "hang" why ever :(
      if (item != null) {
        SpoutClient.getHandle().displayGuiScreen(new GuiAddFavorite(item, this));
      } else {
        updateButtons();
      }
    }
    if (btn.equals(buttonDelete)) {
      if (buttonDelete.getText().equals("Delete")) {
        buttonDelete.setText(ChatColor.RED + "Really?");
        confirmationTimeout = System.currentTimeMillis();
      } else {
        model.removeServer((ServerItem) view.getSelectedItem());
        model.save();
        buttonDelete.setText("Delete");
      }
    }
    if (btn.equals(buttonJoin)) {
      ServerItem item = null;
      if (view.getSelectedRow() > -1) {
        item = (ServerItem) model.getItem(view.getSelectedRow());
      }
      if (item != null) {
        SpoutClient.getInstance().getServerManager().join(item, this, "Favorites");
      } else {
        // Just in case something weird happens
        updateButtons();
      }
    }
    if (btn.equals(buttonMoveUp)) {
      if (view.getSelectedRow() != -1) {
        model.move(view.getSelectedRow(), view.getSelectedRow() - 1);
        view.shiftSelection(-1);
        model.save();
      }
    }
    if (btn.equals(buttonMoveDown)) {
      if (view.getSelectedRow() != -1) {
        model.move(view.getSelectedRow(), view.getSelectedRow() + 1);
        view.shiftSelection(1);
        model.save();
      }
    }
    if (btn.equals(buttonRefresh)) {
      for (int i = 0; i < model.getSize(); i++) {
        ServerItem item = (ServerItem) model.getItem(i);
        item.poll();
      }
    }
  }

  public void doQuickJoin() {
    try {
      String adress = textQuickJoin.getText();
      if (!adress.isEmpty()) {
        String split[] = adress.split(":");
        String ip = split[0];
        int port = split.length > 1 ? Integer.parseInt(split[1]) : 25565;
        SpoutClient.getHandle().gameSettings.lastServer = adress.replace(":", "_");
        SpoutClient.getHandle().gameSettings.saveOptions();
        SpoutClient.getInstance().getServerManager().join(ip, port, this, "Favorites");
      }
    } catch (Exception e) {
    }
  }

  public void updateButtons() {
    boolean enable = true;
    if (view.getSelectedRow() == -1) {
      enable = false;
    }
    buttonEdit.setEnabled(enable);
    buttonDelete.setEnabled(enable);
    buttonJoin.setEnabled(enable);
    buttonDelete.setText("Delete");

    if (model.isPolling()) {
      buttonRefresh.setEnabled(false);
      buttonRefresh.setText("Polling...");
      buttonRefresh.setDisabledColor(new Color(0f, 0f, 1f));
    } else {
      buttonRefresh.setEnabled(true);
      buttonRefresh.setText("Refresh");
    }
  }

  @Override
  public void updateScreen() {
    if (model.isPolling()) {
      Color color = new Color(0, 0f, 0);
      double darkness = 0;
      long t = System.currentTimeMillis() % 1000;
      darkness = Math.cos(t * 2 * Math.PI / 1000) * 0.2 + 0.2;
      color.setBlue(1f - (float) darkness);
      buttonRefresh.setDisabledColor(color);
    }
    if (System.currentTimeMillis() - confirmationTimeout > 5000) {
      buttonDelete.setText("Delete");
    }
    if (System.currentTimeMillis() - confirmationTimeout < 500) {
      buttonDelete.setEnabled(false);
    } else if (!buttonDelete.getText().equals("Delete")) {
      buttonDelete.setEnabled(true);
    }
    super.updateScreen();
  }
}
コード例 #13
0
ファイル: GuiFavorites.java プロジェクト: NuclearW/Spoutcraft
 @Override
 public void buttonClicked(Button btn) {
   if (btn.equals(buttonMainMenu)) {
     SpoutClient.getHandle().displayGuiScreen(new GuiMainMenu());
   }
   if (btn.equals(buttonServerList)) {
     SpoutClient.getHandle().displayGuiScreen(new GuiServerList());
   }
   if (btn.equals(buttonQuickJoin)) {
     doQuickJoin();
   }
   if (btn.equals(buttonAdd)) {
     SpoutClient.getHandle().displayGuiScreen(new GuiAddFavorite(this));
   }
   if (btn.equals(buttonEdit)) {
     ServerItem item = (ServerItem) view.getSelectedItem();
     // Produces a "hang" why ever :(
     if (item != null) {
       SpoutClient.getHandle().displayGuiScreen(new GuiAddFavorite(item, this));
     } else {
       updateButtons();
     }
   }
   if (btn.equals(buttonDelete)) {
     if (buttonDelete.getText().equals("Delete")) {
       buttonDelete.setText(ChatColor.RED + "Really?");
       confirmationTimeout = System.currentTimeMillis();
     } else {
       model.removeServer((ServerItem) view.getSelectedItem());
       model.save();
       buttonDelete.setText("Delete");
     }
   }
   if (btn.equals(buttonJoin)) {
     ServerItem item = null;
     if (view.getSelectedRow() > -1) {
       item = (ServerItem) model.getItem(view.getSelectedRow());
     }
     if (item != null) {
       SpoutClient.getInstance().getServerManager().join(item, this, "Favorites");
     } else {
       // Just in case something weird happens
       updateButtons();
     }
   }
   if (btn.equals(buttonMoveUp)) {
     if (view.getSelectedRow() != -1) {
       model.move(view.getSelectedRow(), view.getSelectedRow() - 1);
       view.shiftSelection(-1);
       model.save();
     }
   }
   if (btn.equals(buttonMoveDown)) {
     if (view.getSelectedRow() != -1) {
       model.move(view.getSelectedRow(), view.getSelectedRow() + 1);
       view.shiftSelection(1);
       model.save();
     }
   }
   if (btn.equals(buttonRefresh)) {
     for (int i = 0; i < model.getSize(); i++) {
       ServerItem item = (ServerItem) model.getItem(i);
       item.poll();
     }
   }
 }