Exemple #1
0
 /**
  * called every time a setting is changed saves settings file to
  * .minecraft/mods/$backendname/guiconfig.properties coming soon: set name of config file
  *
  * @param context The context to save.
  */
 @SuppressWarnings("rawtypes")
 public void save(String context) {
   if (!settingsLoaded) {
     return;
   }
   try {
     File path =
         ModSettings.getAppDir(
             "/" + ModSettings.contextDatadirs.get(context) + "/" + backendname + "/");
     ModSettings.dbgout(
         "saving context "
             + context
             + " ("
             + path.getAbsolutePath()
             + " ["
             + ModSettings.contextDatadirs.get(context)
             + "])");
     if (!path.exists()) {
       path.mkdirs();
     }
     File file = new File(path, "guiconfig.properties");
     Properties p = new Properties();
     for (int i = 0; i < Settings.size(); i++) {
       Setting z = Settings.get(i);
       p.put(z.backendName, z.toString(context));
     }
     FileOutputStream out = new FileOutputStream(file);
     p.store(out, "");
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Exemple #2
0
 /**
  * must be called after all settings are added for loading/saving to work. loads from
  * .minecraft/mods/$backendname/guiconfig.properties if it exists. coming soon: set name of config
  * file
  *
  * @param context The context to load from.
  */
 @SuppressWarnings("rawtypes")
 public void load(String context) {
   for (; ; ) {
     try {
       if (ModSettings.contextDatadirs.get(context) == null) {
         break;
       }
       File path =
           ModSettings.getAppDir(
               "/" + ModSettings.contextDatadirs.get(context) + "/" + backendname + "/");
       if (!path.exists()) {
         break;
       }
       File file = new File(path, "guiconfig.properties");
       if (!file.exists()) {
         break;
       }
       Properties p = new Properties();
       p.load(new FileInputStream(file));
       for (int i = 0; i < Settings.size(); i++) {
         ModSettings.dbgout("setting load");
         Setting z = Settings.get(i);
         if (p.containsKey(z.backendName)) {
           ModSettings.dbgout("setting " + (String) p.get(z.backendName));
           z.fromString((String) p.get(z.backendName), context);
         }
       }
       break;
     } catch (Exception e) {
       System.out.println(e);
       break;
     }
   }
 }
Exemple #3
0
 /**
  * Sets the context for mods. This means you can specify a context on a per world / per server
  * basis, or anything else you would prefer. This will carry thoughout all mods.
  *
  * @param name The name reference of the context.
  * @param location The location that this context stores and loads data from.
  */
 public static void setContext(String name, String location) {
   if (name != null) {
     ModSettings.contextDatadirs.put(name, location);
     ModSettings.currentContext = name;
     if (!name.equals("")) {
       ModSettings.loadAll(ModSettings.currentContext);
     }
   } else {
     ModSettings.currentContext = "";
   }
 }
Exemple #4
0
 /** Hide current screen and show parent screen. */
 public static void back() {
   if (GuiModScreen.currentScreen != null) {
     Minecraft m = ModSettings.getMcinst();
     m.displayGuiScreen(GuiModScreen.currentScreen.parentScreen);
     if (GuiModScreen.currentScreen.parentScreen instanceof GuiModScreen) {
       GuiModScreen.currentScreen = (GuiModScreen) GuiModScreen.currentScreen.parentScreen;
       GuiModScreen.currentScreen.setActive();
     } else {
       GuiModScreen.currentScreen = null;
     }
   }
 }
Exemple #5
0
 /**
  * Show a screen - GuiModScreen version. Show an instance of GuiModScreen - Does not set the
  * parent screen, you have to deal with that yourself!
  *
  * @param screen GuiModScreen instance or subclass to show with parent screen already set to
  *     current screen.
  */
 public static void show(GuiModScreen screen) {
   Minecraft m = ModSettings.getMcinst();
   m.displayGuiScreen(screen);
   screen.setActive();
 }
Exemple #6
0
 /**
  * Play a click sound. Call after the user performs an action. Already called from setting
  * widgets.
  */
 public static void clicksound() {
   Minecraft m = ModSettings.getMcinst();
   m.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
 }
Exemple #7
0
  @Override
  protected void paintWidget(GUI gui) {

    Minecraft minecraft = ModSettings.getMcinst();

    int x = getX();
    int y = getY();
    float scalex = 1f;
    float scaley = 1f;

    int maxWidth = getInnerWidth() - 4;
    int maxHeight = getInnerHeight() - 4;

    int scale = getScaleType();

    if ((scale == -1) && ((maxWidth < 16) || (maxHeight < 16))) {
      scale = 0;
    }

    switch (scale) {
      case 0:
        {
          // largest square
          int size = 0;
          if (maxWidth > maxHeight) {
            size = maxHeight;
          } else {
            size = maxWidth;
          }

          x += ((maxWidth - size) / 2);
          y += ((maxHeight - size) / 2);

          scalex = size / 16f;
          scaley = scalex;
          x /= scalex;
          y /= scaley;
          break;
        }

      case -1:
        {
          // default size in middle
          int size = maxWidth - 16;
          x += size / 2;

          size = maxHeight - 16;
          y += size / 2;
          break;
        }

      case 1:
        {
          // fill / stretch
          scalex = maxWidth / 16f;
          scaley = maxHeight / 16f;
          x /= scalex;
          y /= scaley;
          break;
        }
      default:
        throw new IndexOutOfBoundsException(
            "Scale Type is out of bounds! This should never happen!");
    }

    x += 2;
    y += 1;

    if ((minecraft == null) || (getRenderStack() == null) || (getRenderStack().getItem() == null)) {
      // draw black or something? Maybe NULL?
      return;
    }

    GuiWidgetScreen screen = GuiWidgetScreen.getInstance();
    screen.renderer.pauseRendering();

    screen.renderer.setClipRect();
    GL11.glEnable(GL11.GL_SCISSOR_TEST);
    GL11.glPushMatrix();
    GL11.glDisable(GL11.GL_BLEND);
    GL11.glEnable(32826 /* GL_RESCALE_NORMAL_EXT */ /* GL_RESCALE_NORMAL_EXT */);
    RenderHelper.enableStandardItemLighting();
    RenderHelper.enableGUIStandardItemLighting();

    GL11.glScalef(scalex, scaley, 1);

    ItemStack stack = getRenderStack();

    Tessellator.instance.isDrawing = false;

    int stackBeforeDraw = GL11.glGetInteger(GL11.GL_MODELVIEW_STACK_DEPTH);
    try {

      WidgetItem2DRender.itemRenderer.renderItemIntoGUI(
          minecraft.fontRenderer, minecraft.renderEngine, stack, x, y);
      Tessellator.instance.isDrawing = false;
      WidgetItem2DRender.itemRenderer.renderItemOverlayIntoGUI(
          minecraft.fontRenderer, minecraft.renderEngine, stack, x, y);
      Tessellator.instance.isDrawing = false;
    } catch (Throwable e) {
      Tessellator.instance.isDrawing = false;
    }

    int stackAfterDraw = GL11.glGetInteger(GL11.GL_MODELVIEW_STACK_DEPTH);

    if (stackBeforeDraw != stackAfterDraw) {
      // Yes, this IS stuff to work around 'bad' mods :D
      for (int i = 0; i < (stackAfterDraw - stackBeforeDraw); i++) {
        GL11.glPopMatrix();
      }
    }

    RenderHelper.disableStandardItemLighting();
    GL11.glDisable(32826 /* GL_RESCALE_NORMAL_EXT */ /* GL_RESCALE_NORMAL_EXT */);

    GL11.glPopMatrix();
    GL11.glDisable(GL11.GL_SCISSOR_TEST);
    screen.renderer.resumeRendering();
  }