Add ability to change window title

This commit is contained in:
Agent X 2024-02-22 13:36:22 -05:00
parent a2de8d7957
commit 5c3ebadb8e
12 changed files with 139 additions and 1 deletions

View file

@ -8931,6 +8931,11 @@ function play_transition(transType, time, red, green, blue)
-- ...
end
--- @return nil
function reset_window_title()
-- ...
end
--- @return boolean
function save_file_get_using_backup_slot()
-- ...
@ -9049,6 +9054,12 @@ function set_vertex_color(index, value)
-- ...
end
--- @param title string
--- @return nil
function set_window_title(title)
-- ...
end
--- @param name string
--- @return integer
function smlua_model_util_get_id(name)

View file

@ -1460,6 +1460,24 @@
<br />
## [reset_window_title](#reset_window_title)
### Lua Example
`reset_window_title()`
### Parameters
- None
### Returns
- None
### C Prototype
`void reset_window_title(void);`
[:arrow_up_small:](#)
<br />
## [save_file_get_using_backup_slot](#save_file_get_using_backup_slot)
### Lua Example
@ -1843,6 +1861,26 @@
<br />
## [set_window_title](#set_window_title)
### Lua Example
`set_window_title(title)`
### Parameters
| Field | Type |
| ----- | ---- |
| title | `string` |
### Returns
- None
### C Prototype
`void set_window_title(const char* title);`
[:arrow_up_small:](#)
<br />
---
# functions from smlua_model_utils.h

View file

@ -1672,6 +1672,7 @@
- [is_transition_playing](functions-5.md#is_transition_playing)
- [movtexqc_register](functions-5.md#movtexqc_register)
- [play_transition](functions-5.md#play_transition)
- [reset_window_title](functions-5.md#reset_window_title)
- [save_file_get_using_backup_slot](functions-5.md#save_file_get_using_backup_slot)
- [save_file_set_using_backup_slot](functions-5.md#save_file_set_using_backup_slot)
- [set_environment_region](functions-5.md#set_environment_region)
@ -1691,6 +1692,7 @@
- [set_save_file_modified](functions-5.md#set_save_file_modified)
- [set_ttc_speed_setting](functions-5.md#set_ttc_speed_setting)
- [set_vertex_color](functions-5.md#set_vertex_color)
- [set_window_title](functions-5.md#set_window_title)
<br />

View file

@ -84,6 +84,12 @@ static int gfx_dummy_get_max_msaa(void) {
return 0;
}
static void gfx_dummy_set_window_title(UNUSED const char* title) {
}
static void gfx_dummy_reset_window_title(void) {
}
static void gfx_dummy_wm_swap_buffers_begin(void) {
}
@ -207,6 +213,8 @@ struct GfxWindowManagerAPI gfx_dummy_wm_api = {
gfx_dummy_wm_set_cursor_visible,
gfx_dummy_wm_delay,
gfx_dummy_get_max_msaa,
gfx_dummy_set_window_title,
gfx_dummy_reset_window_title
};
struct GfxRenderingAPI gfx_dummy_renderer_api = {

View file

@ -670,6 +670,14 @@ static int gfx_dxgi_get_max_msaa(void) {
return 0;
}
static void gfx_dxgi_set_window_title(const char* title) {
SetWindowTextA(dxgi.h_wnd, title);
}
static void gfx_dxgi_reset_window_title(void) {
SetWindowTextA(dxgi.h_wnd, TITLE);
}
HWND gfx_dxgi_get_h_wnd(void) {
return dxgi.h_wnd;
}

View file

@ -184,6 +184,14 @@ static int gfx_sdl_get_max_msaa(void) {
return 0;
}
static void gfx_sdl_set_window_title(const char* title) {
SDL_WM_SetCaption(title, NULL);
}
static void gfx_sdl_reset_window_title(void) {
SDL_WM_SetCaption(TITLE, NULL);
}
static void gfx_sdl_shutdown(void) {
if (SDL_WasInit(0))
SDL_Quit();
@ -213,6 +221,8 @@ struct GfxWindowManagerAPI gfx_sdl = {
gfx_sdl_set_cursor_visible,
gfx_sdl_delay,
gfx_sdl_get_max_msaa,
gfx_sdl_set_window_title,
gfx_sdl_reset_window_title
};
#endif // BACKEND_WM

View file

@ -255,6 +255,14 @@ static int gfx_sdl_get_max_msaa(void) {
return maxSamples;
}
static void gfx_sdl_set_window_title(const char* title) {
SDL_SetWindowTitle(wnd, title);
}
static void gfx_sdl_reset_window_title(void) {
SDL_SetWindowTitle(wnd, TITLE);
}
static void gfx_sdl_shutdown(void) {
if (SDL_WasInit(0)) {
if (ctx) { SDL_GL_DeleteContext(ctx); ctx = NULL; }
@ -287,6 +295,8 @@ struct GfxWindowManagerAPI gfx_sdl = {
gfx_sdl_set_cursor_visible,
gfx_sdl_delay,
gfx_sdl_get_max_msaa,
gfx_sdl_set_window_title,
gfx_sdl_reset_window_title
};
#endif // BACKEND_WM

View file

@ -27,6 +27,8 @@ struct GfxWindowManagerAPI {
void (*set_cursor_visible)(bool);
void (*delay)(unsigned int ms);
int (*get_max_msaa)(void);
void (*set_window_title)(const char* title);
void (*reset_window_title)(void);
};
#endif

View file

@ -29414,6 +29414,21 @@ int smlua_func_play_transition(lua_State* L) {
return 1;
}
int smlua_func_reset_window_title(UNUSED lua_State* L) {
if (L == NULL) { return 0; }
int top = lua_gettop(L);
if (top != 0) {
LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "reset_window_title", 0, top);
return 0;
}
reset_window_title();
return 1;
}
int smlua_func_save_file_get_using_backup_slot(UNUSED lua_State* L) {
if (L == NULL) { return 0; }
@ -29745,6 +29760,23 @@ int smlua_func_set_vertex_color(lua_State* L) {
return 1;
}
int smlua_func_set_window_title(lua_State* L) {
if (L == NULL) { return 0; }
int top = lua_gettop(L);
if (top != 1) {
LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "set_window_title", 1, top);
return 0;
}
const char* title = smlua_to_string(L, 1);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "set_window_title"); return 0; }
set_window_title(title);
return 1;
}
/////////////////////////
// smlua_model_utils.h //
/////////////////////////
@ -32973,6 +33005,7 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "is_transition_playing", smlua_func_is_transition_playing);
smlua_bind_function(L, "movtexqc_register", smlua_func_movtexqc_register);
smlua_bind_function(L, "play_transition", smlua_func_play_transition);
smlua_bind_function(L, "reset_window_title", smlua_func_reset_window_title);
smlua_bind_function(L, "save_file_get_using_backup_slot", smlua_func_save_file_get_using_backup_slot);
smlua_bind_function(L, "save_file_set_using_backup_slot", smlua_func_save_file_set_using_backup_slot);
smlua_bind_function(L, "set_environment_region", smlua_func_set_environment_region);
@ -32992,6 +33025,7 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "set_save_file_modified", smlua_func_set_save_file_modified);
smlua_bind_function(L, "set_ttc_speed_setting", smlua_func_set_ttc_speed_setting);
smlua_bind_function(L, "set_vertex_color", smlua_func_set_vertex_color);
smlua_bind_function(L, "set_window_title", smlua_func_set_window_title);
// smlua_model_utils.h
smlua_bind_function(L, "smlua_model_util_get_id", smlua_func_smlua_model_util_get_id);

View file

@ -12,7 +12,7 @@
#include "pc/mods/mod.h"
#include "pc/mods/mods.h"
#include "pc/mods/mods_utils.h"
#include "pc/pc_main.h"
#include "game/object_list_processor.h"
#include "game/rendering_graph_node.h"
#include "game/level_update.h"
@ -638,6 +638,16 @@ void gfx_enable_adjust_for_aspect_ratio(bool enable) {
///
void set_window_title(const char* title) {
WAPI.set_window_title(title);
}
void reset_window_title(void) {
WAPI.reset_window_title();
}
///
const char* get_os_name(void) {
#if defined(_WIN32) || defined(_WIN64)
return "Windows";

View file

@ -158,6 +158,9 @@ bool get_coop_compatibility_enabled(void);
bool gfx_get_adjust_for_aspect_ratio(void);
void gfx_enable_adjust_for_aspect_ratio(bool enable);
void set_window_title(const char* title);
void reset_window_title(void);
const char* get_os_name(void);
#endif

View file

@ -722,6 +722,8 @@ void network_shutdown(bool sendLeaving, bool exiting, bool popup, bool reconnect
extern s16 gMenuMode;
gMenuMode = -1;
reset_window_title();
djui_panel_shutdown();
extern bool gDjuiInMainMenu;
if (!gDjuiInMainMenu) {