UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cl_menu.cpp
Go to the documentation of this file.
1 
6 /*
7 Copyright (C) 2002-2020 UFO: Alien Invasion.
8 
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13 
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 
18 See the GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, 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 
39 static 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]);
45  if (Q_strvalid(binding))
46  binding = _(binding);
47  UI_ExecuteConfunc("keybinding_add %i %i \"%s\" \"%s\"", i + offset, scope, Key_KeynumToString(i), binding);
48  }
49 }
50 
54 static 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 
75 static void CLMN_InitKeyList_f (void)
76 {
77  UI_ExecuteConfunc("keybinding_clear");
78 
81  const int uiBindings = CLMN_AddUIBindings(KEYSPACE_UI);
83 }
84 
85 static 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 
94 static 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 
109 static 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 
129 void 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 
139  GAME_InitUIData();
140 }
141 
142 void CLMN_Shutdown (void)
143 {
144  Cmd_RemoveCommand("mn_init_keylist");
145  Cmd_RemoveCommand("mn_mods");
146 }
bool Q_strnull(const char *string)
Definition: shared.h:138
void Cmd_AddCommand(const char *cmdName, xcommand_t function, const char *desc)
Add a new command to the script interface.
Definition: cmd.cpp:744
int width
Definition: cl_video.h:83
Video driver defs.
void Cmd_RemoveCommand(const char *cmdName)
Removes a command from script interface.
Definition: cmd.cpp:786
char id[MAX_VAR]
Definition: chr_shared.h:298
char * menuKeyBindings[K_KEY_SIZE]
Definition: cl_keys.cpp:64
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
#define _(String)
Definition: cl_shared.h:43
csi_t csi
Definition: common.cpp:39
void Cbuf_AddText(const char *format,...)
Adds command text at the end of the buffer.
Definition: cmd.cpp:126
static void CL_VideoInitMenu(void)
Definition: cl_menu.cpp:94
keyBindSpace_t
Definition: cl_keys.h:173
Shared game type headers.
const char * description
Definition: ui_input.h:36
#define TEAM_CIVILIAN
Definition: q_shared.h:61
uiNode_t * UI_GetOption(int dataId)
Definition: ui_data.cpp:324
static void CLMN_Mods_f(void)
Definition: cl_menu.cpp:85
Header for client menu implementation.
#define Q_strvalid(string)
Definition: shared.h:141
static void CLMN_AddBindings(keyBindSpace_t scope, char **bindings, int offset=0)
Definition: cl_menu.cpp:39
Share stuff between the different cgame implementations.
Header file for keyboard handler.
void CL_LanguageInitMenu(void)
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
QGL_EXTERN GLuint GLsizei GLsizei * length
Definition: r_gl.h:110
static void CL_TeamDefInitMenu(void)
Definition: cl_menu.cpp:109
int FS_GetModList(linkedList_t **mods)
Searches and builds a list of mod directories.
Definition: files.cpp:669
void GAME_InitUIData(void)
Fills the game mode list entries with the parsed values from the script.
Definition: cl_game.cpp:1840
teamDef_t teamDef[MAX_TEAMDEFS]
Definition: q_shared.h:548
Atomic structure used to define most of the UI.
Definition: ui_nodes.h:80
void CLMN_Shutdown(void)
Definition: cl_menu.cpp:142
void CLMN_Init(void)
Initialize the menu data hunk, add cvars and commands.
Definition: cl_menu.cpp:129
int UI_GetKeyBindingCount(void)
Definition: ui_input.cpp:272
char name[MAX_VAR]
Definition: chr_shared.h:299
int numTeamDefs
Definition: q_shared.h:549
void IN_JoystickInitMenu(void)
Adds joysticks to the options menu.
QGL_EXTERN GLint i
Definition: r_gl.h:113
bool VID_GetModeInfo(int modeIndex, vidmode_t *modeInfo)
Definition: cl_video.cpp:88
uiKeyBinding_t * UI_GetKeyBindingByIndex(int index)
Definition: ui_input.cpp:277
void UI_RegisterOption(int dataId, uiNode_t *option)
Definition: ui_data.cpp:311
#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
int VID_GetModeNums(void)
Returns the amount of available video modes.
Definition: cl_video.cpp:81
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
bool inherited
Definition: ui_input.h:37
char * keyBindings[K_KEY_SIZE]
Definition: cl_keys.cpp:63
const uiKeyBinding_t * binding
const char * Cmd_GetCommandDesc(const char *cmdName)
Returns the command description for a given command.
Definition: cmd.cpp:629
const char * Key_KeynumToString(int keynum)
Convert a given keynum to string.
Definition: cl_keys.cpp:485
voidpf uLong offset
Definition: ioapi.h:45
int height
Definition: cl_video.h:83
char * battleKeyBindings[K_KEY_SIZE]
Definition: cl_keys.cpp:65
void UI_ExecuteConfunc(const char *fmt,...)
Executes confunc - just to identify those confuncs in the code - in this frame.
Definition: ui_main.cpp:110
static int CLMN_AddUIBindings(keyBindSpace_t scope)
Adds UI Keybindings to the list for the Keylist UI.
Definition: cl_menu.cpp:54