Feature Alphabetize HP and MP restorer Lists

josmul123

New member
For those interested, I have a patch that will alphabetize the HP and MP restorer lists in KoLMafia. It's a hack and isn't optimal, but it works. I think they should be alphabetized by default, so I'm including this here in case a developer wants to integrate it as the default sort option (Perhaps in a way that isn't stupid about memory).

Code:
Index: src/net/sourceforge/kolmafia/moods/HPRestoreItemList.java
===================================================================
--- src/net/sourceforge/kolmafia/moods/HPRestoreItemList.java	(revision 11440)
+++ src/net/sourceforge/kolmafia/moods/HPRestoreItemList.java	(working copy)
@@ -178,13 +178,28 @@
 		String hpRestoreSetting = Preferences.getString( "hpAutoRecoveryItems" );
 		JCheckBox[] restoreCheckbox = new JCheckBox[ HPRestoreItemList.CONFIGURES.length ];
 
+		String[] names = new String[ HPRestoreItemList.CONFIGURES.length ];
+		String[] names2 = new String[ HPRestoreItemList.CONFIGURES.length ];
+
 		for ( int i = 0; i < HPRestoreItemList.CONFIGURES.length; ++i )
 		{
 			restoreCheckbox[ i ] = new JCheckBox( HPRestoreItemList.CONFIGURES[ i ].toString() );
 			restoreCheckbox[ i ].setSelected( hpRestoreSetting.indexOf( HPRestoreItemList.CONFIGURES[ i ].toString().toLowerCase() ) != -1 );
+			names[ i ] = HPRestoreItemList.CONFIGURES[ i ].toString().toLowerCase();
+			names2[ i ] = HPRestoreItemList.CONFIGURES[ i ].toString().toLowerCase();
 		}
+                java.util.Arrays.sort(names);
 
-		return restoreCheckbox;
+		JCheckBox[] newRestore = new JCheckBox[ HPRestoreItemList.CONFIGURES.length ];
+                for (int j = 0; j < names.length; j++) {
+                   for (int k = 0; k < names2.length; k++) {
+                      if (names2[k].compareTo(names[j]) == 0) {
+                         newRestore[j] = restoreCheckbox[k];
+                      }
+                   }
+                }
+
+		return newRestore;
 	}
 
 	public static final void updateCheckboxes( final JCheckBox[] restoreCheckbox )
Index: src/net/sourceforge/kolmafia/moods/MPRestoreItemList.java
===================================================================
--- src/net/sourceforge/kolmafia/moods/MPRestoreItemList.java	(revision 11440)
+++ src/net/sourceforge/kolmafia/moods/MPRestoreItemList.java	(working copy)
@@ -189,13 +189,29 @@
 		String mpRestoreSetting = Preferences.getString( "mpAutoRecoveryItems" );
 		JCheckBox[] restoreCheckbox = new JCheckBox[ MPRestoreItemList.CONFIGURES.length ];
 
+                String[] names = new String[ MPRestoreItemList.CONFIGURES.length ];
+                String[] names2 = new String[ MPRestoreItemList.CONFIGURES.length ];
+
+
 		for ( int i = 0; i < MPRestoreItemList.CONFIGURES.length; ++i )
 		{
 			restoreCheckbox[ i ] = new JCheckBox( MPRestoreItemList.CONFIGURES[ i ].toString() );
 			restoreCheckbox[ i ].setSelected( mpRestoreSetting.indexOf( MPRestoreItemList.CONFIGURES[ i ].toString().toLowerCase() ) != -1 );
+                        names[ i ] = MPRestoreItemList.CONFIGURES[ i ].toString().toLowerCase();
+                        names2[ i ] = MPRestoreItemList.CONFIGURES[ i ].toString().toLowerCase();
 		}
+                java.util.Arrays.sort(names);
 
-		return restoreCheckbox;
+                JCheckBox[] newRestore = new JCheckBox[ MPRestoreItemList.CONFIGURES.length ];
+                for (int j = 0; j < names.length; j++) {
+                   for (int k = 0; k < names2.length; k++) {
+                      if (names2[k].compareTo(names[j]) == 0) {
+                         newRestore[j] = restoreCheckbox[k];
+                      }
+                   }
+                }
+
+                return newRestore;
 	}
 
 	public static final void updateCheckboxes( final JCheckBox[] restoreCheckbox
 

josmul123

New member
I respectfully disagree. The HP/MP restore classes implement Comparable and the compareTo method to compare items internally by how much health/mana they restore and how much MP they cost for HP restorers. The order of the checkboxes does not seem to have any effect on Mafia using them.

The first few items in the list are sleeping on your clan sofa, resting at your campground, and free disco rest. If Mafia actually thought these were the 3 best ways to restore HP, I wouldn't be using Mafia to restore my HP automatically.

I know you said "essentially the order," implying it's not the exact order... But skills like tongue, disco nap, and cocoon are buried in the middle of the list, and in practice are always the first things Mafia tries to use to restore.

I would also make the argument that a list of checkboxes should always be alphabetized in interface design, and using the order for something counter-intuitive is... well... counter-intuitive.
 

roippi

Developer
I know you said "essentially the order," implying it's not the exact order...

That is indeed what is meant by essentially. The restores are listed in descending order of effectiveness, with only a couple exceptions*. None of the three you mentioned are exceptions. Tongue, for example, restores 35 on average - it is between honey-dipped locust and paisley eggs which restore 36 and 33 respectively.

I'm not arguing that the current presentation is 100% ideal, but there's clearly an intent behind it.

*Galaktik's nostrum and disco rest are out of place.
 

josmul123

New member
Now it makes more sense. Thanks for going through that.

There's some issue that I haven't been able to nail down that causes items to uncheck themselves (possibly between ascension), and I always find myself in that list searching for things to re-enable them... Usually after it spends all my meat buying MMJ when I had ancient magi-wipes.

I'm going to keep this on my checkout. I have my own nightlies anyway. I figured I'd submit it in case someone else wanted it.
 

lostcalpolydude

Developer
Staff member
Now it makes more sense. Thanks for going through that.

There's some issue that I haven't been able to nail down that causes items to uncheck themselves (possibly between ascension), and I always find myself in that list searching for things to re-enable them... Usually after it spends all my meat buying MMJ when I had ancient magi-wipes.

I'm going to keep this on my checkout. I have my own nightlies anyway. I figured I'd submit it in case someone else wanted it.

So there's a bug or a script is messing with your settings, and rather than reporting that you requested a feature that would make it easier to regularly correct the unwanted change?

The only thing mafia should be doing when you ascend is setting the restore thresholds to a negative value so that restoration is disabled. If you want to settle for fixing the symptom, you could have a login script that sets those values the way you want them...
 

josmul123

New member
So there's a bug or a script is messing with your settings, and rather than reporting that you requested a feature that would make it easier to regularly correct the unwanted change?

As I said, I've been unable to track down what exactly is un-checking the boxes. If and when I figure that out, I will post it here if it's a bug or notify the script maintainer if it's a script. Meanwhile, the measure I'm taking is using the interface that's intended for setting this information, which I don't think is an unacceptable solution to an issue I sometimes don't notice until days after it happens. You're absolutely right that I could write a login script to set this stuff, but that would involve going through each item in the list to determine which I want and which I don't... Which is exactly the use case I'm trying to avoid by alphabetizing the list.

This interface's purpose is to provide a place to choose the items you want KOLMafia to use to restore HP and MP. The order they are presented in is not obvious (perhaps if the number of respective points the item restores were listed, it would be more apparent), and I don't think it serves its primary purpose. It's way more likely that a user will be looking for a specific item on that list when using it, rather than looking for items that restore a specific range (let alone the fact that this interface assumes you know what all of these items are and how many points they restore). I get that users might want to see which order KOLMafia will use the items in, but doubling that up on the interface that lets them choose which ones to use seems to be detrimental to its utility.
 
Last edited:

Catch-22

Active member
Personally, I side with josmul on this one. Until today, I had no idea that the restoratives even had an order, and knowing that there is an order is no more helpful, given that I do not know restorative values off the top of my head. This is something I seldom set and I think an alphabetized list would make more sense. One other thing I can think of would be separating the restoratives into segments of misc (sofa, shower, etc.), skills and items, then alphabetizing those segments.
 

Rinn

Developer
Maybe it would be better if it was an inventory type list that had checkboxes, so you could sort it however you wanted.
 
Top