1 package com
.wurmonline
.client
.renderer
.gui
;
3 import com
.wurmonline
.client
.renderer
.Matrix
;
4 import com
.wurmonline
.client
.renderer
.PickData
;
5 import com
.wurmonline
.client
.renderer
.backend
.Primitive
;
6 import com
.wurmonline
.client
.renderer
.backend
.Queue
;
7 import com
.wurmonline
.client
.renderer
.backend
.VertexBuffer
;
8 import java
.nio
.FloatBuffer
;
10 final class EspWCheckBox
12 implements ConfirmListener
{
14 boolean checked
= false;
15 boolean enabled
= true;
16 private boolean needsConfirmOnTick
= false;
17 private String confirmMessageOnTick
;
18 private String confirmQuestionOnTick
;
19 private boolean needsConfirmUnTick
= false;
20 private String confirmMessageUnTick
;
21 private String confirmQuestionUnTick
;
22 private ConfirmWindow confirmWindow
= null;
23 private String hoverString
;
24 private float customR
= 1.0f;
25 private float customG
= 1.0f;
26 private float customB
= 1.0f;
27 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);
28 private final Matrix modelMatrix
;
29 private CheckBoxListener checkboxListener
;
31 EspWCheckBox(String label
, CheckBoxListener checkboxListener
) {
32 super("Checkbox " + label
);
33 this.height
= this.text
.getHeight() + 1;
35 this.modelMatrix
= Matrix
.createIdentity();
36 this.checkboxListener
= checkboxListener
;
39 public void setLabel(String newLabel
) {
40 this.label
= newLabel
;
41 this.setSize(this.text
.getWidth(this.label
) + 16, this.height
);
44 protected void renderComponent(Queue queue
, float alpha
) {
53 Primitive prim
= queue
.reservePrimitive();
54 prim
.type
= Primitive
.Type
.LINES
;
55 prim
.num
= this.checked ?
6 : 4;
60 prim
.texture
[1] = null;
61 prim
.texture
[0] = null;
62 prim
.texenv
[0] = Primitive
.TexEnv
.MODULATE
;
65 prim
.clipRect
= HeadsUpDisplay
.scissor
.getCurrent();
66 int dy
= (this.height
- 8) / 2;
67 this.modelMatrix
.setTranslation((float)this.x
, (float)(this.y
+ dy
), 0.0f);
68 queue
.queue(prim
, this.modelMatrix
);
69 this.text
.moveTo(this.x
+ this.height
, this.y
+ this.text
.getHeight());
70 this.text
.paint(queue
, this.label
, colR
, colG
, colB
, 1.0f);
73 protected void leftPressed(int xMouse
, int yMouse
, int clickCount
) {
74 if (this.enabled
&& xMouse
<= this.x
+ 16 && xMouse
>= this.x
&& yMouse
>= this.y
&& yMouse
<= this.y
+ this.height
) {
75 if (this.needsConfirmOnTick
&& !this.checked
) {
76 this.confirmWindow
= new ConfirmWindow((ConfirmListener
)this, this.getConfirmMessageOnTick(), this.getConfirmQuestionOnTick());
77 } else if (this.needsConfirmUnTick
&& this.checked
) {
78 this.confirmWindow
= new ConfirmWindow((ConfirmListener
)this, this.getConfirmMessageUnTick(), this.getConfirmQuestionUnTick());
80 this.checked
= !this.checked
;
82 this.checkboxListener
.checkboxClicked(this);
86 protected int getMouseCursor(int x
, int y
) {
87 if (this.enabled
&& x
<= this.x
+ 16 && x
>= this.x
&& y
>= this.y
&& y
<= this.y
+ this.height
) {
90 return super.getMouseCursor(x
, y
);
93 public void pick(PickData pickData
, int xMouse
, int yMouse
) {
94 if (this.hoverString
!= null) {
95 pickData
.addText(this.hoverString
);
99 void setCustomColor(float r
, float g
, float b
) {
105 public void setHoverString(String description
) {
106 this.hoverString
= description
;
109 final void setConfirmOnTickMessage(String message
) {
110 this.confirmMessageOnTick
= message
;
113 final void setConfirmOnTickQuestion(String question
) {
114 this.confirmQuestionOnTick
= question
;
115 this.needsConfirmOnTick
= true;
118 final void setConfirm(String messageOnTick
, String questionOnTick
, String messageUnTick
, String questionUnTick
) {
119 this.confirmMessageOnTick
= messageOnTick
;
120 this.confirmQuestionOnTick
= questionOnTick
;
121 this.confirmMessageUnTick
= messageUnTick
;
122 this.confirmQuestionUnTick
= questionUnTick
;
123 this.needsConfirmOnTick
= questionOnTick
.length() > 0;
124 this.needsConfirmUnTick
= questionUnTick
.length() > 0;
127 public String
getConfirmMessageOnTick() {
128 return this.confirmMessageOnTick
;
131 public String
getConfirmQuestionOnTick() {
132 return this.confirmQuestionOnTick
;
135 public String
getConfirmMessageUnTick() {
136 return this.confirmMessageUnTick
;
139 public String
getConfirmQuestionUnTick() {
140 return this.confirmQuestionUnTick
;
143 public void closeConfirmWindow() {
144 if (this.confirmWindow
!= null) {
145 this.confirmWindow
.close();
146 this.confirmWindow
= null;
150 public void confirmed() {
151 this.closeConfirmWindow();
152 this.checked
= !this.checked
;
155 public void cancelled() {
156 this.closeConfirmWindow();
160 FloatBuffer vertex
= vbo
.lock();