1616import java .nio .file .Path ;
1717import java .nio .file .Paths ;
1818import java .util .ArrayList ;
19+ import java .util .Collections ;
1920import java .util .HashSet ;
2021import java .util .List ;
2122import java .util .Objects ;
3536import net .minecraft .client .gui .GuiGraphics ;
3637import net .minecraft .client .gui .components .AbstractWidget ;
3738import net .minecraft .client .gui .components .Button ;
38- import net .minecraft .client .gui .components .ObjectSelectionList ;
3939import net .minecraft .client .gui .components .Renderable ;
4040import net .minecraft .client .gui .components .events .GuiEventListener ;
4141import net .minecraft .client .gui .screens .AlertScreen ;
5151import net .minecraft .util .StringUtil ;
5252import net .wurstclient .WurstClient ;
5353import net .wurstclient .altmanager .*;
54+ import net .wurstclient .clickgui .widgets .MultiSelectEntryListWidget ;
5455import net .wurstclient .mixinterface .IMinecraftClient ;
5556import net .wurstclient .util .MultiProcessingUtils ;
5657import net .wurstclient .util .json .JsonException ;
@@ -77,6 +78,8 @@ public final class AltManagerScreen extends Screen
7778 private Button exportButton ;
7879 private Button logoutButton ;
7980
81+ private List <Alt > pendingDeletion = Collections .emptyList ();
82+
8083 public AltManagerScreen (Screen prevScreen , AltManager altManager )
8184 {
8285 super (Component .literal ("Alt Manager" ));
@@ -165,6 +168,7 @@ public void init()
165168 Button .builder (Component .literal ("Logout" ), b -> pressLogout ())
166169 .bounds (width - 50 - 8 , 8 , 50 , 20 ).build ());
167170
171+ listGui .ensureSelection ();
168172 updateAltButtons ();
169173 boolean windowMode = !minecraft .options .fullscreen ().get ();
170174 importButton .active = windowMode ;
@@ -173,11 +177,17 @@ public void init()
173177
174178 private void updateAltButtons ()
175179 {
176- boolean altSelected = listGui .getSelected () != null ;
177- useButton .active = altSelected ;
178- starButton .active = altSelected ;
179- editButton .active = altSelected ;
180- deleteButton .active = altSelected ;
180+ if (useButton == null || starButton == null || editButton == null
181+ || deleteButton == null || logoutButton == null )
182+ return ;
183+
184+ int selectionCount = listGui != null ? listGui .getSelectionCount () : 0 ;
185+ boolean hasSingleSelection = selectionCount == 1 ;
186+
187+ useButton .active = hasSingleSelection ;
188+ starButton .active = hasSingleSelection ;
189+ editButton .active = hasSingleSelection ;
190+ deleteButton .active = selectionCount > 0 ;
181191
182192 logoutButton .active =
183193 ((IMinecraftClient )minecraft ).getWurstSession () != null ;
@@ -250,16 +260,27 @@ private void pressEdit()
250260
251261 private void pressDelete ()
252262 {
253- Alt alt = listGui .getSelectedAlt ();
254- if (alt == null )
263+ List < Alt > selected = listGui .getSelectedAlts ();
264+ if (selected . isEmpty () )
255265 return ;
256266
257- Component text =
258- Component . literal ( "Are you sure you want to remove this alt?" ) ;
267+ pendingDeletion = List . copyOf ( selected );
268+ boolean plural = pendingDeletion . size () > 1 ;
259269
260- String altName = alt .getDisplayName ();
261- Component message = Component .literal (
262- "\" " + altName + "\" will be lost forever! (A long time!)" );
270+ Component text = plural ? Component .literal ("Remove selected alts?" )
271+ : Component .literal ("Remove this alt?" );
272+
273+ Component message ;
274+ if (plural )
275+ {
276+ message = Component .literal (pendingDeletion .size ()
277+ + " accounts will be lost forever! (A long time!)" );
278+ }else
279+ {
280+ String altName = pendingDeletion .get (0 ).getDisplayName ();
281+ message = Component .literal (
282+ "\" " + altName + "\" will be lost forever! (A long time!)" );
283+ }
263284
264285 ConfirmScreen screen = new ConfirmScreen (this ::confirmRemove , text ,
265286 message , Component .literal ("Delete" ), Component .literal ("Cancel" ));
@@ -398,13 +419,10 @@ private void confirmGenerate(boolean confirmed)
398419
399420 private void confirmRemove (boolean confirmed )
400421 {
401- Alt alt = listGui .getSelectedAlt ();
402- if (alt == null )
403- return ;
404-
405422 if (confirmed )
406- altManager . remove ( alt );
423+ pendingDeletion . forEach ( altManager :: remove );
407424
425+ pendingDeletion = Collections .emptyList ();
408426 minecraft .setScreen (this );
409427 }
410428
@@ -543,14 +561,23 @@ public void onClose()
543561 }
544562
545563 private final class Entry
546- extends ObjectSelectionList .Entry <AltManagerScreen .Entry >
564+ extends MultiSelectEntryListWidget .Entry <AltManagerScreen .Entry >
547565 {
548566 private final Alt alt ;
549567 private long lastClickTime ;
568+ private final String selectionKey ;
550569
551- public Entry (Alt alt )
570+ public Entry (ListGui parent , Alt alt )
552571 {
572+ super (parent );
553573 this .alt = Objects .requireNonNull (alt );
574+ selectionKey = Integer .toHexString (System .identityHashCode (alt ));
575+ }
576+
577+ @ Override
578+ public String selectionKey ()
579+ {
580+ return selectionKey ;
554581 }
555582
556583 @ Override
@@ -567,6 +594,8 @@ public boolean mouseClicked(MouseButtonEvent context,
567594 if (context .button () != GLFW .GLFW_MOUSE_BUTTON_LEFT )
568595 return false ;
569596
597+ super .mouseClicked (context , doubleClick );
598+
570599 long timeSinceLastClick = Util .getMillis () - lastClickTime ;
571600 lastClickTime = Util .getMillis ();
572601
@@ -595,8 +624,9 @@ public void renderContent(GuiGraphics context, int mouseX, int mouseY,
595624 }
596625
597626 // face
627+ boolean selected = parent ().getSelectedEntries ().contains (this );
598628 AltRenderer .drawAltFace (context , alt .getName (), x + 1 , y + 1 , 24 ,
599- 24 , listGui . getSelected () == this );
629+ 24 , selected );
600630
601631 Font tr = minecraft .font ;
602632
@@ -626,15 +656,23 @@ else if(alt.isUncheckedPremium())
626656 }
627657
628658 private final class ListGui
629- extends ObjectSelectionList <AltManagerScreen .Entry >
659+ extends MultiSelectEntryListWidget <AltManagerScreen .Entry >
630660 {
631661 public ListGui (Minecraft minecraft , AltManagerScreen screen ,
632662 List <Alt > list )
633663 {
634664 super (minecraft , screen .width , screen .height - 96 , 36 , 30 );
635665
636- list .stream ().map (AltManagerScreen .Entry :: new )
666+ list .stream ().map (alt -> new AltManagerScreen .Entry ( this , alt ) )
637667 .forEach (this ::addEntry );
668+
669+ setSelectionListener (screen ::updateAltButtons );
670+ }
671+
672+ @ Override
673+ protected String getSelectionKey (AltManagerScreen .Entry entry )
674+ {
675+ return entry .selectionKey ();
638676 }
639677
640678 @ Override
@@ -657,8 +695,18 @@ protected void clearEntries()
657695 */
658696 public Alt getSelectedAlt ()
659697 {
660- AltManagerScreen .Entry selected = getSelected ();
661- return selected != null ? selected .alt : null ;
698+ return getSelectedAlts ().stream ().findFirst ().orElse (null );
699+ }
700+
701+ public List <Alt > getSelectedAlts ()
702+ {
703+ return getSelectedEntries ().stream ().map (entry -> entry .alt )
704+ .toList ();
705+ }
706+
707+ public int getSelectionCount ()
708+ {
709+ return getSelectedEntries ().size ();
662710 }
663711
664712 /**
0 commit comments