29
29
import com .simibubi .create .foundation .gui .widget .ScrollInput ;
30
30
import com .simibubi .create .foundation .utility .Components ;
31
31
import com .simibubi .create .foundation .utility .Couple ;
32
+ import dev .ithundxr .createnumismatics .base .client .rendering .IItemApplicableWidget ;
33
+ import dev .ithundxr .createnumismatics .base .client .rendering .ISalepointStateUpdatingWidget ;
32
34
import dev .ithundxr .createnumismatics .config .NumismaticsConfig ;
33
35
import dev .ithundxr .createnumismatics .content .backend .Coin ;
34
36
import dev .ithundxr .createnumismatics .content .backend .behaviours .SliderStylePriceConfigurationPacket ;
39
41
import dev .ithundxr .createnumismatics .registry .packets .ScrollSlotPacket ;
40
42
import dev .ithundxr .createnumismatics .util .TextUtils ;
41
43
import net .minecraft .client .gui .GuiGraphics ;
44
+ import net .minecraft .client .gui .components .AbstractWidget ;
45
+ import net .minecraft .client .gui .components .Renderable ;
46
+ import net .minecraft .client .gui .components .events .GuiEventListener ;
47
+ import net .minecraft .client .gui .narration .NarratableEntry ;
42
48
import net .minecraft .client .renderer .Rect2i ;
43
49
import net .minecraft .network .chat .Component ;
44
50
import net .minecraft .world .entity .player .Inventory ;
@@ -62,6 +68,8 @@ public class SalepointConfigScreen extends AbstractSimiContainerScreen<Salepoint
62
68
private final Label [] coinLabels = new Label [COIN_COUNT ];
63
69
private final ScrollInput [] coinScrollInputs = new ScrollInput [COIN_COUNT ];
64
70
71
+ private boolean wasDragging ;
72
+
65
73
private List <Rect2i > extraAreas = Collections .emptyList ();
66
74
67
75
public SalepointConfigScreen (SalepointConfigMenu container , Inventory inv , Component title ) {
@@ -82,9 +90,7 @@ protected void init() {
82
90
int y = topPos ;
83
91
84
92
trustListButton = new IconButton (x + 16 , y + background .height - 24 , AllIcons .I_VIEW_SCHEDULE );
85
- trustListButton .withCallback (() -> {
86
- menu .contentHolder .openTrustList ();
87
- });
93
+ trustListButton .withCallback (() -> menu .contentHolder .openTrustList ());
88
94
addRenderableWidget (trustListButton );
89
95
90
96
confirmButton = new IconButton (x + background .width - 33 , y + background .height - 24 , AllIcons .I_CONFIRM );
@@ -118,11 +124,19 @@ protected void init() {
118
124
119
125
ISalepointState <?> salepointState = getSalepointState ();
120
126
if (salepointState != null )
121
- salepointState .createConfigWidgets (this ::addRenderableWidget );
127
+ salepointState .createConfigWidgets (this ::addRenderableWidgetOffset );
122
128
123
129
extraAreas = ImmutableList .of (new Rect2i (x + background .width , y + background .height - 68 , 84 , 84 ));
124
130
}
125
131
132
+ private <T extends GuiEventListener & Renderable & NarratableEntry > T addRenderableWidgetOffset (T widget ) {
133
+ if (widget instanceof AbstractWidget abstractWidget ) {
134
+ abstractWidget .setX (abstractWidget .getX () + leftPos );
135
+ abstractWidget .setY (abstractWidget .getY () + topPos );
136
+ }
137
+ return addRenderableWidget (widget );
138
+ }
139
+
126
140
@ Override
127
141
public List <Rect2i > getExtraAreas () {
128
142
return extraAreas ;
@@ -185,6 +199,50 @@ public boolean mouseScrolled(double mouseX, double mouseY, double delta) {
185
199
return super .mouseScrolled (mouseX , mouseY , delta );
186
200
}
187
201
202
+ @ Override
203
+ public boolean mouseClicked (double mouseX , double mouseY , int button ) {
204
+ if (button == 0 && !menu .getCarried ().isEmpty ()) {
205
+ for (GuiEventListener widget : this .children ()) {
206
+ if (widget .isMouseOver (mouseX , mouseY ) && widget instanceof IItemApplicableWidget itemApplicableWidget ) {
207
+ itemApplicableWidget .onItemApplied (menu .getCarried ());
208
+ }
209
+ }
210
+ }
211
+
212
+ return super .mouseClicked (mouseX , mouseY , button );
213
+ }
214
+
215
+ @ Override
216
+ public boolean mouseDragged (double mouseX , double mouseY , int button , double dragX , double dragY ) {
217
+ wasDragging = true ;
218
+ return super .mouseDragged (mouseX , mouseY , button , dragX , dragY );
219
+ }
220
+
221
+ @ Override
222
+ public boolean mouseReleased (double mouseX , double mouseY , int button ) {
223
+ if (button == 0 && wasDragging && !menu .getCarried ().isEmpty ()) {
224
+ for (GuiEventListener widget : this .children ()) {
225
+ if (widget .isMouseOver (mouseX , mouseY ) && widget instanceof IItemApplicableWidget itemApplicableWidget ) {
226
+ itemApplicableWidget .onItemApplied (menu .getCarried ());
227
+ }
228
+ }
229
+ }
230
+
231
+ wasDragging = false ;
232
+
233
+ return super .mouseReleased (mouseX , mouseY , button );
234
+ }
235
+
236
+ @ Override
237
+ protected void containerTick () {
238
+ super .containerTick ();
239
+ for (GuiEventListener widget : this .children ()) {
240
+ if (widget instanceof ISalepointStateUpdatingWidget salepointStateUpdatingWidget ) {
241
+ salepointStateUpdatingWidget .updateState (getSalepointState ());
242
+ }
243
+ }
244
+ }
245
+
188
246
@ Override
189
247
public void removed () {
190
248
NumismaticsPackets .PACKETS .send (new SliderStylePriceConfigurationPacket (menu .contentHolder ));
0 commit comments