Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class MCM_OptionsScreen extends UIScreen implements(MCM_API, MCM_API_Instance)
config(ModConfigMenu) dependson(UIDialogueBox);


var config int PANEL_X;
var config int PANEL_Y;
var config int TABLIST_WIDTH;
Expand All @@ -15,6 +16,16 @@ var config int FOOTER_HEIGHT;
// Save and Exit button. Allows for bigger menu.
var config bool SHOW_SOLDIER;

//
struct CustomSettingsPage
{
var string TabLabel;
var string ScreenClass;
var eGameMode ShowInGameMode;
var int PageID; // PageID will be overwritten when initializing tabs, so don't assign one in config
};
var config array<CustomSettingsPage> CustomPages;

// Needs major version match and requested minor version needs to be <= actual minor version.
var config int API_MAJOR_VERSION;
var config int API_MINOR_VERSION;
Expand Down Expand Up @@ -91,6 +102,7 @@ simulated function UpdateGameMode()

simulated function OnInit()
{
local CustomSettingsPage TmpSetting;
super.OnInit();

`log("MCM Core: On Init Called.");
Expand All @@ -100,6 +112,20 @@ simulated function OnInit()
`log("MCM Core: hiding soldier guy on main menu for visibility.");
HideSoldierIfMainMenu();
}

// Iterate through all custom settings
foreach CustomPages(TmpSetting)
{
if (TmpSetting.ShowInGameMode == CurrentGameMode)
{
NewConfigSettingsPage(TmpSetting);
}
else
{
TmpSetting.PageID = -1;
}
}

}

simulated function OnRemoved()
Expand Down Expand Up @@ -441,6 +467,58 @@ function bool RegisterClientMod(int major, int minor, delegate<ClientModCallback
}
}

// Config-based custom settings pages=============================================================

simulated function CustomScreenTabClickedHandler(MCM_SettingsTab Caller, int PageID)
{
local MCM_SettingsTab TmpButton;
local CustomSettingsPage TmpSetting;
local class<UIScreen> ScreenClass;
`log("MCM Tab clicked: " $ string(PageID));

Caller.SetChecked(false);

// Now choose the panel.
foreach CustomPages(TmpSetting)
{
if (TmpSetting.PageID == PageID)
{
`log("MCM: Found correct panel, showing screen" @ TmpSetting.ScreenClass);
ScreenClass = class<UIScreen>(DynamicLoadObject(TmpSetting.ScreenClass, class'Class'));
if (ScreenClass != none)
{
Movie.Stack.Push(PC.Pres.Spawn(ScreenClass, PC.Pres));
}
}
}

// Refresh the button. This is important if we're cancelling a tab change.
foreach SettingsTabs(TmpButton)
{
if (TmpButton.SettingsPageID == SelectedPageID)
{
TmpButton.SetChecked(true);
}
else
{
TmpButton.SetChecked(false);
}
}
}

function int NewConfigSettingsPage(out CustomSettingsPage CustomSetting)
{
local MCM_SettingsTab Item;

CustomSetting.PageID = SettingsPageCounter;
SettingsPageCounter++;

Item = Spawn(class'MCM_SettingsTab', TabsList.ItemContainer).InitSettingsTab(CustomSetting.PageID, CustomSetting.TabLabel);
Item.OnClickHandler = CustomScreenTabClickedHandler;

return CustomSetting.PageID;
}

// Defaults ======================================================================================

defaultproperties
Expand Down
14 changes: 14 additions & 0 deletions documentation/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,20 @@ your custom settings page. You will have to implement your own saving/cancelling
An example of how to use `NewCustomSettingsPage` can be found in the `MCM_CustomPageTest.uc` and `MC_CustomPageTestUI.uc`
files in the `ModConfigMenu` project.

### Custom Settings Pages by ini config

You may also add new custom settings pages through ini config without using MCM_API.

To add a custom page entry, create the file `XComModConfigMenu.ini` with the following contents:

```
[ModConfigMenu.MCM_OptionsScreen]
+CustomPages=(TabLabel="Mod Name", ScreenClass="YourMod.YourOptionsScreen", ShowInGameMode=eGameMode_MainMenu)
```

Where `TabLabel` will be the name that appears on the left of the menu. `ScreenClass` will be the class of your custom options screen (Note that you need to include your mod package name to avoid class name conflicts). And `ShowInGameMode` will be the options menu screen your custom page will show up in, the available values can be found in the next section, you will need to repeat the line for each menu you want the custom page to show up on.


### Limit options for main menu / Avenger screen / In-mission screen

MCM will tell you about the game mode through the handler you passed into the version check. You can see an example in
Expand Down