5555import com .cleanroommc .modularui .drawable .ItemDrawable ;
5656import com .cleanroommc .modularui .factory .PosGuiData ;
5757import com .cleanroommc .modularui .screen .ModularPanel ;
58+ import com .cleanroommc .modularui .value .IntValue ;
5859import com .cleanroommc .modularui .value .sync .IntSyncValue ;
60+ import com .cleanroommc .modularui .value .sync .PanelSyncHandler ;
5961import com .cleanroommc .modularui .value .sync .PanelSyncManager ;
6062import com .cleanroommc .modularui .value .sync .SyncHandlers ;
6163import com .cleanroommc .modularui .widget .Widget ;
@@ -77,6 +79,7 @@ public class MetaTileEntityMEInputBus extends MetaTileEntityAEHostableChannelPar
7779
7880 public static final String ITEM_BUFFER_TAG = "ItemSlots" ;
7981 public static final String WORKING_TAG = "WorkingEnabled" ;
82+ public static final String SYNC_HANDLER_NAME = "aeSync" ;
8083
8184 public final static int CONFIG_SIZE = 16 ;
8285 protected ExportOnlyAEItemList aeItemHandler ;
@@ -217,9 +220,8 @@ public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager guiSyncManager)
217220 final boolean isStocking = getAEItemHandler ().isStocking ();
218221 guiSyncManager .registerSlotGroup ("extra_slot" , 1 );
219222
220- final String syncHandlerName = "aeSync" ;
221223 AEItemSyncHandler syncHandler = new AEItemSyncHandler (getAEItemHandler (), this ::markDirty , circuitInventory );
222- guiSyncManager .syncValue (syncHandlerName , syncHandler );
224+ guiSyncManager .syncValue (SYNC_HANDLER_NAME , 0 , syncHandler );
223225
224226 Grid configGrid = new Grid ()
225227 .pos (7 , 25 )
@@ -229,7 +231,7 @@ public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager guiSyncManager)
229231 .minRowHeight (18 )
230232 .matrix (Grid .mapToMatrix ((int ) Math .sqrt (CONFIG_SIZE ), CONFIG_SIZE ,
231233 index -> new AEItemConfigSlot (isStocking , index , this ::isAutoPull )
232- .syncHandler (syncHandlerName )
234+ .syncHandler (SYNC_HANDLER_NAME , 0 )
233235 .debugName ("Index " + index )));
234236
235237 for (IWidget aeWidget : configGrid .getChildren ()) {
@@ -255,7 +257,7 @@ public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager guiSyncManager)
255257 .matrix (Grid .mapToMatrix ((int ) Math .sqrt (CONFIG_SIZE ), CONFIG_SIZE ,
256258 index -> new AEItemDisplaySlot (index )
257259 .background (GTGuiTextures .SLOT_DARK )
258- .syncHandler (syncHandlerName )
260+ .syncHandler (SYNC_HANDLER_NAME , 0 )
259261 .debugName ("Index " + index ))))
260262 .child (Flow .column ()
261263 .pos (7 + 18 * 4 , 25 )
@@ -274,24 +276,7 @@ public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager guiSyncManager)
274276 .height (18 )
275277 .top (5 )
276278 .right (7 )
277- .childIf (!isStocking , new ButtonWidget <>()
278- .width (9 )
279- .height (18 )
280- .onMousePressed (mouseButton -> {
281- syncHandler .modifyConfigAmounts ((index , amount ) -> Math .max (1 , amount / 2 ));
282-
283- return true ;
284- })
285- .addTooltipLine (IKey .str ("Click to divide all slots by 2" ))) // TODO: lang
286- .childIf (!isStocking , new ButtonWidget <>()
287- .width (9 )
288- .height (18 ).onMousePressed (mouseButton -> {
289- syncHandler .modifyConfigAmounts (
290- (index , amount ) -> GTUtility .safeCastLongToInt ((long ) amount * 2 ));
291-
292- return true ;
293- })
294- .addTooltipLine (IKey .str ("Click to multiply all slots by 2" ))) // TODO: lang
279+ .childIf (!isStocking , getMultiplierWidget (guiSyncManager ))
295280 .child (getSettingWidget (guiSyncManager )));
296281 }
297282
@@ -343,6 +328,56 @@ protected int getSettingsPopupHeight() {
343328 return 33 + 14 + 5 ;
344329 }
345330
331+ protected Widget <?> getMultiplierWidget (PanelSyncManager syncManager ) {
332+ IPanelHandler multiplierPopup = syncManager .panel ("multiplier_panel" , this ::buildMultiplierPopup , true );
333+
334+ return new ButtonWidget <>()
335+ .onMousePressed (mouse -> {
336+ if (multiplierPopup .isPanelOpen ()) {
337+ multiplierPopup .closePanel ();
338+ } else {
339+ multiplierPopup .openPanel ();
340+ }
341+
342+ return true ;
343+ })
344+ .addTooltipLine (IKey .lang ("gregtech.machine.me.multiplier.button" ));
345+ // TODO button overlay
346+ }
347+
348+ protected ModularPanel buildMultiplierPopup (PanelSyncManager syncManager , IPanelHandler syncHandler ) {
349+ AEItemSyncHandler aeSyncHandler = (AEItemSyncHandler ) ((PanelSyncHandler ) syncHandler ).getSyncManager ()
350+ .getSyncHandler (PanelSyncManager .makeSyncKey (SYNC_HANDLER_NAME , 0 ));
351+ IntValue multiplier = new IntValue (2 );
352+
353+ return GTGuis .blankPopupPanel ("multiplier" , 100 , 32 )
354+ .child (new ButtonWidget <>()
355+ .onMousePressed (mouse -> {
356+ aeSyncHandler .modifyConfigAmounts (
357+ (index , amount ) -> Math .max (1 , amount / multiplier .getIntValue ()));
358+ return true ;
359+ })
360+ .left (5 )
361+ .top (7 )
362+ .overlay (IKey .str ("÷" )))
363+ .child (new TextFieldWidget ()
364+ .alignX (0.5f )
365+ .top (5 )
366+ .widthRel (0.5f )
367+ .height (18 )
368+ .setNumbers (2 , Integer .MAX_VALUE )
369+ .value (multiplier ))
370+ .child (new ButtonWidget <>()
371+ .onMousePressed (mouse -> {
372+ aeSyncHandler .modifyConfigAmounts ((index , amount ) -> GTUtility
373+ .safeIntegerMultiplication (amount , multiplier .getIntValue ()));
374+ return true ;
375+ })
376+ .right (5 )
377+ .top (7 )
378+ .overlay (IKey .str ("x" )));
379+ }
380+
346381 protected Widget <?> getExtraButton () {
347382 return new Widget <>()
348383 .size (18 );
0 commit comments