Skip to content

Commit 4dcb259

Browse files
committed
Add background toggle option to button and text (box) element
1 parent 4eb8d95 commit 4dcb259

File tree

3 files changed

+36
-184
lines changed

3 files changed

+36
-184
lines changed

src/main/java/mchorse/mclib/client/gui/framework/elements/buttons/GuiButtonElement.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class GuiButtonElement extends GuiClickElement<GuiButtonElement> implemen
1919

2020
public boolean custom;
2121
public int customColor;
22+
public boolean background = true;
2223

2324
public GuiButtonElement(Minecraft mc, IKey label, Consumer<GuiButtonElement> callback)
2425
{
@@ -44,6 +45,13 @@ public GuiButtonElement textColor(int color, boolean shadow)
4445
return this;
4546
}
4647

48+
public GuiButtonElement background(boolean background)
49+
{
50+
this.background = background;
51+
52+
return this;
53+
}
54+
4755
@Override
4856
public void setColor(int color, boolean shadow)
4957
{
@@ -67,7 +75,10 @@ protected void drawSkin(GuiContext context)
6775
color = ColorUtils.multiplyColor(color, 0.85F);
6876
}
6977

70-
GuiDraw.drawBorder(this.area, color);
78+
if (this.background)
79+
{
80+
GuiDraw.drawBorder(this.area, color);
81+
}
7182

7283
String label = this.label.get();
7384
int x = this.area.mx(this.font.getStringWidth(label));

src/main/java/mchorse/mclib/client/gui/framework/elements/input/GuiTextElement.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ public GuiTextElement validator(Predicate<String> validator)
7373
return this;
7474
}
7575

76+
public GuiTextElement background(boolean background)
77+
{
78+
this.field.setEnableBackgroundDrawing(background);
79+
this.resize();
80+
81+
return this;
82+
}
83+
7684
public void setText(String text)
7785
{
7886
if (text == null)
@@ -116,6 +124,14 @@ public void resize()
116124
this.field.y = this.area.y + 1;
117125
this.field.width = this.area.w - 2;
118126
this.field.height = this.area.h - 2;
127+
128+
if (!this.field.getEnableBackgroundDrawing())
129+
{
130+
this.field.x += 4;
131+
this.field.y += ((this.area.h - this.font.FONT_HEIGHT) / 2);
132+
this.field.width -= 8;
133+
this.field.height = this.font.FONT_HEIGHT;
134+
}
119135
}
120136

121137
@Override
Lines changed: 8 additions & 183 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,37 @@
11
package mchorse.mclib.client.gui.mclib;
22

3-
import mchorse.mclib.client.gui.framework.elements.GuiElement;
4-
import mchorse.mclib.client.gui.framework.elements.GuiModelRenderer;
53
import mchorse.mclib.client.gui.framework.elements.buttons.GuiButtonElement;
64
import mchorse.mclib.client.gui.framework.elements.buttons.GuiSlotElement;
75
import mchorse.mclib.client.gui.framework.elements.context.GuiSimpleContextMenu;
8-
import mchorse.mclib.client.gui.framework.elements.input.GuiTransformations;
9-
import mchorse.mclib.client.gui.framework.elements.keyframes.GuiDopeSheet;
10-
import mchorse.mclib.client.gui.framework.elements.keyframes.GuiGraphView;
11-
import mchorse.mclib.client.gui.framework.elements.keyframes.GuiKeyframesEditor;
12-
import mchorse.mclib.client.gui.framework.elements.keyframes.GuiSheet;
6+
import mchorse.mclib.client.gui.framework.elements.input.GuiTextElement;
137
import mchorse.mclib.client.gui.framework.elements.utils.GuiContext;
148
import mchorse.mclib.client.gui.utils.Icons;
159
import mchorse.mclib.client.gui.utils.keys.IKey;
16-
import mchorse.mclib.utils.Color;
17-
import mchorse.mclib.utils.ColorUtils;
18-
import mchorse.mclib.utils.keyframes.Keyframe;
19-
import mchorse.mclib.utils.keyframes.KeyframeChannel;
20-
import mchorse.mclib.utils.keyframes.KeyframeInterpolation;
21-
import mchorse.mclib.utils.wav.Wave;
22-
import mchorse.mclib.utils.wav.WavePlayer;
23-
import mchorse.mclib.utils.wav.WaveReader;
24-
import mchorse.mclib.utils.wav.Waveform;
2510
import net.minecraft.client.Minecraft;
26-
import net.minecraft.client.renderer.GlStateManager;
2711
import net.minecraft.init.Items;
2812
import net.minecraft.item.ItemStack;
2913

3014
public class GuiDebugPanel extends GuiDashboardPanel<GuiAbstractDashboard>
3115
{
32-
public GuiKeyframesEditor<GuiDopeSheet> dopesheet;
33-
public GuiKeyframesEditor<GuiGraphView> graph;
34-
public GuiModelRenderer renderer;
3516
public GuiButtonElement play;
3617
public GuiSlotElement slot;
37-
38-
public GuiTransformations top;
39-
public GuiTransformations bottom;
40-
41-
private WavePlayer player;
42-
private Waveform wave;
43-
44-
public GuiElement element;
18+
public GuiTextElement text;
4519

4620
public GuiDebugPanel(Minecraft mc, GuiAbstractDashboard dashboard)
4721
{
4822
super(mc, dashboard);
4923

50-
this.dopesheet = new GuiKeyframesEditor<GuiDopeSheet>(mc)
51-
{
52-
@Override
53-
protected GuiDopeSheet createElement(Minecraft mc)
54-
{
55-
return new GuiDopeSheet(mc, this::fillData);
56-
}
57-
};
58-
59-
this.graph = new GuiKeyframesEditor<GuiGraphView>(mc)
60-
{
61-
@Override
62-
protected GuiGraphView createElement(Minecraft mc)
63-
{
64-
return new GuiGraphView(mc, this::fillData);
65-
}
66-
};
67-
6824
this.slot = new GuiSlotElement(mc, 0, (t) -> {});
6925
this.slot.flex().relative(this).x(0.5F).y(20).anchorX(0.5F);
7026
this.slot.setStack(new ItemStack(Items.BAKED_POTATO, 42));
7127

72-
KeyframeChannel channel = new KeyframeChannel();
73-
74-
channel.insert(0, 10);
75-
Keyframe a = channel.get(channel.insert(20, 10));
76-
channel.get(channel.insert(80, 0));
77-
channel.get(channel.insert(100, 0));
78-
79-
a.interp = KeyframeInterpolation.BEZIER;
80-
81-
for (int i = 0; i < 5; i++)
82-
{
83-
KeyframeChannel c = new KeyframeChannel();
84-
85-
c.copy(channel);
86-
87-
this.dopesheet.graph.sheets.add(new GuiSheet("" + i, IKey.str("Test " + i), new Color((float) Math.random(), (float) Math.random(), (float) Math.random()).getRGBColor(), c));
88-
}
89-
90-
this.dopesheet.graph.duration = 100;
91-
this.graph.graph.setChannel(channel, 0x0088ff);
92-
this.graph.graph.duration = 100;
93-
94-
this.dopesheet.flex().relative(this).y(0).wh(1F, 0.5F);
95-
this.graph.flex().relative(this).y(0.5F).wh(1F, 0.5F);
96-
97-
this.renderer = new GuiModelRenderer(mc)
98-
{
99-
@Override
100-
protected void drawUserModel(GuiContext context)
101-
{}
102-
};
103-
this.play = new GuiButtonElement(mc, IKey.str("Play me!"), this::play);
104-
105-
this.top = new GuiTransformations(mc);
106-
this.top.fillR(90, 0, -90);
107-
this.top.fillT(1, 5, -2);
108-
this.bottom = new GuiTransformations(mc);
109-
this.bottom.fillT(0, -2, 1.5);
110-
this.bottom.fillS(2, 2, 2);
111-
this.bottom.fillR(0, 180, 0);
28+
this.play = new GuiButtonElement(mc, IKey.str("Play me!"), null).background(false);
29+
this.play.flex().relative(this).xy(10, 10).w(80);
11230

113-
this.top.flex().relative(this).x(0.5F).y(10).wh(190, 70).anchor(0.5F, 0);
114-
this.bottom.flex().relative(this).x(0.5F).y(1F, -10).wh(190, 70).anchor(0.5F, 1F);
31+
this.text = new GuiTextElement(mc, 1000, null).background(false);
32+
this.text.flex().relative(this).xy(10, 40).w(80);
11533

116-
this.renderer.flex().relative(this).wh(1F, 1F);
117-
this.play.flex().relative(this).xy(10, 10).w(80);
118-
this.add(/* this.renderer, this.play, */this.slot);
119-
// this.add(this.graph, this.dopesheet);
120-
// this.add(this.top, this.bottom);
34+
this.add(this.slot, this.play, this.text);
12135

12236
this.context(() ->
12337
{
@@ -130,34 +44,6 @@ protected void drawUserModel(GuiContext context)
13044

13145
return contextMenu;
13246
});
133-
134-
this.element = new GuiElement(mc);
135-
this.element.flex().relative(this).wh(0.33F, 0.33F).row(5).resize().width(80).padding(10);
136-
137-
for (int i = 0; i < 5; i ++)
138-
{
139-
GuiButtonElement buttonElement = new GuiButtonElement(mc, IKey.str(String.valueOf(i)), null);
140-
141-
buttonElement.flex().h(20);
142-
143-
if (i == 1)
144-
{
145-
buttonElement.marginLeft(0);
146-
buttonElement.marginRight(30);
147-
}
148-
else if (i == 2)
149-
{
150-
buttonElement.marginTop(50);
151-
}
152-
else if (i == 3)
153-
{
154-
buttonElement.marginBottom(50);
155-
}
156-
157-
this.element.add(buttonElement);
158-
}
159-
160-
// this.add(this.element);
16147
}
16248

16349
@Override
@@ -166,78 +52,17 @@ public boolean isClientSideOnly()
16652
return true;
16753
}
16854

169-
private void play(GuiButtonElement button)
170-
{
171-
try
172-
{
173-
if (this.player != null)
174-
{
175-
this.player.delete();
176-
}
177-
178-
if (this.wave != null)
179-
{
180-
this.wave.delete();
181-
}
182-
183-
WaveReader reader = new WaveReader();
184-
Wave data = reader.read(this.getClass().getResourceAsStream("/assets/mclib/8.wav"));
185-
186-
if (data.getBytesPerSample() > 2)
187-
{
188-
data = data.convertTo16();
189-
}
190-
191-
this.player = new WavePlayer().initialize(data);
192-
this.player.play();
193-
194-
this.wave = new Waveform();
195-
this.wave.generate(data, 20, 150);
196-
}
197-
catch (Exception e)
198-
{
199-
e.printStackTrace();
200-
}
201-
}
202-
20355
@Override
20456
public void resize()
20557
{
20658
super.resize();
207-
208-
this.dopesheet.graph.resetView();
209-
this.graph.graph.resetView();
21059
}
21160

21261
@Override
21362
public void draw(GuiContext context)
21463
{
215-
this.element.area.draw(ColorUtils.HALF_BLACK);
216-
217-
if (this.player != null && !this.player.isPlaying())
218-
{
219-
this.player.delete();
220-
this.player = null;
221-
}
222-
22364
super.draw(context);
22465

225-
if (this.wave != null)
226-
{
227-
int w = this.wave.getWidth();
228-
int h = this.wave.getHeight();
229-
230-
GlStateManager.enableTexture2D();
231-
232-
GlStateManager.color(0, 0, 0, 1);
233-
this.wave.draw(this.area.x + 10, this.area.my() - h / 2 - 2, 0, 0, w, h);
234-
235-
GlStateManager.color(0.25F, 0.25F, 0.25F, 1);
236-
this.wave.draw(this.area.x + 10, this.area.my() - h / 2, 0, 0, 200, h);
237-
GlStateManager.color(0.5F, 0.5F, 0.5F, 1);
238-
this.wave.draw(this.area.x + 10 + 200, this.area.my() - h / 2, 200, 0, 200, h);
239-
GlStateManager.color(1, 1, 1, 1);
240-
this.wave.draw(this.area.x + 10 + 400, this.area.my() - h / 2, 400, 0, w, h);
241-
}
66+
this.text.background(System.currentTimeMillis() % 2000 < 1000);
24267
}
24368
}

0 commit comments

Comments
 (0)