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

Go to the source code of this file.

Functions

void CampaignList_LoadMap (entity btn, entity me)
entity makeXonoticCampaignList ()
void MultiCampaign_Next (entity btn, entity me)
void MultiCampaign_Prev (entity btn, entity me)
void rewrapCampaign (float w, float l0, float emptyheight, vector theFontSize)
void XonoticCampaignList_campaignGo (entity me, float step)
void XonoticCampaignList_configureXonoticCampaignList (entity me)
void XonoticCampaignList_destroy (entity me)
void XonoticCampaignList_doubleClickListBoxItem (entity me, float i, vector where)
void XonoticCampaignList_draw (entity me)
void XonoticCampaignList_drawListBoxItem (entity me, int i, vector absSize, bool isSelected, bool isFocused)
float XonoticCampaignList_keyDown (entity me, float scan, float ascii, float shift)
void XonoticCampaignList_loadCvars (entity me)
void XonoticCampaignList_resizeNotify (entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
void XonoticCampaignList_saveCvars (entity me)
void XonoticCampaignList_setSelected (entity me, float i)

Variables

string campaign_longdesc_wrapped [CAMPAIGN_MAX_ENTRIES]

Function Documentation

◆ CampaignList_LoadMap()

void CampaignList_LoadMap ( entity btn,
entity me )

Definition at line 262 of file campaign.qc.

263{
264 if(me.selectedItem >= me.nItems || me.selectedItem < 0)
265 return;
266 CampaignSetup(me.selectedItem);
267}
void CampaignSetup(int n)

References CampaignSetup(), and entity().

Referenced by XonoticCampaignList::ATTRIB(), XonoticCampaignList_doubleClickListBoxItem(), XonoticCampaignList_keyDown(), and XonoticSingleplayerDialog_fill().

◆ makeXonoticCampaignList()

entity makeXonoticCampaignList ( )

Definition at line 48 of file campaign.qc.

49{
51 me.configureXonoticCampaignList(me);
52 return me;
53}
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
#define NEW(cname,...)
Definition oo.qh:117

References entity(), and NEW.

Referenced by XonoticCampaignList::ATTRIB(), and XonoticSingleplayerDialog_fill().

◆ MultiCampaign_Next()

void MultiCampaign_Next ( entity btn,
entity me )

Definition at line 141 of file campaign.qc.

142{
143 me.campaignGo(me, +1);
144}

References entity().

Referenced by XonoticCampaignList::ATTRIB(), and XonoticSingleplayerDialog_fill().

◆ MultiCampaign_Prev()

void MultiCampaign_Prev ( entity btn,
entity me )

Definition at line 145 of file campaign.qc.

146{
147 me.campaignGo(me, -1);
148}

References entity().

Referenced by XonoticCampaignList::ATTRIB(), and XonoticSingleplayerDialog_fill().

◆ rewrapCampaign()

void rewrapCampaign ( float w,
float l0,
float emptyheight,
vector theFontSize )

Definition at line 8 of file campaign.qc.

9{
10 int i, j;
11 int n;
12 float l;
13 string r, s;
14 for(i = 0; i < campaign_entries; ++i)
15 {
16 l = l0;
18 n = tokenizebyseparator(campaign_longdesc[i], "\n");
19 r = "";
20 for(j = 0; j < n; ++j)
21 {
22 s = argv(j);
23 if(s == "")
24 {
25 l -= emptyheight;
26 r = strcat(r, "\n");
27 continue;
28 }
29
32 {
34 if(--l < 0) goto toolong;
35 r = strcat(r, s, "\n");
36 }
37 }
38 goto nottoolong;
39LABEL(toolong)
40 while(substring(r, strlen(r) - 1, 1) == "\n")
41 r = substring(r, 0, strlen(r) - 1);
42 r = strcat(r, "...\n");
43LABEL(nottoolong)
45 }
46}
int campaign_entries
string getWrappedLine(float maxWidth, vector theFontSize, textLengthUpToWidth_widthFunction_t tw)
Definition util.qc:1131
string getWrappedLine_remaining
Definition util.qh:147
#define LABEL(id)
Definition compiler.qh:34
#define strlen
#define tokenizebyseparator
float draw_TextWidth_WithoutColors(string s, vector theFontSize)
Definition draw.qc:397
string campaign_longdesc_wrapped[CAMPAIGN_MAX_ENTRIES]
Definition campaign.qc:6
string substring(string s, float start, float length)
string strzone(string s)
string argv(float n)
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))
#define strfree(this)
Definition string.qh:59

References argv(), campaign_entries, campaign_longdesc_wrapped, draw_TextWidth_WithoutColors(), getWrappedLine(), getWrappedLine_remaining, LABEL, strcat(), strfree, strlen, strzone(), substring(), tokenizebyseparator, and vector.

Referenced by XonoticCampaignList_loadCvars(), and XonoticCampaignList_resizeNotify().

◆ XonoticCampaignList_campaignGo()

void XonoticCampaignList_campaignGo ( entity me,
float step )

Definition at line 96 of file campaign.qc.

97{
98 string s;
99 float i, j, n;
100
101 if(me.campaignGlob >= 0)
102 {
103 n = search_getsize(me.campaignGlob);
104 if(n > 0)
105 {
106 j = -1;
107 s = strcat("maps/campaign", campaign_name, ".txt");
108 for(i = 0; i < n; ++i)
109 {
110 if(search_getfilename(me.campaignGlob, i) == s)
111 j = i;
112 }
113 if(j < 0)
114 {
115 s = strcat("maps/campaign", cvar_defstring("g_campaign_name"), ".txt");
116 for(i = 0; i < n; ++i)
117 {
118 if(search_getfilename(me.campaignGlob, i) == s)
119 j = i;
120 }
121 }
122 if(j < 0)
123 {
124 if(step >= 0)
125 j = 0;
126 else
127 j = n - 1;
128 }
129 else
130 j = mod(j + step, n);
131 s = search_getfilename(me.campaignGlob, j);
132 s = substring(s, 13, strlen(s) - 17);
133 cvar_set("g_campaign_name", s);
134 me.loadCvars(me);
135 me.hasNextCampaign = (j != n - 1);
136 me.hasPrevCampaign = (j != 0);
137 }
138 }
139}
string campaign_name
float mod(float val, float m)
void cvar_set(string name, string value)
string search_getfilename(float handle, float num)
float search_getsize(float handle)
const string cvar_defstring(string name)

References campaign_name, cvar_defstring(), cvar_set(), entity(), mod(), search_getfilename(), search_getsize(), strcat(), strlen, and substring().

◆ XonoticCampaignList_configureXonoticCampaignList()

void XonoticCampaignList_configureXonoticCampaignList ( entity me)

Definition at line 54 of file campaign.qc.

55{
56 me.configureXonoticListBox(me);
57 me.campaignGlob = search_begin("maps/campaign*.txt", true, true);
58 me.loadCvars(me);
59 me.campaignGo(me, 0); // it makes work buttons too
60}
float search_begin(string pattern, float caseinsensitive, float quiet)

References entity(), and search_begin().

◆ XonoticCampaignList_destroy()

void XonoticCampaignList_destroy ( entity me)

Definition at line 62 of file campaign.qc.

63{
64 if(me.campaignGlob >= 0)
65 search_end(me.campaignGlob);
66}
void search_end(float handle)

References entity(), and search_end().

◆ XonoticCampaignList_doubleClickListBoxItem()

void XonoticCampaignList_doubleClickListBoxItem ( entity me,
float i,
vector where )

Definition at line 190 of file campaign.qc.

191{
192 CampaignList_LoadMap(me, me);
193}
void CampaignList_LoadMap(entity btn, entity me)
Definition campaign.qc:262

References CampaignList_LoadMap(), entity(), and vector.

◆ XonoticCampaignList_draw()

void XonoticCampaignList_draw ( entity me)

Definition at line 150 of file campaign.qc.

151{
152 if(me.buttonNext)
153 me.buttonNext.disabled = !me.hasNextCampaign;
154 if(me.buttonPrev)
155 me.buttonPrev.disabled = !me.hasPrevCampaign;
156
157 if(cvar(me.controlledCvar) != me.campaignIndex || cvar_string("g_campaign_name") != campaign_name)
158 me.loadCvars(me);
159 SUPER(XonoticCampaignList).draw(me);
160}
float cvar(string name)
const string cvar_string(string name)
#define SUPER(cname)
Definition oo.qh:231

References campaign_name, cvar(), cvar_string(), entity(), and SUPER.

◆ XonoticCampaignList_drawListBoxItem()

void XonoticCampaignList_drawListBoxItem ( entity me,
int i,
vector absSize,
bool isSelected,
bool isFocused )

Definition at line 194 of file campaign.qc.

195{
196 string s;
197 vector theColor;
198 float theAlpha;
199 float j, n;
200 vector o;
201
202 if(i < me.campaignIndex)
203 {
204 theAlpha = SKINALPHA_CAMPAIGN_SELECTABLE;
205 theColor = SKINCOLOR_CAMPAIGN_SELECTABLE;
206 }
207 else if(i == me.campaignIndex)
208 {
209 theAlpha = SKINALPHA_CAMPAIGN_CURRENT;
210 theColor = SKINCOLOR_CAMPAIGN_CURRENT;
211 }
212 else
213 {
214 theAlpha = SKINALPHA_CAMPAIGN_FUTURE;
215 theColor = SKINCOLOR_CAMPAIGN_FUTURE;
216 }
217
218 if(isSelected)
219 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_SELECTED, SKINALPHA_LISTBOX_SELECTED);
220 else if(isFocused)
221 {
222 me.focusedItemAlpha = getFadedAlpha(me.focusedItemAlpha, SKINALPHA_LISTBOX_FOCUSED, SKINFADEALPHA_LISTBOX_FOCUSED);
223 draw_Fill('0 0 0', '1 1 0', SKINCOLOR_LISTBOX_FOCUSED, me.focusedItemAlpha);
224 }
225
226 if(draw_PictureSize(strcat("/maps/", campaign_mapname[i])) == '0 0 0')
227 draw_Picture(me.columnPreviewOrigin * eX, "nopreview_map", me.columnPreviewSize * eX + eY, '1 1 1', theAlpha);
228 else
229 draw_Picture(me.columnPreviewOrigin * eX, strcat("/maps/", campaign_mapname[i]), me.columnPreviewSize * eX + eY, '1 1 1', theAlpha);
230
231 s = strcat("gametype_", campaign_gametype[i]);
232 if(i <= me.campaignIndex && draw_PictureSize(s) != '0 0 0')
233 draw_Picture(me.typeIconOrigin, s, me.typeIconSize, '1 1 1', 1);
234
235 if(i < me.campaignIndex)
236 draw_Picture(me.checkMarkOrigin, "checkmark", me.checkMarkSize, '1 1 1', 1);
237
238 if(i <= me.campaignIndex)
239 s = campaign_shortdesc[i]; // fteqcc sucks
240 else
241 s = "???";
242 // NOTE the following string should be equal to the one used in the Welcome dialog
243 // to avoid adding a slightly different string to translate
244 s = draw_TextShortenToWidth(strcat(sprintf(_("Level %d:"), i+1), " ", s), me.columnNameSize, 0, me.realFontSize);
245 draw_Text(me.realUpperMargin1 * eY + (me.columnNameOrigin + 0.00 * (me.columnNameSize - draw_TextWidth(s, 0, me.realFontSize))) * eX, s, me.realFontSize, theColor, theAlpha, 0);
246
247 if(i <= me.campaignIndex)
248 {
250 n = tokenizebyseparator(s, "\n");
251 o = me.realUpperMargin2 * eY + me.columnNameOrigin * eX;
252 for(j = 0; j < n; ++j)
253 if(argv(j) != "")
254 {
255 draw_Text(o, argv(j), me.realFontSize, theColor, theAlpha * SKINALPHA_CAMPAIGN_DESCRIPTION, 0);
256 o.y += me.realFontSize.y;
257 }
258 else
259 o.y += me.realFontSize.y * me.emptyLineHeight;
260 }
261}
string campaign_gametype[CAMPAIGN_MAX_ENTRIES]
string campaign_mapname[CAMPAIGN_MAX_ENTRIES]
string draw_TextShortenToWidth(string theText, float maxWidth, float ICanHasKallerz, vector SizeThxBye)
Definition draw.qc:378
void draw_Picture(vector theOrigin, string pic, vector theSize, vector theColor, float theAlpha)
Definition draw.qc:72
void draw_Text(vector theOrigin, string theText, vector theSize, vector theColor, float theAlpha, float ICanHasKallerz)
Definition draw.qc:282
vector draw_PictureSize(string pic)
Definition draw.qc:80
float draw_TextWidth(string theText, float ICanHasKallerz, vector SizeThxBye)
Definition draw.qc:304
void draw_Fill(vector theOrigin, vector theSize, vector theColor, float theAlpha)
Definition draw.qc:97
float getFadedAlpha(float currentAlpha, float startAlpha, float targetAlpha)
Definition util.qc:816
vector
Definition self.qh:92
const vector eY
Definition vector.qh:45
const vector eX
Definition vector.qh:44

References argv(), campaign_gametype, campaign_longdesc_wrapped, campaign_mapname, draw_Fill(), draw_Picture(), draw_PictureSize(), draw_Text(), draw_TextShortenToWidth(), draw_TextWidth(), entity(), eX, eY, getFadedAlpha(), strcat(), tokenizebyseparator, and vector.

◆ XonoticCampaignList_keyDown()

float XonoticCampaignList_keyDown ( entity me,
float scan,
float ascii,
float shift )

Definition at line 275 of file campaign.qc.

276{
277 if(scan == K_ENTER || scan == K_SPACE || scan == K_KP_ENTER)
278 CampaignList_LoadMap(me, me);
279 else
280 return SUPER(XonoticCampaignList).keyDown(me, scan, ascii, shift);
281 return 1;
282}
float K_SPACE
Definition keycodes.qc:10
float K_ENTER
Definition keycodes.qc:8
float K_KP_ENTER
Definition keycodes.qc:74

References CampaignList_LoadMap(), entity(), K_ENTER, K_KP_ENTER, K_SPACE, and SUPER.

◆ XonoticCampaignList_loadCvars()

void XonoticCampaignList_loadCvars ( entity me)

Definition at line 68 of file campaign.qc.

69{
70 // read campaign cvars
71 strcpy(campaign_name, cvar_string("g_campaign_name"));
72 strcpy(me.controlledCvar, strcat("g_campaign", campaign_name, "_index"));
73 registercvar(me.controlledCvar, "", 0); // saved by server QC anyway
76 me.campaignIndex = bound(0, cvar(me.controlledCvar), campaign_entries);
77 cvar_set(me.controlledCvar, ftos(me.campaignIndex));
78 if(me.columnNameSize)
79 rewrapCampaign(me.columnNameSize, me.rowsPerItem - 3, me.emptyLineHeight, me.realFontSize);
80 me.nItems = min(me.campaignIndex + 2, campaign_entries);
81 me.setSelected(me, min(me.campaignIndex, me.nItems - 1));
82 if(me.nItems - 1 > me.campaignIndex)
83 me.scrollToItem(me, me.nItems - 1);
84 if(me.labelTitle)
85 me.labelTitle.setText(me.labelTitle, campaign_title);
86}
string campaign_title
void CampaignFile_Unload()
#define CAMPAIGN_MAX_ENTRIES
float CampaignFile_Load(float offset, float entries)
void rewrapCampaign(float w, float l0, float emptyheight, vector theFontSize)
Definition campaign.qc:8
float registercvar(string name, string value, float flags)
float bound(float min, float value, float max)
float min(float f,...)
string ftos(float f)
#define strcpy(this, s)
Definition string.qh:52

References bound(), campaign_entries, CAMPAIGN_MAX_ENTRIES, campaign_name, campaign_title, CampaignFile_Load(), CampaignFile_Unload(), cvar(), cvar_set(), cvar_string(), entity(), ftos(), min(), registercvar(), rewrapCampaign(), strcat(), and strcpy.

◆ XonoticCampaignList_resizeNotify()

void XonoticCampaignList_resizeNotify ( entity me,
vector relOrigin,
vector relSize,
vector absOrigin,
vector absSize )

Definition at line 162 of file campaign.qc.

163{
164 me.itemAbsSize = '0 0 0';
165 SUPER(XonoticCampaignList).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
166
167 me.itemAbsSize.y = absSize.y * me.itemHeight;
168 me.itemAbsSize.x = absSize.x * (1 - me.controlWidth);
169 me.realFontSize.y = me.fontSize / me.itemAbsSize.y;
170 me.realFontSize.x = me.fontSize / me.itemAbsSize.x;
171 me.realUpperMargin1 = 0.5 * me.realFontSize.y;
172 me.realUpperMargin2 = me.realUpperMargin1 + 2 * me.realFontSize.y;
173
174 me.checkMarkSize = (eX * (me.itemAbsSize.y / me.itemAbsSize.x) + eY) * 0.5;
175
176 me.columnPreviewOrigin = 0;
177 me.columnPreviewSize = me.itemAbsSize.y / me.itemAbsSize.x * 4 / 3;
178 me.columnCheckMarkSize = me.checkMarkSize.x;
179 me.columnNameSize = 1 - me.columnPreviewSize - me.columnCheckMarkSize - 4 * me.realFontSize.x;
180 me.columnNameOrigin = me.columnPreviewOrigin + me.columnPreviewSize + me.realFontSize.x;
181 me.columnCheckMarkOrigin = me.columnNameOrigin + me.columnNameSize + me.realFontSize.x * 2;
182
183 me.checkMarkOrigin = eY + eX * (me.columnCheckMarkOrigin + me.columnCheckMarkSize) - me.checkMarkSize;
184
185 me.typeIconOrigin = vec3(me.columnPreviewSize - me.checkMarkSize.x, me.checkMarkOrigin.y, 0);
186 me.typeIconSize = me.checkMarkSize;
187
188 rewrapCampaign(me.columnNameSize, me.rowsPerItem - 3, me.emptyLineHeight, me.realFontSize);
189}
#define vec3(_x, _y, _z)
Definition vector.qh:95

References entity(), eX, eY, rewrapCampaign(), SUPER, vec3, and vector.

◆ XonoticCampaignList_saveCvars()

void XonoticCampaignList_saveCvars ( entity me)

Definition at line 88 of file campaign.qc.

89{
90 // write campaign cvars
91 // no reason to do this!
92 // cvar_set("g_campaign_name", campaign_name);
93 // cvar_set(me.controlledCvar, ftos(me.campaignIndex)); // NOTE: only server QC does that!
94}

References entity().

◆ XonoticCampaignList_setSelected()

void XonoticCampaignList_setSelected ( entity me,
float i )

Definition at line 269 of file campaign.qc.

270{
271 // prevent too late items from being played
272 SUPER(XonoticCampaignList).setSelected(me, min(i, me.campaignIndex));
273}

References entity(), min(), and SUPER.

Variable Documentation

◆ campaign_longdesc_wrapped

string campaign_longdesc_wrapped[CAMPAIGN_MAX_ENTRIES]

Definition at line 6 of file campaign.qc.

Referenced by rewrapCampaign(), and XonoticCampaignList_drawListBoxItem().