Xonotic
playermodel.qc
Go to the documentation of this file.
1 #include "playermodel.qh"
2 
4 {
5  entity me;
7  me.configureXonoticPlayerModelSelector(me);
8  return me;
9 }
10 
11 const float BUFMODELS_TITLE = 0;
12 const float BUFMODELS_IMAGE = 1;
13 const float BUFMODELS_MODEL = 2;
14 const float BUFMODELS_SKIN = 3;
15 const float BUFMODELS_DESC = 4;
16 const float BUFMODELS_COUNT = 5;
17 
18 #define XONVOTE186 1 // (nyov) removal of model text description
19 
21 {
22  me.configureXonoticImage(me, string_null, -1);
23 }
24 
26 {
27  int i;
28  string fn;
29 
30  float glob = search_begin(get_model_datafilename(string_null, -1, "txt"), true, true);
31  if (glob < 0)
32  return;
33 
34  float sortbuf = buf_create();
35  for(i = 0; i < search_getsize(glob); ++i)
36  {
37  // select model #i!
38  fn = search_getfilename(glob, i);
39  if(!get_model_parameters(fn, -1))
40  continue;
42  continue;
43  bufstr_add(sortbuf, sprintf("%-128s%s", get_model_parameters_name, fn), 1);
44  }
45  search_end(glob);
46  buf_sort(sortbuf, 128, 0);
47  me.numModels = buf_getsize(sortbuf);
48  me.bufModels = buf_create();
49  for(i = 0; i < me.numModels; ++i)
50  {
51  fn = substring(bufstr_get(sortbuf, i), 128, -1);
52  if(!get_model_parameters(fn, -1))
53  error("But it JUST worked!");
55  continue;
56  bufstr_set(me.bufModels, BUFMODELS_COUNT*i+BUFMODELS_TITLE, get_model_parameters_name);
61 #if XONVOTE186
64 #else
73 #endif
74  while(substring(get_model_parameters_desc, -1, 1) == "\n")
76  bufstr_set(me.bufModels, BUFMODELS_COUNT*i+BUFMODELS_DESC, get_model_parameters_desc);
77  }
78  buf_del(sortbuf);
80  me.loadCvars(me); // this will select the initial model, depending on the current cvars
81  me.go(me, 0); // this will set the vars for the selected model
82 }
83 
85 {
86  if(me.bufModels >= 0)
87  {
88  buf_del(me.bufModels);
89  me.bufModels = -1;
90  }
91 }
92 
94 {
95  string skin, modelname;
96  float i;
97 
98  skin = cvar_string("_cl_playerskin");
99  modelname = cvar_string("_cl_playermodel");
100 
101  for(i = 0; i < me.numModels; ++i)
102  {
103  if(bufstr_get(me.bufModels, BUFMODELS_COUNT*i+BUFMODELS_MODEL) == modelname)
104  if(bufstr_get(me.bufModels, BUFMODELS_COUNT*i+BUFMODELS_SKIN) == skin)
105  break;
106  }
107  if(i >= me.numModels) // fail
108  i = 0;
109  me.idxModels = i;
110 }
111 
113 {
114  me.idxModels = mod(me.idxModels + d + me.numModels, me.numModels);
115 
116  // select model #i!
117  strcpy(me.currentModelTitle, bufstr_get(me.bufModels, BUFMODELS_COUNT*me.idxModels+BUFMODELS_TITLE));
118  strcpy(me.currentModelImage, bufstr_get(me.bufModels, BUFMODELS_COUNT*me.idxModels+BUFMODELS_IMAGE));
119  me.currentSkin = stof(bufstr_get(me.bufModels, BUFMODELS_COUNT*me.idxModels+BUFMODELS_SKIN));
120  strcpy(me.currentModel, bufstr_get(me.bufModels, BUFMODELS_COUNT*me.idxModels+BUFMODELS_MODEL));
121  strcpy(me.currentModelDescription, bufstr_get(me.bufModels, BUFMODELS_COUNT*me.idxModels+BUFMODELS_DESC));
122 
123  // fix the image
124  if(draw_PictureSize(me.currentModelImage) == '0 0 0')
125  me.src = "nopreview_player";
126  else
127  me.src = me.currentModelImage;
128  me.updateAspect(me);
129 }
130 
132 {
133  if (me.numModels <= 0)
134  return;
135  me.go(me, +1);
136  me.saveCvars(me);
137 }
138 
140 {
141  if (me.numModels <= 0)
142  return;
143  me.go(me, -1);
144  me.saveCvars(me);
145 }
146 
148 {
149  // we can't immediately apply here because of flood control
150  cvar_set("_cl_playermodel", me.currentModel);
151  cvar_set("_cl_playerskin", ftos(me.currentSkin));
152 }
153 
155 {
156  float i, n;
157  vector o;
158 
159  if (me.numModels <= 0)
160  {
161  draw_CenterText('0.5 0.5 0', _("<no model found>"), me.realFontSize, SKINCOLOR_TEXT, 0.6, false);
162  return;
163  }
164 
166  // draw text on the image, handle \n in the description
167 
169 
170 #if XONVOTE186 // (nyov) lower name display looks better when there is no description text
171  draw_CenterText('0.5 0.8 0', me.currentModelTitle, me.realFontSize * (me.titleFontSize / me.fontSize), SKINCOLOR_MODELTITLE, SKINALPHA_MODELTITLE, false);
172 #else
173  draw_CenterText('0.5 0 0', me.currentModelTitle, me.realFontSize * (me.titleFontSize / me.fontSize), SKINCOLOR_MODELTITLE, SKINALPHA_MODELTITLE, false);
174 #endif
175 
177 
178  o = '0.5 1 0' - eY * me.realFontSize.y * ((n = tokenizebyseparator(me.currentModelDescription, "\n")) + 0.5);
179  for(i = 0; i < n; ++i)
180  {
181  draw_CenterText(o, argv(i), me.realFontSize, SKINCOLOR_TEXT, 1, false);
182  o += eY * me.realFontSize.y;
183  }
184 }
185 
186 void XonoticPlayerModelSelector_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
187 {
188  SUPER(XonoticPlayerModelSelector).resizeNotify(me, relOrigin, relSize, absOrigin, absSize);
189  me.realFontSize_y = me.fontSize / absSize.y;
190  me.realFontSize_x = me.fontSize / absSize.x;
191 }
192 
194 {
195  // Reinitialize self.
196  me.destroy(me);
197  me.loadModels(me);
198 }
float get_model_parameters_weight
Definition: util.qh:142
string get_model_datafilename(string m, float sk, string fil)
Definition: util.qc:1245
string get_model_parameters_desc
Definition: util.qh:152
const float BUFMODELS_SKIN
Definition: playermodel.qc:14
#define draw_endBoldFont()
Definition: draw.qh:5
string string_null
Definition: nil.qh:9
void XonoticPlayerModelSelector_saveCvars(entity me)
Definition: playermodel.qc:147
skin
Definition: ent_cs.qc:143
const vector eY
Definition: vector.qh:45
#define NEW(cname,...)
Definition: oo.qh:105
float get_model_parameters(string m, float sk)
Definition: util.qc:1258
#define draw_beginBoldFont()
Definition: draw.qh:4
string get_model_parameters_description
Definition: util.qh:145
entity() spawn
void XonoticPlayerModelSelector_resizeNotify(entity me, vector relOrigin, vector relSize, vector absOrigin, vector absSize)
Definition: playermodel.qc:186
const float BUFMODELS_DESC
Definition: playermodel.qc:15
void PlayerModelSelector_Next_Click(entity btn, entity me)
Definition: playermodel.qc:131
void XonoticPlayerModelSelector_draw(entity me)
Definition: playermodel.qc:154
#define strcpy(this, s)
Definition: string.qh:49
string get_model_parameters_sex
Definition: util.qh:141
#define SUPER(cname)
Definition: oo.qh:219
float get_model_parameters_age
Definition: util.qh:143
float get_model_parameters_modelskin
Definition: util.qh:138
#define buf_create
Definition: dpextensions.qh:63
void XonoticPlayerModelSelector_loadCvars(entity me)
Definition: playermodel.qc:93
void XonoticPlayerModelSelector_go(entity me, float d)
Definition: playermodel.qc:112
void PlayerModelSelector_Prev_Click(entity btn, entity me)
Definition: playermodel.qc:139
void XonoticPlayerModelSelector_configureXonoticPlayerModelSelector(entity me)
Definition: playermodel.qc:20
string get_model_parameters_modelname
Definition: util.qh:137
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
const float BUFMODELS_IMAGE
Definition: playermodel.qc:12
const float BUFMODELS_TITLE
Definition: playermodel.qc:11
const float BUFMODELS_COUNT
Definition: playermodel.qc:16
entity makeXonoticPlayerModelSelector()
Definition: playermodel.qc:3
vector(float skel, float bonenum) _skel_get_boneabs_hidden
void XonoticPlayerModelSelector_showNotify(entity me)
Definition: playermodel.qc:193
#define tokenizebyseparator
Definition: dpextensions.qh:21
bool get_model_parameters_hidden
Definition: util.qh:144
void XonoticPlayerModelSelector_loadModels(entity me)
Definition: playermodel.qc:25
const float BUFMODELS_MODEL
Definition: playermodel.qc:13
void XonoticPlayerModelSelector_destroy(entity me)
Definition: playermodel.qc:84
string get_model_parameters_name
Definition: util.qh:139