Commit 86bd548cdcd50809f1e0dd1384f46b2911ebd10d

Authored by Mumfrey
1 parent 10a436e9

LiteLoader 1.6.4_02 - experimental - commented horrible GUI code, fixed scrollbar visual bug

java/com/mumfrey/liteloader/core/LiteLoader.java
... ... @@ -587,7 +587,7 @@ public final class LiteLoader
587 587 /**
588 588 * Get a reference to a loaded mod, if the mod exists
589 589 *
590   - * @param modName Mod's name or class name
  590 + * @param modName Mod's name, meta name or class name
591 591 * @return
592 592 * @throws InvalidActivityException
593 593 */
... ... @@ -606,7 +606,9 @@ public final class LiteLoader
606 606  
607 607 for (LiteMod mod : this.mods)
608 608 {
609   - if (modName.equalsIgnoreCase(mod.getName()) || modName.equalsIgnoreCase(mod.getClass().getSimpleName()))
  609 + String metaName = this.getModMetaName(mod.getClass());
  610 +
  611 + if (modName.equalsIgnoreCase(mod.getName()) || modName.equalsIgnoreCase(metaName) || modName.equalsIgnoreCase(mod.getClass().getSimpleName()))
610 612 return (T)mod;
611 613 }
612 614  
... ...
java/com/mumfrey/liteloader/gui/GuiScreenModInfo.java
... ... @@ -39,50 +39,101 @@ import net.minecraft.src.Tessellator;
39 39 */
40 40 public class GuiScreenModInfo extends GuiScreen
41 41 {
42   - private static final int LEFT_EDGE = 80;
43   - private static final int TAB_WIDTH = 20;
44   - private static final int TAB_HEIGHT = 40;
45   - private static final int TAB_TOP = 20;
  42 + private static final int LEFT_EDGE = 80;
  43 + private static final int TAB_WIDTH = 20;
  44 + private static final int TAB_HEIGHT = 40;
  45 + private static final int TAB_TOP = 20;
  46 + private static final int PANEL_TOP = 83;
  47 + private static final int PANEL_BOTTOM = 26;
  48 +
  49 + private static final double TWEEN_RATE = 0.08;
46 50  
47 51 /**
48 52 * Used for clipping
49 53 */
50 54 private static DoubleBuffer doubleBuffer = BufferUtils.createByteBuffer(64).asDoubleBuffer();
51 55  
  56 + // Texture resources for the "about mods" screen, we load the texture directly anyway so it won't be from an RP
52 57 public static ResourceLocation aboutTextureResource;
53 58 private static DynamicTexture aboutTexture;
54 59  
  60 + /**
  61 + * Reference to the main menu which this screen is either overlaying or using as its background
  62 + */
55 63 private GuiMainMenu mainMenu;
56 64  
  65 + /**
  66 + * Tick number (update counter) used for tweening
  67 + */
57 68 private long tickNumber;
58 69  
  70 + /**
  71 + * Last tick number, for tweening
  72 + */
59 73 private double lastTick;
60 74  
61   - private double tweenAmount = 0.0, tweenRate = 0.08;
  75 + /**
  76 + * Current tween percentage (0.0 -> 1.0)
  77 + */
  78 + private double tweenAmount = 0.0;
62 79  
  80 + /**
  81 + * Since we don't get real mouse events we have to simulate them by tracking the mouse state
  82 + */
63 83 private boolean mouseDown, toggled;
64 84  
  85 + /**
  86 + * Hover opacity for the tab
  87 + */
65 88 private float tabOpacity = 0.0F;
66 89  
  90 + /**
  91 + * List of enumerated mods
  92 + */
67 93 private List<GuiModListEntry> mods = new ArrayList<GuiModListEntry>();
68 94  
  95 + /**
  96 + * Currently selected mod
  97 + */
69 98 private GuiModListEntry selectedMod = null;
70 99  
  100 + /**
  101 + * Text to display under the header
  102 + */
71 103 private String activeModText = "0 mod(s) loaded";
72 104  
73   - private int listHeight;
  105 + /**
  106 + * Height of all the items in the list
  107 + */
  108 + private int listHeight = 100;
74 109  
  110 + /**
  111 + * Scroll bar control for the mods list
  112 + */
75 113 private GuiSimpleScrollBar scrollBar = new GuiSimpleScrollBar();
76 114  
  115 + /**
  116 + * Enable / disable button
  117 + */
77 118 private GuiButton btnToggle;
78 119  
  120 + /**
  121 + * Enable the mod info tab checkbox
  122 + */
79 123 private GuiCheckbox chkEnabled;
80 124  
  125 + /**
  126 + * @param minecraft
  127 + * @param mainMenu
  128 + * @param loader
  129 + * @param enabledModsList
  130 + */
81 131 public GuiScreenModInfo(Minecraft minecraft, GuiMainMenu mainMenu, LiteLoader loader, EnabledModsList enabledModsList)
82 132 {
83 133 this.mc = minecraft;
84 134 this.mainMenu = mainMenu;
85 135  
  136 + // Spawn the texture resource if we haven't already
86 137 if (aboutTexture == null)
87 138 {
88 139 try
... ... @@ -107,26 +158,29 @@ public class GuiScreenModInfo extends GuiScreen
107 158 {
108 159 this.activeModText = String.format("%d mod(s) loaded", loader.getLoadedMods().size());
109 160  
  161 + // Add mods to this treeset first, in order to sort them
110 162 Map<String, GuiModListEntry> sortedMods = new TreeMap<String, GuiModListEntry>();
111 163  
  164 + // Active mods
112 165 for (LiteMod mod : loader.getLoadedMods())
113 166 {
114 167 GuiModListEntry modListEntry = new GuiModListEntry(loader, enabledModsList, this.mc.fontRenderer, mod);
115 168 sortedMods.put(modListEntry.getKey(), modListEntry);
116 169 }
117 170  
  171 + // Disabled mods
118 172 for (ModFile disabledMod : loader.getDisabledMods())
119 173 {
120 174 GuiModListEntry modListEntry = new GuiModListEntry(loader, enabledModsList, this.mc.fontRenderer, disabledMod);
121 175 sortedMods.put(modListEntry.getKey(), modListEntry);
122 176 }
123   -
  177 +
  178 + // Add the sorted mods to the mods list
124 179 this.mods.addAll(sortedMods.values());
125 180  
  181 + // Select the first mod in the list
126 182 if (this.mods.size() > 0)
127   - {
128 183 this.selectedMod = this.mods.get(0);
129   - }
130 184 }
131 185  
132 186 /**
... ... @@ -155,8 +209,8 @@ public class GuiScreenModInfo extends GuiScreen
155 209 int left = LEFT_EDGE + 16 + (this.width - LEFT_EDGE - 28) / 2;
156 210  
157 211 this.buttonList.clear();
158   - this.buttonList.add(this.btnToggle = new GuiButton(0, left, this.height - 50, 100, 20, "Enable mod"));
159   - this.buttonList.add(this.chkEnabled = new GuiCheckbox(1, LEFT_EDGE + 12, this.height - 17, "Show LiteLoader tab on main menu"));
  212 + this.buttonList.add(this.btnToggle = new GuiButton(0, left, this.height - PANEL_BOTTOM - 24, 100, 20, "Enable mod"));
  213 + this.buttonList.add(this.chkEnabled = new GuiCheckbox(1, LEFT_EDGE + 12, this.height - PANEL_BOTTOM + 9, "Show LiteLoader tab on main menu"));
160 214  
161 215 this.selectMod(this.selectedMod);
162 216 }
... ... @@ -204,23 +258,32 @@ public class GuiScreenModInfo extends GuiScreen
204 258 {
205 259 boolean active = this.mc.currentScreen == this;
206 260  
207   - this.width = this.mainMenu.width;
208   - this.height = this.mainMenu.height;
209   -
210 261 if (active)
211 262 {
  263 + // Draw the parent screen as our background if we are the active screen
212 264 glClear(GL_DEPTH_BUFFER_BIT);
213 265 this.mainMenu.drawScreen(-10, -10, partialTicks);
214 266 glClear(GL_DEPTH_BUFFER_BIT);
215 267 }
216   -
  268 + else
  269 + {
  270 + // If this is not the active screen, copy the width and height from the parent GUI
  271 + this.width = this.mainMenu.width;
  272 + this.height = this.mainMenu.height;
  273 + }
  274 +
  275 + // Calculate the current tween position
217 276 float xOffset = (this.width - LEFT_EDGE) * this.calcTween(partialTicks, active) + 16.0F + (this.tabOpacity * -32.0F);
218 277 mouseX -= (int)xOffset;
219 278  
  279 + // Handle mouse stuff here since we won't get mouse events when not the active GUI
220 280 boolean mouseOverTab = mouseX > LEFT_EDGE - TAB_WIDTH && mouseX < LEFT_EDGE && mouseY > TAB_TOP && mouseY < TAB_TOP + TAB_HEIGHT;
221 281 this.handleMouseClick(mouseX, mouseY, partialTicks, active, mouseOverTab);
222 282  
  283 + // Calculate the tab opacity, not framerate adjusted because we don't really care
223 284 this.tabOpacity = mouseOverTab || this.tweenAmount > 0.0 ? 0.5F : Math.max(0.0F, this.tabOpacity - partialTicks * 0.1F);
  285 +
  286 + // Draw the panel contents
224 287 this.drawPanel(mouseX, mouseY, partialTicks, active, xOffset);
225 288 }
226 289  
... ... @@ -236,31 +299,38 @@ public class GuiScreenModInfo extends GuiScreen
236 299 glPushMatrix();
237 300 glTranslatef(xOffset, 0.0F, 0.0F);
238 301  
  302 + // Draw the background and left edge
239 303 drawRect(LEFT_EDGE, 0, this.width, this.height, 0xB0000000);
240 304 drawRect(LEFT_EDGE, 0, LEFT_EDGE + 1, TAB_TOP, 0xFFFFFFFF);
241 305 drawRect(LEFT_EDGE, TAB_TOP + TAB_HEIGHT, LEFT_EDGE + 1, this.height, 0xFFFFFFFF);
242 306  
  307 + // Draw the tab
243 308 this.mc.getTextureManager().bindTexture(aboutTextureResource);
244 309 glDrawTexturedRect(LEFT_EDGE - TAB_WIDTH, TAB_TOP, TAB_WIDTH + 1, TAB_HEIGHT, 80, 80, 122, 160, 0.5F + this.tabOpacity);
245 310  
  311 + // Only draw the panel contents if we are actually open
246 312 if (this.tweenAmount > 0.0)
247 313 {
248   - glDrawTexturedRect(LEFT_EDGE + 12, 12, 128, 40, 0, 0, 256, 80, 1.0F);
249   - glDrawTexturedRect(this.width - 32 - 12, 12, 32, 45, 0, 80, 64, 170, 1.0F);
  314 + // Draw the header pieces
  315 + glDrawTexturedRect(LEFT_EDGE + 12, 12, 128, 40, 0, 0, 256, 80, 1.0F); // liteloader logo
  316 + glDrawTexturedRect(this.width - 32 - 12, 12, 32, 45, 0, 80, 64, 170, 1.0F); // chicken
250 317  
  318 + // Draw header text
251 319 this.fontRenderer.drawString("Version " + LiteLoader.getVersion(), LEFT_EDGE + 12 + 38, 50, 0xFFFFFFFF);
252 320 this.fontRenderer.drawString(this.activeModText, LEFT_EDGE + 12 + 38, 60, 0xFFAAAAAA);
253 321  
  322 + // Draw top and bottom horizontal rules
254 323 drawRect(LEFT_EDGE + 12, 80, this.width - 12, 81, 0xFF999999);
255   - drawRect(LEFT_EDGE + 12, this.height - 24, this.width - 12, this.height - 23, 0xFF999999);
  324 + drawRect(LEFT_EDGE + 12, this.height - PANEL_BOTTOM + 2, this.width - 12, this.height - PANEL_BOTTOM + 3, 0xFF999999);
256 325  
257   - int panelTop = 83;
258 326 int innerWidth = this.width - LEFT_EDGE - 24 - 4;
259   - int listWidth = innerWidth / 2;
  327 + int panelWidth = innerWidth / 2;
  328 + int panelHeight = this.height - PANEL_BOTTOM - PANEL_TOP;
260 329  
261   - this.drawModsList(mouseX, mouseY, partialTicks, panelTop, listWidth);
262   - this.drawSelectedMod(mouseX, mouseY, partialTicks, panelTop, listWidth);
  330 + this.drawModsList(mouseX, mouseY, partialTicks, panelWidth, panelHeight);
  331 + this.drawSelectedMod(mouseX, mouseY, partialTicks, panelWidth, panelHeight);
263 332  
  333 + // Draw other controls inside the transform so that they slide properly
264 334 super.drawScreen(mouseX, mouseY, partialTicks);
265 335 }
266 336  
... ... @@ -271,49 +341,52 @@ public class GuiScreenModInfo extends GuiScreen
271 341 * @param mouseX
272 342 * @param mouseY
273 343 * @param partialTicks
274   - * @param panelWidth
  344 + * @param width
  345 + * @param height
275 346 */
276   - public void drawModsList(int mouseX, int mouseY, float partialTicks, int panelTop, int panelWidth)
  347 + public void drawModsList(int mouseX, int mouseY, float partialTicks, int width, int height)
277 348 {
278   - int panelHeight = this.height - 26 - panelTop;
279   - this.scrollBar.drawScrollBar(mouseX, mouseY, partialTicks, LEFT_EDGE + 12 + panelWidth - 5, panelTop, 5, panelHeight, this.listHeight);
  349 + this.scrollBar.drawScrollBar(mouseX, mouseY, partialTicks, LEFT_EDGE + 12 + width - 5, PANEL_TOP, 5, height, this.listHeight);
280 350  
281   - glEnableClipping(LEFT_EDGE + 12, LEFT_EDGE + 12 + panelWidth - 6, panelTop, this.height - 26);
  351 + // clip outside of scroll area
  352 + glEnableClipping(LEFT_EDGE + 12, LEFT_EDGE + 12 + width - 6, PANEL_TOP, this.height - PANEL_BOTTOM);
282 353  
  354 + // handle scrolling
283 355 glPushMatrix();
284   - glTranslatef(0.0F, panelTop - this.scrollBar.getValue(), 0.0F);
  356 + glTranslatef(0.0F, PANEL_TOP - this.scrollBar.getValue(), 0.0F);
285 357  
286   - mouseY -= (panelTop - this.scrollBar.getValue());
  358 + mouseY -= (PANEL_TOP - this.scrollBar.getValue());
287 359  
288 360 int yPos = 0;
289 361 for (GuiModListEntry mod : this.mods)
290 362 {
291   - yPos += mod.drawListEntry(mouseX, mouseY, partialTicks, LEFT_EDGE + 12, yPos, panelWidth - 6, mod == this.selectedMod);
  363 + // drawListEntry returns a value indicating the height of the item drawn
  364 + yPos += mod.drawListEntry(mouseX, mouseY, partialTicks, LEFT_EDGE + 12, yPos, width - 6, mod == this.selectedMod);
292 365 }
293 366  
294 367 glPopMatrix();
295 368 glDisableClipping();
296 369  
297 370 this.listHeight = yPos;
298   - this.scrollBar.setMaxValue(this.listHeight - panelHeight);
  371 + this.scrollBar.setMaxValue(this.listHeight - height);
299 372 }
300 373  
301 374 /**
302 375 * @param mouseX
303 376 * @param mouseY
304 377 * @param partialTicks
305   - * @param panelTop
306   - * @param listWidth
  378 + * @param width
  379 + * @param height
307 380 */
308   - public void drawSelectedMod(int mouseX, int mouseY, float partialTicks, int panelTop, int listWidth)
  381 + public void drawSelectedMod(int mouseX, int mouseY, float partialTicks, int width, int height)
309 382 {
310 383 if (this.selectedMod != null)
311 384 {
312   - int left = LEFT_EDGE + 12 + listWidth;
  385 + int left = LEFT_EDGE + 12 + width;
313 386 int right = this.width - 12;
314 387  
315   - glEnableClipping(left, right, panelTop, this.height - 54);
316   - this.selectedMod.drawInfo(mouseX, mouseY, partialTicks, left, panelTop, right - left);
  388 + glEnableClipping(left, right, PANEL_TOP, this.height - PANEL_BOTTOM - 28);
  389 + this.selectedMod.drawInfo(mouseX, mouseY, partialTicks, left, PANEL_TOP, right - left);
317 390 glDisableClipping();
318 391 }
319 392 }
... ... @@ -384,7 +457,7 @@ public class GuiScreenModInfo extends GuiScreen
384 457 this.scrollBar.setDragging(true);
385 458 }
386 459  
387   - if (mouseY > 83 && mouseY < this.height - 26)
  460 + if (mouseY > PANEL_TOP && mouseY < this.height - PANEL_BOTTOM)
388 461 {
389 462 for (GuiModListEntry mod : this.mods)
390 463 {
... ... @@ -456,11 +529,11 @@ public class GuiScreenModInfo extends GuiScreen
456 529  
457 530 if (active && this.tweenAmount < 1.0)
458 531 {
459   - this.tweenAmount = Math.min(1.0, this.tweenAmount + ((tickValue - this.lastTick) * this.tweenRate));
  532 + this.tweenAmount = Math.min(1.0, this.tweenAmount + ((tickValue - this.lastTick) * TWEEN_RATE));
460 533 }
461 534 else if (!active && this.tweenAmount > 0.0)
462 535 {
463   - this.tweenAmount = Math.max(0.0, this.tweenAmount - ((tickValue - this.lastTick) * this.tweenRate));
  536 + this.tweenAmount = Math.max(0.0, this.tweenAmount - ((tickValue - this.lastTick) * TWEEN_RATE));
464 537 }
465 538  
466 539 this.lastTick = tickValue;
... ...
java/com/mumfrey/liteloader/gui/GuiSimpleScrollBar.java
... ... @@ -121,7 +121,7 @@ public class GuiSimpleScrollBar extends Gui
121 121 float pct = Math.min(1.0F, (float)slideHeight / (float)totalHeight);
122 122 int barHeight = (int)(pct * slideHeight);
123 123 int barTravel = slideHeight - barHeight;
124   - int barPosition = this.maxValue > 0 ? yPosition + 1 + (int)((this.value / (float)this.maxValue) * barTravel) : 0;
  124 + int barPosition = yPosition + 1 + (this.maxValue > 0 ? (int)((this.value / (float)this.maxValue) * barTravel) : 0);
125 125  
126 126 drawRect(xPosition + 1, barPosition, xPosition + width - 1, barPosition + barHeight, this.foreColour);
127 127  
... ...