SirHack'nSmash
Recruit

To assist with mod development, I want to add a button to the escape menu that can be used to call code within a C# function. So far I have added a DLL that includes a couple of functions, both of which are confirmed working by calling them in the OnCampaignStart event:
I have also added a button to the escape menu that appears to work (it highlights on mouse over and makes a sound when clicked) by modifying the file
"MyMod\GUI\Prefabs\EscapeMenu.xml" with the following markup, added below the </ListPanel> tag in the original file.
Where the button markup shows:
Command.Click="[HELP]"
I have tried:
Command.Click="TestClick"
Command.Click="Main.TestClick"
Command.Click="MyMod.Main.TestClick"
In my "MyMod.dll" file, the "MyMod" namespace contains the "Main" class wherein the "TestClick()" function is defined, so the attempts to call it above where just guesses. None worked so I looked back at the original markup for the "EscapeMenuButtonWidget" which I copied from within the same file.
The original markup uses Command.Click="ExecuteAction" which seems to refer to an action property of a list in the data model because the button is defined as a template for multiple buttons within a ListPanel. The use of the word "Action" led me to look into the System.Action delegate but I'm taking guesses here and have no real idea how to link my button to some code.
Does anyone have any idea how to make an escape menu button that calls C# code?
插入代码块:
public void TestClick()
{
ShowMessage("Click", "#ffffffff");
}
/// <summary>
/// Displays a message in a specified colour.
/// Colour string format is "#RRGGBBAA". Alpha is required but not used.
/// </summary>
public void ShowMessage(string strText, string strColour)
{
TaleWorlds.Library.Color xColor = TaleWorlds.Library.Color.ConvertStringToColor(strColour);
InformationMessage xMessage = new InformationMessage(strText, xColor);
InformationManager.DisplayMessage(xMessage);
}
I have also added a button to the escape menu that appears to work (it highlights on mouse over and makes a sound when clicked) by modifying the file
"MyMod\GUI\Prefabs\EscapeMenu.xml" with the following markup, added below the </ListPanel> tag in the original file.
插入代码块:
<!-- Modified -->
<EscapeMenuButtonWidget DoNotPassEventsToChildren="true" Command.Click="[HELP]" WidthSizePolicy="Fixed"
HeightSizePolicy="Fixed" SuggestedWidth="!ContextButton.Width" SuggestedHeight="!ContextButton.Height" HorizontalAlignment="Right"
VerticalAlignment="Center" Brush="ButtonBrush2" PositiveBehaviourBrush="ButtonBrush1" IsDisabled="@IsDisabled"
IsPositiveBehavioured="@IsPositiveBehavioured" MarginBottom="30">
<Children>
<TextWidget WidthSizePolicy="StretchToParent" HeightSizePolicy="StretchToParent" PositionYOffset="1" Text="Click Me"
Brush="OverlayPopup.ButtonText" ClipContents="false"/>
</Children>
</EscapeMenuButtonWidget>
<!-- Modified -->
Where the button markup shows:
Command.Click="[HELP]"
I have tried:
Command.Click="TestClick"
Command.Click="Main.TestClick"
Command.Click="MyMod.Main.TestClick"
In my "MyMod.dll" file, the "MyMod" namespace contains the "Main" class wherein the "TestClick()" function is defined, so the attempts to call it above where just guesses. None worked so I looked back at the original markup for the "EscapeMenuButtonWidget" which I copied from within the same file.
The original markup uses Command.Click="ExecuteAction" which seems to refer to an action property of a list in the data model because the button is defined as a template for multiple buttons within a ListPanel. The use of the word "Action" led me to look into the System.Action delegate but I'm taking guesses here and have no real idea how to link my button to some code.
Does anyone have any idea how to make an escape menu button that calls C# code?