8
8
9
9
import static com .google .common .base .Preconditions .checkState ;
10
10
import static java .lang .Math .round ;
11
+ import static java .lang .System .currentTimeMillis ;
11
12
import static net .smyler .smylib .SmyLib .getGameClient ;
12
13
13
14
public class VanillaScreenProxy extends net .minecraft .client .gui .screens .Screen {
14
15
private final Screen screen ;
16
+ private final long [] lastClickTimesMs = new long [getGameClient ().mouse ().getButtonCount ()];
17
+ private final float [] lastClickX = new float [getGameClient ().mouse ().getButtonCount ()];
18
+ private final float [] lastClickY = new float [getGameClient ().mouse ().getButtonCount ()];
15
19
16
20
public VanillaScreenProxy (Screen screen ) {
17
21
super (Component .literal ("SmyLib screen" ));
@@ -21,7 +25,6 @@ public VanillaScreenProxy(Screen screen) {
21
25
22
26
@ Override
23
27
public void render (GuiGraphics guiGraphics , int x , int y , float partialTicks ) {
24
-
25
28
GameClient game = getGameClient ();
26
29
WrappedGuiGraphics uiDrawContext = (WrappedGuiGraphics ) game .guiDrawContext ();
27
30
checkState (
@@ -57,25 +60,36 @@ public boolean isPauseScreen() {
57
60
return this .screen .shouldPauseGame ();
58
61
}
59
62
60
- //FIXME mouse and keyboard support in screen proxy
61
-
62
63
@ Override
63
64
public boolean mouseClicked (double x , double y , int button ) {
64
- //TODO implement double clicks
65
- this .screen .onClick ((float )x , (float )y , button , null );
65
+ float xf = (float ) x ;
66
+ float yf = (float ) y ;
67
+ boolean hasMoved = this .lastClickX [button ] != xf || this .lastClickY [button ] != yf ;
68
+ long ct = currentTimeMillis ();
69
+ long dt = ct - lastClickTimesMs [button ];
70
+ if (dt < 500 && !hasMoved ) {
71
+ this .screen .onDoubleClick (xf , yf , button , null );
72
+ } else {
73
+ this .screen .onClick (xf , yf , button , null );
74
+ }
75
+ this .lastClickTimesMs [button ] = ct ;
76
+ this .lastClickX [button ] = xf ;
77
+ this .lastClickY [button ] = yf ;
66
78
return super .mouseClicked (x , y , button );
67
79
}
68
80
69
81
@ Override
70
82
public boolean mouseReleased (double x , double y , int button ) {
71
- this .screen .onMouseReleased ((float )x , (float )y , button , null ); //FIXME track dragged widget
83
+ this .screen .onMouseReleased ((float )x , (float )y , button , null );
72
84
return super .mouseReleased (x , y , button );
73
85
}
74
86
75
87
@ Override
76
88
public boolean mouseDragged (double x , double y , int button , double dX , double dY ) {
77
- //TODO verify arguments are what they seem
78
- this .screen .onMouseDragged ((float )x , (float )y , (float )dX , (float ) dY , button , null , 0 ); //FIXME provide dt
89
+ long ct = currentTimeMillis ();
90
+ long dt = ct - this .lastClickTimesMs [button ];
91
+ this .lastClickTimesMs [button ] = ct ;
92
+ this .screen .onMouseDragged ((float )x , (float )y , (float )dX , (float ) dY , button , null , dt );
79
93
return super .mouseDragged (x , y , button , dX , dY );
80
94
}
81
95
@@ -103,7 +117,7 @@ public void mouseMoved(double d, double e) {
103
117
}
104
118
105
119
public net .smyler .smylib .gui .screen .Screen getScreen () {
106
- return screen ;
120
+ return this . screen ;
107
121
}
108
122
109
123
private void drawBackground (GuiGraphics guiGraphics ) {
0 commit comments