Author Topic: Proposed Save Game Update  (Read 11737 times)

Offline x4000

  • Chris McElligott Park, Arcen Founder and Lead Dev
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 31,651
Re: Proposed Save Game Update
« Reply #15 on: June 29, 2017, 08:22:24 pm »
Holy smokes!  That's really quite a mod right there. :D
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline BadgerBadger

  • Arcen Volunteer
  • Hero Member Mark III
  • *****
  • Posts: 1,229
  • BadgerBadgerBadgerBadger
Re: Proposed Save Game Update
« Reply #16 on: June 30, 2017, 11:43:08 am »
It would not be too hard to wire up the Load screen to work with an identical view (I'd provide a "Load Mode" to the Window_SaveGame class so I can reuse all the same code, then just have the "load game" button point there. Using a seperate Window_LoadGame class is not a good idea to my mind, since you want a consistent UI between save/load and don't want to duplicate code). I don't know what you/Keith had in mind for the interface, but I think at least this is much nicer than how saves worked in AIWC.

There are a number of improvements I'd like to make, but some are reliant on improved UI elements to work with (mouseover of a save could show in game elapsed time/wall clock time, for example). I'd like to be able to modify the font size inside the buttons to allow me to fit more things on the screen at a time. Relatedly, it might be nice to have buttons whose size didn't scale with the size of the screen. When I fullscreen on my large monitor, I have truly enormous "Save Game" buttons, which seems excessive.

The AI Type/Difficulty would be good to include along with campaign name and map type, but I don't see a ToString() method for either of those.

Offline x4000

  • Chris McElligott Park, Arcen Founder and Lead Dev
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 31,651
Re: Proposed Save Game Update
« Reply #17 on: June 30, 2017, 11:49:31 am »
The AI Type/Difficulty would be good to include along with campaign name and map type, but I don't see a ToString() method for either of those.

World_AIW2.Instance.Setup.MasterAIType.Name
World_AIW2.Instance.Setup.Difficulty.Name

Those ones are populated directly from the xml, and no wrapping ToString() method is needed.

Cheers!
Have ideas or bug reports for one of our games?  Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline keith.lamothe

  • Arcen Games Staff
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 19,505
Re: Proposed Save Game Update
« Reply #18 on: June 30, 2017, 11:50:41 am »
Looks great :) I've been hoping to do a campaign-based approach, with each campaign getting a save folder inside Saves/ , with a metadata file in there for things like how many times you've loaded a save from that campaign, how many times you've loaded a save from before the "furthest point reached" in that campaign in terms of game-time, etc. It'd also be great to do some automated parseable logs of things like AIP increases, tech unlocks, planet captures, etc, so that AAR writers don't have to do all the grunt work of telling us what happened.

On save and load being different windows, it's fine to merge them, probably, but bear in mind that these aren't really filesystem clones. Load runs when you don't have a game loaded at all (a very different context than if you do), and deals with all possible save files. Save runs with a world present, and deals (ideally, with the campaign thing) only with files in the same campaign.
Have ideas or bug reports for one of our games? Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline BadgerBadger

  • Arcen Volunteer
  • Hero Member Mark III
  • *****
  • Posts: 1,229
  • BadgerBadgerBadgerBadger
Re: Proposed Save Game Update
« Reply #19 on: June 30, 2017, 05:59:25 pm »
Man, Keith, I'm really excited to by all those possibilities! That all sounds great.

I figure of all the things for Keith to be working on, improving the save game menu isn't particularly high on he list. So if you guys would like to use what I come up with as an interim solution then you are welcome to do so.  Otherwise, I'll just hoard my nice save game menu until Keith makes a better one.

Offline BadgerBadger

  • Arcen Volunteer
  • Hero Member Mark III
  • *****
  • Posts: 1,229
  • BadgerBadgerBadgerBadger
Re: Proposed Save Game Update
« Reply #20 on: July 05, 2017, 05:47:56 pm »
So I have successfully made a usable and more fun save game menu for myself. Here's how it works. When you click "Load Game" you get taken to the Campaign Screen. There you select which Campaign from which you want to load a game. Clicking on a given campaign will bring up the Load Screen, which shows saved games from that campaign that you can load.

The Save Game menu now correctly only shows games from the current campaign.

If other people would like to use this mod I am happy to share the code. Otherwise this is good enough for me for the moment!
« Last Edit: July 05, 2017, 08:42:56 pm by BadgerBadger »

Offline Pumpkin

  • Hero Member Mark III
  • *****
  • Posts: 1,201
  • Neinzul Gardener Enclave
Re: Proposed Save Game Update
« Reply #21 on: July 06, 2017, 06:57:12 am »
Impressive. I hope this feature will be officially integrated into the vanilla game, at some point.

I used to use a very specific pattern for my saves in AIWC, something like "[map type] [difficulty] - [minor factions]  - [where I was]". I imagined some user-defined patterns could be used, like "%T %D - %F - %u" for the example above. Something inspired by the format option of the unix "date" command. But that campaign folder approach is pretty awesome!

There is at least a game, I can't remember which one, that display a tiny panel with some interesting metadata when hovering over a save. Like the time played and current gold and level and stuff.

Just adding some ideas on that big pile of juicy features! I don't have time (and motivation) to dive into the code, right now. I'll be back for content creation! (At some time when the UI will be more... less... well, better. ;P)

Badger, congratulation!
Please excuse my english: I'm not a native speaker. Don't hesitate to correct me.

Offline keith.lamothe

  • Arcen Games Staff
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 19,505
Re: Proposed Save Game Update
« Reply #22 on: July 06, 2017, 12:31:06 pm »
If other people would like to use this mod I am happy to share the code. Otherwise this is good enough for me for the moment!
I'd certainly be happy to try to pull it into this release or the next and see how it goes :)
Have ideas or bug reports for one of our games? Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline BadgerBadger

  • Arcen Volunteer
  • Hero Member Mark III
  • *****
  • Posts: 1,229
  • BadgerBadgerBadgerBadger
Re: Proposed Save Game Update
« Reply #23 on: July 06, 2017, 12:42:05 pm »
Here are the files I modified. This should apply cleanly onto an install of .500.

The code is reasonably commented, but I'll explain quickly what I've done for your reference. As Chris suggested, I have encoded metadata about the game into the Save Game name. We use the ~ symbol to indicate the beginning of the metadata portion, with # as the field seperator. Those characters are currently not allowed in save or campaign names.

I created a SaveGameData struct that contains the metadata for each Save Game, and there's also an additional helper class in  Window_SaveGameMenu.cs which is also used by LoadGameMenu.cs.

The Window_LoadGameMenu.cs runs in 2 modes, Campaign and Load. I originally tried to create a Window_CampaignGameMenu.cs, but I got errors about there being no reference to a "Campaign Window Class" in the Arcen Universal code.

Existing saved games will be placed into the campaign "Unknown", but should be otherwise adequately compatible with this code.

There is a known problem when you load games across different campaigns without closing the application; it causes the wrong Campaign Name to be auto-filled into the Save Game menu.

Offline keith.lamothe

  • Arcen Games Staff
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 19,505
Re: Proposed Save Game Update
« Reply #24 on: July 06, 2017, 07:08:07 pm »
Wonderful, many thanks :) Just put that in for 0.501.

FYI, structures like these:
Code: [Select]
if ( x.secondsSinceGameStart == null && y.secondsSinceGameStart == null ) return 0;
else if ( x.secondsSinceGameStart == null ) return -1;
else if ( y.secondsSinceGameStart == null ) return 1;
else return ( -x.secondsSinceGameStart.CompareTo( y.secondsSinceGameStart ) );

Can just be:
Code: [Select]
return ( -x.secondsSinceGameStart.CompareTo( y.secondsSinceGameStart ) );
Because secondsSinceGameStart is an int field and can't be null. For that matter, x and y are both structs in this case, so you don't even need to null-check them.

I noticed these because it spits out warnings about that kind of thing. Didn't hurt anything, certainly.
Have ideas or bug reports for one of our games? Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline Draco18s

  • Resident Velociraptor
  • Core Member Mark V
  • *****
  • Posts: 4,251
Re: Proposed Save Game Update
« Reply #25 on: July 07, 2017, 12:06:32 am »
Didn't hurt anything, certainly.

Safe > Sorry

Offline BadgerBadger

  • Arcen Volunteer
  • Hero Member Mark III
  • *****
  • Posts: 1,229
  • BadgerBadgerBadgerBadger
Re: Proposed Save Game Update
« Reply #26 on: July 07, 2017, 12:23:17 am »
It's more "I had never written any C# before AIW2 mods, so I am utterly ignorant of the subtleties and take excessive precautions/don't know what I'm doing in terms of good C# idiom"

Offline keith.lamothe

  • Arcen Games Staff
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 19,505
Re: Proposed Save Game Update
« Reply #27 on: July 07, 2017, 06:56:19 am »
Oh, I wouldn't know a good C# idiom myself if it bit me on the shin. Great work, especially for someone new to C# :)
Have ideas or bug reports for one of our games? Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!

Offline BadgerBadger

  • Arcen Volunteer
  • Hero Member Mark III
  • *****
  • Posts: 1,229
  • BadgerBadgerBadgerBadger
Re: Proposed Save Game Update
« Reply #28 on: July 10, 2017, 12:17:21 am »
It occurs to me that sometimes I'd like a "Save and Quit" button. There are definitely times when you want to save and then exit, so giving a button for this scenario just seems like a nice quality of life boost for the user. I put the button between "Save" and "Close" so it should be hard to click by accident (though since you just saved, it's hardly a problem).

This code to do it when added to Window_SaveGameMenu.cs. It's the same code from the ordinary Save button, but with the QuitRequested line added. There is an unfortunate gotcha here, which is that if there's not some sort of sleep between queueing the Save Command and the Quit instruction, you lose the save which is why I have included a very hacky 5 second sleep. I'm sure there's a better technique though....

Code: [Select]
      public class bSaveAndQuit : ButtonAbstractBase
        {
            //This button is like Save, but it also quits the game                                                                                                 
            public override void GetTextToShow( ArcenDoubleCharacterBuffer Buffer )
            {
                base.GetTextToShow( Buffer );
                Buffer.Add( "Save And Quit" );
            }
            public override void HandleClick()
            {
              debug = true;
                if ( iCampaignName.Instance.CampaignName.Trim().Length <= 0 )
                    iCampaignName.Instance.CampaignName = World_AIW2.Instance.Setup.MapType.InternalName + "." + World_AIW2.Instance.Setup.Seed;
                Window_SaveGameMenu.Instance.OverallCampaignName = iCampaignName.Instance.CampaignName;
                GameCommand command = GameCommand.Create( GameCommandType.SaveGame );
                //generate the saveGame entry from the name and state of the game                                                                                   
                DateTime dt = DateTime.Now;
                //Generate a SaveGameData from the saveGame and campaignName boxes,                                                                                 
                //along with game metadata                                                                                                                         
                SaveGameData data = new SaveGameData( iSaveGameName.Instance.SaveName, World_AIW2.Instance.Setup.Seed,
                                                       World_AIW2.Instance.GameSecond, iCampaignName.Instance.CampaignName,
                                                       dt, World_AIW2.Instance.Setup.MasterAIType.Name, World_AIW2.Instance.Setup.Difficulty.Name );

                data.setShortMapType( World_AIW2.Instance.Setup.MapType.InternalName );
                command.RelatedString = data.ToString();
                World_AIW2.Instance.QueueGameCommand( command, true );
                Window_SaveGameMenu.Instance.Close();
                System.Threading.Thread.Sleep(5000); /* If you call QuitRequested immediately after queuing the save command                                       
                                                          it seems like sometimes the save doesn't take place.                                                     
                                                          Inserting a 5 seconds sleep seems to alleviate this,                                                     
                                                          but it feels incredibly hacky. Is there a way to insert a memory fence/barrier                           
                                                          or it's c# equivalent? */
                Engine_AIW2.QuitRequested = true;
            }
            public override void HandleMouseover() { }
            public override void OnUpdate() { }


        }

And its companion code to KDL_UIWindows.xml
Code: [Select]
     <element prefab_lookup_name="BasicText" x="52.0" y="9.0"  y_align="Bottom" width="20" height="4" type_name="tCampaignHeader" />
     <element prefab_lookup_name="BasicTextbox" x="66.0" y="9.0"  y_align="Bottom" width="15" height="4" type_name="iCampaignName" />
     <element prefab_lookup_name="ButtonBlueSmallerCenter" x="11.0" y_align="Bottom" y="3.0" width="12" height="6"  type_name="bSaveGameName" />
    <element prefab_lookup_name="ButtonBlueSmallerCenter" x="25.0" y_align="Bottom" y="3.0" width="12" height="6"  type_name="bSaveAndQuit" /> <!-- This line in particular -->
     <element prefab_lookup_name="ButtonBlueSmallerCenter" x="39.0"  y_align="Bottom" y="3.0" width="12" height="6" type_name="bClose" />
[\code]

Offline keith.lamothe

  • Arcen Games Staff
  • Arcen Staff
  • Zenith Council Member Mark III
  • *****
  • Posts: 19,505
Re: Proposed Save Game Update
« Reply #29 on: July 24, 2017, 11:57:18 am »
Just in for 0.503:

* Added BadgerBadger's "Save and Quit" button to save menu.

Thanks :)

I sorted out the save/quit synchronization thing with a small modification to the core dll.
Have ideas or bug reports for one of our games? Mantis for Suggestions and Bug Reports. Thanks for helping to make our games better!