Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
menu_cmd.qc File Reference
#include "menu_cmd.qh"
#include "../menu.qh"
#include "../item.qh"
#include <menu/item/dialog.qh>
#include <menu/mutators/_mod.qh>
#include <common/command/_mod.qh>
Include dependency graph for menu_cmd.qc:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void _dumptree_close (entity pass, entity me)
void _dumptree_open (entity pass, entity me)
void GameCommand (string theCommand)
float updateConwidths (float width, float height, float pixelheight)
 void (entity me, int argsbuf) readInputArgs

Variables

string _dumptree_space
entity firstChild
entity nextSibling

Function Documentation

◆ _dumptree_close()

void _dumptree_close ( entity pass,
entity me )

Definition at line 31 of file menu_cmd.qc.

32{
33 if (me.firstChild)
34 {
36 print(_dumptree_space, "}\n");
37 }
38}
#define strlen
string _dumptree_space
Definition menu_cmd.qc:14
string substring(string s, float start, float length)
void print(string text,...)

References _dumptree_space, entity(), pass, print(), strlen, and substring().

◆ _dumptree_open()

void _dumptree_open ( entity pass,
entity me )

Definition at line 15 of file menu_cmd.qc.

16{
17 string s = me.toString(me);
18 if (s == "") s = me.classname;
19 else s = strcat(me.classname, ": ", s);
20 print(_dumptree_space, etos(me), " (", s, ")");
21 if (me.firstChild)
22 {
23 print(" {\n");
25 }
26 else
27 {
28 print("\n");
29 }
30}
string etos(entity e)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))

References _dumptree_space, entity(), etos(), pass, print(), and strcat().

◆ GameCommand()

void GameCommand ( string theCommand)

Definition at line 42 of file menu_cmd.qc.

43{
44 int argc = tokenize_console(theCommand);
45 string ss = strtolower(argv(0));
46
47 // TODO port these commands to the command system
48 if (argv(0) == "help" || argc == 0)
49 {
50 LOG_HELP("Usage:^3 menu_cmd <command> [<item>], where possible commands are:");
51 LOG_HELP(" 'sync' reloads all cvars on the current menu page");
52 LOG_HELP(" 'directmenu' shows the menu window named <item> (or the menu window containing an item named <item>)");
53 LOG_HELP(" 'closemenu' closes the menu window named <item> (or the menu window containing an item named <item>)");
54 LOG_HELP(" if <item> is not specified it shows the list of available items in the console");
55 LOG_HELP(" 'dumptree' dumps the state of the menu as a tree to the console");
56 LOG_HELP(" 'isdemo' checks if engine is currently running a demo. If given an <item> then 1 / 0 is placed");
57 LOG_HELP(" in the cvar with that name. Otherwise without an argument the result is printed to console.");
58
59 LOG_HELP("\nGeneric commands shared by all programs:");
61
62 return;
63 }
64
65 if (GenericCommand(theCommand)) return;
66
67 if (argv(0) == "sync")
68 {
69 m_sync();
70 return;
71 }
72
73 if (argv(0) == "update_conwidths_before_vid_restart")
74 {
75 updateConwidths(cvar("vid_width"), cvar("vid_height"), cvar("vid_pixelheight"));
76 return;
77 }
78
79 string argcmd = argv(0);
80 string filter = string_null;
81 bool close_mode = false;
82 if (argcmd == "closemenu")
83 {
84 close_mode = true;
85 argcmd = "directmenu";
86 }
87 else if (argcmd == "directpanelhudmenu")
88 {
89 filter = "HUD";
90 argcmd = "directmenu";
91 }
92
93 if (argcmd == "directmenu")
94 {
95 if (argc == 1)
96 {
97 LOG_HELP("Available items (* = closable):");
98
99 FOREACH_ENTITY_ORDERED(it.name != "", {
100 if (it.classname == "vtbl") continue;
101 string s = it.name;
102 if (filter)
103 {
104 if (!startsWith(s, filter)) continue;
105 s = substring(s, strlen(filter), strlen(s) - strlen(filter));
106 }
107 if (it.instanceOfContainer && it.closable)
108 LOG_HELP(" * ", s);
109 else
110 LOG_HELP(" ", s);
111 });
112 }
113 else if (argc == 2 && !close_mode && (!isdemo() || argv(1) == "Welcome")) // don't allow this command in demos
114 {
116 m_goto(strcat(filter, argv(1)), true); // switch to a menu item
117 }
118 else if(argc > 2 && (!isdemo() || argv(1) == "Welcome"))
119 {
120 entity e = NULL;
121 float argsbuf = 0;
122 string s = strzone(argv(1)); // dialog name
123 for(int i = 0; (e = nextent(e)); )
124 if(e.classname != "vtbl" && e.name == strcat(filter, s))
125 {
126 argsbuf = buf_create();
127 if(argsbuf >= 0)
128 if(e.readInputArgs)
129 {
130 for(i = 2; i < argc; ++i)
131 bufstr_add(argsbuf, argv(i), 1);
132 e.readInputArgs(e, argsbuf);
133 if (!close_mode)
134 m_goto(strcat(filter, s), true);
135 }
136 if(argsbuf >= 0)
137 buf_del(argsbuf);
138
139 // NOTE input args are read even in close mode
140 if (close_mode)
141 {
142 if (e.instanceOfContainer && e.closable && e.focused)
143 Dialog_Close(e, e);
144 }
145 }
146 }
147 return;
148 }
149
150 switch (argv(0))
151 {
152 // unlike menu_cmd directmenu, the menu won't be closed when these menu items will be closed
153 case "nexposee": m_goto("nexposee", false); return;
154 case "servers": m_goto("servers", false); return;
155 case "profile": m_goto("profile", false); return;
156 case "skinselect": m_goto("skinselector", false); return;
157 case "languageselect": m_goto("languageselector", false); return;
158 case "settings": m_goto("settings", false); return;
159 case "inputsettings": m_goto("inputsettings", false); return;
160 case "videosettings": m_goto("videosettings", false); return;
161 }
162
163 if (argv(0) == "dumptree")
164 {
165 _dumptree_space = "";
167 return;
168 }
169
170 if (argv(0) == "isdemo")
171 {
172 int value = isdemo();
173
174 if (argv(1) != "")
175 {
176 cvar_set(argv(1), ftos(value));
177 }
178 else
179 {
180 print(sprintf("%d\n", value));
181 }
182
183 return;
184 }
185
186 if(MUTATOR_CALLHOOK(Menu_ConsoleCommand, ss, argc, theCommand)) // handled by a mutator
187 return;
188
189 LOG_INFO("Invalid command. For a list of supported commands, try menu_cmd help.");
190}
entity parent
Definition animhost.qc:7
#define MUTATOR_CALLHOOK(id,...)
Definition base.qh:143
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
void depthfirst(entity start,.entity up,.entity downleft,.entity right, void(entity, entity) funcPre, void(entity, entity) funcPost, entity pass)
Definition util.qc:392
string strtolower(string s)
#define tokenize_console
#define buf_create
void GenericCommand_macro_help()
Definition generic.qc:567
float GenericCommand(string command)
Definition generic.qc:603
#define FOREACH_ENTITY_ORDERED(cond, body)
Definition iter.qh:138
#define main
Definition _all.inc:202
#define LOG_HELP(...)
Definition log.qh:85
#define LOG_INFO(...)
Definition log.qh:65
void Dialog_Close(entity button, entity me)
Definition dialog.qc:7
void m_play_click_sound(string soundfile)
Definition menu.qc:1111
void m_sync()
Definition menu.qc:45
void m_goto(string itemname, bool hide_menu_on_close)
Definition menu.qc:1056
const string MENU_SOUND_OPEN
Definition menu.qh:53
float updateConwidths(float width, float height, float pixelheight)
entity nextSibling
Definition menu_cmd.qc:12
void _dumptree_close(entity pass, entity me)
Definition menu_cmd.qc:31
entity firstChild
Definition menu_cmd.qc:12
void _dumptree_open(entity pass, entity me)
Definition menu_cmd.qc:15
void cvar_set(string name, string value)
float isdemo()
entity nextent(entity e)
float cvar(string name)
string ftos(float f)
string strzone(string s)
string argv(float n)
string string_null
Definition nil.qh:9
#define NULL
Definition post.qh:14
if(frag_attacker.flagcarried)
Definition sv_ctf.qc:2318

References argv(), buf_create, cvar(), Dialog_Close(), entity(), FOREACH_ENTITY_ORDERED, GenericCommand(), GenericCommand_macro_help(), if(), isdemo(), LOG_HELP, m_goto(), m_play_click_sound(), m_sync(), MENU_SOUND_OPEN, nextent(), NULL, strcat(), string_null, strtolower(), strzone(), tokenize_console, and updateConwidths().

◆ updateConwidths()

float updateConwidths ( float width,
float height,
float pixelheight )

Definition at line 8 of file slider_resolution.qc.

9{
10 vector r, c;
11 float minfactor, maxfactor;
12 float sz, f;
13
14 sz = cvar("menu_vid_scale");
15 if (sz < -1)
16 return 0; // No recalculation.
17
18 // Save off current settings.
19 cvar_set("_menu_vid_width", ftos(width));
20 cvar_set("_menu_vid_height", ftos(height));
21 cvar_set("_menu_vid_pixelheight", ftos(pixelheight));
22 cvar_set("_menu_vid_desktopfullscreen", cvar_string("vid_desktopfullscreen"));
23
24 // engine is handling conwidth calculations!
25 if((cvar_type("vid_conwidthauto") & CVAR_TYPEFLAG_ENGINE) && cvar("vid_conwidthauto"))
26 {
27 if(vid_conwidth != cvar("vid_conwidth") || vid_conheight != cvar("vid_conheight"))
28 {
29 // Please reload resolutions list and such stuff.
31 vid_conwidth = cvar("vid_conwidth");
32 vid_conheight = cvar("vid_conheight");
33 return 1;
34 }
35 return 0; // No recalculation
36 }
37
38 r_x = width;
39 r_y = height;
40 r_z = pixelheight;
41
42 // calculate the base resolution
43 c_z = 0;
44 c_x = 800;
45 c_y = c.x * r.y * r.z / r.x;
46 if(c.y < 600)
47 {
48 c_y = 600;
49 c_x = c.y * r.x / (r.y * r.z);
50 }
51
52 f = min(r.x / c.x, r.y / c.y);
53 if(f < 1)
54 c *= f; // ensures that c_x <= r_x and c_y <= r_y
55
56 minfactor = min(1, 640 / c.x); // can be > 1 only if c_x is <640
57 maxfactor = max(1, r.x / c.x, r.y / c.y); // can be < 1 only if r_x < c_x and r_y < c_y
58 LOG_TRACE("min factor: ", ftos(minfactor));
59 LOG_TRACE("max factor: ", ftos(maxfactor));
60
61 if(sz < 0)
62 f = 1 - (maxfactor - 1) * sz;
63 else if(sz > 0)
64 f = 1 + (minfactor - 1) * sz;
65 else
66 f = 1;
67 c *= f; // fteqcc fail
68
69 c_x = rint(c.x);
70 c_y = rint(c.y);
71
72 // Please reload resolutions list and such stuff.
74
75 if (c.x != cvar("vid_conwidth") || c.y != cvar("vid_conheight"))
76 {
77 cvar_set("vid_conwidth", ftos(c.x));
78 cvar_set("vid_conheight", ftos(c.y));
79 return 1;
80 }
81 return 0;
82}
float height
Definition bobbing.qc:3
float CVAR_TYPEFLAG_ENGINE
noref float vid_conwidth
Definition draw.qh:8
noref float vid_conheight
Definition draw.qh:9
#define LOG_TRACE(...)
Definition log.qh:76
const string cvar_string(string name)
float min(float f,...)
float rint(float f)
float max(float f,...)
vector
Definition self.qh:92
float XonoticResolutionSlider_DataHasChanged

References cvar(), cvar_set(), cvar_string(), CVAR_TYPEFLAG_ENGINE, ftos(), height, LOG_TRACE, max(), min(), rint(), vector, vid_conheight, vid_conwidth, and XonoticResolutionSlider_DataHasChanged.

Referenced by GameCommand(), and UpdateConWidthHeight().

◆ void()

void ( entity me,
int argsbuf )

References entity().

Variable Documentation

◆ _dumptree_space

string _dumptree_space

Definition at line 14 of file menu_cmd.qc.

Referenced by _dumptree_close(), and _dumptree_open().

◆ firstChild

◆ nextSibling

entity nextSibling

Definition at line 12 of file menu_cmd.qc.

Referenced by forAllDescendants().