• We'll be making a number of structural changes to the forums on Wednesday, 06.12.2023. No downtime is expected. Read more here.

Suggestion General Dynamically populated UI VM's

Users who are viewing this thread

Jance

Recruit
Currently, several screens (CharacterCreation and CustomBattleMenu for example) are populated using hard-coded static fields. Here is an example from CustomBattleData.cs:

C#:
public static IEnumerable<BasicCharacterObject> Characters
    {
      get
      {
        yield return Game.Current.ObjectManager.GetObject<BasicCharacterObject>("commander_1");
        if (!Module.CurrentModule.IsOnlyCoreContentEnabled)
        {
          yield return Game.Current.ObjectManager.GetObject<BasicCharacterObject>("commander_2");
          yield return Game.Current.ObjectManager.GetObject<BasicCharacterObject>("commander_3");
          yield return Game.Current.ObjectManager.GetObject<BasicCharacterObject>("commander_4");
          yield return Game.Current.ObjectManager.GetObject<BasicCharacterObject>("commander_5");
          yield return Game.Current.ObjectManager.GetObject<BasicCharacterObject>("commander_6");
          yield return Game.Current.ObjectManager.GetObject<BasicCharacterObject>("commander_7");
          yield return Game.Current.ObjectManager.GetObject<BasicCharacterObject>("commander_8");
          yield return Game.Current.ObjectManager.GetObject<BasicCharacterObject>("commander_9");
          yield return Game.Current.ObjectManager.GetObject<BasicCharacterObject>("commander_10");
        }
        yield return Game.Current.ObjectManager.GetObject<BasicCharacterObject>("commander_11");
        if (!Module.CurrentModule.IsOnlyCoreContentEnabled)
          yield return Game.Current.ObjectManager.GetObject<BasicCharacterObject>("commander_12");
      }
    }

    public static IEnumerable<BasicCultureObject> Factions
    {
      get
      {
        yield return Game.Current.ObjectManager.GetObject<BasicCultureObject>("empire");
        if (!Module.CurrentModule.IsOnlyCoreContentEnabled)
        {
          yield return Game.Current.ObjectManager.GetObject<BasicCultureObject>("sturgia");
          yield return Game.Current.ObjectManager.GetObject<BasicCultureObject>("aserai");
          yield return Game.Current.ObjectManager.GetObject<BasicCultureObject>("vlandia");
          yield return Game.Current.ObjectManager.GetObject<BasicCultureObject>("battania");
          yield return Game.Current.ObjectManager.GetObject<BasicCultureObject>("khuzait");
        }
      }
    }

The character creation culture selection VM is populated in a similar fashion, and I wouldn't be surprised if other UI VM's also are populated with static fields.

A simple solution would be making those methods virtual, which would allow for modders to implement their own class inheriting from CustomBattleData which loads whichever cultures/characters/etc. they want without having to use harmony patching/re-implementing a significant amount of code.
 
I'll take a look at these, thank you for the report!
Thanks for the quick reply. In addition:

- You should add a default brush in MultiplayerLobbyClassFilterFactionItemWidget when there isn't a brush found matching the current query:
C#:
this.Brush = this.Context.BrushFactory.GetBrush(this.BaseBrushName + "." + this.Culture[0].ToString().ToUpper() + this.Culture.Substring(1).ToLower());

- The code for populating the culture selection VM is deeply nested in the Character Creation code, so the virtual method approach might not be useful for fixing that. Instead, I would recommend making the culture selection screen scrollable, and add an xml attribute to cultures (eg. is_playable) which can be queried dynamically
 
1. Makes sense, I'll add it to my notes
2. Thank you, will look into this as well
 
Back
Top Bottom