Nuclide
Software Development Kit for id Technology (BETA)
defs.h
1/*
2 * Copyright (c) 2016-2024 Vera Visions LLC.
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
13 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
14 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15*/
16
17#include "Platform.h"
18#include "Locale.h"
19#include "AchievementManager.h"
20#include "ActivityPubClient.h"
21#include "ArchiveItemManager.h"
22#include "CustomGameLibrary.h"
23#include "ControlBindingsManager.h"
24#include "RenderingManager.h"
25#include "FingerClient.h"
26#include "GopherClient.h"
27#include "HTTPReceiver.h"
28#include "MPDClient.h"
29#include "MapLibrary.h"
30#include "MatrixClient.h"
31#include "MenuBackground.h"
32#include "MenuDataFeed.h"
33#include "MusicController.h"
34#include "OnlineServices.h"
35#include "PackageManager.h"
36#include "PlatformCommands.h"
37#include "ProfileManager.h"
38#include "RichPresence.h"
39#include "SaveGameLibrary.h"
40#include "ServerErrorHandler.h"
41#include "PlayerModelLibrary.h"
42#include "GametypeLibrary.h"
43#include "TCPHandler.h"
44#include "WorldFinder.h"
45#include "WorldSetup.h"
46
48typedef enum
49{
50 GPMI_NAME,
51 GPMI_CATEGORY,
52 GPMI_TITLE,
53 GPMI_VERSION,
54 GPMI_DESCRIPTION,
55 GPMI_LICENSE,
56 GPMI_AUTHOR,
57 GPMI_WEBSITE,
58 GPMI_INSTALLED,
59 GPMI_ACTION,
60 GPMI_AVAILABLE,
61 GPMI_FILESIZE,
62} packageType_t;
63
64.float movetype;
65.float solid;;
66.vector avelocity;
67float clframetime;
68.entity owner;
69
70#include "../shared/system/ConstantManager.h"
71#include "../shared/system/ConstantManager.qc"
72
73int stoi(string inputString)
74{
75 return (int)stof(inputString);
76}
77
78#define MOVETYPE_FLY 0
79#define SOLID_NOT 0
80
81__variant(float prnum, string varname) externvalue = #203;
82
83__variant
84linkToMenuProgs(string funcName)
85{
86 static void empty(void)
87 {
88 print("Called unimplemented menu-side API call.\n");
89 }
90
91 void *func = externvalue(0, funcName);
92
93 if (func) {
94 return ((__variant)func);
95 } else {
96 return (empty);
97 }
98}
99
100
102void drawrect(vector pos, vector sz, float thickness, vector rgb, float al, optional float dfl)
103{
104 /* top */
105 drawfill(pos, [sz[0], thickness], rgb, al, dfl);
106 /* bottom */
107 drawfill(pos + [0, sz[1] - thickness], [sz[0], thickness], rgb, al, dfl);
108 /* left */
109 drawfill(pos + [0, thickness], [thickness, sz[1] - (thickness * 2)], rgb, al, dfl);
110 /* right */
111 drawfill(pos + [sz[0] - thickness, thickness], [thickness, sz[1] - (thickness * 2)], rgb, al, dfl);
112}
113
114void
115UIPF_draw_Rect(vector pos, vector size, vector rgb, float a)
116{
117 drawfill(pos, size, rgb, a);
118}
119
120void
121UIPF_draw_RectOutline(vector pos, vector size, float thickness, vector rgb, float a)
122{
123 drawrect(pos, size, thickness, rgb, a);
124}
125
126void
127UIPF_draw_RoundedRectOutline(vector pos, vector size, vector rgb, float a)
128{
129 float tileScale = 1.0f;
130
131 if (size[1] < 32) {
132 tileScale = size[1] / 32;
133 }
134
135 vector tileSize = g_vec_null;
136 tileSize[0] = tileSize[1] = (16 * tileScale);
137
138 drawpic(pos, "gfx/ui/m_linetopleft.tga", [16,16], rgb, a, 0);
139 drawpic(pos + [size[0] - 16, 0], "gfx/ui/m_linetopright.tga", [16,16], rgb, a, 0);
140 drawpic(pos + [0, size[1] - 16], "gfx/ui/m_linebottomleft.tga", [16,16], rgb, a, 0);
141 drawpic(pos + [size[0] - 16, size[1] - 16], "gfx/ui/m_linebottomright.tga", [16,16], rgb, a, 0);
142
143 if (size_x > 32) {
144 drawpic(pos + [16, 0], "gfx/ui/m_linetop.tga", [size[0] - 32, 16], rgb, a, 0);
145 drawpic(pos + [16, size[1] - 16], "gfx/ui/m_linebottom.tga", [size[0] - 32, 16], rgb, a, 0);
146 }
147
148 if (size_y > 32) {
149 drawpic(pos + [0, 16], "gfx/ui/m_lineleft.tga", [16, size[1] - 32], rgb, a, 0);
150 drawpic(pos + [size[0] - 16, 16], "gfx/ui/m_lineright.tga", [16, size[1] - 32], rgb, a, 0);
151 drawpic(pos + [16, 16], "gfx/ui/m_linemid.tga", [size[0] - 32, size[1] - 32], rgb, a, 0);
152 }
153}
154
155void
156UIPF_draw_RoundedBox(vector pos, vector size, vector rgb, float a)
157{
158 float tileScale = 1.0f;
159
160 if (size[1] < 32) {
161 tileScale = size[1] / 32;
162 }
163
164 vector tileSize = g_vec_null;
165 tileSize[0] = tileSize[1] = (16 * tileScale);
166
167 drawpic(pos, "gfx/ui/m_topleft.tga", tileSize, rgb, a, 0);
168 drawpic(pos + [size[0] - tileSize[0], 0], "gfx/ui/m_topright.tga", tileSize, rgb, a, 0);
169 drawpic(pos + [0, size[1] - tileSize[1]], "gfx/ui/m_bottomleft.tga", tileSize, rgb, a, 0);
170 drawpic(pos + [size[0] - tileSize[0], size[1] - tileSize[1]], "gfx/ui/m_bottomright.tga", tileSize, rgb, a, 0);
171
172 if (size_x > 32) {
173 drawpic(pos + [tileSize[0], 0], "gfx/ui/m_top.tga", [size[0] - (tileSize[0] * 2), tileSize[1]], rgb, a, 0);
174 drawpic(pos + [tileSize[0], size[1] - tileSize[1]], "gfx/ui/m_bottom.tga", [size[0] - (tileSize[0] * 2), tileSize[1]], rgb, a, 0);
175 }
176
177 if (size_y > 32) {
178 drawpic(pos + [0, tileSize[1]], "gfx/ui/m_left.tga", [tileSize[0], size[1] - (tileSize[0] * 2)], rgb, a, 0);
179 drawpic(pos + [size[0] - tileSize[0], tileSize[1]], "gfx/ui/m_right.tga", [tileSize[0], size[1] - (tileSize[0] * 2)], rgb, a, 0);
180 drawpic(pos + [tileSize[0], tileSize[1]], "gfx/ui/m_mid.tga", [size[0] - (tileSize[0] * 2), size[1] - (tileSize[0] * 2)], rgb, a, 0);
181 }
182}
183
184void
185UIPF_draw_Line(float thickness, vector pos1, vector pos2, vector rgb, float a)
186{
187 drawline(thickness, pos1, pos2, rgb, a);
188}
189
190void
191UIPF_draw_Pic(vector pos, string material, vector size, vector rgb, float a, float imageFlags)
192{
193 drawpic(pos, material, size, rgb, a, imageFlags);
194}
195
196void
197UIPF_draw_SubPic(vector pos, vector displaySize, string material, vector sourcePos, vector sourceSize, vector rgb, float a, float imageFlags)
198{
199 drawsubpic(pos, displaySize, material, sourcePos, sourceSize, rgb, a, imageFlags);
200}
201
202
203int
204Util_CheckMouse(int x, int y, int sx, int sy)
205{
206 int mins[2];
207 int maxs[2];
208
209 x += g_menuofs[0];
210 y += g_menuofs[1];
211
212 mins[0] = x;
213 mins[1] = y;
214 maxs[0] = x + sx;
215 maxs[1] = y + sy;
216
217 if (g_vecMousePos[0] >= mins[0] && g_vecMousePos[0] <= maxs[0]) {
218 if (g_vecMousePos[1] >= mins[1] && g_vecMousePos[1] <= maxs[1]) {
219 return (1);
220 }
221 }
222
223 return (0);
224}
225
226string
227Util_CmdToKey(string cmd)
228{
229 float fBindKey = tokenize(findkeysforcommand(cmd));
230 string sBindTx = "";
231 float j, k;
232
233 for(j = 0; j < fBindKey; ++j) {
234 k = stof(argv(j));
235 if(k != -1) {
236 if(sBindTx != "") {
237 sBindTx = strcat(sBindTx, ", ");
238 }
239 sBindTx = strcat(sBindTx, keynumtostring(k));
240 }
241 }
242
243 return sBindTx;
244}
245
var materialAPI_t material
Access atlasPicAPI_t functions using this variable.
Definition: api_func.h:569