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,7 +587,7 @@ public final class LiteLoader
587 /** 587 /**
588 * Get a reference to a loaded mod, if the mod exists 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 * @return 591 * @return
592 * @throws InvalidActivityException 592 * @throws InvalidActivityException
593 */ 593 */
@@ -606,7 +606,9 @@ public final class LiteLoader @@ -606,7 +606,9 @@ public final class LiteLoader
606 606
607 for (LiteMod mod : this.mods) 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 return (T)mod; 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,50 +39,101 @@ import net.minecraft.src.Tessellator;
39 */ 39 */
40 public class GuiScreenModInfo extends GuiScreen 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 * Used for clipping 52 * Used for clipping
49 */ 53 */
50 private static DoubleBuffer doubleBuffer = BufferUtils.createByteBuffer(64).asDoubleBuffer(); 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 public static ResourceLocation aboutTextureResource; 57 public static ResourceLocation aboutTextureResource;
53 private static DynamicTexture aboutTexture; 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 private GuiMainMenu mainMenu; 63 private GuiMainMenu mainMenu;
56 64
  65 + /**
  66 + * Tick number (update counter) used for tweening
  67 + */
57 private long tickNumber; 68 private long tickNumber;
58 69
  70 + /**
  71 + * Last tick number, for tweening
  72 + */
59 private double lastTick; 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 private boolean mouseDown, toggled; 83 private boolean mouseDown, toggled;
64 84
  85 + /**
  86 + * Hover opacity for the tab
  87 + */
65 private float tabOpacity = 0.0F; 88 private float tabOpacity = 0.0F;
66 89
  90 + /**
  91 + * List of enumerated mods
  92 + */
67 private List<GuiModListEntry> mods = new ArrayList<GuiModListEntry>(); 93 private List<GuiModListEntry> mods = new ArrayList<GuiModListEntry>();
68 94
  95 + /**
  96 + * Currently selected mod
  97 + */
69 private GuiModListEntry selectedMod = null; 98 private GuiModListEntry selectedMod = null;
70 99
  100 + /**
  101 + * Text to display under the header
  102 + */
71 private String activeModText = "0 mod(s) loaded"; 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 private GuiSimpleScrollBar scrollBar = new GuiSimpleScrollBar(); 113 private GuiSimpleScrollBar scrollBar = new GuiSimpleScrollBar();
76 114
  115 + /**
  116 + * Enable / disable button
  117 + */
77 private GuiButton btnToggle; 118 private GuiButton btnToggle;
78 119
  120 + /**
  121 + * Enable the mod info tab checkbox
  122 + */
79 private GuiCheckbox chkEnabled; 123 private GuiCheckbox chkEnabled;
80 124
  125 + /**
  126 + * @param minecraft
  127 + * @param mainMenu
  128 + * @param loader
  129 + * @param enabledModsList
  130 + */
81 public GuiScreenModInfo(Minecraft minecraft, GuiMainMenu mainMenu, LiteLoader loader, EnabledModsList enabledModsList) 131 public GuiScreenModInfo(Minecraft minecraft, GuiMainMenu mainMenu, LiteLoader loader, EnabledModsList enabledModsList)
82 { 132 {
83 this.mc = minecraft; 133 this.mc = minecraft;
84 this.mainMenu = mainMenu; 134 this.mainMenu = mainMenu;
85 135
  136 + // Spawn the texture resource if we haven't already
86 if (aboutTexture == null) 137 if (aboutTexture == null)
87 { 138 {
88 try 139 try
@@ -107,26 +158,29 @@ public class GuiScreenModInfo extends GuiScreen @@ -107,26 +158,29 @@ public class GuiScreenModInfo extends GuiScreen
107 { 158 {
108 this.activeModText = String.format("%d mod(s) loaded", loader.getLoadedMods().size()); 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 Map<String, GuiModListEntry> sortedMods = new TreeMap<String, GuiModListEntry>(); 162 Map<String, GuiModListEntry> sortedMods = new TreeMap<String, GuiModListEntry>();
111 163
  164 + // Active mods
112 for (LiteMod mod : loader.getLoadedMods()) 165 for (LiteMod mod : loader.getLoadedMods())
113 { 166 {
114 GuiModListEntry modListEntry = new GuiModListEntry(loader, enabledModsList, this.mc.fontRenderer, mod); 167 GuiModListEntry modListEntry = new GuiModListEntry(loader, enabledModsList, this.mc.fontRenderer, mod);
115 sortedMods.put(modListEntry.getKey(), modListEntry); 168 sortedMods.put(modListEntry.getKey(), modListEntry);
116 } 169 }
117 170
  171 + // Disabled mods
118 for (ModFile disabledMod : loader.getDisabledMods()) 172 for (ModFile disabledMod : loader.getDisabledMods())
119 { 173 {
120 GuiModListEntry modListEntry = new GuiModListEntry(loader, enabledModsList, this.mc.fontRenderer, disabledMod); 174 GuiModListEntry modListEntry = new GuiModListEntry(loader, enabledModsList, this.mc.fontRenderer, disabledMod);
121 sortedMods.put(modListEntry.getKey(), modListEntry); 175 sortedMods.put(modListEntry.getKey(), modListEntry);
122 } 176 }
123 - 177 +
  178 + // Add the sorted mods to the mods list
124 this.mods.addAll(sortedMods.values()); 179 this.mods.addAll(sortedMods.values());
125 180
  181 + // Select the first mod in the list
126 if (this.mods.size() > 0) 182 if (this.mods.size() > 0)
127 - {  
128 this.selectedMod = this.mods.get(0); 183 this.selectedMod = this.mods.get(0);
129 - }  
130 } 184 }
131 185
132 /** 186 /**
@@ -155,8 +209,8 @@ public class GuiScreenModInfo extends GuiScreen @@ -155,8 +209,8 @@ public class GuiScreenModInfo extends GuiScreen
155 int left = LEFT_EDGE + 16 + (this.width - LEFT_EDGE - 28) / 2; 209 int left = LEFT_EDGE + 16 + (this.width - LEFT_EDGE - 28) / 2;
156 210
157 this.buttonList.clear(); 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 this.selectMod(this.selectedMod); 215 this.selectMod(this.selectedMod);
162 } 216 }
@@ -204,23 +258,32 @@ public class GuiScreenModInfo extends GuiScreen @@ -204,23 +258,32 @@ public class GuiScreenModInfo extends GuiScreen
204 { 258 {
205 boolean active = this.mc.currentScreen == this; 259 boolean active = this.mc.currentScreen == this;
206 260
207 - this.width = this.mainMenu.width;  
208 - this.height = this.mainMenu.height;  
209 -  
210 if (active) 261 if (active)
211 { 262 {
  263 + // Draw the parent screen as our background if we are the active screen
212 glClear(GL_DEPTH_BUFFER_BIT); 264 glClear(GL_DEPTH_BUFFER_BIT);
213 this.mainMenu.drawScreen(-10, -10, partialTicks); 265 this.mainMenu.drawScreen(-10, -10, partialTicks);
214 glClear(GL_DEPTH_BUFFER_BIT); 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 float xOffset = (this.width - LEFT_EDGE) * this.calcTween(partialTicks, active) + 16.0F + (this.tabOpacity * -32.0F); 276 float xOffset = (this.width - LEFT_EDGE) * this.calcTween(partialTicks, active) + 16.0F + (this.tabOpacity * -32.0F);
218 mouseX -= (int)xOffset; 277 mouseX -= (int)xOffset;
219 278
  279 + // Handle mouse stuff here since we won't get mouse events when not the active GUI
220 boolean mouseOverTab = mouseX > LEFT_EDGE - TAB_WIDTH && mouseX < LEFT_EDGE && mouseY > TAB_TOP && mouseY < TAB_TOP + TAB_HEIGHT; 280 boolean mouseOverTab = mouseX > LEFT_EDGE - TAB_WIDTH && mouseX < LEFT_EDGE && mouseY > TAB_TOP && mouseY < TAB_TOP + TAB_HEIGHT;
221 this.handleMouseClick(mouseX, mouseY, partialTicks, active, mouseOverTab); 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 this.tabOpacity = mouseOverTab || this.tweenAmount > 0.0 ? 0.5F : Math.max(0.0F, this.tabOpacity - partialTicks * 0.1F); 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 this.drawPanel(mouseX, mouseY, partialTicks, active, xOffset); 287 this.drawPanel(mouseX, mouseY, partialTicks, active, xOffset);
225 } 288 }
226 289
@@ -236,31 +299,38 @@ public class GuiScreenModInfo extends GuiScreen @@ -236,31 +299,38 @@ public class GuiScreenModInfo extends GuiScreen
236 glPushMatrix(); 299 glPushMatrix();
237 glTranslatef(xOffset, 0.0F, 0.0F); 300 glTranslatef(xOffset, 0.0F, 0.0F);
238 301
  302 + // Draw the background and left edge
239 drawRect(LEFT_EDGE, 0, this.width, this.height, 0xB0000000); 303 drawRect(LEFT_EDGE, 0, this.width, this.height, 0xB0000000);
240 drawRect(LEFT_EDGE, 0, LEFT_EDGE + 1, TAB_TOP, 0xFFFFFFFF); 304 drawRect(LEFT_EDGE, 0, LEFT_EDGE + 1, TAB_TOP, 0xFFFFFFFF);
241 drawRect(LEFT_EDGE, TAB_TOP + TAB_HEIGHT, LEFT_EDGE + 1, this.height, 0xFFFFFFFF); 305 drawRect(LEFT_EDGE, TAB_TOP + TAB_HEIGHT, LEFT_EDGE + 1, this.height, 0xFFFFFFFF);
242 306
  307 + // Draw the tab
243 this.mc.getTextureManager().bindTexture(aboutTextureResource); 308 this.mc.getTextureManager().bindTexture(aboutTextureResource);
244 glDrawTexturedRect(LEFT_EDGE - TAB_WIDTH, TAB_TOP, TAB_WIDTH + 1, TAB_HEIGHT, 80, 80, 122, 160, 0.5F + this.tabOpacity); 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 if (this.tweenAmount > 0.0) 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 this.fontRenderer.drawString("Version " + LiteLoader.getVersion(), LEFT_EDGE + 12 + 38, 50, 0xFFFFFFFF); 319 this.fontRenderer.drawString("Version " + LiteLoader.getVersion(), LEFT_EDGE + 12 + 38, 50, 0xFFFFFFFF);
252 this.fontRenderer.drawString(this.activeModText, LEFT_EDGE + 12 + 38, 60, 0xFFAAAAAA); 320 this.fontRenderer.drawString(this.activeModText, LEFT_EDGE + 12 + 38, 60, 0xFFAAAAAA);
253 321
  322 + // Draw top and bottom horizontal rules
254 drawRect(LEFT_EDGE + 12, 80, this.width - 12, 81, 0xFF999999); 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 int innerWidth = this.width - LEFT_EDGE - 24 - 4; 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 super.drawScreen(mouseX, mouseY, partialTicks); 334 super.drawScreen(mouseX, mouseY, partialTicks);
265 } 335 }
266 336
@@ -271,49 +341,52 @@ public class GuiScreenModInfo extends GuiScreen @@ -271,49 +341,52 @@ public class GuiScreenModInfo extends GuiScreen
271 * @param mouseX 341 * @param mouseX
272 * @param mouseY 342 * @param mouseY
273 * @param partialTicks 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 glPushMatrix(); 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 int yPos = 0; 360 int yPos = 0;
289 for (GuiModListEntry mod : this.mods) 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 glPopMatrix(); 367 glPopMatrix();
295 glDisableClipping(); 368 glDisableClipping();
296 369
297 this.listHeight = yPos; 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 * @param mouseX 375 * @param mouseX
303 * @param mouseY 376 * @param mouseY
304 * @param partialTicks 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 if (this.selectedMod != null) 383 if (this.selectedMod != null)
311 { 384 {
312 - int left = LEFT_EDGE + 12 + listWidth; 385 + int left = LEFT_EDGE + 12 + width;
313 int right = this.width - 12; 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 glDisableClipping(); 390 glDisableClipping();
318 } 391 }
319 } 392 }
@@ -384,7 +457,7 @@ public class GuiScreenModInfo extends GuiScreen @@ -384,7 +457,7 @@ public class GuiScreenModInfo extends GuiScreen
384 this.scrollBar.setDragging(true); 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 for (GuiModListEntry mod : this.mods) 462 for (GuiModListEntry mod : this.mods)
390 { 463 {
@@ -456,11 +529,11 @@ public class GuiScreenModInfo extends GuiScreen @@ -456,11 +529,11 @@ public class GuiScreenModInfo extends GuiScreen
456 529
457 if (active && this.tweenAmount < 1.0) 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 else if (!active && this.tweenAmount > 0.0) 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 this.lastTick = tickValue; 539 this.lastTick = tickValue;
java/com/mumfrey/liteloader/gui/GuiSimpleScrollBar.java
@@ -121,7 +121,7 @@ public class GuiSimpleScrollBar extends Gui @@ -121,7 +121,7 @@ public class GuiSimpleScrollBar extends Gui
121 float pct = Math.min(1.0F, (float)slideHeight / (float)totalHeight); 121 float pct = Math.min(1.0F, (float)slideHeight / (float)totalHeight);
122 int barHeight = (int)(pct * slideHeight); 122 int barHeight = (int)(pct * slideHeight);
123 int barTravel = slideHeight - barHeight; 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 drawRect(xPosition + 1, barPosition, xPosition + width - 1, barPosition + barHeight, this.foreColour); 126 drawRect(xPosition + 1, barPosition, xPosition + width - 1, barPosition + barHeight, this.foreColour);
127 127