77import io .exterminator3618 .client .Constants ;
88import io .exterminator3618 .client .utils .Renderer ;
99import io .exterminator3618 .client .utils .Assets ;
10+
11+ /**
12+ * A simple text button with an optional 9-patch-style background frame.
13+ */
1014public class TextButton {
1115
1216 public String text ;
@@ -16,6 +20,16 @@ public class TextButton {
1620 public String middleRegion ;
1721 public String rightRegion ;
1822
23+ /**
24+ * Creates a new TextButton.
25+ *
26+ * @param text The text to display.
27+ * @param x The x-coordinate (bottom-left).
28+ * @param y The y-coordinate (bottom-left).
29+ * @param width The button's width.
30+ * @param height The button's height.
31+ * @param hasFrame True to draw the 9-patch style frame, false for text only.
32+ */
1933 public TextButton (String text , float x , float y , float width , float height , boolean hasFrame ) {
2034 this .text = text ;
2135 this .bounds = new Rectangle (x , y , width , height );
@@ -30,25 +44,28 @@ public TextButton(String text, float x, float y, float width, float height, bool
3044 this .rightRegion = null ;
3145 }
3246 }
47+
3348 /**
34- * Tạo một TextButton mới .
49+ * Creates a new TextButton without a frame .
3550 *
36- * @param text Văn bản sẽ hiển thị .
37- * @param x Tọa độ X (góc DƯỚI-BÊN TRÁI) của vùng nhấp .
38- * @param y Tọa độ Y (góc DƯỚI-BÊN TRÁI) của vùng nhấp .
39- * @param width Chiều rộng của vùng nhấp .
40- * @param height Chiều cao của vùng nhấp .
51+ * @param text The text to display .
52+ * @param x The x-coordinate (bottom-left) .
53+ * @param y The y-coordinate (bottom-left) .
54+ * @param width The button's width .
55+ * @param height The button's height .
4156 */
4257 public TextButton (String text , float x , float y , float width , float height ) {
4358 this .text = text ;
4459 this .bounds = new Rectangle (x , y , width , height );
4560 }
4661
4762 /**
48- * Vẽ button này bằng Renderer.
63+ * Draws the button (frame and text) using the provided Renderer.
64+ * @param renderer The renderer to use for drawing.
4965 */
5066 public void draw (Renderer renderer ) {
5167
68+ // Draw the 9-patch style frame if regions are defined
5269 if (leftRegion != null && middleRegion != null && rightRegion != null ) {
5370
5471 TextureRegion leftTex = Assets .getUiRegion (leftRegion );
@@ -63,10 +80,13 @@ public void draw(Renderer renderer) {
6380 int width = (int )bounds .width ;
6481 int height = (int )bounds .height ;
6582
83+ // Draw left cap
6684 renderer .drawUi (leftRegion , x , y , leftWidth , height );
6785
86+ // Draw right cap
6887 renderer .drawUi (rightRegion , (x + width ) - rightWidth , y , rightWidth , height );
6988
89+ // Draw tiled middle section
7090 int middleX = x + leftWidth ;
7191 int middleWidth = width - leftWidth - rightWidth ;
7292
@@ -76,21 +96,20 @@ public void draw(Renderer renderer) {
7696 }
7797 }
7898
99+ // Draw the text centered
79100 int centerX = (int )(bounds .x + bounds .width / 2 );
80101 int centerY = (int )(bounds .y + bounds .height / 2 );
81102 renderer .drawTextMiddle (text , centerX , centerY );
82103 }
83104
84105 /**
85- * Kiểm tra xem tọa độ (đã được unproject) có nằm trong nút này không .
106+ * Checks if the given (unprojected) coordinates are within the button's bounds .
86107 *
87- * @param touchX Tọa độ X của thế giới game (đã qua camera.unproject ).
88- * @param touchY Tọa độ Y của thế giới game (đã qua camera.unproject ).
89- * @return true nếu được nhấp , false nếu không .
108+ * @param touchX The world x-coordinate (already unprojected ).
109+ * @param touchY The world y-coordinate (already unprojected ).
110+ * @return true if clicked , false otherwise .
90111 */
91112 public boolean isClicked (float touchX , float touchY ) {
92113 return bounds .contains (touchX , touchY );
93114 }
94-
95-
96115}
0 commit comments