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 32 of file menu_cmd.qc.

33{
34 if (me.firstChild)
35 {
37 print(_dumptree_space, "}\n");
38 }
39}
#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;
18 s = me.toString(me);
19 if (s == "") s = me.classname;
20 else s = strcat(me.classname, ": ", s);
21 print(_dumptree_space, etos(me), " (", s, ")");
22 if (me.firstChild)
23 {
24 print(" {\n");
26 }
27 else
28 {
29 print("\n");
30 }
31}
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 43 of file menu_cmd.qc.

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

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 = 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 = 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().