Author Topic: Best way to implement cheats with options  (Read 4948 times)

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Best way to implement cheats with options
« on: December 05, 2012, 12:10:11 AM »
I am almost finished implementing the cheats menus.  I'm trying to stick as close to the same style as the other menus as possible (I'm sure it will need some tweaking once I get everything committed).  The main difference is that these preference screens are generated dynamically, so they are not defined in the xml layout, and are instead built programatically.  There is one last piece I am a little stumped on, which deals more with presentation than functionality, really.

I'm trying to think of a good way to implement the cheats which have options as preferences.  Most cheats are simple check-boxes, but a good number of them also have a list of options to choose from.  To further complicate the matter some but not all cheats (both the simple checkbox variety and the option list variety), have additional details attached to them.  The interface needs to allow the user to do three things:

1) Enable and Disable a cheat
2) Select the options for a cheat if available
3) View the additional details for a cheat if available

It should also be visually apparent to the user whether a cheat is selected or not, and whether it has additional details or not.

I started by trying to copy what I had before, but it is different working with preference screens and dialogs.  I began by making every cheat a checkbox, hooking up long-press to show additional details in a pop-up dialog, and marking those cheats that have additional details with the summary text "(long press for more info)".  This takes care of everything except requirement 2.  I could make it so those are not checkboxes, but normal preferences where I bring up a preference dialog with radio buttons, but then requirement 1 becomes a problem (how to disable/ enable).  That would also make it so the user can not see whether these cheats are enabled or not, unless I write the selected option in the summary, which would then make it so they can not see whether these cheats have additional information or not.

I feel like I'm approaching the problem wrong.  I think I need to write a custom preference type here that is based on a checkbox, but has a click listener that brings up a list preference (somehow need to remember the choice), and has a long-press listener to bring up the details dialog.  Does that seem like a sane approach, or is there a different way I'm not seeing because I've gotten tunnel vision with the way I wrote the cheats menu before?
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline littleguy

  • Moderator
  • double
  • *****
  • Posts: 1945
    • View Profile
Re: Best way to implement cheats with options
« Reply #1 on: December 05, 2012, 06:08:11 AM »
On my way out the door, but could you make a branch on github and post the code?  Even if it's buggy or won't even build that would be good.
2012 Nexus 7, rooted stock Lollipop
Samsung Galaxy Victory, rooted stock Jelly Bean
Xperia PLAY, stock Gingerbread
OUYA, retail version

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Best way to implement cheats with options
« Reply #2 on: December 05, 2012, 07:20:05 AM »
Good idea - I'll do that tonight and then it will be easier to see what I'm talking about.  I thought about this some more last night, and I think I'll use something similar to the file path browser you wrote.  It will have the options, and a "disable" button on the bottom (or possibly a "don't use" option in the list - I'll see what looks better).  The cheats themselves would all be checkboxes.  But instead of checking/ unchecking when clicked, these special cheats would bring up the option selector - then the cheat it is attached to would be checked/ unchecked programmatically depending on what the user chooses.
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Best way to implement cheats with options
« Reply #3 on: December 09, 2012, 08:34:30 AM »
Just a quick progress update on the cheats:  I solved the argument parsing problem (turned out to be a problem in my logic).  Trying to figure out another strange behavior now, where every argument is being spit out as "unrecognized argument" by the front-end native library and being ignored.  Strangely, this includes the ROM name, yet the right game starts somehow (just all other arguments are ignored).  This of course prevents cheats from working (as well as the framelimiter disable option).  I'm looking into the possibility that I encoded the strings wrong during the conversion from Java String to C char* (maybe related to this).  The other possibility is that usage has changed (very unlikely), so I'll look into that just to make sure.
« Last Edit: December 09, 2012, 08:42:20 AM by Paul »
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline littleguy

  • Moderator
  • double
  • *****
  • Posts: 1945
    • View Profile
Re: Best way to implement cheats with options
« Reply #4 on: December 09, 2012, 10:01:00 AM »
Great.  Have you solved the front-end challenges for the cheats?  I'm happy to lend a set of eyes.
2012 Nexus 7, rooted stock Lollipop
Samsung Galaxy Victory, rooted stock Jelly Bean
Xperia PLAY, stock Gingerbread
OUYA, retail version

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Best way to implement cheats with options
« Reply #5 on: December 09, 2012, 11:05:51 PM »
I solved the unrecognized parameter issue - for some reason, char*'s that are acquired from jstrings from JNI, are not encoded correctly if you use the normal method of sticking in '\0' chars to split strings.  I suspect it is something to do with the "modified UTF-8" thing, but from the way I understand it, it shouldn't affect the normal ASCII characters which we are dealing with here.  Anyway, the solution was to do a strdup on the string -- apparently c is smart enough to figure out what the string is supposed to be, and duplicating it generates a "nice" string that can be recognized by the front-end library.  I still haven't tested on filenames that contain unusual UTF-8 characters (symbols, letters from other languages, etc), so that will need to be tested eventually.

Anyway, cheats are now working!  I just need to implement the option chooser pop-up, and should be good to go (going to copy a little from the file chooser -- this will be a lot simpler design).
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline littleguy

  • Moderator
  • double
  • *****
  • Posts: 1945
    • View Profile
Re: Best way to implement cheats with options
« Reply #6 on: December 09, 2012, 11:32:13 PM »
Awesome, can't wait to check it out!
2012 Nexus 7, rooted stock Lollipop
Samsung Galaxy Victory, rooted stock Jelly Bean
Xperia PLAY, stock Gingerbread
OUYA, retail version

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Best way to implement cheats with options
« Reply #7 on: December 11, 2012, 04:11:15 PM »
Another progress update: last night I finished implementing a new preference type which extends CheckBoxPreference.  Instead of check/ uncheck on a normal press, it brings up an option dialog (like a DialogPreference would).  The first entry in the option dialog is the "negative" option, and the others are the various options you can choose from.  The "negative" option closes the option dialog, unchecks the box, and clears the summary text.  The other options close the option dialog, check the box, and update the summary text to match whichever option was chosen.  On a long press, it brings up a simple dialog with summary information.

This fits the bill of a preference type that is somewhere between a CheckBoxPreference and a DialogPreference.  I'm not sure if we'll need it for anything besides the cheats, but it could be useful for other things down the road.  The last piece I need to hook up is the ability to long-press on the options in the option dialog to bring up another dialog with summary information.

Sorry for the delay on getting this implemented - I got distracted on a few other bugs along the way.  I'll try and finish hooking this up tonight if I get some free time.  Only reason I haven't posted the interim code to github is that I am kind of having fun figuring out the logistics for this myself without any help from the more experienced devs on there ;D  Once it's put up there, I'm sure we'll be able to chop it down and simplify in a few places.
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline littleguy

  • Moderator
  • double
  • *****
  • Posts: 1945
    • View Profile
Re: Best way to implement cheats with options
« Reply #8 on: December 11, 2012, 04:16:20 PM »
Sounds like a nice clean design 8).  Seems like an especially tricky preference to make a UI for.
2012 Nexus 7, rooted stock Lollipop
Samsung Galaxy Victory, rooted stock Jelly Bean
Xperia PLAY, stock Gingerbread
OUYA, retail version

Offline littleguy

  • Moderator
  • double
  • *****
  • Posts: 1945
    • View Profile
Re: Best way to implement cheats with options
« Reply #9 on: December 11, 2012, 04:27:26 PM »
On a related note, I think we should tweak the menu arrangement again, with the new cheats implementation and the new options Gillou added.  This will only require rearranging the lines of code in preferences.xml.  I'll make a little concept branch and we can tinker with the arrangement.  I'm thinking it will only take a few iterations, a few commits.  Then we'd squash that branch before merging back to master, to keep a tidy history.
2012 Nexus 7, rooted stock Lollipop
Samsung Galaxy Victory, rooted stock Jelly Bean
Xperia PLAY, stock Gingerbread
OUYA, retail version

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Best way to implement cheats with options
« Reply #10 on: December 11, 2012, 04:32:33 PM »
Agreed - things may be starting to get a tad cluttered, although the influx of new options is really awesome - something the users are going to love!

As for the cheat preference - all it really is at the end of the day is just a DialogPreference with a list of options to choose from.  The trickiness is all in the presentation -- displaying that summary information to the user, which contains important information to explain what a cheat or cheat option does, and making it easy for the user to see if a particular cheat is turned on or not.
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline Lioncash

  • Developer
  • byte
  • *****
  • Posts: 29
    • View Profile
Re: Best way to implement cheats with options
« Reply #11 on: December 11, 2012, 07:02:19 PM »
making it easy for the user to see if a particular cheat is turned on or not.

List of checkboxes with a cheat description beside them should be simple.

Offline littleguy

  • Moderator
  • double
  • *****
  • Posts: 1945
    • View Profile
Re: Best way to implement cheats with options
« Reply #12 on: December 11, 2012, 07:21:31 PM »
The trickiness is all in the presentation ...
Exactly.
2012 Nexus 7, rooted stock Lollipop
Samsung Galaxy Victory, rooted stock Jelly Bean
Xperia PLAY, stock Gingerbread
OUYA, retail version

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Best way to implement cheats with options
« Reply #13 on: December 11, 2012, 08:10:00 PM »
making it easy for the user to see if a particular cheat is turned on or not.

List of checkboxes with a cheat description beside them should be simple.

Exactly what I thought originally, which led to the extension of CheckBoxPreference that functions as a DialogPreference.  It looks a lot nicer than the implementation I did in <= 1.9.2, mainly because I'm not using a custom layout and option chooser.  Another possible implementation I considered would be a type of "check pane" - a checkable frame that could fit the entire description, rather than just two lines for title and summary like most preferences.  Would still need the option dialog pop-up for option cheats, of course, which could itself have frames in it with full descriptions too.  Decided to go with the simpler design to start with, and we can always play around with different ideas once it's committed, to see what works best.
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted

Offline Paul

  • Administrator
  • double
  • *****
  • Posts: 3499
  • Developer
    • View Profile
    • PaulsCode.Com
Re: Best way to implement cheats with options
« Reply #14 on: December 12, 2012, 02:16:13 AM »
Have to put it off another day, sadly.  I originally implemented the cheats menu as a separate activity, just to avoid clutter in MenuActivity and collisions from the repository updates while I was working on it.  I got everything working today, and decided to clean the code up, get rid of the extra activity, and create a cheats menu handler for populating the dynamic part (the game-specific cheats list).  The static pieces are now in the xml file with the other MenuActivity preferences.  When the cheats PreferenceScreen is opened, the handler pulls up the sub PreferenceCategory, empties it if it has anything, and then puts in the cheats preferences.  Everything works, except for one small thing -- I'm having trouble getting the long-presses to work now.  I wrote the original code for listening to long presses in a way that required just one page of preferences, so moving that into MenuActivity is taking some thought.  The code I came up with this evening looks like it should work, but no long-presses are picked up, so I suspect I overlooked something simple.  I'll have to finish it tomorrow evening.
Device: Samsung Galaxy Nexus i515
CPU: TI OMAP4460, 1.2 GHz (dual core, ARM Cortex-A9)
GPU: PowerVR SGX540, 307 MHz
RAM: 1 GB
Resolution: 720 x 1280
Rom: omni-4.4.4-20141014-toro-FML KitKat 4.4.4, rooted

Device: Eee PC 1015PEM
CPU: Intel Atom N550, 1.5 GHz (dual core, x86)
GPU: Intel GMA 3150, 200 MHz (dual core)
RAM: 2GB
Resolution: 1024 x 600
Rom: android-x86-4.3-20130725 Jelly Bean 4.3, rooted