82327c1d |
1 | /* |
2 | * Decompiled with CFR 0.151. |
3 | * |
4 | * Could not load the following classes: |
5 | * com.wurmonline.client.renderer.Matrix |
6 | * com.wurmonline.client.renderer.PickData |
7 | * com.wurmonline.client.renderer.backend.Primitive |
8 | * com.wurmonline.client.renderer.backend.Primitive$TexEnv |
9 | * com.wurmonline.client.renderer.backend.Primitive$Type |
10 | * com.wurmonline.client.renderer.backend.Queue |
11 | * com.wurmonline.client.renderer.backend.VertexBuffer |
12 | * com.wurmonline.client.renderer.backend.VertexBuffer$Usage |
13 | * com.wurmonline.client.renderer.gui.ConfirmListener |
14 | * com.wurmonline.client.renderer.gui.ConfirmWindow |
15 | * com.wurmonline.client.renderer.gui.FlexComponent |
16 | * com.wurmonline.client.renderer.gui.HeadsUpDisplay |
17 | */ |
18 | package com.wurmonline.client.renderer.gui; |
19 | |
20 | import com.wurmonline.client.renderer.Matrix; |
21 | import com.wurmonline.client.renderer.PickData; |
22 | import com.wurmonline.client.renderer.backend.Primitive; |
23 | import com.wurmonline.client.renderer.backend.Queue; |
24 | import com.wurmonline.client.renderer.backend.VertexBuffer; |
25 | import java.nio.FloatBuffer; |
26 | |
27 | final class EspWCheckBox |
28 | extends FlexComponent |
29 | implements ConfirmListener { |
30 | private String label; |
31 | boolean checked = false; |
32 | boolean enabled = true; |
33 | private boolean needsConfirmOnTick = false; |
34 | private String confirmMessageOnTick; |
35 | private String confirmQuestionOnTick; |
36 | private boolean needsConfirmUnTick = false; |
37 | private String confirmMessageUnTick; |
38 | private String confirmQuestionUnTick; |
39 | private ConfirmWindow confirmWindow = null; |
40 | private String hoverString; |
41 | private float customR = 1.0f; |
42 | private float customG = 1.0f; |
43 | private float customB = 1.0f; |
44 | private static final VertexBuffer vbo = VertexBuffer.create((VertexBuffer.Usage)VertexBuffer.Usage.GUI, (int)12, (boolean)true, (boolean)false, (boolean)false, (boolean)false, (boolean)false, (int)0, (int)0, (boolean)false, (boolean)true); |
45 | private final Matrix modelMatrix; |
46 | private CheckBoxListener checkboxListener; |
47 | |
48 | EspWCheckBox(String label, CheckBoxListener checkboxListener) { |
49 | super("Checkbox " + label); |
50 | this.height = this.text.getHeight() + 1; |
51 | this.setLabel(label); |
52 | this.modelMatrix = Matrix.createIdentity(); |
53 | this.checkboxListener = checkboxListener; |
54 | } |
55 | |
56 | public void setLabel(String newLabel) { |
57 | this.label = newLabel; |
58 | this.setSize(this.text.getWidth(this.label) + 16, this.height); |
59 | } |
60 | |
61 | protected void renderComponent(Queue queue, float alpha) { |
62 | float colR = 0.8f; |
63 | float colG = 0.8f; |
64 | float colB = 0.8f; |
65 | if (this.enabled) { |
66 | colR = this.customR; |
67 | colG = this.customG; |
68 | colB = this.customB; |
69 | } |
70 | Primitive prim = queue.reservePrimitive(); |
71 | prim.type = Primitive.Type.LINES; |
72 | prim.num = this.checked ? 6 : 4; |
73 | prim.r = colR; |
74 | prim.g = colG; |
75 | prim.b = colB; |
76 | prim.a = 1.0f; |
77 | prim.texture[1] = null; |
78 | prim.texture[0] = null; |
79 | prim.texenv[0] = Primitive.TexEnv.MODULATE; |
80 | prim.vertex = vbo; |
81 | prim.index = null; |
82 | prim.clipRect = HeadsUpDisplay.scissor.getCurrent(); |
83 | int dy = (this.height - 8) / 2; |
84 | this.modelMatrix.setTranslation((float)this.x, (float)(this.y + dy), 0.0f); |
85 | queue.queue(prim, this.modelMatrix); |
86 | this.text.moveTo(this.x + this.height, this.y + this.text.getHeight()); |
87 | this.text.paint(queue, this.label, colR, colG, colB, 1.0f); |
88 | } |
89 | |
90 | protected void leftPressed(int xMouse, int yMouse, int clickCount) { |
91 | if (this.enabled && xMouse <= this.x + 16 && xMouse >= this.x && yMouse >= this.y && yMouse <= this.y + this.height) { |
92 | if (this.needsConfirmOnTick && !this.checked) { |
93 | this.confirmWindow = new ConfirmWindow((ConfirmListener)this, this.getConfirmMessageOnTick(), this.getConfirmQuestionOnTick()); |
94 | } else if (this.needsConfirmUnTick && this.checked) { |
95 | this.confirmWindow = new ConfirmWindow((ConfirmListener)this, this.getConfirmMessageUnTick(), this.getConfirmQuestionUnTick()); |
96 | } else { |
97 | this.checked = !this.checked; |
98 | } |
99 | this.checkboxListener.checkboxClicked(this); |
100 | } |
101 | } |
102 | |
103 | protected int getMouseCursor(int x, int y) { |
104 | if (this.enabled && x <= this.x + 16 && x >= this.x && y >= this.y && y <= this.y + this.height) { |
105 | return 1; |
106 | } |
107 | return super.getMouseCursor(x, y); |
108 | } |
109 | |
110 | public void pick(PickData pickData, int xMouse, int yMouse) { |
111 | if (this.hoverString != null) { |
112 | pickData.addText(this.hoverString); |
113 | } |
114 | } |
115 | |
116 | void setCustomColor(float r, float g, float b) { |
117 | this.customR = r; |
118 | this.customG = g; |
119 | this.customB = b; |
120 | } |
121 | |
122 | public void setHoverString(String description) { |
123 | this.hoverString = description; |
124 | } |
125 | |
126 | final void setConfirmOnTickMessage(String message) { |
127 | this.confirmMessageOnTick = message; |
128 | } |
129 | |
130 | final void setConfirmOnTickQuestion(String question) { |
131 | this.confirmQuestionOnTick = question; |
132 | this.needsConfirmOnTick = true; |
133 | } |
134 | |
135 | final void setConfirm(String messageOnTick, String questionOnTick, String messageUnTick, String questionUnTick) { |
136 | this.confirmMessageOnTick = messageOnTick; |
137 | this.confirmQuestionOnTick = questionOnTick; |
138 | this.confirmMessageUnTick = messageUnTick; |
139 | this.confirmQuestionUnTick = questionUnTick; |
140 | this.needsConfirmOnTick = questionOnTick.length() > 0; |
141 | this.needsConfirmUnTick = questionUnTick.length() > 0; |
142 | } |
143 | |
144 | public String getConfirmMessageOnTick() { |
145 | return this.confirmMessageOnTick; |
146 | } |
147 | |
148 | public String getConfirmQuestionOnTick() { |
149 | return this.confirmQuestionOnTick; |
150 | } |
151 | |
152 | public String getConfirmMessageUnTick() { |
153 | return this.confirmMessageUnTick; |
154 | } |
155 | |
156 | public String getConfirmQuestionUnTick() { |
157 | return this.confirmQuestionUnTick; |
158 | } |
159 | |
160 | public void closeConfirmWindow() { |
161 | if (this.confirmWindow != null) { |
162 | this.confirmWindow.close(); |
163 | this.confirmWindow = null; |
164 | } |
165 | } |
166 | |
167 | public void confirmed() { |
168 | this.closeConfirmWindow(); |
169 | this.checked = !this.checked; |
170 | } |
171 | |
172 | public void cancelled() { |
173 | this.closeConfirmWindow(); |
174 | } |
175 | |
176 | static { |
177 | FloatBuffer vertex = vbo.lock(); |
178 | vertex.put(4.0f); |
179 | vertex.put(0.0f); |
180 | vertex.put(0.0f); |
181 | vertex.put(13.0f); |
182 | vertex.put(0.0f); |
183 | vertex.put(0.0f); |
184 | vertex.put(3.0f); |
185 | vertex.put(8.0f); |
186 | vertex.put(0.0f); |
187 | vertex.put(13.0f); |
188 | vertex.put(8.0f); |
189 | vertex.put(0.0f); |
190 | vertex.put(4.0f); |
191 | vertex.put(0.0f); |
192 | vertex.put(0.0f); |
193 | vertex.put(4.0f); |
194 | vertex.put(8.0f); |
195 | vertex.put(0.0f); |
196 | vertex.put(13.0f); |
197 | vertex.put(0.0f); |
198 | vertex.put(0.0f); |
199 | vertex.put(13.0f); |
200 | vertex.put(8.0f); |
201 | vertex.put(0.0f); |
202 | vertex.put(6.0f); |
203 | vertex.put(2.0f); |
204 | vertex.put(0.0f); |
205 | vertex.put(11.0f); |
206 | vertex.put(7.0f); |
207 | vertex.put(0.0f); |
208 | vertex.put(11.0f); |
209 | vertex.put(2.0f); |
210 | vertex.put(0.0f); |
211 | vertex.put(6.0f); |
212 | vertex.put(7.0f); |
213 | vertex.put(0.0f); |
214 | vbo.unlock(); |
215 | } |
216 | } |
217 | |