Discussion Suggestion Internal methods all around GameMenu related code makes it hard to manage menus

Users who are viewing this thread

azakhi

TAFKAD
Sergeant Knight
Hello,
For a mod I am developing, I needed to dynamically add/remove menus and menu options. Unfortunately a lot of methods through relevant code are defined `internal`. I was able to use `CampaignGameStarter` to add and remove menus. Same class is usable for adding menu options too. However I can't remove menu options because
1- All the methods are internal
2- `CampaignGameStarter.AddGameMenuOption` doesn't let us give a related object.
Why is the related object null here instead of an argument with default value?
C#:
public void AddGameMenuOption(string menuId, string optionId, string optionText, GameMenuOption.OnConditionDelegate condition, GameMenuOption.OnConsequenceDelegate consequence, bool isLeave = false, int index = -1, bool isRepeatable = false)
{
    this.GetPresumedGameMenu(menuId).AddOption(optionId, new TextObject(optionText, null), condition, consequence, index, isLeave, isRepeatable, null);
}

Please either give us the ability to pass related objects to this method or change internal methods.
 
Access modifiers such as internal and private are a code design choice to enforce good practices and ensure that specialized parts are not misused. They are a part of our software engineering work and not there to enforce / enable mod compatibility.
 
Thanks.

Hopefully the above mentioned method can be updated to allow passing related object.
 
While on this topic, this part seems to be a bug/oversight:
C#:
public void RemoveRelatedGameMenus(object relatedObject)
{
    List<string> list = new List<string>();
    foreach (KeyValuePair<string, GameMenu> keyValuePair in this._gameMenus)
    {
        if (keyValuePair.Value.RelatedObject == relatedObject)
        {
            list.Add(keyValuePair.Key);
        }
    }
    foreach (string key in list)
    {
        this._gameMenus.Remove(key);
    }
}

public void RemoveRelatedGameMenuOptions(object relatedObject)
{
    foreach (KeyValuePair<string, GameMenu> keyValuePair in this._gameMenus.ToList<KeyValuePair<string, GameMenu>>())
    {
        foreach (GameMenuOption gameMenuOption in keyValuePair.Value.MenuOptions.ToList<GameMenuOption>())
        {
            if (gameMenuOption.RelatedObject == relatedObject)
            {
                keyValuePair.Value.RemoveMenuOption(gameMenuOption);
                break;
            }
        }
    }
}

`RemoveRelatedGameMenus` removes all the menus with related object while `RemoveRelatedGameMenuOptions` removes only 1 option from every menu that has it, although the method name suggests otherwise.
 
Hello, instead of removing and adding game menus, you can define variables to enable/disable a game menu option at any time using "GameMenuOption.OnConditionDelegate".

As for the "RemoveRelatedGameMenuOptions" bug, it is fixed internally and will be released in upcoming versions :smile:
 
Hello, instead of removing and adding game menus, you can define variables to enable/disable a game menu option at any time using "GameMenuOption.OnConditionDelegate".

As for the "RemoveRelatedGameMenuOptions" bug, it is fixed internally and will be released in upcoming versions :smile:
Thanks for fixing the bug.
As for disabling game menus, suppose number of menu options can change. Like a future update or another mod brings an ability to have different number of workshops in a town and I want to have a menu option for every workshop. In that case how can I do that with enabling/disabling? Surely I shouldn't be adding 10 extra menu options just in case and disabling them (which means they are still visible), don't you think?
 
Back
Top Bottom