mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 03:25:14 -04:00
Make the GUI code a little bit less ugly
This commit is contained in:
parent
5801e7888d
commit
6fe58feae6
@ -16,8 +16,6 @@
|
||||
#include "Funcs.h"
|
||||
|
||||
struct _GuiData Gui;
|
||||
struct HUDScreen* Gui_HUD;
|
||||
struct ChatScreen* Gui_Chat;
|
||||
struct Screen* Gui_Screens[GUI_MAX_SCREENS];
|
||||
static cc_uint8 priorities[GUI_MAX_SCREENS];
|
||||
|
||||
|
@ -179,11 +179,6 @@ enum GuiPriority {
|
||||
GUI_PRIORITY_LOADING = 5
|
||||
};
|
||||
|
||||
struct HUDScreen;
|
||||
struct ChatScreen;
|
||||
extern struct HUDScreen* Gui_HUD;
|
||||
extern struct ChatScreen* Gui_Chat;
|
||||
|
||||
#define GUI_MAX_SCREENS 10
|
||||
extern struct Screen* Gui_Screens[GUI_MAX_SCREENS];
|
||||
|
||||
|
20
src/Input.c
20
src/Input.c
@ -792,7 +792,7 @@ void InputHandler_PickBlocks(void) {
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*------------------------------------------------------Key helpers--------------------------------------------------------*
|
||||
*-----------------------------------------------------Input helpers-------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static cc_bool InputHandler_IsShutdown(int key) {
|
||||
if (key == KEY_F4 && Key_IsAltPressed()) return true;
|
||||
@ -823,15 +823,19 @@ cc_bool InputHandler_SetFOV(int fov) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static cc_bool InputHandler_DoFovZoom(float deltaPrecise) {
|
||||
cc_bool Input_HandleMouseWheel(float delta) {
|
||||
struct HacksComp* h;
|
||||
cc_bool hotbar;
|
||||
|
||||
hotbar = Key_IsAltPressed() || Key_IsControlPressed() || Key_IsShiftPressed();
|
||||
if (!hotbar && Camera.Active->Zoom(delta)) return true;
|
||||
if (!KeyBind_IsPressed(KEYBIND_ZOOM_SCROLL)) return false;
|
||||
|
||||
h = &LocalPlayer_Instance.Hacks;
|
||||
if (!h->Enabled || !h->CanUseThirdPerson) return false;
|
||||
|
||||
if (input_fovIndex == -1.0f) input_fovIndex = (float)Game_ZoomFov;
|
||||
input_fovIndex -= deltaPrecise * 5.0f;
|
||||
input_fovIndex -= delta * 5.0f;
|
||||
|
||||
Math_Clamp(input_fovIndex, 1.0f, Game_DefaultFov);
|
||||
return InputHandler_SetFOV((int)input_fovIndex);
|
||||
@ -951,22 +955,12 @@ static cc_bool HandleLocalPlayerKey(int key) {
|
||||
static void OnMouseWheel(void* obj, float delta) {
|
||||
struct Screen* s;
|
||||
int i;
|
||||
struct Widget* widget;
|
||||
cc_bool hotbar;
|
||||
|
||||
for (i = 0; i < Gui.ScreensCount; i++) {
|
||||
s = Gui_Screens[i];
|
||||
s->dirty = true;
|
||||
if (s->VTABLE->HandlesMouseScroll(s, delta)) return;
|
||||
}
|
||||
|
||||
hotbar = Key_IsAltPressed() || Key_IsControlPressed() || Key_IsShiftPressed();
|
||||
if (!hotbar && Camera.Active->Zoom(delta)) return;
|
||||
if (InputHandler_DoFovZoom(delta) || !Inventory.CanChangeSelected) return;
|
||||
|
||||
widget = HUDScreen_GetHotbar();
|
||||
Elem_HandlesMouseScroll(widget, delta);
|
||||
((struct Screen*)Gui_Chat)->dirty = true;
|
||||
}
|
||||
|
||||
static void OnPointerMove(void* obj, int idx, int xDelta, int yDelta) {
|
||||
|
@ -160,6 +160,7 @@ void StoredHotkeys_Remove(int trigger, cc_uint8 modifiers);
|
||||
void StoredHotkeys_Add(int trigger, cc_uint8 modifiers, cc_bool moreInput, const cc_string* text);
|
||||
|
||||
cc_bool InputHandler_SetFOV(int fov);
|
||||
cc_bool Input_HandleMouseWheel(float delta);
|
||||
void InputHandler_PickBlocks(void);
|
||||
void InputHandler_OnScreensChanged(void);
|
||||
|
||||
|
@ -41,6 +41,12 @@ void Screen_NullFunc(void* screen) { }
|
||||
void Screen_NullUpdate(void* screen, double delta) { }
|
||||
int Screen_InputDown(void* screen, int key) { return key < KEY_F1 || key > KEY_F24; }
|
||||
|
||||
/* TODO: Remove these */
|
||||
struct HUDScreen;
|
||||
struct ChatScreen;
|
||||
static struct HUDScreen* Gui_HUD;
|
||||
static struct ChatScreen* Gui_Chat;
|
||||
|
||||
CC_NOINLINE static cc_bool IsOnlyChatActive(void) {
|
||||
struct Screen* s;
|
||||
int i;
|
||||
@ -252,6 +258,17 @@ static int HUDscreen_PointerDown(void* screen, int id, int x, int y) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static int HUDscreen_MouseScroll(void* screen, float delta) {
|
||||
struct HUDScreen* s = (struct HUDScreen*)screen;
|
||||
/* The default scrolling behaviour (e.g. camera, zoom) needs to be checked */
|
||||
/* BEFORE the hotbar is scrolled, but AFTER chat (maybe) handles scrolling. */
|
||||
/* Therefore need to check the default behaviour here, hacky as that may be. */
|
||||
if (Input_HandleMouseWheel(delta)) return false;
|
||||
|
||||
if (!Inventory.CanChangeSelected) return false;
|
||||
return Elem_HandlesMouseScroll(&s->hotbar, delta);
|
||||
}
|
||||
|
||||
static void HUDScreen_HacksChanged(void* obj) {
|
||||
((struct HUDScreen*)obj)->hacksChanged = true;
|
||||
}
|
||||
@ -292,7 +309,7 @@ static const struct ScreenVTABLE HUDScreen_VTABLE = {
|
||||
HUDScreen_Init, HUDScreen_Update, HUDScreen_Free,
|
||||
HUDScreen_Render, HUDScreen_BuildMesh,
|
||||
HUDScreen_KeyDown, HUDScreen_KeyUp, Screen_FKeyPress, Screen_FText,
|
||||
HUDscreen_PointerDown, Screen_FPointer, Screen_FPointer, Screen_FMouseScroll,
|
||||
HUDscreen_PointerDown, Screen_FPointer, Screen_FPointer, HUDscreen_MouseScroll,
|
||||
HUDScreen_Layout, HUDScreen_ContextLost, HUDScreen_ContextRecreated
|
||||
};
|
||||
void HUDScreen_Show(void) {
|
||||
@ -302,10 +319,6 @@ void HUDScreen_Show(void) {
|
||||
Gui_Add((struct Screen*)s, GUI_PRIORITY_HUD);
|
||||
}
|
||||
|
||||
struct Widget* HUDScreen_GetHotbar(void) {
|
||||
return (struct Widget*)&HUDScreen_Instance.hotbar;
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
*----------------------------------------------------TabListOverlay-----------------------------------------------------*
|
||||
|
@ -42,5 +42,4 @@ void ChatScreen_OpenInput(const cc_string* text);
|
||||
void ChatScreen_AppendInput(const cc_string* text);
|
||||
/* Sets number of visible lines in the main chat widget. */
|
||||
void ChatScreen_SetChatlines(int lines);
|
||||
struct Widget* HUDScreen_GetHotbar(void);
|
||||
#endif
|
||||
|
@ -2430,7 +2430,6 @@ static void SpecialInputWidget_Make(struct SpecialInputWidget* w, struct Special
|
||||
|
||||
void SpecialInputWidget_Redraw(struct SpecialInputWidget* w) {
|
||||
SpecialInputWidget_Make(w, &w->tabs[w->selectedIndex]);
|
||||
w->width = w->tex.Width;
|
||||
w->pendingRedraw = false;
|
||||
Widget_Layout(w);
|
||||
}
|
||||
@ -2447,6 +2446,7 @@ static void SpecialInputWidget_Free(void* widget) {
|
||||
|
||||
static void SpecialInputWidget_Reposition(void* widget) {
|
||||
struct SpecialInputWidget* w = (struct SpecialInputWidget*)widget;
|
||||
w->width = w->tex.Width;
|
||||
w->height = w->active ? w->tex.Height : 0;
|
||||
Widget_CalcPosition(w);
|
||||
w->tex.X = w->x; w->tex.Y = w->y;
|
||||
|
Loading…
x
Reference in New Issue
Block a user