mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-11-22 12:05:11 +00:00
djui_hud_get_raw_mouse_x/y, djui_hud_set_mouse_locked (#91)
This commit is contained in:
parent
d8e669d9d3
commit
4bc13ef275
8 changed files with 149 additions and 2 deletions
|
@ -3575,6 +3575,16 @@ function djui_hud_get_mouse_y()
|
|||
-- ...
|
||||
end
|
||||
|
||||
--- @return number
|
||||
function djui_hud_get_raw_mouse_x()
|
||||
-- ...
|
||||
end
|
||||
|
||||
--- @return number
|
||||
function djui_hud_get_raw_mouse_y()
|
||||
-- ...
|
||||
end
|
||||
|
||||
--- @return integer
|
||||
function djui_hud_get_screen_height()
|
||||
-- ...
|
||||
|
@ -3637,6 +3647,12 @@ function djui_hud_set_font(fontType)
|
|||
-- ...
|
||||
end
|
||||
|
||||
--- @param locked boolean
|
||||
--- @return nil
|
||||
function djui_hud_set_mouse_locked(locked)
|
||||
-- ...
|
||||
end
|
||||
|
||||
--- @param resolutionType HudUtilsResolution
|
||||
--- @return nil
|
||||
function djui_hud_set_resolution(resolutionType)
|
||||
|
|
|
@ -2033,6 +2033,42 @@
|
|||
|
||||
<br />
|
||||
|
||||
## [djui_hud_get_raw_mouse_x](#djui_hud_get_raw_mouse_x)
|
||||
|
||||
### Lua Example
|
||||
`local numberValue = djui_hud_get_raw_mouse_x()`
|
||||
|
||||
### Parameters
|
||||
- None
|
||||
|
||||
### Returns
|
||||
- `number`
|
||||
|
||||
### C Prototype
|
||||
`f32 djui_hud_get_raw_mouse_x(void);`
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
<br />
|
||||
|
||||
## [djui_hud_get_raw_mouse_y](#djui_hud_get_raw_mouse_y)
|
||||
|
||||
### Lua Example
|
||||
`local numberValue = djui_hud_get_raw_mouse_y()`
|
||||
|
||||
### Parameters
|
||||
- None
|
||||
|
||||
### Returns
|
||||
- `number`
|
||||
|
||||
### C Prototype
|
||||
`f32 djui_hud_get_raw_mouse_y(void);`
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
<br />
|
||||
|
||||
## [djui_hud_get_screen_height](#djui_hud_get_screen_height)
|
||||
|
||||
### Lua Example
|
||||
|
@ -2205,6 +2241,26 @@
|
|||
|
||||
<br />
|
||||
|
||||
## [djui_hud_set_mouse_locked](#djui_hud_set_mouse_locked)
|
||||
|
||||
### Lua Example
|
||||
`djui_hud_set_mouse_locked(locked)`
|
||||
|
||||
### Parameters
|
||||
| Field | Type |
|
||||
| ----- | ---- |
|
||||
| locked | `boolean` |
|
||||
|
||||
### Returns
|
||||
- None
|
||||
|
||||
### C Prototype
|
||||
`void djui_hud_set_mouse_locked(bool locked);`
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
<br />
|
||||
|
||||
## [djui_hud_set_resolution](#djui_hud_set_resolution)
|
||||
|
||||
### Lua Example
|
||||
|
|
|
@ -704,6 +704,8 @@
|
|||
- djui_hud_utils.h
|
||||
- [djui_hud_get_mouse_x](functions-3.md#djui_hud_get_mouse_x)
|
||||
- [djui_hud_get_mouse_y](functions-3.md#djui_hud_get_mouse_y)
|
||||
- [djui_hud_get_raw_mouse_x](functions-3.md#djui_hud_get_raw_mouse_x)
|
||||
- [djui_hud_get_raw_mouse_y](functions-3.md#djui_hud_get_raw_mouse_y)
|
||||
- [djui_hud_get_screen_height](functions-3.md#djui_hud_get_screen_height)
|
||||
- [djui_hud_get_screen_width](functions-3.md#djui_hud_get_screen_width)
|
||||
- [djui_hud_measure_text](functions-3.md#djui_hud_measure_text)
|
||||
|
@ -712,6 +714,7 @@
|
|||
- [djui_hud_render_rect_interpolated](functions-3.md#djui_hud_render_rect_interpolated)
|
||||
- [djui_hud_set_color](functions-3.md#djui_hud_set_color)
|
||||
- [djui_hud_set_font](functions-3.md#djui_hud_set_font)
|
||||
- [djui_hud_set_mouse_locked](functions-3.md#djui_hud_set_mouse_locked)
|
||||
- [djui_hud_set_resolution](functions-3.md#djui_hud_set_resolution)
|
||||
- [djui_hud_world_pos_to_screen_pos](functions-3.md#djui_hud_world_pos_to_screen_pos)
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "game/level_update.h"
|
||||
|
||||
#include "pc/djui/djui.h"
|
||||
#include "pc/djui/djui_hud_utils.h"
|
||||
|
||||
#define MAX_JOYBINDS 32
|
||||
#define MAX_MOUSEBUTTONS 8 // arbitrary
|
||||
|
@ -160,16 +161,20 @@ static inline void update_button(const int i, const bool new) {
|
|||
}
|
||||
}
|
||||
|
||||
u8 ignore_lock = FALSE;
|
||||
static void controller_sdl_read(OSContPad *pad) {
|
||||
if (!init_ok) {
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef BETTERCAMERA
|
||||
if (newcam_mouse == 1 && sCurrPlayMode != 2)
|
||||
if (newcam_mouse == 1 && sCurrPlayMode != 2) {
|
||||
SDL_SetRelativeMouseMode(SDL_TRUE);
|
||||
else
|
||||
ignore_lock = TRUE;
|
||||
} else {
|
||||
SDL_SetRelativeMouseMode(SDL_FALSE);
|
||||
ignore_lock = FALSE;
|
||||
}
|
||||
|
||||
u32 mouse = SDL_GetRelativeMouseState(&mouse_x, &mouse_y);
|
||||
|
||||
|
@ -182,6 +187,22 @@ static void controller_sdl_read(OSContPad *pad) {
|
|||
last_mouse = (mouse_buttons ^ mouse) & mouse;
|
||||
mouse_buttons = mouse;
|
||||
#endif
|
||||
if (!ignore_lock && sCurrPlayMode != 2) {
|
||||
SDL_SetRelativeMouseMode(gDjuiHudLockMouse ? SDL_TRUE : SDL_FALSE);
|
||||
|
||||
#ifndef BETTERCAMERA
|
||||
u32 mouse = SDL_GetRelativeMouseState(&mouse_x, &mouse_y);
|
||||
|
||||
if (!gInteractableOverridePad) {
|
||||
for (u32 i = 0; i < num_mouse_binds; ++i)
|
||||
if (mouse & SDL_BUTTON(mouse_binds[i][0]))
|
||||
pad->button |= mouse_binds[i][1];
|
||||
}
|
||||
// remember buttons that changed from 0 to 1
|
||||
last_mouse = (mouse_buttons ^ mouse) & mouse;
|
||||
mouse_buttons = mouse;
|
||||
#endif
|
||||
}
|
||||
|
||||
SDL_GameControllerUpdate();
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ static enum HudUtilsResolution sResolution = RESOLUTION_DJUI;
|
|||
static enum DjuiFontType sFont = FONT_NORMAL;
|
||||
|
||||
f32 gDjuiHudUtilsZ = 0;
|
||||
u8 gDjuiHudLockMouse = FALSE;
|
||||
|
||||
extern ALIGNED8 const u8 texture_hud_char_camera[];
|
||||
extern ALIGNED8 const u8 texture_hud_char_lakitu[];
|
||||
|
@ -162,6 +163,18 @@ f32 djui_hud_get_mouse_y(void) {
|
|||
return mouse_window_y / djui_gfx_get_scale();
|
||||
}
|
||||
|
||||
f32 djui_hud_get_raw_mouse_x(void) {
|
||||
return mouse_x;
|
||||
}
|
||||
|
||||
f32 djui_hud_get_raw_mouse_y(void) {
|
||||
return mouse_y;
|
||||
}
|
||||
|
||||
void djui_hud_set_mouse_locked(bool locked) {
|
||||
gDjuiHudLockMouse = locked;
|
||||
}
|
||||
|
||||
f32 djui_hud_measure_text(const char* message) {
|
||||
if (message == NULL) { return 0; }
|
||||
const struct DjuiFont* font = gDjuiFonts[sFont];
|
||||
|
|
|
@ -26,6 +26,7 @@ struct GlobalTextures {
|
|||
|
||||
extern struct GlobalTextures gGlobalTextures;
|
||||
extern f32 gDjuiHudUtilsZ;
|
||||
extern u8 gDjuiHudLockMouse;
|
||||
|
||||
void djui_hud_set_resolution(enum HudUtilsResolution resolutionType);
|
||||
void djui_hud_set_font(enum DjuiFontType fontType);
|
||||
|
@ -36,6 +37,9 @@ u32 djui_hud_get_screen_height(void);
|
|||
|
||||
f32 djui_hud_get_mouse_x(void);
|
||||
f32 djui_hud_get_mouse_y(void);
|
||||
f32 djui_hud_get_raw_mouse_x(void);
|
||||
f32 djui_hud_get_raw_mouse_y(void);
|
||||
void djui_hud_set_mouse_locked(bool locked);
|
||||
|
||||
f32 djui_hud_measure_text(const char* message);
|
||||
void djui_hud_print_text(const char* message, float x, float y, float scale);
|
||||
|
|
|
@ -26,10 +26,12 @@ void djui_panel_camera_create(struct DjuiBase* caller) {
|
|||
djui_interactable_hook_value_change(&checkbox2->base, djui_panel_camera_value_changed);
|
||||
djui_base_set_size(&checkbox2->base, 1.0f, 32);
|
||||
|
||||
#ifdef BETTERCAMERA
|
||||
struct DjuiCheckbox* checkbox3 = djui_checkbox_create(&body->base, "Mouse Look", &configCameraMouse);
|
||||
djui_base_set_size_type(&checkbox3->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
|
||||
djui_interactable_hook_value_change(&checkbox3->base, djui_panel_camera_value_changed);
|
||||
djui_base_set_size(&checkbox3->base, 1.0f, 32);
|
||||
#endif
|
||||
|
||||
struct DjuiCheckbox* checkbox4 = djui_checkbox_create(&body->base, "Invert X", &configCameraInvertX);
|
||||
djui_base_set_size_type(&checkbox4->base, DJUI_SVT_RELATIVE, DJUI_SVT_ABSOLUTE);
|
||||
|
|
|
@ -7204,6 +7204,24 @@ int smlua_func_djui_hud_get_mouse_y(UNUSED lua_State* L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
int smlua_func_djui_hud_get_raw_mouse_x(UNUSED lua_State* L) {
|
||||
if(!smlua_functions_valid_param_count(L, 0)) { return 0; }
|
||||
|
||||
|
||||
lua_pushnumber(L, djui_hud_get_raw_mouse_x());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int smlua_func_djui_hud_get_raw_mouse_y(UNUSED lua_State* L) {
|
||||
if(!smlua_functions_valid_param_count(L, 0)) { return 0; }
|
||||
|
||||
|
||||
lua_pushnumber(L, djui_hud_get_raw_mouse_y());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int smlua_func_djui_hud_get_screen_height(UNUSED lua_State* L) {
|
||||
if(!smlua_functions_valid_param_count(L, 0)) { return 0; }
|
||||
|
||||
|
@ -7320,6 +7338,17 @@ int smlua_func_djui_hud_set_font(lua_State* L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
int smlua_func_djui_hud_set_mouse_locked(lua_State* L) {
|
||||
if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
|
||||
|
||||
bool locked = smlua_to_boolean(L, 1);
|
||||
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter 1"); return 0; }
|
||||
|
||||
djui_hud_set_mouse_locked(locked);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int smlua_func_djui_hud_set_resolution(lua_State* L) {
|
||||
if(!smlua_functions_valid_param_count(L, 1)) { return 0; }
|
||||
|
||||
|
@ -16856,6 +16885,8 @@ void smlua_bind_functions_autogen(void) {
|
|||
// djui_hud_utils.h
|
||||
smlua_bind_function(L, "djui_hud_get_mouse_x", smlua_func_djui_hud_get_mouse_x);
|
||||
smlua_bind_function(L, "djui_hud_get_mouse_y", smlua_func_djui_hud_get_mouse_y);
|
||||
smlua_bind_function(L, "djui_hud_get_raw_mouse_x", smlua_func_djui_hud_get_raw_mouse_x);
|
||||
smlua_bind_function(L, "djui_hud_get_raw_mouse_y", smlua_func_djui_hud_get_raw_mouse_y);
|
||||
smlua_bind_function(L, "djui_hud_get_screen_height", smlua_func_djui_hud_get_screen_height);
|
||||
smlua_bind_function(L, "djui_hud_get_screen_width", smlua_func_djui_hud_get_screen_width);
|
||||
smlua_bind_function(L, "djui_hud_measure_text", smlua_func_djui_hud_measure_text);
|
||||
|
@ -16864,6 +16895,7 @@ void smlua_bind_functions_autogen(void) {
|
|||
smlua_bind_function(L, "djui_hud_render_rect_interpolated", smlua_func_djui_hud_render_rect_interpolated);
|
||||
smlua_bind_function(L, "djui_hud_set_color", smlua_func_djui_hud_set_color);
|
||||
smlua_bind_function(L, "djui_hud_set_font", smlua_func_djui_hud_set_font);
|
||||
smlua_bind_function(L, "djui_hud_set_mouse_locked", smlua_func_djui_hud_set_mouse_locked);
|
||||
smlua_bind_function(L, "djui_hud_set_resolution", smlua_func_djui_hud_set_resolution);
|
||||
smlua_bind_function(L, "djui_hud_world_pos_to_screen_pos", smlua_func_djui_hud_world_pos_to_screen_pos);
|
||||
|
||||
|
|
Loading…
Reference in a new issue