Commit cc303e4eb8b60adf43a2664cc9744dd13ebc0993

Authored by Mumfrey
1 parent 7aa49e45

LiteLoader 1.6.4_02 - dev only - added keyboard support to mod info list, better…

… behaviour when tab is "hidden"
java/com/mumfrey/liteloader/core/LiteLoader.java
... ... @@ -1062,12 +1062,12 @@ public final class LiteLoader
1062 1062 */
1063 1063 void postRender(int mouseX, int mouseY, float partialTicks)
1064 1064 {
1065   - if (this.minecraft.currentScreen instanceof GuiMainMenu && this.displayModInfoScreenTab && !this.hideModInfoScreenTab)
  1065 + if (this.minecraft.currentScreen instanceof GuiMainMenu && ((this.displayModInfoScreenTab && !this.hideModInfoScreenTab) || (this.modInfoScreen != null && this.modInfoScreen.isTweeningOrOpen())))
1066 1066 {
1067 1067 // If we're at the main menu, prepare the overlay
1068 1068 if (this.modInfoScreen == null || this.modInfoScreen.getMenu() != this.minecraft.currentScreen)
1069 1069 {
1070   - this.modInfoScreen = new GuiScreenModInfo(this.minecraft, (GuiMainMenu)this.minecraft.currentScreen, this, this.enabledModsList, this.configManager);
  1070 + this.modInfoScreen = new GuiScreenModInfo(this.minecraft, (GuiMainMenu)this.minecraft.currentScreen, this, this.enabledModsList, this.configManager, this.hideModInfoScreenTab);
1071 1071 }
1072 1072  
1073 1073 this.modInfoScreen.drawScreen(mouseX, mouseY, partialTicks);
... ... @@ -1221,7 +1221,8 @@ public final class LiteLoader
1221 1221 */
1222 1222 public void displayModInfoScreen(GuiMainMenu parentScreen)
1223 1223 {
1224   - this.minecraft.displayGuiScreen(new GuiScreenModInfo(this.minecraft, parentScreen, this, this.enabledModsList, this.configManager));
  1224 + this.modInfoScreen = new GuiScreenModInfo(this.minecraft, parentScreen, this, this.enabledModsList, this.configManager, this.hideModInfoScreenTab);
  1225 + this.minecraft.displayGuiScreen(this.modInfoScreen);
1225 1226 }
1226 1227  
1227 1228 private static void logInfo(String string, Object... args)
... ...
java/com/mumfrey/liteloader/gui/GuiModListEntry.java
... ... @@ -163,6 +163,11 @@ public class GuiModListEntry extends Gui
163 163 return PANEL_HEIGHT + PANEL_SPACING;
164 164 }
165 165  
  166 + public int getHeight()
  167 + {
  168 + return PANEL_HEIGHT + PANEL_SPACING;
  169 + }
  170 +
166 171 /**
167 172 * Draw this entry as the info page
168 173 *
... ...
java/com/mumfrey/liteloader/gui/GuiScreenModInfo.java
... ... @@ -96,6 +96,8 @@ public class GuiScreenModInfo extends GuiScreen
96 96 */
97 97 private float tabOpacity = 0.0F;
98 98  
  99 + private boolean hideTab = true;
  100 +
99 101 /**
100 102 * List of enumerated mods
101 103 */
... ... @@ -149,11 +151,13 @@ public class GuiScreenModInfo extends GuiScreen
149 151 * @param loader
150 152 * @param enabledModsList
151 153 */
152   - public GuiScreenModInfo(Minecraft minecraft, GuiMainMenu mainMenu, LiteLoader loader, EnabledModsList enabledModsList, ConfigManager configManager)
  154 + public GuiScreenModInfo(Minecraft minecraft, GuiMainMenu mainMenu, LiteLoader loader, EnabledModsList enabledModsList, ConfigManager configManager, boolean hideTab)
153 155 {
154 156 this.mc = minecraft;
  157 + this.fontRenderer = minecraft.fontRenderer;
155 158 this.mainMenu = mainMenu;
156 159 this.configManager = configManager;
  160 + this.hideTab = hideTab;
157 161  
158 162 // Spawn the texture resource if we haven't already
159 163 if (aboutTexture == null)
... ... @@ -220,7 +224,15 @@ public class GuiScreenModInfo extends GuiScreen
220 224 {
221 225 return this.mainMenu;
222 226 }
223   -
  227 +
  228 + /**
  229 + * @return
  230 + */
  231 + public boolean isTweeningOrOpen()
  232 + {
  233 + return this.tweenAmount > 0.0;
  234 + }
  235 +
224 236 /* (non-Javadoc)
225 237 * @see net.minecraft.src.GuiScreen#initGui()
226 238 */
... ... @@ -233,14 +245,25 @@ public class GuiScreenModInfo extends GuiScreen
233 245 this.configPanel.setSize(this.width - LEFT_EDGE, this.height);
234 246 }
235 247  
236   - int left = LEFT_EDGE + MARGIN + 4 + (this.width - LEFT_EDGE - MARGIN - MARGIN - 4) / 2;
  248 + int rightPanelLeftEdge = LEFT_EDGE + MARGIN + 4 + (this.width - LEFT_EDGE - MARGIN - MARGIN - 4) / 2;
237 249  
238 250 this.buttonList.clear();
239   - this.buttonList.add(this.btnToggle = new GuiButton(0, left, this.height - PANEL_BOTTOM - 24, 90, 20, "Enable mod"));
240   - this.buttonList.add(this.btnConfig = new GuiButton(1, left + 92, this.height - PANEL_BOTTOM - 24, 69, 20, "Settings..."));
241   - this.buttonList.add(this.chkEnabled = new GuiCheckbox(2, LEFT_EDGE + MARGIN, this.height - PANEL_BOTTOM + 9, "Show LiteLoader tab on main menu"));
  251 + this.buttonList.add(this.btnToggle = new GuiButton(0, rightPanelLeftEdge, this.height - PANEL_BOTTOM - 24, 90, 20, "Enable mod"));
  252 + this.buttonList.add(this.btnConfig = new GuiButton(1, rightPanelLeftEdge + 92, this.height - PANEL_BOTTOM - 24, 69, 20, "Settings..."));
  253 + if (!this.hideTab)
  254 + {
  255 + this.buttonList.add(this.chkEnabled = new GuiCheckbox(2, LEFT_EDGE + MARGIN, this.height - PANEL_BOTTOM + 9, "Show LiteLoader tab on main menu"));
  256 + }
242 257  
243 258 this.selectMod(this.selectedMod);
  259 +
  260 + Keyboard.enableRepeatEvents(true);
  261 + }
  262 +
  263 + @Override
  264 + public void onGuiClosed()
  265 + {
  266 + Keyboard.enableRepeatEvents(false);
244 267 }
245 268  
246 269 /* (non-Javadoc)
... ... @@ -273,8 +296,10 @@ public class GuiScreenModInfo extends GuiScreen
273 296  
274 297 if (this.mc.currentScreen == this)
275 298 {
  299 + this.mc.currentScreen = this.mainMenu;
276 300 this.mainMenu.updateScreen();
277   - this.chkEnabled.checked = LiteLoader.getInstance().getDisplayModInfoScreenTab();
  301 + this.mc.currentScreen = this;
  302 + if (this.chkEnabled != null) this.chkEnabled.checked = LiteLoader.getInstance().getDisplayModInfoScreenTab();
278 303 }
279 304  
280 305 if (this.toggled)
... ... @@ -310,17 +335,22 @@ public class GuiScreenModInfo extends GuiScreen
310 335  
311 336 // Calculate the current tween position
312 337 float xOffset = (this.width - LEFT_EDGE) * this.calcTween(partialTicks, active) + 16.0F + (this.tabOpacity * -32.0F);
313   - mouseX -= (int)xOffset;
  338 + int offsetMouseX = mouseX - (int)xOffset;
314 339  
315 340 // Handle mouse stuff here since we won't get mouse events when not the active GUI
316   - boolean mouseOverTab = mouseX > LEFT_EDGE - TAB_WIDTH && mouseX < LEFT_EDGE && mouseY > TAB_TOP && mouseY < TAB_TOP + TAB_HEIGHT;
317   - this.handleMouseClick(mouseX, mouseY, partialTicks, active, mouseOverTab);
  341 + boolean mouseOverTab = !this.hideTab && (offsetMouseX > LEFT_EDGE - TAB_WIDTH && offsetMouseX < LEFT_EDGE && mouseY > TAB_TOP && mouseY < TAB_TOP + TAB_HEIGHT);
  342 + this.handleMouseClick(offsetMouseX, mouseY, partialTicks, active, mouseOverTab);
318 343  
319 344 // Calculate the tab opacity, not framerate adjusted because we don't really care
320   - this.tabOpacity = mouseOverTab || this.tweenAmount > 0.0 ? 0.5F : Math.max(0.0F, this.tabOpacity - partialTicks * 0.1F);
  345 + this.tabOpacity = mouseOverTab || this.isTweeningOrOpen() ? 0.5F : Math.max(0.0F, this.tabOpacity - partialTicks * 0.1F);
321 346  
322 347 // Draw the panel contents
323   - this.drawPanel(mouseX, mouseY, partialTicks, active, xOffset);
  348 + this.drawPanel(offsetMouseX, mouseY, partialTicks, active, xOffset);
  349 +
  350 + if (mouseOverTab && this.tweenAmount < 0.01)
  351 + {
  352 + this.drawTooltip("LiteLoader Mods", mouseX, mouseY, this.width - TAB_WIDTH - 2, this.height, 0xFFFFFF, 0xB0000000);
  353 + }
324 354 }
325 355  
326 356 /**
... ... @@ -337,15 +367,23 @@ public class GuiScreenModInfo extends GuiScreen
337 367  
338 368 // Draw the background and left edge
339 369 drawRect(LEFT_EDGE, 0, this.width, this.height, 0xB0000000);
340   - drawRect(LEFT_EDGE, 0, LEFT_EDGE + 1, TAB_TOP, 0xFFFFFFFF);
341   - drawRect(LEFT_EDGE, TAB_TOP + TAB_HEIGHT, LEFT_EDGE + 1, this.height, 0xFFFFFFFF);
342 370  
343   - // Draw the tab
344   - this.mc.getTextureManager().bindTexture(aboutTextureResource);
345   - glDrawTexturedRect(LEFT_EDGE - TAB_WIDTH, TAB_TOP, TAB_WIDTH + 1, TAB_HEIGHT, 80, 80, 122, 160, 0.5F + this.tabOpacity);
346   -
  371 + if (!this.hideTab)
  372 + {
  373 + drawRect(LEFT_EDGE, 0, LEFT_EDGE + 1, TAB_TOP, 0xFFFFFFFF);
  374 + drawRect(LEFT_EDGE, TAB_TOP + TAB_HEIGHT, LEFT_EDGE + 1, this.height, 0xFFFFFFFF);
  375 +
  376 + this.mc.getTextureManager().bindTexture(aboutTextureResource);
  377 + glDrawTexturedRect(LEFT_EDGE - TAB_WIDTH, TAB_TOP, TAB_WIDTH + 1, TAB_HEIGHT, 80, 80, 122, 160, 0.5F + this.tabOpacity);
  378 + }
  379 + else
  380 + {
  381 + drawRect(LEFT_EDGE, 0, LEFT_EDGE + 1, this.height, 0xFFFFFFFF);
  382 + this.mc.getTextureManager().bindTexture(aboutTextureResource);
  383 + }
  384 +
347 385 // Only draw the panel contents if we are actually open
348   - if (this.tweenAmount > 0.0)
  386 + if (this.isTweeningOrOpen())
349 387 {
350 388 if (this.configPanel != null)
351 389 {
... ... @@ -487,6 +525,18 @@ public class GuiScreenModInfo extends GuiScreen
487 525 this.btnConfig.drawButton = this.configManager.hasPanel(this.selectedMod.getModClass());
488 526 }
489 527 }
  528 +
  529 + /**
  530 + * Toggle the selected mod's enabled status
  531 + */
  532 + public void toggleSelectedMod()
  533 + {
  534 + if (this.selectedMod != null)
  535 + {
  536 + this.selectedMod.toggleEnabled();
  537 + this.selectMod(this.selectedMod);
  538 + }
  539 + }
490 540  
491 541 /* (non-Javadoc)
492 542 * @see net.minecraft.src.GuiScreen#actionPerformed(net.minecraft.src.GuiButton)
... ... @@ -494,10 +544,9 @@ public class GuiScreenModInfo extends GuiScreen
494 544 @Override
495 545 protected void actionPerformed(GuiButton button)
496 546 {
497   - if (button.id == 0 && this.selectedMod != null)
  547 + if (button.id == 0)
498 548 {
499   - this.selectedMod.toggleEnabled();
500   - this.selectMod(this.selectedMod);
  549 + this.toggleSelectedMod();
501 550 }
502 551  
503 552 if (button.id == 1)
... ... @@ -505,7 +554,7 @@ public class GuiScreenModInfo extends GuiScreen
505 554 this.openConfigPanel();
506 555 }
507 556  
508   - if (button.id == 2)
  557 + if (button.id == 2 && this.chkEnabled != null)
509 558 {
510 559 this.chkEnabled.checked = !this.chkEnabled.checked;
511 560 LiteLoader.getInstance().setDisplayModInfoScreenTab(this.chkEnabled.checked);
... ... @@ -534,8 +583,52 @@ public class GuiScreenModInfo extends GuiScreen
534 583 this.onToggled();
535 584 return;
536 585 }
  586 + else if (keyCode == Keyboard.KEY_UP)
  587 + {
  588 + int selectedIndex = this.mods.indexOf(this.selectedMod) - 1;
  589 + if (selectedIndex > -1) this.selectMod(this.mods.get(selectedIndex));
  590 + this.scrollSelectedModIntoView();
  591 + }
  592 + else if (keyCode == Keyboard.KEY_DOWN)
  593 + {
  594 + int selectedIndex = this.mods.indexOf(this.selectedMod);
  595 + if (selectedIndex > -1 && selectedIndex < this.mods.size() - 1) this.selectMod(this.mods.get(selectedIndex + 1));
  596 + this.scrollSelectedModIntoView();
  597 + }
  598 + else if (keyCode == Keyboard.KEY_SPACE || keyCode == Keyboard.KEY_RETURN || keyCode == Keyboard.KEY_NUMPADENTER || keyCode == Keyboard.KEY_RIGHT)
  599 + {
  600 + this.toggleSelectedMod();
  601 + }
537 602 }
538 603  
  604 + private void scrollSelectedModIntoView()
  605 + {
  606 + if (this.selectedMod == null) return;
  607 +
  608 + int yPos = 0;
  609 + for (GuiModListEntry mod : this.mods)
  610 + {
  611 + if (mod == this.selectedMod) break;
  612 + yPos += mod.getHeight();
  613 + }
  614 +
  615 + // Mod is above the top of the visible window
  616 + if (yPos < this.scrollBar.getValue())
  617 + {
  618 + this.scrollBar.setValue(yPos);
  619 + return;
  620 + }
  621 +
  622 + int panelHeight = this.height - PANEL_BOTTOM - PANEL_TOP;
  623 + int modHeight = this.selectedMod.getHeight();
  624 +
  625 + // Mod is below the bottom of the visible window
  626 + if (yPos - this.scrollBar.getValue() + modHeight > panelHeight)
  627 + {
  628 + this.scrollBar.setValue(yPos - panelHeight + modHeight);
  629 + }
  630 + }
  631 +
539 632 /* (non-Javadoc)
540 633 * @see net.minecraft.src.GuiScreen#mouseClicked(int, int, int)
541 634 */
... ... @@ -630,7 +723,7 @@ public class GuiScreenModInfo extends GuiScreen
630 723 public void handleMouseClick(int mouseX, int mouseY, float partialTicks, boolean active, boolean mouseOverTab)
631 724 {
632 725 boolean mouseDown = Mouse.isButtonDown(0);
633   - if (((active && mouseX < LEFT_EDGE) || mouseOverTab) && !this.mouseDown && mouseDown)
  726 + if (((active && mouseX < LEFT_EDGE && this.tweenAmount > 0.75) || mouseOverTab) && !this.mouseDown && mouseDown)
634 727 {
635 728 this.mouseDown = true;
636 729 this.toggled = true;
... ... @@ -654,7 +747,7 @@ public class GuiScreenModInfo extends GuiScreen
654 747 {
655 748 this.tweenAmount = Math.min(1.0, this.tweenAmount + ((tickValue - this.lastTick) * TWEEN_RATE));
656 749 }
657   - else if (!active && this.tweenAmount > 0.0)
  750 + else if (!active && this.isTweeningOrOpen())
658 751 {
659 752 this.tweenAmount = Math.max(0.0, this.tweenAmount - ((tickValue - this.lastTick) * TWEEN_RATE));
660 753 }
... ... @@ -707,6 +800,29 @@ public class GuiScreenModInfo extends GuiScreen
707 800 }
708 801  
709 802 /**
  803 + * Draw a tooltip at the specified location and clip to screenWidth and screenHeight
  804 + *
  805 + * @param fontRenderer
  806 + * @param tooltipText
  807 + * @param mouseX
  808 + * @param mouseY
  809 + * @param screenWidth
  810 + * @param screenHeight
  811 + * @param colour
  812 + * @param backgroundColour
  813 + */
  814 + protected void drawTooltip(String tooltipText, int mouseX, int mouseY, int screenWidth, int screenHeight, int colour, int backgroundColour)
  815 + {
  816 + int textSize = this.fontRenderer.getStringWidth(tooltipText);
  817 + mouseX = Math.max(0, Math.min(screenWidth - textSize - 6, mouseX - 6));
  818 + mouseY = Math.max(0, Math.min(screenHeight - 16, mouseY - 18));
  819 +
  820 + drawRect(mouseX, mouseY, mouseX + textSize + 6, mouseY + 16, backgroundColour);
  821 + this.fontRenderer.drawStringWithShadow(tooltipText, mouseX + 3, mouseY + 4, colour);
  822 + }
  823 +
  824 +
  825 + /**
710 826 * @param x
711 827 * @param y
712 828 * @param width
... ...