mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-11-21 19:45:10 +00:00
Fix Popup Setting (#485)
* Remove old setting * Readded setting * Make setting actually work * Add override functions * Reset overrides on network shutdown * Use djui_is_popup_disabled instead of ternary expression * Move all the other stuff out of .h file
This commit is contained in:
parent
cf20658079
commit
95d4d627ea
8 changed files with 157 additions and 0 deletions
|
@ -8524,6 +8524,11 @@ function deref_s32_pointer(pointer)
|
|||
-- ...
|
||||
end
|
||||
|
||||
--- @return boolean
|
||||
function djui_is_popup_disabled()
|
||||
-- ...
|
||||
end
|
||||
|
||||
--- @param message string
|
||||
--- @param lines integer
|
||||
--- @return nil
|
||||
|
@ -8531,6 +8536,17 @@ function djui_popup_create_global(message, lines)
|
|||
-- ...
|
||||
end
|
||||
|
||||
--- @return nil
|
||||
function djui_reset_popup_disabled_override()
|
||||
-- ...
|
||||
end
|
||||
|
||||
--- @param value boolean
|
||||
--- @return nil
|
||||
function djui_set_popup_disabled_override(value)
|
||||
-- ...
|
||||
end
|
||||
|
||||
--- @return integer
|
||||
function get_current_save_file_num()
|
||||
-- ...
|
||||
|
|
|
@ -606,6 +606,24 @@
|
|||
|
||||
<br />
|
||||
|
||||
## [djui_is_popup_disabled](#djui_is_popup_disabled)
|
||||
|
||||
### Lua Example
|
||||
`local booleanValue = djui_is_popup_disabled()`
|
||||
|
||||
### Parameters
|
||||
- None
|
||||
|
||||
### Returns
|
||||
- `boolean`
|
||||
|
||||
### C Prototype
|
||||
`bool djui_is_popup_disabled(void);`
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
<br />
|
||||
|
||||
## [djui_popup_create_global](#djui_popup_create_global)
|
||||
|
||||
### Lua Example
|
||||
|
@ -627,6 +645,44 @@
|
|||
|
||||
<br />
|
||||
|
||||
## [djui_reset_popup_disabled_override](#djui_reset_popup_disabled_override)
|
||||
|
||||
### Lua Example
|
||||
`djui_reset_popup_disabled_override()`
|
||||
|
||||
### Parameters
|
||||
- None
|
||||
|
||||
### Returns
|
||||
- None
|
||||
|
||||
### C Prototype
|
||||
`void djui_reset_popup_disabled_override(void);`
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
<br />
|
||||
|
||||
## [djui_set_popup_disabled_override](#djui_set_popup_disabled_override)
|
||||
|
||||
### Lua Example
|
||||
`djui_set_popup_disabled_override(value)`
|
||||
|
||||
### Parameters
|
||||
| Field | Type |
|
||||
| ----- | ---- |
|
||||
| value | `boolean` |
|
||||
|
||||
### Returns
|
||||
- None
|
||||
|
||||
### C Prototype
|
||||
`void djui_set_popup_disabled_override(bool value);`
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
<br />
|
||||
|
||||
## [get_current_save_file_num](#get_current_save_file_num)
|
||||
|
||||
### Lua Example
|
||||
|
|
|
@ -1590,7 +1590,10 @@
|
|||
- [camera_unfreeze](functions-5.md#camera_unfreeze)
|
||||
- [course_is_main_course](functions-5.md#course_is_main_course)
|
||||
- [deref_s32_pointer](functions-5.md#deref_s32_pointer)
|
||||
- [djui_is_popup_disabled](functions-5.md#djui_is_popup_disabled)
|
||||
- [djui_popup_create_global](functions-5.md#djui_popup_create_global)
|
||||
- [djui_reset_popup_disabled_override](functions-5.md#djui_reset_popup_disabled_override)
|
||||
- [djui_set_popup_disabled_override](functions-5.md#djui_set_popup_disabled_override)
|
||||
- [get_current_save_file_num](functions-5.md#get_current_save_file_num)
|
||||
- [get_dialog_box_state](functions-5.md#get_dialog_box_state)
|
||||
- [get_dialog_id](functions-5.md#get_dialog_id)
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#include "audio/external.h"
|
||||
#include "pc/network/network.h"
|
||||
#include "pc/utils/misc.h"
|
||||
#include "pc/configfile.h"
|
||||
#include "pc/lua/utils/smlua_misc_utils.h"
|
||||
|
||||
#define DJUI_POPUP_LIFETIME 6.0f
|
||||
|
||||
|
@ -34,6 +36,7 @@ static void djui_popup_destroy(struct DjuiBase* base) {
|
|||
}
|
||||
|
||||
void djui_popup_create(const char* message, int lines) {
|
||||
if (djui_is_popup_disabled()) { return; }
|
||||
struct DjuiPopup* popup = calloc(1, sizeof(struct DjuiPopup));
|
||||
struct DjuiBase* base = &popup->base;
|
||||
|
||||
|
|
|
@ -28248,6 +28248,21 @@ int smlua_func_deref_s32_pointer(lua_State* L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
int smlua_func_djui_is_popup_disabled(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", "djui_is_popup_disabled", 0, top);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
lua_pushboolean(L, djui_is_popup_disabled());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int smlua_func_djui_popup_create_global(lua_State* L) {
|
||||
if (L == NULL) { return 0; }
|
||||
|
||||
|
@ -28267,6 +28282,38 @@ int smlua_func_djui_popup_create_global(lua_State* L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
int smlua_func_djui_reset_popup_disabled_override(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", "djui_reset_popup_disabled_override", 0, top);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
djui_reset_popup_disabled_override();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int smlua_func_djui_set_popup_disabled_override(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", "djui_set_popup_disabled_override", 1, top);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool value = smlua_to_boolean(L, 1);
|
||||
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "djui_set_popup_disabled_override"); return 0; }
|
||||
|
||||
djui_set_popup_disabled_override(value);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int smlua_func_get_current_save_file_num(UNUSED lua_State* L) {
|
||||
if (L == NULL) { return 0; }
|
||||
|
||||
|
@ -32133,7 +32180,10 @@ void smlua_bind_functions_autogen(void) {
|
|||
smlua_bind_function(L, "camera_unfreeze", smlua_func_camera_unfreeze);
|
||||
smlua_bind_function(L, "course_is_main_course", smlua_func_course_is_main_course);
|
||||
smlua_bind_function(L, "deref_s32_pointer", smlua_func_deref_s32_pointer);
|
||||
smlua_bind_function(L, "djui_is_popup_disabled", smlua_func_djui_is_popup_disabled);
|
||||
smlua_bind_function(L, "djui_popup_create_global", smlua_func_djui_popup_create_global);
|
||||
smlua_bind_function(L, "djui_reset_popup_disabled_override", smlua_func_djui_reset_popup_disabled_override);
|
||||
smlua_bind_function(L, "djui_set_popup_disabled_override", smlua_func_djui_set_popup_disabled_override);
|
||||
smlua_bind_function(L, "get_current_save_file_num", smlua_func_get_current_save_file_num);
|
||||
smlua_bind_function(L, "get_dialog_box_state", smlua_func_get_dialog_box_state);
|
||||
smlua_bind_function(L, "get_dialog_id", smlua_func_get_dialog_id);
|
||||
|
|
|
@ -49,6 +49,30 @@ void djui_popup_create_global(const char* message, int lines) {
|
|||
network_send_global_popup(message, lines);
|
||||
}
|
||||
|
||||
struct AllowDjuiPopupOverride {
|
||||
bool value;
|
||||
bool override;
|
||||
};
|
||||
|
||||
struct AllowDjuiPopupOverride sAllowDjuiPopupOverride;
|
||||
|
||||
bool djui_is_popup_disabled(void) {
|
||||
// return override if there is one, otherwise return the value in the config.
|
||||
return sAllowDjuiPopupOverride.override ? sAllowDjuiPopupOverride.value : configDisablePopups;
|
||||
}
|
||||
|
||||
void djui_set_popup_disabled_override(bool value) {
|
||||
// enable override
|
||||
sAllowDjuiPopupOverride.override = true;
|
||||
// set override to value specified in lua mod
|
||||
sAllowDjuiPopupOverride.value = value;
|
||||
}
|
||||
|
||||
void djui_reset_popup_disabled_override(void) {
|
||||
// disable override
|
||||
sAllowDjuiPopupOverride.override = false;
|
||||
}
|
||||
|
||||
///
|
||||
|
||||
void hud_hide(void) {
|
||||
|
|
|
@ -34,6 +34,9 @@ enum HudDisplayFlags {
|
|||
};
|
||||
|
||||
void djui_popup_create_global(const char* message, int lines);
|
||||
bool djui_is_popup_disabled(void);
|
||||
void djui_set_popup_disabled_override(bool value);
|
||||
void djui_reset_popup_disabled_override(void);
|
||||
void hud_hide(void);
|
||||
void hud_show(void);
|
||||
bool hud_is_hidden(void);
|
||||
|
|
|
@ -695,4 +695,6 @@ void network_shutdown(bool sendLeaving, bool exiting, bool popup, bool reconnect
|
|||
discord_activity_update();
|
||||
#endif
|
||||
packet_ordered_clear_all();
|
||||
|
||||
djui_reset_popup_disabled_override();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue