UFO: Alien Invasion
Loading...
Searching...
No Matches
cl_menu.cpp
Go to the documentation of this file.
1
5
6/*
7Copyright (C) 2002-2025 UFO: Alien Invasion.
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
18See the GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24*/
25
26#include "cl_menu.h"
27#include "cl_shared.h"
28#include "cgame/cl_game.h"
29#include "input/cl_keys.h"
30#include "input/cl_joystick.h"
31#include "cl_video.h"
32#include "cl_language.h"
33#include "ui/ui_main.h"
34#include "ui/ui_input.h"
35#include "ui/ui_nodes.h"
36#include "ui/ui_popup.h"
38
39static inline void CLMN_AddBindings (keyBindSpace_t scope, char** bindings, int offset = 0)
40{
41 for (int i = K_FIRST_KEY; i < K_LAST_KEY; i++) {
42 if (Q_strnull(bindings[i]))
43 continue;
44 const char* binding = Cmd_GetCommandDesc(bindings[i]);
46 binding = _(binding);
47 UI_ExecuteConfunc("keybinding_add %i %i \"%s\" \"%s\"", i + offset, scope, Key_KeynumToString(i), binding);
48 }
49}
50
54static inline int CLMN_AddUIBindings (keyBindSpace_t scope)
55{
56 int cnt = 0;
57 const int num = UI_GetKeyBindingCount();
58 for (int i = 0; i < num; i++) {
60 if (binding == nullptr)
61 continue;
62 if (binding->inherited)
63 continue;
64 if (!Q_strvalid(binding->description))
65 continue;
66
67 UI_ExecuteConfunc("keybinding_add %i %i \"%s\" \"%s\"", cnt++, scope, Key_KeynumToString(binding->key), _(binding->description));
68 }
69 return cnt;
70}
71
84
85static void CLMN_Mods_f (void)
86{
87 linkedList_t* mods = nullptr;
88 FS_GetModList(&mods);
89 LIST_Foreach(mods, const char, mod) {
90 Cbuf_AddText("mn_mods_result %s\n", mod);
91 }
92}
93
94static void CL_VideoInitMenu (void)
95{
97 if (option != nullptr) {
98 return;
99 }
100 const int length = VID_GetModeNums();
101 for (int i = 0; i < length; i++) {
102 vidmode_t vidmode;
103 if (VID_GetModeInfo(i, &vidmode))
104 UI_AddOption(&option, va("r%ix%i", vidmode.width, vidmode.height), va("%i x %i", vidmode.width, vidmode.height), va("%i", i));
105 }
107}
108
109static void CL_TeamDefInitMenu (void)
110{
112 if (option != nullptr)
113 return;
114
115 for (int i = 0; i < csi.numTeamDefs; i++) {
116 const teamDef_t* td = &csi.teamDef[i];
117 if (td->team != TEAM_CIVILIAN)
118 UI_AddOption(&option, td->id, va("_%s", td->name), td->id);
119 }
121}
122
129void CLMN_Init (void)
130{
131 /* print the keyBindings to mn.menuText */
132 Cmd_AddCommand("mn_init_keylist", CLMN_InitKeyList_f);
133 Cmd_AddCommand("mn_mods", CLMN_Mods_f);
134
140}
141
142void CLMN_Shutdown (void)
143{
144 Cmd_RemoveCommand("mn_init_keylist");
145 Cmd_RemoveCommand("mn_mods");
146}
void GAME_InitUIData(void)
Fills the game mode list entries with the parsed values from the script.
Definition cl_game.cpp:1649
Shared game type headers.
void IN_JoystickInitMenu(void)
Adds joysticks to the options menu.
char * keyBindings[K_KEY_SIZE]
Definition cl_keys.cpp:63
char * menuKeyBindings[K_KEY_SIZE]
Definition cl_keys.cpp:64
const char * Key_KeynumToString(int keynum)
Convert a given keynum to string.
Definition cl_keys.cpp:485
char * battleKeyBindings[K_KEY_SIZE]
Definition cl_keys.cpp:65
Header file for keyboard handler.
@ K_FIRST_KEY
Definition cl_keys.h:36
@ K_LAST_KEY
Definition cl_keys.h:169
keyBindSpace_t
Definition cl_keys.h:173
@ KEYSPACE_UI
Definition cl_keys.h:174
@ KEYSPACE_BATTLE
Definition cl_keys.h:176
@ KEYSPACE_GAME
Definition cl_keys.h:175
void CL_LanguageInitMenu(void)
static int CLMN_AddUIBindings(keyBindSpace_t scope)
Adds UI Keybindings to the list for the Keylist UI.
Definition cl_menu.cpp:54
static void CLMN_InitKeyList_f(void)
Prints a list of tab and newline separated string to keylist char array that hold the key and the com...
Definition cl_menu.cpp:75
static void CL_TeamDefInitMenu(void)
Definition cl_menu.cpp:109
void CLMN_Init(void)
Initialize the menu data hunk, add cvars and commands.
Definition cl_menu.cpp:129
static void CL_VideoInitMenu(void)
Definition cl_menu.cpp:94
static void CLMN_AddBindings(keyBindSpace_t scope, char **bindings, int offset=0)
Definition cl_menu.cpp:39
static void CLMN_Mods_f(void)
Definition cl_menu.cpp:85
void CLMN_Shutdown(void)
Definition cl_menu.cpp:142
Header for client menu implementation.
Share stuff between the different cgame implementations.
#define _(String)
Definition cl_shared.h:44
bool VID_GetModeInfo(int modeIndex, vidmode_t *modeInfo)
Definition cl_video.cpp:91
int VID_GetModeNums(void)
Returns the amount of available video modes.
Definition cl_video.cpp:84
Video driver defs.
void Cmd_RemoveCommand(const char *cmdName)
Removes a command from script interface.
Definition cmd.cpp:786
void Cmd_AddCommand(const char *cmdName, xcommand_t function, const char *desc)
Add a new command to the script interface.
Definition cmd.cpp:744
void Cbuf_AddText(const char *format,...)
Adds command text at the end of the buffer.
Definition cmd.cpp:126
const char * Cmd_GetCommandDesc(const char *cmdName)
Returns the command description for a given command.
Definition cmd.cpp:629
csi_t csi
Definition common.cpp:39
int FS_GetModList(linkedList_t **mods)
Searches and builds a list of mod directories.
Definition files.cpp:669
voidpf uLong offset
Definition ioapi.h:45
#define LIST_Foreach(list, type, var)
Iterates over a linked list, it's safe to delete the returned entry from the list while looping over ...
Definition list.h:41
#define TEAM_CIVILIAN
Definition q_shared.h:61
QGL_EXTERN GLuint GLsizei GLsizei * length
Definition r_gl.h:110
QGL_EXTERN GLint i
Definition r_gl.h:113
#define Q_strvalid(string)
Definition shared.h:141
bool Q_strnull(const char *string)
Definition shared.h:138
const char * va(const char *format,...)
does a varargs printf into a temp buffer, so I don't need to have varargs versions of all text functi...
Definition shared.cpp:410
char id[MAX_VAR]
Definition chr_shared.h:309
char name[MAX_VAR]
Definition chr_shared.h:310
Atomic structure used to define most of the UI.
Definition ui_nodes.h:80
int height
Definition cl_video.h:86
int width
Definition cl_video.h:86
void UI_RegisterOption(int dataId, uiNode_t *option)
Definition ui_data.cpp:311
uiNode_t * UI_GetOption(int dataId)
Definition ui_data.cpp:324
uiNode_t * UI_AddOption(uiNode_t **tree, const char *name, const char *label, const char *value)
Append an option to an option list.
Definition ui_data.cpp:172
@ OPTION_TEAMDEFS
Definition ui_dataids.h:84
@ OPTION_VIDEO_RESOLUTIONS
Definition ui_dataids.h:77
uiKeyBinding_t * UI_GetKeyBindingByIndex(int index)
Definition ui_input.cpp:277
int UI_GetKeyBindingCount(void)
Definition ui_input.cpp:272
void UI_ExecuteConfunc(const char *fmt,...)
Executes confunc - just to identify those confuncs in the code - in this frame.
Definition ui_main.cpp:110
const uiKeyBinding_t * binding