Skip to content

Commit dbef16a

Browse files
committedDec 18, 2023
Feature: Add example of config callback
1 parent 361806d commit dbef16a

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed
 

‎content/ExampleActions.cs

+16-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,26 @@ namespace ExampleMod.Content;
55
internal static class ExampleActions
66
{
77
[Hotfixable]
8-
public static bool example_trait_special_effect(BaseSimObject pTarget, WorldTile pTile){
8+
public static bool example_trait_special_effect(BaseSimObject pTarget, WorldTile pTile)
9+
{
910
if (pTarget == null || !pTarget.isAlive()) return false;
1011
// You can modify the method when game running. And click the reload button in the mod menu to reload the method.
1112
// 你可以在游戏运行时修改方法,然后点击mod菜单中的reload按钮来重新加载方法。
1213
ExampleModMain.LogInfo($"{pTarget.base_data.name} is being affected by ExampleTrait");
1314
return true;
1415
}
16+
17+
// This method will be called when config value set. ATTENTION: It might be called when game start.
18+
// 这个方法会在配置值被设置时调用。注意:这个方法会在模组被加载时调用。
19+
public static void ExampleSwitchConfigCallBack(bool pCurrentValue)
20+
{
21+
ExampleModMain.LogInfo($"Current value of a switch config is '{pCurrentValue}'");
22+
}
23+
24+
// This method will be called when config value set. ATTENTION: It might be called when game start.
25+
// 这个方法会在配置值被设置时调用。注意:这个方法会在模组被加载时调用。
26+
public static void ExampleSliderConfigCallback(float pCurrentValue)
27+
{
28+
ExampleModMain.LogInfo($"Current value of a slider config is '{pCurrentValue}'");
29+
}
1530
}

‎default_config.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
"Id": "Example Switch",
55
"Type": "SWITCH",
66
"IconPath": "ui/icons/iconHideUI",
7-
"BoolVal": true
7+
"BoolVal": true,
8+
"Callback": "ExampleActions:ExampleSwitchConfigCallBack"
89
},
910
{
1011
"Id": "Example Slider",
1112
"Type": "SLIDER",
1213
"IconPath": "ui/icons/iconKingdomZones",
13-
"FloatVal": 0.5
14+
"FloatVal": 0.5,
15+
"Callback": "ExampleActions:ExampleSliderConfigCallback"
1416
},
1517
{
1618
"Id": "Example TextInput",

0 commit comments

Comments
 (0)