GuiLiteLoaderPanel.java
27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
/*
* This file is part of LiteLoader.
* Copyright (C) 2012-16 Adam Mummery-Smith
* All Rights Reserved.
*/
package com.mumfrey.liteloader.client.gui;
import static com.mumfrey.liteloader.gl.GL.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import com.mumfrey.liteloader.LiteMod;
import com.mumfrey.liteloader.api.BrandingProvider;
import com.mumfrey.liteloader.api.LiteAPI;
import com.mumfrey.liteloader.api.ModInfoDecorator;
import com.mumfrey.liteloader.client.api.LiteLoaderBrandingProvider;
import com.mumfrey.liteloader.core.LiteLoader;
import com.mumfrey.liteloader.core.LiteLoaderMods;
import com.mumfrey.liteloader.core.LiteLoaderVersion;
import com.mumfrey.liteloader.core.ModInfo;
import com.mumfrey.liteloader.core.api.LiteLoaderCoreAPI;
import com.mumfrey.liteloader.launch.LoaderEnvironment;
import com.mumfrey.liteloader.launch.LoaderProperties;
import com.mumfrey.liteloader.modconfig.ConfigManager;
import com.mumfrey.liteloader.modconfig.ConfigPanel;
import com.mumfrey.liteloader.util.render.Icon;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.VertexBuffer;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.ResourceLocation;
/**
* GUI screen which displays info about loaded mods and also allows them to be
* enabled and disabled. An instance of this class is created every time the
* main menu is displayed and is drawn as an overlay until the tab is clicked,
* at which point it becomes the active GUI screen and draws the parent main
* menu screen as its background to give the appearance of being overlaid on the
* main menu.
*
* @author Adam Mummery-Smith
*/
public class GuiLiteLoaderPanel extends GuiScreen
{
static final int WHITE = 0xFFFFFFFF;
static final int OPAQUE = 0xFF000000;
static final int NOTIFICATION_TOOLTIP_FOREGROUND = 0xFFFFFF;
static final int NOTIFICATION_TOOLTIP_BACKGROUND = 0xB0000099;
static final int ERROR_TOOLTIP_FOREGROUND = 0xFF5555;
static final int ERROR_TOOLTIP_BACKGROUND = 0xB0330000;
static final int HEADER_HR_COLOUR = 0xFF999999;
static final int HEADER_TEXT_COLOUR = GuiLiteLoaderPanel.WHITE;
static final int HEADER_TEXT_COLOUR_SUB = 0xFFAAAAAA;
static final int TOOLTIP_FOREGROUND = 0xFFFFFF;
static final int TOOLTIP_FOREGROUND_SUB = 0xCCCCCC;
static final int TOOLTIP_BACKGROUND = 0xB0000000;
static final int LEFT_EDGE = 80;
static final int MARGIN = 12;
static final int TAB_WIDTH = 20;
static final int TAB_HEIGHT = 40;
static final int TAB_TOP = 20;
static final int PANEL_TOP = 83;
static final int PANEL_BOTTOM = 26;
private static final double TWEEN_RATE = 0.08;
private static boolean displayErrorToolTip = true;
/**
* Reference to the main menu which this screen is either overlaying or
* using as its background.
*/
private GuiScreen parentScreen;
@SuppressWarnings("unused")
private final LoaderEnvironment environment;
private final LoaderProperties properties;
/**
* Tick number (update counter) used for tweening
*/
private long tickNumber;
/**
* Last tick number, for tweening
*/
private double lastTick;
/**
* Current tween percentage (0.0 -> 1.0)
*/
private double tweenAmount = 0.0;
/**
* Since we don't get real mouse events we have to simulate them by tracking
* the mouse state.
*/
private boolean mouseDown, toggled, toggleable;
/**
* Hover opacity for the tab
*/
private float tabOpacity = 0.0F;
private boolean showTab = true;
/**
* Text to display under the header
*/
private String activeModText, versionText;
/**
* Configuration panel
*/
private GuiPanel currentPanel;
private final GuiPanelMods modsPanel;
private final GuiPanelSettings settingsPanel;
private int brandColour = LiteLoaderBrandingProvider.BRANDING_COLOUR;
private ResourceLocation logoResource = LiteLoaderBrandingProvider.ABOUT_TEXTURE;
private Icon logoCoords = LiteLoaderBrandingProvider.LOGO_COORDS;
private ResourceLocation iconResource = LiteLoaderBrandingProvider.ABOUT_TEXTURE;
private Icon iconCoords = LiteLoaderBrandingProvider.ICON_COORDS;
private List<ModInfoDecorator> modInfoDecorators = new ArrayList<ModInfoDecorator>();
private boolean mouseOverLogo = false;
private int startupErrorCount = 0, criticalErrorCount = 0;
private String notification;
private boolean isSnapshot;
/**
* @param minecraft
* @param parentScreen
* @param mods
*/
public GuiLiteLoaderPanel(Minecraft minecraft, GuiScreen parentScreen, LiteLoaderMods mods, LoaderEnvironment environment,
LoaderProperties properties, ConfigManager configManager, boolean showTab)
{
this.mc = minecraft;
this.fontRendererObj = minecraft.fontRendererObj;
this.parentScreen = parentScreen;
this.showTab = showTab;
this.environment = environment;
this.properties = properties;
this.toggleable = true;
this.versionText = I18n.format("gui.about.versiontext", LiteLoader.getVersion());
this.activeModText = I18n.format("gui.about.modsloaded", LiteLoader.getLoadedModsCount());
this.initBranding();
this.currentPanel = this.modsPanel = new GuiPanelMods(this, minecraft, mods, environment, configManager,
this.brandColour, this.modInfoDecorators);
this.settingsPanel = new GuiPanelSettings(this, minecraft);
this.startupErrorCount = mods.getStartupErrorCount();
this.criticalErrorCount = mods.getCriticalErrorCount();
String branding = LiteLoader.getBranding();
if (branding != null && branding.contains("SNAPSHOT"))
{
this.isSnapshot = true;
this.versionText = "\247c" + branding;
}
}
/**
*
*/
private void initBranding()
{
LiteAPI logoProvider = null;
int brandingColourProviderPriority = Integer.MIN_VALUE;
int logoProviderPriority = Integer.MIN_VALUE;
int iconProviderPriority = Integer.MIN_VALUE;
for (LiteAPI api : LiteLoader.getAPIs())
{
BrandingProvider brandingProvider = LiteLoader.getCustomisationProvider(api, BrandingProvider.class);
if (brandingProvider != null)
{
if (brandingProvider.getBrandingColour() != 0 && brandingProvider.getPriority() > brandingColourProviderPriority)
{
brandingColourProviderPriority = brandingProvider.getPriority();
this.brandColour = GuiLiteLoaderPanel.OPAQUE | brandingProvider.getBrandingColour();
}
ResourceLocation logoResource = brandingProvider.getLogoResource();
Icon logoCoords = brandingProvider.getLogoCoords();
if (logoResource != null && logoCoords != null && brandingProvider.getPriority() > logoProviderPriority)
{
logoProvider = api;
logoProviderPriority = brandingProvider.getPriority();
this.logoResource = logoResource;
this.logoCoords = logoCoords;
}
ResourceLocation iconResource = brandingProvider.getIconResource();
Icon iconCoords = brandingProvider.getIconCoords();
if (iconResource != null && iconCoords != null && brandingProvider.getPriority() > iconProviderPriority)
{
iconProviderPriority = brandingProvider.getPriority();
this.iconResource = iconResource;
this.iconCoords = iconCoords;
}
}
ModInfoDecorator modInfoDecorator = LiteLoader.getCustomisationProvider(api, ModInfoDecorator.class);
if (modInfoDecorator != null)
{
this.modInfoDecorators.add(modInfoDecorator);
}
}
if (logoProvider != null && !LiteLoaderCoreAPI.class.isAssignableFrom(logoProvider.getClass()))
{
this.versionText = I18n.format("gui.about.poweredbyversion", logoProvider.getVersion(), LiteLoader.getVersion());
}
}
/**
* Get the computed branding colour
*/
public int getBrandColour()
{
return this.brandColour;
}
/**
* Release references prior to being disposed
*/
public void release()
{
this.parentScreen = null;
}
/**
* Get the parent menu
*/
public GuiScreen getScreen()
{
return this.parentScreen;
}
/**
* Return true if the panel is not fully closed (tweening or open)
*/
public boolean isOpen()
{
return this.tweenAmount > 0.0;
}
public void setToggleable(boolean toggleable)
{
this.toggleable = toggleable;
}
public void setNotification(String notification)
{
this.notification = notification;
}
/* (non-Javadoc)
* @see net.minecraft.client.gui.GuiScreen#initGui()
*/
@Override
public void initGui()
{
// Hide the tooltip once the user opens the panel
GuiLiteLoaderPanel.displayErrorToolTip = false;
this.currentPanel.setSize(this.width - LEFT_EDGE, this.height);
this.buttonList.add(new GuiHoverLabel(2, LEFT_EDGE + MARGIN, this.height - PANEL_BOTTOM + 9, this.fontRendererObj,
I18n.format("gui.about.taboptions"), this.brandColour));
if (LiteLoaderVersion.getUpdateSite().canCheckForUpdate() && this.mc.theWorld == null && !this.isSnapshot)
{
this.buttonList.add(new GuiHoverLabel(3, LEFT_EDGE + MARGIN + 38 + this.fontRendererObj.getStringWidth(this.versionText) + 6, 50,
this.fontRendererObj, I18n.format("gui.about.checkupdates"), this.brandColour));
}
Keyboard.enableRepeatEvents(true);
}
@Override
public void onGuiClosed()
{
Keyboard.enableRepeatEvents(false);
}
/* (non-Javadoc)
* @see net.minecraft.client.gui.GuiScreen
* #setWorldAndResolution(net.minecraft.client.Minecraft, int, int)
*/
@Override
public void setWorldAndResolution(Minecraft minecraft, int width, int height)
{
if (this.mc.currentScreen == this)
{
// Set res in parent screen if we are the active GUI
this.parentScreen.setWorldAndResolution(minecraft, width, height);
}
super.setWorldAndResolution(minecraft, width, height);
}
/* (non-Javadoc)
* @see net.minecraft.client.gui.GuiScreen#updateScreen()
*/
@Override
public void updateScreen()
{
this.currentPanel.onTick();
this.tickNumber++;
if (this.mc.currentScreen == this)
{
this.mc.currentScreen = this.parentScreen;
this.parentScreen.updateScreen();
this.mc.currentScreen = this;
}
if (this.toggled && this.toggleable)
{
this.onToggled();
}
}
/* (non-Javadoc)
* @see net.minecraft.client.gui.GuiScreen#drawScreen(int, int, float)
*/
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
this.drawScreen(mouseX, mouseY, partialTicks, false);
}
/**
* @param mouseX
* @param mouseY
* @param partialTicks
* @param alwaysExpandTab
*/
public void drawScreen(int mouseX, int mouseY, float partialTicks, boolean alwaysExpandTab)
{
boolean active = this.mc.currentScreen == this;
if (active)
{
// Draw the parent screen as our background if we are the active screen
glClear(GL_DEPTH_BUFFER_BIT);
this.parentScreen.drawScreen(-10, -10, partialTicks);
glClear(GL_DEPTH_BUFFER_BIT);
}
else
{
// If this is not the active screen, copy the width and height from the parent GUI
this.width = this.parentScreen.width;
this.height = this.parentScreen.height;
}
// Calculate the current tween position
float xOffset = (this.width - LEFT_EDGE) * this.calcTween(partialTicks, active) + 16.0F + (this.tabOpacity * -32.0F);
int offsetMouseX = mouseX - (int)xOffset;
// Handle mouse stuff here since we won't get mouse events when not the active GUI
boolean mouseOverTab = this.showTab && (offsetMouseX > LEFT_EDGE - TAB_WIDTH
&& offsetMouseX < LEFT_EDGE
&& mouseY > TAB_TOP
&& mouseY < TAB_TOP + TAB_HEIGHT);
this.handleMouseClick(offsetMouseX, mouseY, partialTicks, active, mouseOverTab);
// Calculate the tab opacity, not framerate adjusted because we don't really care
this.tabOpacity = mouseOverTab || alwaysExpandTab || this.startupErrorCount > 0 || this.notification != null
|| this.isOpen() ? 0.5F : Math.max(0.0F, this.tabOpacity - partialTicks * 0.1F);
// Draw the panel contents
this.drawPanel(offsetMouseX, mouseY, partialTicks, active, xOffset);
this.drawTooltips(mouseX, mouseY, partialTicks, active, xOffset, mouseOverTab);
}
/**
* @param mouseX
* @param mouseY
* @param partialTicks
* @param active
* @param xOffset
*/
private void drawPanel(int mouseX, int mouseY, float partialTicks, boolean active, float xOffset)
{
this.mouseOverLogo = false;
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
glPushMatrix();
glTranslatef(xOffset, 0.0F, 0.0F);
// Draw the background and left edge
drawRect(LEFT_EDGE, 0, this.width, this.height, GuiLiteLoaderPanel.TOOLTIP_BACKGROUND);
if (this.showTab)
{
drawRect(LEFT_EDGE, 0, LEFT_EDGE + 1, TAB_TOP, GuiLiteLoaderPanel.WHITE);
drawRect(LEFT_EDGE, TAB_TOP + TAB_HEIGHT, LEFT_EDGE + 1, this.height, GuiLiteLoaderPanel.WHITE);
this.mc.getTextureManager().bindTexture(LiteLoaderBrandingProvider.ABOUT_TEXTURE);
glDrawTexturedRect(LEFT_EDGE - TAB_WIDTH, TAB_TOP, TAB_WIDTH + 1, TAB_HEIGHT, 80, 80, 122, 160, 0.5F + this.tabOpacity);
if (this.startupErrorCount > 0)
{
glDrawTexturedRect(LEFT_EDGE - TAB_WIDTH + 7, TAB_TOP + 2, 12, 12, 134, 92, 134 + 12, 92 + 12, 0.5F + this.tabOpacity);
}
else if (this.notification != null)
{
glDrawTexturedRect(LEFT_EDGE - TAB_WIDTH + 7, TAB_TOP + 2, 12, 12, 134 + 12, 92, 134 + 24, 92 + 12, 0.5F + this.tabOpacity);
}
}
else
{
drawRect(LEFT_EDGE, 0, LEFT_EDGE + 1, this.height, GuiLiteLoaderPanel.WHITE);
}
// Only draw the panel contents if we are actually open
if (this.isOpen())
{
if (this.currentPanel.isCloseRequested())
{
this.closeCurrentPanel();
}
this.drawCurrentPanel(mouseX, mouseY, partialTicks);
if (!this.currentPanel.stealFocus())
{
// Draw other controls inside the transform so that they slide properly
super.drawScreen(mouseX, mouseY, partialTicks);
}
}
else
{
this.closeCurrentPanel();
}
glPopMatrix();
}
/**
* @param mouseX
* @param mouseY
* @param partialTicks
*/
private void drawCurrentPanel(int mouseX, int mouseY, float partialTicks)
{
glPushMatrix();
glTranslatef(LEFT_EDGE, 0, 0);
this.currentPanel.draw(mouseX - LEFT_EDGE, mouseY, partialTicks);
glPopMatrix();
}
/**
* @param mouseX
* @param mouseY
* @param partialTicks
*/
protected boolean drawInfoPanel(int mouseX, int mouseY, float partialTicks, int left, int bottom)
{
int right = this.width - MARGIN - LEFT_EDGE + left;
left += MARGIN;
// Draw the header pieces
this.mc.getTextureManager().bindTexture(this.logoResource);
glDrawTexturedRect(left, MARGIN, this.logoCoords, 1.0F);
this.mc.getTextureManager().bindTexture(this.iconResource);
glDrawTexturedRect(right - this.iconCoords.getIconWidth(), MARGIN, this.iconCoords, 1.0F);
// Draw header text
this.fontRendererObj.drawString(this.versionText, left + 38, 50, GuiLiteLoaderPanel.HEADER_TEXT_COLOUR);
this.fontRendererObj.drawString(this.activeModText, left + 38, 60, GuiLiteLoaderPanel.HEADER_TEXT_COLOUR_SUB);
// Draw top and bottom horizontal rules
drawRect(left, 80, right, 81, GuiLiteLoaderPanel.HEADER_HR_COLOUR);
drawRect(left, this.height - bottom + 2, right, this.height - bottom + 3, GuiLiteLoaderPanel.HEADER_HR_COLOUR);
this.mouseOverLogo = (mouseY > MARGIN && mouseY < MARGIN + this.logoCoords.getIconHeight()
&& mouseX > left && mouseX < left + this.logoCoords.getIconWidth());
return this.mouseOverLogo;
}
private void drawTooltips(int mouseX, int mouseY, float partialTicks, boolean active, float xOffset, boolean mouseOverTab)
{
boolean annoyingTip = this.startupErrorCount > 0 || this.notification != null;
if (mouseOverTab && this.tweenAmount < 0.01)
{
GuiLiteLoaderPanel.drawTooltip(this.fontRendererObj, LiteLoader.getVersionDisplayString(), mouseX, mouseY, this.width, this.height,
GuiLiteLoaderPanel.TOOLTIP_FOREGROUND, GuiLiteLoaderPanel.TOOLTIP_BACKGROUND);
GuiLiteLoaderPanel.drawTooltip(this.fontRendererObj, this.activeModText, mouseX, mouseY + 13, this.width, this.height,
GuiLiteLoaderPanel.TOOLTIP_FOREGROUND_SUB, GuiLiteLoaderPanel.TOOLTIP_BACKGROUND);
if (annoyingTip)
{
this.drawNotificationTooltip(mouseX, mouseY - 13);
}
}
else if (GuiLiteLoaderPanel.displayErrorToolTip && annoyingTip && !active && this.parentScreen instanceof GuiMainMenu)
{
this.drawNotificationTooltip((int)xOffset + LEFT_EDGE - 12, TAB_TOP + 2);
}
}
private void drawNotificationTooltip(int left, int top)
{
if (this.startupErrorCount > 0)
{
GuiLiteLoaderPanel.drawTooltip(this.fontRendererObj, I18n.format("gui.error.tooltip", this.startupErrorCount, this.criticalErrorCount),
left, top, this.width, this.height, GuiLiteLoaderPanel.ERROR_TOOLTIP_FOREGROUND, GuiLiteLoaderPanel.ERROR_TOOLTIP_BACKGROUND);
}
else if (this.notification != null)
{
GuiLiteLoaderPanel.drawTooltip(this.fontRendererObj, this.notification, left, top, this.width, this.height,
GuiLiteLoaderPanel.NOTIFICATION_TOOLTIP_FOREGROUND, GuiLiteLoaderPanel.NOTIFICATION_TOOLTIP_BACKGROUND);
}
}
/* (non-Javadoc)
* @see net.minecraft.client.gui.GuiScreen
* #actionPerformed(net.minecraft.client.gui.GuiButton)
*/
@Override
protected void actionPerformed(GuiButton button)
{
if (button.id == 2)
{
this.setCurrentPanel(this.settingsPanel);
}
if (button.id == 3)
{
this.setCurrentPanel(new GuiPanelUpdateCheck(this, this.mc, LiteLoaderVersion.getUpdateSite(), "LiteLoader", this.properties));
}
}
/* (non-Javadoc)
* @see net.minecraft.client.gui.GuiScreen#keyTyped(char, int)
*/
@Override
protected void keyTyped(char keyChar, int keyCode)
{
this.currentPanel.keyPressed(keyChar, keyCode);
}
/**
*
*/
void showLogPanel()
{
this.setCurrentPanel(new GuiPanelLiteLoaderLog(this.mc, this));
}
/**
*
*/
void showAboutPanel()
{
this.setCurrentPanel(new GuiPanelAbout(this.mc, this));
}
public void showErrorPanel(ModInfo<?> mod)
{
this.setCurrentPanel(new GuiPanelError(this.mc, this, mod));
}
/* (non-Javadoc)
* @see net.minecraft.client.gui.GuiScreen#mouseClicked(int, int, int)
*/
@Override
protected void mouseClicked(int mouseX, int mouseY, int button) throws IOException
{
this.currentPanel.mousePressed(mouseX - LEFT_EDGE, mouseY, button);
if (button == 0 && this.mouseOverLogo && !this.currentPanel.stealFocus())
{
this.showAboutPanel();
}
if (!this.currentPanel.stealFocus())
{
super.mouseClicked(mouseX, mouseY, button);
}
}
/* (non-Javadoc)
* @see net.minecraft.client.gui.GuiScreen#mouseReleased(int, int, int)
*/
@Override
protected void mouseReleased(int mouseX, int mouseY, int button)
{
if (button == -1)
{
this.currentPanel.mouseMoved(mouseX - LEFT_EDGE, mouseY);
}
else
{
this.currentPanel.mouseReleased(mouseX - LEFT_EDGE, mouseY, button);
}
if (!this.currentPanel.stealFocus())
{
super.mouseReleased(mouseX, mouseY, button);
}
}
/* (non-Javadoc)
* @see net.minecraft.client.gui.GuiScreen#handleMouseInput()
*/
@Override
public void handleMouseInput() throws IOException
{
int mouseWheelDelta = Mouse.getEventDWheel();
if (mouseWheelDelta != 0)
{
this.currentPanel.mouseWheelScrolled(mouseWheelDelta);
}
super.handleMouseInput();
}
/**
* @param mouseX
* @param active
* @param mouseOverTab
*/
public void handleMouseClick(int mouseX, int mouseY, float partialTicks, boolean active, boolean mouseOverTab)
{
boolean mouseDown = Mouse.isButtonDown(0);
if (((active && mouseX < LEFT_EDGE && this.tweenAmount > 0.75) || mouseOverTab) && !this.mouseDown && mouseDown)
{
this.mouseDown = true;
this.toggled = true;
}
else if (this.mouseDown && !mouseDown)
{
this.mouseDown = false;
}
}
/**
* @param partialTicks
* @param active
*/
private float calcTween(float partialTicks, boolean active)
{
double tickValue = this.tickNumber + partialTicks;
if (active && this.tweenAmount < 1.0)
{
this.tweenAmount = Math.min(1.0, this.tweenAmount + ((tickValue - this.lastTick) * TWEEN_RATE));
}
else if (!active && this.isOpen())
{
this.tweenAmount = Math.max(0.0, this.tweenAmount - ((tickValue - this.lastTick) * TWEEN_RATE));
}
this.lastTick = tickValue;
return 1.0F - (float)Math.sin(this.tweenAmount * 0.5 * Math.PI);
}
/**
* Called when the tab is clicked
*/
void onToggled()
{
this.toggled = false;
this.mc.displayGuiScreen(this.mc.currentScreen == this ? this.parentScreen : this);
}
/**
* Callback for the "config" button, display the config panel for the
* currently selected mod.
*/
void openConfigPanel(ConfigPanel panel, LiteMod mod)
{
if (panel != null)
{
this.setCurrentPanel(new GuiPanelConfigContainer(this.mc, panel, mod));
}
}
/**
* @param newPanel
*/
private void setCurrentPanel(GuiPanel newPanel)
{
this.closeCurrentPanel();
this.currentPanel = newPanel;
this.currentPanel.setSize(this.width - LEFT_EDGE, this.height);
this.currentPanel.onShown();
}
/* (non-Javadoc)
* @see com.mumfrey.liteloader.modconfig.ConfigPanelHost#close()
*/
private void closeCurrentPanel()
{
this.currentPanel.onHidden();
this.currentPanel = this.modsPanel;
this.modsPanel.setSize(this.width - LEFT_EDGE, this.height);
}
/**
* Draw a tooltip at the specified location and clip to screenWidth and
* screenHeight
*
* @param fontRenderer
* @param tooltipText
* @param mouseX
* @param mouseY
* @param screenWidth
* @param screenHeight
* @param colour
* @param backgroundColour
*/
public static void drawTooltip(FontRenderer fontRenderer, String tooltipText, int mouseX, int mouseY, int screenWidth, int screenHeight,
int colour, int backgroundColour)
{
int textSize = fontRenderer.getStringWidth(tooltipText);
mouseX = Math.max(0, Math.min(screenWidth - 4, mouseX - 4));
mouseY = Math.max(0, Math.min(screenHeight - 16, mouseY));
drawRect(mouseX - textSize - 2, mouseY, mouseX + 2, mouseY + 12, backgroundColour);
fontRenderer.drawStringWithShadow(tooltipText, mouseX - textSize, mouseY + 2, colour);
}
/**
* @param x
* @param y
* @param width
* @param height
* @param u
* @param v
* @param u2
* @param v2
* @param alpha
*/
static void glDrawTexturedRect(int x, int y, int width, int height, int u, int v, int u2, int v2, float alpha)
{
float texMapScale = 0.00390625F; // 256px
glDrawTexturedRect(x, y, width, height, u * texMapScale, v * texMapScale, u2 * texMapScale, v2 * texMapScale, alpha);
}
/**
* @param x
* @param y
* @param width
* @param height
* @param u
* @param v
* @param u2
* @param v2
* @param alpha
*/
static void glDrawTexturedRect(int x, int y, int width, int height, float u, float v, float u2, float v2, float alpha)
{
glDisableLighting();
glEnableBlend();
glAlphaFunc(GL_GREATER, 0.0F);
glEnableTexture2D();
glColor4f(1.0F, 1.0F, 1.0F, alpha);
Tessellator tessellator = Tessellator.getInstance();
VertexBuffer buf = tessellator.getBuffer();
buf.begin(GL_QUADS, VF_POSITION_TEX);
buf.pos(x + 0, y + height, 0).tex(u , v2).endVertex();
buf.pos(x + width, y + height, 0).tex(u2, v2).endVertex();
buf.pos(x + width, y + 0, 0).tex(u2, v ).endVertex();
buf.pos(x + 0, y + 0, 0).tex(u , v ).endVertex();
tessellator.draw();
glDisableBlend();
glAlphaFunc(GL_GREATER, 0.01F);
}
/**
* @param x
* @param y
* @param icon
* @param alpha
*/
static void glDrawTexturedRect(int x, int y, Icon icon, float alpha)
{
glDrawTexturedRect(x, y, icon.getIconWidth(), icon.getIconHeight(), icon.getMinU(), icon.getMinV(), icon.getMaxU(), icon.getMaxV(), alpha);
}
}