mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-08-20 13:24:40 -04:00
Gamemode service improvements. Disable achievements on custom gamemodes (for now)
This commit is contained in:
+34
-42
@@ -699,7 +699,7 @@ const GamemodeDesc gamemodeDesc = {
|
||||
.onPlayFunction = nullptr, // Called when "Play" is pressed on the prelaunch menu
|
||||
.onSaveLoadedFunction = onSaveLoaded, // Called when a save is loaded
|
||||
.onNewSaveFunction = nullptr, // Called after a new savefile is created
|
||||
.onNewSaveSelectFunction = nullptr, // Called while the flow before the file name select is ran (see below)
|
||||
.onNewSaveSelectFunction = nullptr, // Called during the flow before the file name select is ran (see below)
|
||||
.onGameResetFunction = nullptr, // Called when the game is reset
|
||||
.onTickFunction = nullptr, // Called every game tick while the gamemode is active
|
||||
};
|
||||
@@ -710,55 +710,47 @@ Within the gamemode service, a gamemode can also request to load a UI for per-sa
|
||||
create a new file is pressed.
|
||||
|
||||
```cpp
|
||||
#include "d/d_file_select.h" // Requires game feature
|
||||
IMPORT_SERVICE(GamemodeService, svc_gamemode);
|
||||
IMPORT_SERVICE(UiService, svc_ui);
|
||||
|
||||
bool proceedUI = false;
|
||||
UiWindowHandle windowHandle;
|
||||
void onNewSaveSelect(bool *out_proceedToNameSelect, bool *out_returnToFileSelect) {
|
||||
static bool *proceedToNameSelect;
|
||||
static bool *returnToFileSelect;
|
||||
static UiWindowHandle windowHandle;
|
||||
|
||||
bool onNewSaveSelect(dFile_select_c *fileSelect) {
|
||||
if (fileSelect->mGamemodeSaveStartBuildUi) {
|
||||
proceedUI = false;
|
||||
UiTabDesc tabs[1]{};
|
||||
// Used within callbacks as needed
|
||||
proceedToNameSelect = out_proceedToNameSelect;
|
||||
returnToFileSelect = out_returnToFileSelect;
|
||||
|
||||
tabs[0].struct_size = sizeof(UiTabDesc);
|
||||
tabs[0].title = "Play";
|
||||
tabs[0].build = [](ModContext* ctx, UiWindowHandle, UiElementHandle leftPane, UiElementHandle rightPane, void*, ModError*) {
|
||||
UiControlDesc desc = UI_CONTROL_DESC_INIT;
|
||||
desc.kind = UI_CONTROL_BUTTON;
|
||||
desc.label = "Play";
|
||||
desc.help_rml = "Play Button";
|
||||
desc.on_pressed = [](ModContext* ctx, void* userdata) {
|
||||
proceedUI = true;
|
||||
svc_ui->window_close(ctx, *static_cast<UiWindowHandle*>(userdata));
|
||||
};
|
||||
desc.user_data = &windowHandle;
|
||||
svc_ui->pane_add_control(mod_ctx, leftPane, &desc, nullptr);
|
||||
return MOD_OK;
|
||||
UiTabDesc tabs[1]{};
|
||||
|
||||
tabs[0].struct_size = sizeof(UiTabDesc);
|
||||
tabs[0].title = "Play";
|
||||
tabs[0].build = [](ModContext* ctx, UiWindowHandle, UiElementHandle leftPane, UiElementHandle rightPane, void*, ModError*) {
|
||||
UiControlDesc desc = UI_CONTROL_DESC_INIT;
|
||||
desc.kind = UI_CONTROL_BUTTON;
|
||||
desc.label = "Play";
|
||||
desc.help_rml = "Play Button";
|
||||
desc.on_pressed = [](ModContext* ctx, void* userdata) {
|
||||
*proceedToNameSelect = true;
|
||||
svc_ui->window_close(ctx, *static_cast<UiWindowHandle*>(userdata));
|
||||
};
|
||||
desc.user_data = &windowHandle;
|
||||
svc_ui->pane_add_control(mod_ctx, leftPane, &desc, nullptr);
|
||||
return MOD_OK;
|
||||
};
|
||||
|
||||
UiWindowDesc desc = UI_WINDOW_DESC_INIT;
|
||||
desc.tabs = tabs;
|
||||
desc.tab_count = 1;
|
||||
desc.user_data = fileSelect;
|
||||
desc.on_closed = [](ModContext *, UiWindowHandle, void *userdata) {
|
||||
dFile_select_c *i_this = static_cast<dFile_select_c *>(userdata);
|
||||
UiWindowDesc desc = UI_WINDOW_DESC_INIT;
|
||||
desc.tabs = tabs;
|
||||
desc.tab_count = 1;
|
||||
desc.on_closed = [](ModContext *, UiWindowHandle, void *userdata) {
|
||||
// If closing the window through backing out, return to file select
|
||||
if (*proceedToNameSelect == false) {
|
||||
*returnToFileSelect = true;
|
||||
}
|
||||
};
|
||||
|
||||
// if closing the window through backing out, return to file select
|
||||
if (!proceedUI) {
|
||||
i_this->backToDataSelectMove();
|
||||
}
|
||||
};
|
||||
|
||||
svc_ui->window_push(mod_ctx, &desc, &windowHandle);
|
||||
}
|
||||
|
||||
// When we hit play in the UI, return true (tells the file select that we can proceed)
|
||||
if (proceedUI) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
svc_ui->window_push(mod_ctx, &desc, &windowHandle);
|
||||
}
|
||||
|
||||
const GamemodeDesc gamemodeDesc = {
|
||||
|
||||
Reference in New Issue
Block a user