-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathCharacterCreate.lua
558 lines (493 loc) · 16.9 KB
/
CharacterCreate.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
CHARACTER_FACING_INCREMENT = 2;
MAX_RACES = 10;
MAX_CLASSES_PER_RACE = 10;
NUM_CHAR_CUSTOMIZATIONS = 5;
MIN_CHAR_NAME_LENGTH = 2;
CHARACTER_CREATE_ROTATION_START_X = nil;
CHARACTER_CREATE_INITIAL_FACING = nil;
PAID_CHARACTER_CUSTOMIZATION = 1;
PAID_RACE_CHANGE = 2;
PAID_FACTION_CHANGE = 3;
PAID_SERVICE_CHARACTER_ID = nil;
PAID_SERVICE_TYPE = nil;
FACTION_BACKDROP_COLOR_TABLE = {
["Alliance"] = {0.5, 0.5, 0.5, 0.09, 0.09, 0.19},
["Horde"] = {0.5, 0.2, 0.2, 0.19, 0.05, 0.05},
};
FRAMES_TO_BACKDROP_COLOR = {
"CharacterCreateCharacterRace",
"CharacterCreateCharacterClass",
-- "CharacterCreateCharacterFaction",
"CharacterCreateNameEdit",
};
RACE_ICON_TCOORDS = {
["HUMAN_MALE"] = {0, 0.125, 0, 0.25},
["DWARF_MALE"] = {0.125, 0.25, 0, 0.25},
["GNOME_MALE"] = {0.25, 0.375, 0, 0.25},
["NIGHTELF_MALE"] = {0.375, 0.5, 0, 0.25},
["TAUREN_MALE"] = {0, 0.125, 0.25, 0.5},
["SCOURGE_MALE"] = {0.125, 0.25, 0.25, 0.5},
["TROLL_MALE"] = {0.25, 0.375, 0.25, 0.5},
["ORC_MALE"] = {0.375, 0.5, 0.25, 0.5},
["HUMAN_FEMALE"] = {0, 0.125, 0.5, 0.75},
["DWARF_FEMALE"] = {0.125, 0.25, 0.5, 0.75},
["GNOME_FEMALE"] = {0.25, 0.375, 0.5, 0.75},
["NIGHTELF_FEMALE"] = {0.375, 0.5, 0.5, 0.75},
["TAUREN_FEMALE"] = {0, 0.125, 0.75, 1.0},
["SCOURGE_FEMALE"] = {0.125, 0.25, 0.75, 1.0},
["TROLL_FEMALE"] = {0.25, 0.375, 0.75, 1.0},
["ORC_FEMALE"] = {0.375, 0.5, 0.75, 1.0},
["BLOODELF_MALE"] = {0.5, 0.625, 0.25, 0.5},
["BLOODELF_FEMALE"] = {0.5, 0.625, 0.75, 1.0},
["DRAENEI_MALE"] = {0.5, 0.625, 0, 0.25},
["DRAENEI_FEMALE"] = {0.5, 0.625, 0.5, 0.75},
};
CLASS_ICON_TCOORDS = {
["WARRIOR"] = {0, 0.25, 0, 0.25},
["MAGE"] = {0.25, 0.49609375, 0, 0.25},
["ROGUE"] = {0.49609375, 0.7421875, 0, 0.25},
["DRUID"] = {0.7421875, 0.98828125, 0, 0.25},
["HUNTER"] = {0, 0.25, 0.25, 0.5},
["SHAMAN"] = {0.25, 0.49609375, 0.25, 0.5},
["PRIEST"] = {0.49609375, 0.7421875, 0.25, 0.5},
["WARLOCK"] = {0.7421875, 0.98828125, 0.25, 0.5},
["PALADIN"] = {0, 0.25, 0.5, 0.75},
["DEATHKNIGHT"] = {0.25, 0.49609375, 0.5, 0.75},
};
function CharacterCreate_OnLoad(self)
self:SetSequence(0);
self:SetCamera(0);
CharacterCreate.numRaces = 0;
CharacterCreate.selectedRace = 0;
CharacterCreate.numClasses = 0;
CharacterCreate.selectedClass = 0;
CharacterCreate.selectedGender = 0;
SetCharCustomizeFrame("CharacterCreate");
for i=1, NUM_CHAR_CUSTOMIZATIONS, 1 do
_G["CharacterCustomizationButtonFrame"..i.."Text"]:SetText(_G["CHAR_CUSTOMIZATION"..i.."_DESC"]);
end
-- Color edit box backdrop
local backdropColor = FACTION_BACKDROP_COLOR_TABLE["Alliance"];
CharacterCreateNameEdit:SetBackdropBorderColor(backdropColor[1], backdropColor[2], backdropColor[3]);
CharacterCreateNameEdit:SetBackdropColor(backdropColor[4], backdropColor[5], backdropColor[6]);
end
function CharacterCreate_OnShow()
for i=1, MAX_CLASSES_PER_RACE, 1 do
local button = _G["CharacterCreateClassButton"..i];
button:Enable();
SetButtonDesaturated(button, false)
end
for i=1, MAX_RACES, 1 do
local button = _G["CharacterCreateRaceButton"..i];
button:Enable();
SetButtonDesaturated(button, false)
end
if ( PAID_SERVICE_TYPE ) then
CustomizeExistingCharacter( PAID_SERVICE_CHARACTER_ID );
CharacterCreateNameEdit:SetText( PaidChange_GetName() );
else
--randomly selects a combination
ResetCharCustomize();
CharacterCreateNameEdit:SetText("");
CharCreateRandomizeButton:Show();
end
CharacterCreateEnumerateRaces(GetAvailableRaces());
SetCharacterRace(GetSelectedRace());
CharacterCreateEnumerateClasses(GetAvailableClasses());
local_,_,index = GetSelectedClass();
SetCharacterClass(index);
SetCharacterGender(GetSelectedSex())
-- Hair customization stuff
CharacterCreate_UpdateHairCustomization();
SetCharacterCreateFacing(-15);
if ( ALLOW_RANDOM_NAME_BUTTON ) then
CharacterCreateRandomName:Show();
end
-- setup customization
CharacterChangeFixup();
end
function CharacterCreate_OnHide()
PAID_SERVICE_CHARACTER_ID = nil;
PAID_SERVICE_TYPE = nil;
end
function CharacterCreateFrame_OnMouseDown(button)
if ( button == "LeftButton" ) then
CHARACTER_CREATE_ROTATION_START_X = GetCursorPosition();
CHARACTER_CREATE_INITIAL_FACING = GetCharacterCreateFacing();
end
end
function CharacterCreateFrame_OnMouseUp(button)
if ( button == "LeftButton" ) then
CHARACTER_CREATE_ROTATION_START_X = nil
end
end
function CharacterCreateFrame_OnUpdate()
if ( CHARACTER_CREATE_ROTATION_START_X ) then
local x = GetCursorPosition();
local diff = (x - CHARACTER_CREATE_ROTATION_START_X) * CHARACTER_ROTATION_CONSTANT;
CHARACTER_CREATE_ROTATION_START_X = GetCursorPosition();
SetCharacterCreateFacing(GetCharacterCreateFacing() + diff);
end
end
function CharacterCreateEnumerateRaces(...)
CharacterCreate.numRaces = select("#", ...)/3;
if ( CharacterCreate.numRaces > MAX_RACES ) then
message("Too many races! Update MAX_RACES");
return;
end
local coords;
local index = 1;
local button;
local gender;
local selectedSex = GetSelectedSex();
if ( selectedSex == SEX_MALE ) then
gender = "MALE";
elseif ( selectedSex == SEX_FEMALE ) then
gender = "FEMALE";
end
for i=1, select("#", ...), 3 do
coords = RACE_ICON_TCOORDS[strupper(select(i+1, ...).."_"..gender)];
_G["CharacterCreateRaceButton"..index.."NormalTexture"]:SetTexCoord(coords[1], coords[2], coords[3], coords[4]);
_G["CharacterCreateRaceButton"..index.."PushedTexture"]:SetTexCoord(coords[1], coords[2], coords[3], coords[4]);
button = _G["CharacterCreateRaceButton"..index];
button:Show();
if ( select(i+2, ...) == 1 ) then
button.enable = true;
SetButtonDesaturated(button);
button.name = select(i, ...)
button.tooltip = select(i, ...);
else
button.enable = false;
SetButtonDesaturated(button, 1);
button.name = select(i, ...)
button.tooltip = _G[strupper(select(i+1, ...).."_".."DISABLED")];
end
index = index + 1;
end
for i=CharacterCreate.numRaces + 1, MAX_RACES, 1 do
_G["CharacterCreateRaceButton"..i]:Hide();
end
end
function CharacterCreateEnumerateClasses(...)
CharacterCreate.numClasses = select("#", ...)/3;
if ( CharacterCreate.numClasses > MAX_CLASSES_PER_RACE ) then
message("Too many classes! Update MAX_CLASSES_PER_RACE");
return;
end
local coords;
local index = 1;
local button;
for i=1, select("#", ...), 3 do
coords = CLASS_ICON_TCOORDS[strupper(select(i+1, ...))];
_G["CharacterCreateClassButton"..index.."NormalTexture"]:SetTexCoord(coords[1], coords[2], coords[3], coords[4]);
_G["CharacterCreateClassButton"..index.."PushedTexture"]:SetTexCoord(coords[1], coords[2], coords[3], coords[4]);
button = _G["CharacterCreateClassButton"..index];
button:Show();
if ( (select(i+2, ...) == 1) and (IsRaceClassValid(CharacterCreate.selectedRace, index)) ) then
button.enable = true;
button:Enable();
SetButtonDesaturated(button);
button.name = select(i, ...)
button.tooltip = select(i, ...);
_G["CharacterCreateClassButton"..index.."DisableTexture"]:Hide();
else
button.enable = false;
button:Disable();
SetButtonDesaturated(button, 1);
button.name = select(i, ...)
button.tooltip = _G[strupper(select(i+1, ...).."_".."DISABLED")];
_G["CharacterCreateClassButton"..index.."DisableTexture"]:Show();
end
index = index + 1;
end
for i=CharacterCreate.numClasses + 1, MAX_CLASSES_PER_RACE, 1 do
_G["CharacterCreateClassButton"..i]:Hide();
end
end
function SetCharacterRace(id)
CharacterCreate.selectedRace = id;
local selectedButton;
for i=1, CharacterCreate.numRaces, 1 do
local button = _G["CharacterCreateRaceButton"..i];
if ( i == id ) then
_G["CharacterCreateRaceButton"..i.."Text"]:SetText(button.name);
button:SetChecked(1);
selectedButton = button;
else
_G["CharacterCreateRaceButton"..i.."Text"]:SetText("");
button:SetChecked(0);
end
end
-- Set Faction
local name, faction = GetFactionForRace(CharacterCreate.selectedRace);
-- Set Race
local race, fileString = GetNameForRace();
CharacterCreateRaceLabel:SetText(race);
fileString = strupper(fileString);
if ( GetSelectedSex() == SEX_MALE ) then
gender = "MALE";
else
gender = "FEMALE";
end
local coords = RACE_ICON_TCOORDS[fileString.."_"..gender];
CharacterCreateRaceIcon:SetTexCoord(coords[1], coords[2], coords[3], coords[4]);
local raceText = _G["RACE_INFO_"..fileString];
local abilityIndex = 1;
local tempText = _G["ABILITY_INFO_"..fileString..abilityIndex];
abilityText = "";
while ( tempText ) do
abilityText = abilityText..tempText.."\n\n";
abilityIndex = abilityIndex + 1;
tempText = _G["ABILITY_INFO_"..fileString..abilityIndex];
end
CharacterCreateRaceScrollFrameScrollBar:SetValue(0);
CharacterCreateRaceText:SetText(GetFlavorText("RACE_INFO_"..strupper(fileString), GetSelectedSex()).."|n|n");
if ( abilityText and abilityText ~= "" ) then
CharacterCreateRaceAbilityText:SetText(abilityText);
else
CharacterCreateRaceAbilityText:SetText("");
end
-- Set backdrop colors based on faction
local backdropColor = FACTION_BACKDROP_COLOR_TABLE[faction];
local frame;
for index, value in pairs(FRAMES_TO_BACKDROP_COLOR) do
frame = _G[value];
frame:SetBackdropColor(backdropColor[4], backdropColor[5], backdropColor[6]);
end
CharacterCreateConfigurationBackground:SetVertexColor(backdropColor[4], backdropColor[5], backdropColor[6]);
local backgroundFilename = GetCreateBackgroundModel();
SetBackgroundModel(CharacterCreate, backgroundFilename);
end
function SetCharacterClass(id)
CharacterCreate.selectedClass = id;
for i=1, CharacterCreate.numClasses, 1 do
local button = _G["CharacterCreateClassButton"..i];
if ( i == id ) then
CharacterCreateClassName:SetText(button.name);
button:SetChecked(1);
else
button:SetChecked(0);
end
end
local className, classFileName, _, tank, healer, damage = GetSelectedClass();
local abilityIndex = 0;
local tempText = _G["CLASS_INFO_"..classFileName..abilityIndex];
abilityText = "";
while ( tempText ) do
abilityText = abilityText..tempText.."\n\n";
abilityIndex = abilityIndex + 1;
tempText = _G["CLASS_INFO_"..classFileName..abilityIndex];
end
local coords = CLASS_ICON_TCOORDS[classFileName];
CharacterCreateClassIcon:SetTexCoord(coords[1], coords[2], coords[3], coords[4]);
CharacterCreateClassLabel:SetText(className);
CharacterCreateClassRolesText:SetText(abilityText);
CharacterCreateClassText:SetText(GetFlavorText("CLASS_"..strupper(classFileName), GetSelectedSex()).."|n|n");
CharacterCreateClassScrollFrameScrollBar:SetValue(0);
end
function CharacterCreate_OnChar()
end
function CharacterCreate_OnKeyDown(key)
if ( key == "ESCAPE" ) then
CharacterCreate_Back();
elseif ( key == "ENTER" ) then
CharacterCreate_Okay();
elseif ( key == "PRINTSCREEN" ) then
Screenshot();
end
end
function CharacterCreate_UpdateModel(self)
UpdateCustomizationScene();
self:AdvanceTime();
end
function CharacterCreate_Okay()
if ( PAID_SERVICE_TYPE ) then
GlueDialog_Show("CONFIRM_PAID_SERVICE");
else
CreateCharacter(CharacterCreateNameEdit:GetText());
end
PlaySound("gsCharacterCreationCreateChar");
end
function CharacterCreate_Back()
PlaySound("gsCharacterCreationCancel");
SetGlueScreen("charselect");
end
function CharacterClass_OnClick(id)
PlaySound("gsCharacterCreationClass");
local _,_,currClass = GetSelectedClass();
if ( currClass ~= id and IsRaceClassValid(GetSelectedRace(), id) ) then
SetSelectedClass(id);
SetCharacterClass(id);
SetCharacterRace(GetSelectedRace());
CharacterChangeFixup();
end
end
function CharacterRace_OnClick(self, id)
PlaySound("gsCharacterCreationClass");
if ( not self:GetChecked() ) then
self:SetChecked(1);
return;
end
if ( GetSelectedRace() ~= id ) then
SetSelectedRace(id);
SetCharacterRace(id);
SetSelectedSex(GetSelectedSex());
SetCharacterCreateFacing(-15);
CharacterCreateEnumerateClasses(GetAvailableClasses());
local _,_,classIndex = GetSelectedClass();
if ( PAID_SERVICE_TYPE ) then
classIndex = PaidChange_GetCurrentClassIndex();
end
SetCharacterClass(classIndex);
-- Hair customization stuff
CharacterCreate_UpdateHairCustomization();
CharacterChangeFixup();
end
end
function SetCharacterGender(sex)
local gender;
SetSelectedSex(sex);
if ( sex == SEX_MALE ) then
gender = "MALE";
CharacterCreateGender:SetText(MALE);
CharacterCreateGenderButtonMale:SetChecked(1);
CharacterCreateGenderButtonFemale:SetChecked(nil);
elseif ( sex == SEX_FEMALE ) then
gender = "FEMALE";
CharacterCreateGender:SetText(FEMALE);
CharacterCreateGenderButtonMale:SetChecked(nil);
CharacterCreateGenderButtonFemale:SetChecked(1);
end
-- Update race images to reflect gender
CharacterCreateEnumerateRaces(GetAvailableRaces());
CharacterCreateEnumerateClasses(GetAvailableClasses());
SetCharacterRace(GetSelectedRace());
local _,_,classIndex = GetSelectedClass();
if ( PAID_SERVICE_TYPE ) then
classIndex = PaidChange_GetCurrentClassIndex();
end
SetCharacterClass(classIndex);
CharacterCreate_UpdateHairCustomization();
-- Update right hand race portrait to reflect gender change
-- Set Race
local race, fileString = GetNameForRace();
CharacterCreateRaceLabel:SetText(race);
fileString = strupper(fileString);
local coords = RACE_ICON_TCOORDS[fileString.."_"..gender];
CharacterCreateRaceIcon:SetTexCoord(coords[1], coords[2], coords[3], coords[4]);
CharacterChangeFixup();
end
function CharacterCustomization_Left(id)
PlaySound("gsCharacterCreationLook");
CycleCharCustomization(id, -1);
end
function CharacterCustomization_Right(id)
PlaySound("gsCharacterCreationLook");
CycleCharCustomization(id, 1);
end
function CharacterCreate_Randomize()
PlaySound("gsCharacterCreationLook");
RandomizeCharCustomization();
end
function CharacterCreateRotateRight_OnUpdate(self)
if ( self:GetButtonState() == "PUSHED" ) then
SetCharacterCreateFacing(GetCharacterCreateFacing() + CHARACTER_FACING_INCREMENT);
end
end
function CharacterCreateRotateLeft_OnUpdate(self)
if ( self:GetButtonState() == "PUSHED" ) then
SetCharacterCreateFacing(GetCharacterCreateFacing() - CHARACTER_FACING_INCREMENT);
end
end
function CharacterCreate_UpdateHairCustomization()
CharacterCustomizationButtonFrame3Text:SetText(_G["HAIR_"..GetHairCustomization().."_STYLE"]);
CharacterCustomizationButtonFrame4Text:SetText(_G["HAIR_"..GetHairCustomization().."_COLOR"]);
CharacterCustomizationButtonFrame5Text:SetText(_G["FACIAL_HAIR_"..GetFacialHairCustomization()]);
end
function SetButtonDesaturated(button, desaturated, r, g, b)
if ( not button ) then
return;
end
local icon = button:GetNormalTexture();
if ( not icon ) then
return;
end
local shaderSupported = icon:SetDesaturated(desaturated);
if ( not desaturated ) then
r = 1.0;
g = 1.0;
b = 1.0;
elseif ( not r or not shaderSupported ) then
r = 0.5;
g = 0.5;
b = 0.5;
end
icon:SetVertexColor(r, g, b);
end
function GetFlavorText(tagname, sex)
local primary, secondary;
if ( sex == SEX_MALE ) then
primary = "";
secondary = "_FEMALE";
else
primary = "_FEMALE";
secondary = "";
end
local text = _G[tagname..primary];
if ( (text == nil) or (text == "") ) then
text = _G[tagname..secondary];
end
return text;
end
function CharacterCreate_DeathKnightSwap(self)
local _, classFilename = GetSelectedClass();
if ( classFilename == "DEATHKNIGHT" ) then
if (self.currentModel ~= "DEATHKNIGHT") then
self.currentModel = "DEATHKNIGHT";
self:SetNormalTexture("Interface\\Glues\\Common\\Glue-Panel-Button-Up-Blue");
self:SetPushedTexture("Interface\\Glues\\Common\\Glue-Panel-Button-Down-Blue");
self:SetHighlightTexture("Interface\\Glues\\Common\\Glue-Panel-Button-Highlight-Blue");
end
else
if (self.currentModel == "DEATHKNIGHT") then
self.currentModel = nil;
self:SetNormalTexture("Interface\\Glues\\Common\\Glue-Panel-Button-Up");
self:SetPushedTexture("Interface\\Glues\\Common\\Glue-Panel-Button-Down");
self:SetHighlightTexture("Interface\\Glues\\Common\\Glue-Panel-Button-Highlight");
end
end
end
function CharacterChangeFixup()
if ( PAID_SERVICE_TYPE ) then
for i=1, MAX_CLASSES_PER_RACE, 1 do
if (CharacterCreate.selectedClass ~= i) then
local button = _G["CharacterCreateClassButton"..i];
button:Disable();
SetButtonDesaturated(button, true)
end
end
for i=1, MAX_RACES, 1 do
local allow = false;
if ( PAID_SERVICE_TYPE == PAID_FACTION_CHANGE ) then
local faction = GetFactionForRace(PaidChange_GetCurrentRaceIndex());
if ( (i == PaidChange_GetCurrentRaceIndex()) or ((GetFactionForRace(i) ~= faction) and (IsRaceClassValid(i,CharacterCreate.selectedClass))) ) then
allow = true;
end
elseif ( PAID_SERVICE_TYPE == PAID_RACE_CHANGE ) then
local faction = GetFactionForRace(PaidChange_GetCurrentRaceIndex());
if ( (i == PaidChange_GetCurrentRaceIndex()) or ((GetFactionForRace(i) == faction) and (IsRaceClassValid(i,CharacterCreate.selectedClass))) ) then
allow = true
end
elseif ( PAID_SERVICE_TYPE == PAID_CHARACTER_CUSTOMIZATION ) then
if ( i == CharacterCreate.selectedRace ) then
allow = true
end
end
if (not allow) then
local button = _G["CharacterCreateRaceButton"..i];
button:Disable();
SetButtonDesaturated(button, true)
end
end
end
end