Advertisement
Guest User

CharacterCreate.LUA

a guest
Jan 25th, 2015
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 58.35 KB | None | 0 0
  1. CHARACTER_FACING_INCREMENT = 2;
  2. MAX_RACES = 11;
  3. MAX_CLASSES_PER_RACE = 10;
  4. NUM_CHAR_CUSTOMIZATIONS = 5;
  5. MIN_CHAR_NAME_LENGTH = 2;
  6. CHARACTER_CREATE_ROTATION_START_X = nil;
  7. CHARACTER_CREATE_INITIAL_FACING = nil;
  8. NUM_PREVIEW_FRAMES = 14;
  9. TUSKARR_RACE_ID = 600;
  10. local featureIndex = 1
  11. local FeatureType = 1
  12.  
  13. CHAR_CREATE_MORE_INFO = "More Info";
  14. CUSTOMIZE = "Next";
  15. NEXT = "Next";
  16. FINISH = "Finish";
  17.  
  18. PAID_CHARACTER_CUSTOMIZATION = 1;
  19. PAID_RACE_CHANGE = 2;
  20. PAID_FACTION_CHANGE = 3;
  21. PAID_SERVICE_CHARACTER_ID = nil;
  22. PAID_SERVICE_TYPE = nil;
  23.  
  24. PREVIEW_FRAME_HEIGHT = 130;
  25. PREVIEW_FRAME_X_OFFSET = 19;
  26. PREVIEW_FRAME_Y_OFFSET = -7;
  27.  
  28. FACTION_BACKDROP_COLOR_TABLE = {
  29.         ["Alliance"] = {0.5, 0.5, 0.5, 0.09, 0.09, 0.19, 0, 0, 0.2, 0.29, 0.33, 0.91},
  30.         ["Horde"] = {0.5, 0.2, 0.2, 0.19, 0.05, 0.05, 0.2, 0, 0, 0.90, 0.05, 0.07},
  31.         ["Player"] = {0.2, 0.5, 0.2, 0.05, 0.2, 0.05, 0.05, 0.2, 0.05, 1, 1, 1},
  32. };
  33. FRAMES_TO_BACKDROP_COLOR = {
  34.         "CharacterCreateCharacterRace",
  35.         "CharacterCreateCharacterClass",
  36. --      "CharacterCreateCharacterFaction",
  37.         "CharacterCreateNameEdit",
  38. };
  39. RACE_ICON_TCOORDS = {
  40.         ["HUMAN_MALE"]          = {0, 0.125, 0, 0.25},
  41.         ["DWARF_MALE"]          = {0.125, 0.25, 0, 0.25},
  42.         ["GNOME_MALE"]          = {0.25, 0.375, 0, 0.25},
  43.         ["NIGHTELF_MALE"]       = {0.375, 0.5, 0, 0.25},
  44.        
  45.         ["TAUREN_MALE"]         = {0, 0.125, 0.25, 0.5},
  46.         ["SCOURGE_MALE"]        = {0.125, 0.25, 0.25, 0.5},
  47.         ["TROLL_MALE"]          = {0.25, 0.375, 0.25, 0.5},
  48.         ["ORC_MALE"]            = {0.375, 0.5, 0.25, 0.5},
  49.  
  50.         ["HUMAN_FEMALE"]        = {0, 0.125, 0.5, 0.75},  
  51.         ["DWARF_FEMALE"]        = {0.125, 0.25, 0.5, 0.75},
  52.         ["GNOME_FEMALE"]        = {0.25, 0.375, 0.5, 0.75},
  53.         ["NIGHTELF_FEMALE"]     = {0.375, 0.5, 0.5, 0.75},
  54.        
  55.         ["TAUREN_FEMALE"]       = {0, 0.125, 0.75, 1.0},  
  56.         ["SCOURGE_FEMALE"]      = {0.125, 0.25, 0.75, 1.0},
  57.         ["TROLL_FEMALE"]        = {0.25, 0.375, 0.75, 1.0},
  58.         ["ORC_FEMALE"]          = {0.375, 0.5, 0.75, 1.0},
  59.        
  60.         ["BLOODELF_MALE"]       = {0.5, 0.625, 0.25, 0.5},
  61.         ["BLOODELF_FEMALE"]     = {0.5, 0.625, 0.75, 1.0},
  62.  
  63.         ["DRAENEI_MALE"]        = {0.5, 0.625, 0, 0.25},
  64.         ["DRAENEI_FEMALE"]      = {0.5, 0.625, 0.5, 0.75},
  65.        
  66.         ["GOBLIN_MALE"]        = {0.5, 0.625, 0, 0.25},
  67.         ["GOBLIN_FEMALE"]      = {0.5, 0.625, 0.5, 0.75},
  68. };
  69. CLASS_ICON_TCOORDS = {
  70.         ["WARRIOR"]     = {0, 0.25, 0, 0.25},
  71.         ["MAGE"]        = {0.25, 0.49609375, 0, 0.25},
  72.         ["ROGUE"]       = {0.49609375, 0.7421875, 0, 0.25},
  73.         ["DRUID"]       = {0.7421875, 0.98828125, 0, 0.25},
  74.         ["HUNTER"]      = {0, 0.25, 0.25, 0.5},
  75.         ["SHAMAN"]      = {0.25, 0.49609375, 0.25, 0.5},
  76.         ["PRIEST"]      = {0.49609375, 0.7421875, 0.25, 0.5},
  77.         ["WARLOCK"]     = {0.7421875, 0.98828125, 0.25, 0.5},
  78.         ["PALADIN"]     = {0, 0.25, 0.5, 0.75},
  79.         ["DEATHKNIGHT"] = {0.49609375, 0.7421875, 0.5, 0.75},
  80. };
  81. MODEL_CAMERA_CONFIG = {
  82.         [2] = {
  83.                 ["Draenei"] = { tx = 0.191, ty = -0.015, tz = 2.302, cz = 2.160, distance = 1.116, light =  0.80 },
  84.                 ["NightElf"] = { tx = 0.095, ty = -0.008, tz = 2.240, cz = 2.045, distance = 0.830, light =  0.85 },
  85.                 ["Scourge"] = { tx = 0.094, ty = -0.172, tz = 1.675, cz = 1.478, distance = 0.691, light =  0.80 },
  86.                 ["Orc"] = { tx = 0.346, ty = -0.001, tz = 1.878, cz = 1.793, distance = 1.074, light =  0.80 },
  87.                 ["Gnome"] = { tx = 0.051, ty = 0.015, tz = 0.845, cz = 0.821, distance = 0.821, light =  0.85 },
  88.                 ["Dwarf"] = { tx = 0.037, ty = 0.009, tz = 1.298, cz = 1.265, distance = 0.839, light =  0.85 },
  89.                 ["Tauren"] = { tx = 0.516, ty = -0.003, tz = 1.654, cz = 1.647, distance = 1.266, light =  0.80 },
  90.                 ["Troll"] = { tx = 0.402, ty = 0.016, tz = 2.076, cz = 1.980, distance = 0.943, light =  0.75 },
  91.                 ["BloodElf"] = { tx = 0.009, ty = -0.120, tz = 1.914, cz = 1.712, distance = 0.727, light =  0.80 },
  92.                 ["Goblin"] = { tx = 0.009, ty = -0.120, tz = 1.914, cz = 1.712, distance = 0.727, light =  0.80 },
  93.                 ["Human"] = { tx = 0.055, ty = 0.006, tz = 1.863, cz = 1.749, distance = 0.714, light =  0.75 },
  94.         },
  95.         [3] = {
  96.                 ["Draenei"] = { tx = 0.155, ty = 0.009, tz = 2.177, cz = 1.971, distance = 0.734, light =  0.75 },
  97.                 ["NightElf"] = { tx = 0.071, ty = 0.034, tz = 2.068, cz = 2.055, distance = 0.682, light =  0.85 },
  98.                 ["Scourge"] = { tx = 0.198, ty = 0.001, tz = 1.669, cz = 1.509, distance = 0.563, light =  0.75 },
  99.                 ["Orc"] = { tx = -0.069, ty = -0.007, tz = 1.863, cz = 1.718, distance = 0.585, light =  0.75 },
  100.                 ["Gnome"] = { tx = 0.031, ty = 0.009, tz = 0.787, cz = 0.693, distance = 0.726, light =  0.85 },
  101.                 ["Dwarf"] = { tx = -0.060, ty = -0.010, tz = 1.326, cz = 1.343, distance = 0.720, light =  0.80 },
  102.                 ["Tauren"] = { tx = 0.337, ty = -0.008, tz = 1.918, cz = 1.855, distance = 0.891, light =  0.75 },
  103.                 ["Troll"] = { tx = 0.031, ty = -0.082, tz = 2.226, cz = 2.248, distance = 0.674, light =  0.75 },
  104.                 ["BloodElf"] = { tx = -0.072, ty = 0.009, tz = 1.789, cz = 1.792, distance = 0.717, light =  0.80 },
  105.                 ["Goblin"] = { tx = 0.009, ty = -0.120, tz = 1.914, cz = 1.712, distance = 0.727, light =  0.80 },
  106.                 ["Human"] = { tx = -0.044, ty = -0.015, tz = 1.755, cz = 1.689, distance = 0.612, light =  0.75 },
  107.         }
  108. };
  109.  
  110. BANNER_DEFAULT_TEXTURE_COORDS = {0.109375, 0.890625, 0.201171875, 0.80078125};
  111. BANNER_DEFAULT_SIZE = {200, 308};
  112.  
  113. CHAR_CUSTOMIZE_HAIR_COLOR = 4;
  114.  
  115. function CharacterCreate_OnLoad(self)
  116.         self:RegisterEvent("RANDOM_CHARACTER_NAME_RESULT");
  117.         self:RegisterEvent("GLUE_UPDATE_EXPANSION_LEVEL");
  118.        
  119.         self:SetSequence(0);
  120.         self:SetCamera(0);
  121.  
  122.         CharacterCreate.numRaces = 0;
  123.         CharacterCreate.selectedRace = 0;
  124.         CharacterCreate.numClasses = 0;
  125.         CharacterCreate.selectedClass = 0;
  126.         CharacterCreate.selectedGender = 0;
  127.  
  128.         SetCharCustomizeFrame("CharacterCreate");
  129.  
  130.         for i=1, NUM_CHAR_CUSTOMIZATIONS, 1 do
  131.                 _G["CharCreateCustomizationButton"..i].text:SetText(_G["CHAR_CUSTOMIZATION"..i.."_DESC"]);
  132.         end
  133.  
  134.         -- Color edit box backdrop
  135.         local backdropColor = FACTION_BACKDROP_COLOR_TABLE["Alliance"];
  136.         CharacterCreateNameEdit:SetBackdropBorderColor(backdropColor[1], backdropColor[2], backdropColor[3]);
  137.         CharacterCreateNameEdit:SetBackdropColor(backdropColor[4], backdropColor[5], backdropColor[6]);
  138.  
  139.         CharacterCreateFrame.state = "CLASSRACE";
  140.        
  141.         CharCreatePreviewFrame.previews = { };
  142. end
  143.  
  144. function CharCustomizeButtonClick(id)
  145.         CycleCharCustomization(id, 1);
  146.         --[[FeatureType = id
  147.         for i=1,5 do
  148.                 _G["CharCreateCustomizationButton"..i]:SetChecked(0);
  149.         end
  150.         _G["CharCreateCustomizationButton"..id]:SetChecked(1);]]
  151.  
  152. end
  153.  
  154. function CharacterCreate_OnShow()
  155.         for i=1, MAX_CLASSES_PER_RACE, 1 do
  156.                 local button = _G["CharCreateClassButton"..i];
  157.                 button:Enable();
  158.                 SetButtonDesaturated(button, false)
  159.         end
  160.         for i=1, MAX_RACES, 1 do
  161.                 local button = _G["CharCreateRaceButton"..i];
  162.                 button:Enable();
  163.                 SetButtonDesaturated(button, false)
  164.         end
  165.  
  166.         if ( PAID_SERVICE_TYPE ) then
  167.                 CustomizeExistingCharacter( PAID_SERVICE_CHARACTER_ID );
  168.                 CharacterCreateNameEdit:SetText( PaidChange_GetName() );
  169.         else
  170.                 --randomly selects a combination
  171.                 ResetCharCustomize();
  172.                 CharacterCreateNameEdit:SetText("");
  173.                 CharCreateRandomizeButton:Show();
  174.         end
  175.        
  176.         CharacterCreateEnumerateRaces(GetAvailableRaces());
  177.         SetCharacterRace(GetSelectedRace());
  178.        
  179.         CharacterCreateEnumerateClasses(GetAvailableClasses());
  180.         local_,_,index = GetSelectedClass();
  181.         SetCharacterClass(index);
  182.  
  183.         if ( GetSelectedRace() == TUSKARR_RACE_ID ) then
  184.                 SetCharacterGender(SEX_MALE);
  185.                 CharCreateMaleButton:SetChecked(1);
  186.                 CharCreateFemaleButton:SetChecked(0);
  187.         else
  188.                 SetCharacterGender(GetSelectedSex());
  189.         end
  190.        
  191.         -- Hair customization stuff
  192.         CharacterCreate_UpdateHairCustomization();
  193.  
  194.         SetCharacterCreateFacing(-15);
  195.        
  196.         -- setup customization
  197.         CharacterChangeFixup();
  198.  
  199.         --SetFaceCustomizeCamera(false);
  200. end
  201.  
  202. function CharacterCreate_OnHide()
  203.         PAID_SERVICE_CHARACTER_ID = nil;
  204.         PAID_SERVICE_TYPE = nil;
  205.         if ( CharacterCreateFrame.state == "CUSTOMIZATION" ) then
  206.                 CharacterCreate_Back();
  207.         end
  208.         -- character previews will need to be redone if coming back to character create. One reason is all the memory used for
  209.         -- tracking the frames (on the c side) will get released if the user returns to the login screen
  210.         CharCreatePreviewFrame.rebuildPreviews = true;
  211. end
  212.  
  213. function CharacterCreate_OnEvent(event, arg1, arg2, arg3)
  214.         if ( event == "RANDOM_CHARACTER_NAME_RESULT" ) then
  215.                 if ( arg1 == 0 ) then
  216.                         -- Failed.  Generate a random name locally.
  217.                         CharacterCreateNameEdit:SetText(GenerateRandomName());
  218.                 else
  219.                         -- Succeeded.  Use what the server sent.
  220.                         CharacterCreateNameEdit:SetText(arg2);
  221.                 end
  222.                 CharacterCreateRandomName:Enable();
  223.                 CharCreateOkayButton:Enable();
  224.                 PlaySound("gsCharacterCreationLook");
  225.         elseif ( event == "GLUE_UPDATE_EXPANSION_LEVEL" ) then
  226.                 -- Expansion level changed while online, so enable buttons as needed
  227.                 if ( CharacterCreateFrame:IsShown() ) then
  228.                         CharacterCreateEnumerateRaces(GetAvailableRaces());
  229.                         CharacterCreateEnumerateClasses(GetAvailableClasses());
  230.                 end
  231.         end
  232. end
  233.  
  234. function CharacterCreateFrame_OnMouseDown(button)
  235.         if ( button == "LeftButton" ) then
  236.                 CHARACTER_CREATE_ROTATION_START_X = GetCursorPosition();
  237.                 CHARACTER_CREATE_INITIAL_FACING = GetCharacterCreateFacing();
  238.         end
  239. end
  240.  
  241. function CharacterCreateFrame_OnMouseUp(button)
  242.         if ( button == "LeftButton" ) then
  243.                 CHARACTER_CREATE_ROTATION_START_X = nil
  244.         end
  245. end
  246.  
  247. function CharacterCreateFrame_OnUpdate(self, elapsed)
  248.         if ( CHARACTER_CREATE_ROTATION_START_X ) then
  249.                 local x = GetCursorPosition();
  250.                 local diff = (x - CHARACTER_CREATE_ROTATION_START_X) * CHARACTER_ROTATION_CONSTANT;
  251.                 CHARACTER_CREATE_ROTATION_START_X = GetCursorPosition();
  252.                 SetCharacterCreateFacing(GetCharacterCreateFacing() + diff);
  253.                 CharCreate_RotatePreviews();
  254.         end
  255.         CharacterCreateWhileMouseDown_Update(elapsed);
  256. end
  257.  
  258. function CharacterCreateEnumerateRaces(...)
  259.         CharacterCreate.numRaces = select("#", ...)/3;
  260.         if ( CharacterCreate.numRaces > MAX_RACES ) then
  261.                 message("Too many races!  Update MAX_RACES");
  262.                 return;
  263.         end
  264.         local coords;
  265.         local index = 1;
  266.         local button;
  267.         local gender;
  268.         local selectedSex = GetSelectedSex();
  269.         if ( selectedSex == SEX_MALE ) then
  270.                 gender = "MALE";
  271.         else
  272.                 gender = "FEMALE";
  273.         end
  274.         for i=1, select("#", ...), 3 do
  275.                 local name = select(i, ...);
  276.                 if ( index == TUSKARR_RACE_ID ) then
  277.                         coords = RACE_ICON_TCOORDS[strupper(select(i+1, ...).."_MALE")];
  278.                 else
  279.                         coords = RACE_ICON_TCOORDS[strupper(select(i+1, ...).."_"..gender)];
  280.                 end
  281.                 _G["CharCreateRaceButton"..index.."NormalTexture"]:SetTexCoord(coords[1], coords[2], coords[3], coords[4]);
  282.                 _G["CharCreateRaceButton"..index.."PushedTexture"]:SetTexCoord(coords[1], coords[2], coords[3], coords[4]);
  283.                 button = _G["CharCreateRaceButton"..index];
  284.                 if ( not button  ) then
  285.                         return;
  286.                 end
  287.                 button.nameFrame.text:SetText(name);
  288.                 --button.nameFrame.text:SetText(tostring(index));
  289.                 if ( select(i+2, ...) == 1 and name ~= "Worgen"--[[ and (name ~= "Goblin"or gender == "MALE")]]) then
  290.                         button:Enable();
  291.                         SetButtonDesaturated(button);
  292.                         button.name = name;
  293.                         button.tooltip = name;
  294.                 else
  295.                         button:Disable();
  296.                         SetButtonDesaturated(button, 1);
  297.                         button.name = name;
  298.                         local disabledReason = _G[strupper(select(i+1, ...).."_".."DISABLED")];
  299.                         if ( disabledReason ) then
  300.                                 button.tooltip = name.."|n"..disabledReason;
  301.                         else
  302.                                 button.tooltip = nil;
  303.                         end
  304.                 end
  305.                 index = index + 1;
  306.         end
  307.         for i=CharacterCreate.numRaces + 1, MAX_RACES, 1 do
  308.                 _G["CharCreateRaceButton"..i]:Hide();
  309.         end
  310. end
  311.  
  312. function CharacterCreateEnumerateClasses(...)
  313.         CharacterCreate.numClasses = select("#", ...)/3;
  314.         if ( CharacterCreate.numClasses > MAX_CLASSES_PER_RACE ) then
  315.                 message("Too many classes!  Update MAX_CLASSES_PER_RACE");
  316.                 return;
  317.         end
  318.         local coords;
  319.         local index = 1;
  320.         local button;
  321.         for i=1, select("#", ...), 3 do
  322.                 coords = CLASS_ICON_TCOORDS[strupper(select(i+1, ...))];
  323.                 _G["CharCreateClassButton"..index.."NormalTexture"]:SetTexCoord(coords[1], coords[2], coords[3], coords[4]);
  324.                 _G["CharCreateClassButton"..index.."PushedTexture"]:SetTexCoord(coords[1], coords[2], coords[3], coords[4]);
  325.                 button = _G["CharCreateClassButton"..index];
  326.                 button:Show();
  327.                 button.nameFrame.text:SetText(select(i, ...));
  328.                 if ( select(i+2, ...) == 1 ) then
  329.                         if (IsRaceClassValid(CharacterCreate.selectedRace, index)) then
  330.                                 button:Enable();
  331.                                 SetButtonDesaturated(button);
  332.                                 button.tooltip = nil;
  333.                                 _G["CharCreateClassButton"..index.."DisableTexture"]:Hide();
  334.                         else
  335.                                 button:Disable();
  336.                                 SetButtonDesaturated(button, 1);
  337.                                 button.tooltip = CLASS_DISABLED;
  338.                                 _G["CharCreateClassButton"..index.."DisableTexture"]:Show();
  339.                         end
  340.                 else
  341.                         button:Disable();
  342.                         SetButtonDesaturated(button, 1);
  343.                         button.tooltip = _G[strupper(select(i+1, ...).."_".."DISABLED")];
  344.                         _G["CharCreateClassButton"..index.."DisableTexture"]:Show();
  345.                 end
  346.                 index = index + 1;
  347.         end
  348.         for i=CharacterCreate.numClasses + 1, MAX_CLASSES_PER_RACE, 1 do
  349.                 _G["CharCreateClassButton"..i]:Hide();
  350.         end
  351. end
  352.  
  353. function SetCharacterRace(id)
  354.  
  355.         CharacterCreate.selectedRace = id;
  356.         for i=1, CharacterCreate.numRaces, 1 do
  357.                 local button = _G["CharCreateRaceButton"..i];
  358.                 if ( i == id ) then
  359.                         button:SetChecked(1);
  360.                 else
  361.                         button:SetChecked(0);
  362.                 end
  363.         end
  364.  
  365.         local name, faction = GetFactionForRace(CharacterCreate.selectedRace);
  366.  
  367.         -- during a paid service we have to set alliance/horde for neutral races
  368.         -- hard-coded for Pandaren because of alliance/horde pseudo buttons
  369.         local canProceed = true;
  370.         if ( id == TUSKARR_RACE_ID and PAID_SERVICE_TYPE ) then
  371.                 --[[
  372.                 --local currentFaction = PaidChange_GetCurrentFaction();
  373.                 if ( PaidChange_GetCurrentRaceIndex() == TUSKARR_RACE_ID and PAID_SERVICE_TYPE == PAID_FACTION_CHANGE ) then
  374.                         -- this is an original pandaren staying or becoming selected
  375.                         -- check the pseudo-buttons
  376.                         faction = PandarenFactionButtons_GetSelectedFaction();
  377.                         --if ( faction == currentFaction ) then
  378.                                 canProceed = false;
  379.                         --end
  380.                 else
  381.                         -- for faction change use the opposite faction of current character
  382.                         if ( PAID_SERVICE_TYPE == PAID_FACTION_CHANGE ) then
  383.                                 --if ( currentFaction == "Horde" ) then
  384.                                         faction = "Alliance";
  385.                                 --elseif ( currentFaction == "Alliance" ) then
  386.                                 --      faction = "Horde";
  387.                                 --end
  388.                         -- for race change and customization use the same faction as current character
  389.                         else
  390.                                 faction = "Alliance";
  391.                         end
  392.                 end
  393.                 ]]
  394.                 faction = "Alliance";
  395.         else
  396.                 PandarenFactionButtons_ClearSelection();
  397.         end
  398.         CharCreate_EnableNextButton(canProceed);
  399.  
  400.         -- Set background
  401.         local backgroundFilename = GetCreateBackgroundModel(faction);
  402.         if CharacterCreate.selectedClass == 11 then
  403.                 backgroundFilename = "DEMONHUNTER"
  404.         end
  405.         SetBackgroundModel(CharacterCreate, backgroundFilename);
  406.  
  407.         if faction == nil then
  408.                 faction = "Alliance";
  409.         end
  410.        
  411.         -- Set backdrop colors based on faction
  412.         local backdropColor = FACTION_BACKDROP_COLOR_TABLE[faction];
  413.         CharCreateRaceFrame.factionBg:SetGradient("VERTICAL", 0, 0, 0, backdropColor[7], backdropColor[8], backdropColor[9]);
  414.         CharCreateClassFrame.factionBg:SetGradient("VERTICAL", 0, 0, 0, backdropColor[7], backdropColor[8], backdropColor[9]);
  415.         CharCreateCustomizationFrame.factionBg:SetGradient("VERTICAL", 0, 0, 0, backdropColor[7], backdropColor[8], backdropColor[9]);
  416.         CharCreatePreviewFrame.factionBg:SetGradient("VERTICAL", 0, 0, 0, backdropColor[7], backdropColor[8], backdropColor[9]);
  417.         CharCreateCustomizationFrameBanner:SetVertexColor(backdropColor[10], backdropColor[11], backdropColor[12]);
  418.         CharacterCreateNameEdit:SetBackdropColor(backdropColor[4], backdropColor[5], backdropColor[6]);
  419.         CharCreateRaceInfoFrame.factionBg:SetGradient("VERTICAL", 0, 0, 0, backdropColor[7], backdropColor[8], backdropColor[9]);
  420.         CharCreateClassInfoFrame.factionBg:SetGradient("VERTICAL", 0, 0, 0, backdropColor[7], backdropColor[8], backdropColor[9]);
  421.        
  422.         -- race info
  423.         local frame = CharCreateRaceInfoFrame;
  424.         local race, fileString = GetNameForRace();
  425.         frame.title:SetText(race);
  426.         fileString = strupper(fileString);
  427.         local gender;
  428.         if ( GetSelectedSex() == SEX_MALE ) then
  429.                 gender = "MALE";
  430.         else
  431.                 gender = "FEMALE";
  432.         end
  433.         local raceText = _G["RACE_INFO_"..fileString];
  434.         local abilityIndex = 1;
  435.         local tempText = _G["ABILITY_INFO_"..fileString..abilityIndex];
  436.         abilityText = "";
  437.         while ( tempText ) do
  438.                 abilityText = abilityText..tempText.."\n\n";
  439.                 abilityIndex = abilityIndex + 1;
  440.                 tempText = _G["ABILITY_INFO_"..fileString..abilityIndex];
  441.         end
  442.         CharCreateRaceInfoFrameScrollFrameScrollBar:SetValue(0);
  443.         CharCreateRaceInfoFrame.scrollFrame.scrollChild.infoText:SetText(GetFlavorText("RACE_INFO_"..strupper(fileString), GetSelectedSex()).."|n|n");
  444.         if ( abilityText and abilityText ~= "" ) then
  445.                 CharCreateRaceInfoFrame.scrollFrame.scrollChild.bulletText:SetText(abilityText);
  446.         else
  447.                 CharCreateRaceInfoFrame.scrollFrame.scrollChild.bulletText:SetText("");
  448.         end    
  449.  
  450.         -- Altered form
  451.         --[[if (HasAlteredForm()) then
  452.                 SetPortraitTexture(CharacterCreateAlternateFormTopPortrait, 22, GetSelectedSex());
  453.                 SetPortraitTexture(CharacterCreateAlternateFormBottomPortrait, 23, GetSelectedSex());
  454.                 CharacterCreateAlternateFormTop:Show();
  455.                 CharacterCreateAlternateFormBottom:Show();
  456.                 if( IsViewingAlteredForm() ) then
  457.                         CharacterCreateAlternateFormTop:SetChecked(false);
  458.                         CharacterCreateAlternateFormBottom:SetChecked(true);
  459.                 else
  460.                         CharacterCreateAlternateFormTop:SetChecked(true);
  461.                         CharacterCreateAlternateFormBottom:SetChecked(false);
  462.                 end
  463.         else
  464.                 CharacterCreateAlternateFormTop:Hide();
  465.                 CharacterCreateAlternateFormBottom:Hide();
  466.         end]]
  467. end
  468.  
  469. function SetCharacterClass(id)
  470.         CharacterCreate.selectedClass = id;
  471.         for i=1, CharacterCreate.numClasses, 1 do
  472.                 local button = _G["CharCreateClassButton"..i];
  473.                 if ( i == id ) then
  474.                         button:SetChecked(1);
  475.                 else
  476.                         button:SetChecked(0);
  477.                         button.selection:Hide();
  478.                 end
  479.         end
  480.        
  481.         -- class info
  482.         local frame = CharCreateClassInfoFrame;
  483.         local className, classFileName, _, tank, healer, damage = GetSelectedClass();
  484.         local abilityIndex = 0;
  485.         if not (classFileName) then
  486.                 classFileName = "Goblin"
  487.         end
  488.         local tempText = _G["CLASS_INFO_"..classFileName..abilityIndex];
  489.         abilityText = "";
  490.         while ( tempText ) do
  491.                 abilityText = abilityText..tempText.."\n\n";
  492.                 abilityIndex = abilityIndex + 1;
  493.                 tempText = _G["CLASS_INFO_"..classFileName..abilityIndex];
  494.         end
  495.         CharCreateClassInfoFrame.title:SetText(className);
  496.         CharCreateClassInfoFrame.scrollFrame.scrollChild.bulletText:SetText(abilityText);
  497.         local textt = GetFlavorText("CLASS_"..strupper(classFileName), GetSelectedSex())
  498.         if not textt then
  499.                 textt = "Not implemented."
  500.         end
  501.         CharCreateClassInfoFrame.scrollFrame.scrollChild.infoText:SetText(textt.."|n|n");
  502.         CharCreateClassInfoFrameScrollFrameScrollBar:SetValue(0);
  503. end
  504.  
  505. function CharacterCreate_OnChar()
  506. end
  507.  
  508. function CharacterCreate_OnKeyDown(key)
  509.         if ( key == "ESCAPE" ) then
  510.                 CharacterCreate_Back();
  511.         elseif ( key == "ENTER" ) then
  512.                 CharacterCreate_Forward();
  513.         elseif ( key == "PRINTSCREEN" ) then
  514.                 Screenshot();
  515.         end
  516. end
  517.  
  518. function CharacterCreate_UpdateModel(self)
  519.         UpdateCustomizationScene();
  520.         self:AdvanceTime();
  521. end
  522.  
  523. function CharacterCreate_Finish()
  524.         PlaySound("gsCharacterCreationCreateChar");
  525.  
  526.         -- If something disabled this button, ignore this message.
  527.         -- This can happen if you press enter while it's disabled, for example.
  528.         if ( not CharCreateOkayButton:IsEnabled() ) then
  529.                 return;
  530.         end
  531.        
  532.         --[[if GetCVar("realmList") ~= GLOBAL_REALMLIST then
  533.                 message("You are not connecting to "..GLOBAL_REALMLIST.." thus new characters cannot be created. Close WoW and uninstall this custom patch to continue.")
  534.                 return;
  535.         end]]
  536.  
  537.         if ( PAID_SERVICE_TYPE ) then
  538.                 GlueDialog_Show("CONFIRM_PAID_SERVICE");
  539.         else
  540.                 -- if using templates, pandaren must pick a faction
  541.                 local _, faction = GetFactionForRace(CharacterCreate.selectedRace);
  542.                 --if ( IsUsingCharacterTemplate() and ( faction ~= "Alliance" and faction ~= "Horde" ) ) then
  543.                 --      CharacterTemplateConfirmDialog:Show();
  544.                 --else
  545.                         CreateCharacter(CharacterCreateNameEdit:GetText());
  546.                 --end
  547.         end
  548. end
  549.  
  550. function CharacterCreate_Back()
  551.         if ( CharacterCreateFrame.state == "CUSTOMIZATION" ) then
  552.                 PlaySound("gsCharacterCreationCancel");
  553.                 CharacterCreateFrame.state = "CLASSRACE"
  554.                 CharCreateClassFrame:Show();
  555.                 CharCreateRaceFrame:Show();
  556.                 CharCreateMoreInfoButton:Show();
  557.                 CharCreateCustomizationFrame:Hide();
  558.                 CharCreatePreviewFrame:Hide();
  559.                 CharCreateOkayButton:SetText(NEXT);
  560.                 CharacterCreateNameEdit:Hide();
  561.                 CharacterCreateRandomName:Hide();
  562.                
  563.                 CharCreateOkayButton:Enable()
  564.  
  565.                 --back to awesome gear
  566.                 --SetSelectedPreviewGearType(1);
  567.  
  568.                 -- back to normal camera
  569.                 --SetFaceCustomizeCamera(false);
  570.  
  571.                 return;
  572.         end
  573.  
  574.         PlaySound("gsCharacterCreationCancel");
  575.         CHARACTER_SELECT_BACK_FROM_CREATE = true;
  576.         SetGlueScreen("charselect");
  577. end
  578.  
  579. function CharacterCreate_UpdateFacialHairCustomization()
  580.         if ( GetFacialHairCustomization() == "NONE" ) then
  581.                 CharacterCustomizationButtonFrame5:Hide();
  582.                 CharCreateRandomizeButton:SetPoint("TOP", "CharacterCustomizationButtonFrame5", "BOTTOM", 0, -5);
  583.         else
  584.                 CharacterCustomizationButtonFrame5Text:SetText(_G["FACIAL_HAIR_"..GetFacialHairCustomization()]);              
  585.                 CharacterCustomizationButtonFrame5:Show();
  586.                 CharCreateRandomizeButton:SetPoint("TOP", "CharacterCustomizationButtonFrame5", "BOTTOM", 0, -5);
  587.         end
  588. end
  589.  
  590. function CharacterCreate_UpdateHairCustomization()
  591.         CharacterCustomizationButtonFrame3Text:SetText(_G["HAIR_"..GetHairCustomization().."_STYLE"]);
  592.         CharacterCustomizationButtonFrame4Text:SetText(_G["HAIR_"..GetHairCustomization().."_COLOR"]);
  593. end
  594.  
  595. function CharacterCreate_Forward()
  596.         if ( CharacterCreateFrame.state == "CLASSRACE" ) then
  597.                 CharacterCreateFrame.state = "CUSTOMIZATION"
  598.                 PlaySound("gsCharacterSelectionCreateNew");
  599.                 CharCreateClassFrame:Hide();
  600.                 CharCreateRaceFrame:Hide();
  601.                 CharCreateMoreInfoButton:Hide();
  602.                 CharCreateCustomizationFrame:Show();
  603.                 --CharCreatePreviewFrame:Show();
  604.                 CharacterTemplateConfirmDialog:Hide();
  605.  
  606.                 CharCreate_PrepPreviewModels();
  607.                 if ( CharacterCreateFrame.customizationType ) then
  608.                         CharCreate_ResetFeaturesDisplay();
  609.                 else
  610.                         CharCreateSelectCustomizationType(1);
  611.                 end
  612.  
  613.                 CharCreateOkayButton:SetText(FINISH);
  614.                 CharacterCreateNameEdit:Show();
  615.                 if ( ALLOW_RANDOM_NAME_BUTTON ) then
  616.                         CharacterCreateRandomName:Show();
  617.                 end
  618.  
  619.                 if (CharacterCreate.selectedClass == 6 or CharacterCreate.selectedRace == 12 or CharacterCreate.selectedRace == 6) then -- ENGINEER / Goblin / Tuskarr
  620.                         CharCreateOkayButton:Disable()
  621.                 else
  622.                         CharCreateOkayButton:Enable()
  623.                 end
  624.  
  625.                 --You just went to customization mode - show the boring start gear
  626.                 --SetSelectedPreviewGearType(0);
  627.  
  628.                 -- set cam
  629.                 --[[if (CharacterCreateFrame.customizationType and CharacterCreateFrame.customizationType > 1) then
  630.                         SetFaceCustomizeCamera(true);
  631.                 else
  632.                         SetFaceCustomizeCamera(false);
  633.                 end]]
  634.         else
  635.                 CharacterCreate_Finish();
  636.         end
  637. end
  638.  
  639. function CharCreateCustomizationFrame_OnShow ()
  640.         -- reset size/tex coord to default to facilitate switching between genders for Pandaren
  641.         CharCreateCustomizationFrameBanner:SetSize(BANNER_DEFAULT_SIZE[1], BANNER_DEFAULT_SIZE[2]);
  642.         CharCreateCustomizationFrameBanner:SetTexCoord(BANNER_DEFAULT_TEXTURE_COORDS[1], BANNER_DEFAULT_TEXTURE_COORDS[2], BANNER_DEFAULT_TEXTURE_COORDS[3], BANNER_DEFAULT_TEXTURE_COORDS[4]);
  643.  
  644.         -- check each button and hide it if there are no values select
  645.         local resize = 0;
  646.         local lastGood = 0;
  647.         local isSkinVariantHair = false --GetSkinVariationIsHairColor(CharacterCreate.selectedRace);
  648.         local isDefaultSet = 0;
  649.         local checkedButton = 1;
  650.  
  651.         -- check if this was set, if not, default to 1
  652.         if ( CharacterCreateFrame.customizationType == 0 or CharacterCreateFrame.customizationType == nil ) then
  653.                 CharacterCreateFrame.customizationType = 1;
  654.         end
  655.         for i=1, NUM_CHAR_CUSTOMIZATIONS, 1 do
  656.                 if ( ( --[[GetNumFeatureVariationsForType(i)]]5 <= 1 ) or ( isSkinVariantHair and i == CHAR_CUSTOMIZE_HAIR_COLOR ) ) then
  657.                         resize = resize + 1;
  658.                         _G["CharCreateCustomizationButton"..i]:Hide();
  659.                 else
  660.                         _G["CharCreateCustomizationButton"..i]:Show();
  661.                         --_G["CharCreateCustomizationButton"..i]:SetChecked(0); -- we will handle default selection
  662.                         -- this must be done since a selected button can 'disappear' when swapping genders
  663.                         if ( isDefaultSet == 0 and CharacterCreateFrame.customizationType == i) then
  664.                                 isDefaultSet = 1;
  665.                                 checkedButton = i;
  666.                         end
  667.                         -- set your anchor to be the last good, this currently means button 1 HAS to be shown
  668.                         if (i > 1) then  
  669.                                 _G["CharCreateCustomizationButton"..i]:SetPoint( "TOP",_G["CharCreateCustomizationButton"..lastGood]:GetName() , "BOTTOM");
  670.                         end
  671.                         lastGood = i;
  672.                 end
  673.         end
  674.  
  675.         if (isDefaultSet == 0) then
  676.                 CharacterCreateFrame.customizationType = lastGood;
  677.                 checkedButton = lastGood;
  678.         end
  679.         --_G["CharCreateCustomizationButton"..checkedButton]:SetChecked(1);
  680.  
  681.         if (resize > 0) then
  682.         -- we need to resize and remap the banner texture
  683.                 local buttonx, buttony = CharCreateCustomizationButton1:GetSize()
  684.                 local screenamount = resize*buttony;
  685.                 print(screenamount);
  686.                 local frameX, frameY = CharCreateCustomizationFrameBanner:GetSize();
  687.                 local pctShrink = .2*resize;
  688.                 local uvXDefaultSize = BANNER_DEFAULT_TEXTURE_COORDS[2] - BANNER_DEFAULT_TEXTURE_COORDS[1];
  689.                 local uvYDefaultSize = BANNER_DEFAULT_TEXTURE_COORDS[4] - BANNER_DEFAULT_TEXTURE_COORDS[3];
  690.                 local newYUV = pctShrink*uvYDefaultSize + BANNER_DEFAULT_TEXTURE_COORDS[3];
  691.                 -- end coord stay the same
  692.                 CharCreateCustomizationFrameBanner:SetTexCoord(BANNER_DEFAULT_TEXTURE_COORDS[1], BANNER_DEFAULT_TEXTURE_COORDS[2], newYUV, BANNER_DEFAULT_TEXTURE_COORDS[4]);
  693.                 print(pctShrink);
  694.                 CharCreateCustomizationFrameBanner:SetSize(frameX, frameY - screenamount);
  695.                 print(CharCreateCustomizationFrameBanner:GetTexCoord());
  696.         end
  697.        
  698.         CharCreateRandomizeButton:SetPoint("TOP", _G["CharCreateCustomizationButton"..lastGood]:GetName(), "BOTTOM", 0, 0);
  699. end
  700.  
  701. function CharacterClass_OnClick(self, id)
  702.         if( self:IsEnabled() ) then
  703.                 PlaySound("gsCharacterCreationClass");
  704.                 local _,_,currClass = GetSelectedClass();
  705.                 if ( currClass ~= id ) then
  706.                         SetSelectedClass(id);
  707.                         SetCharacterClass(id);
  708.                         SetCharacterRace(GetSelectedRace());
  709.                         CharacterChangeFixup();
  710.                 else
  711.                         self:SetChecked(1);
  712.                 end
  713.         else
  714.                 self:SetChecked(0);
  715.         end
  716. end
  717.  
  718. function CharacterRace_OnClick(self, id, forceSelect)
  719.         if( self:IsEnabled() ) then
  720.                 PlaySound("gsCharacterCreationClass");
  721.                 if ( GetSelectedRace() ~= id or forceSelect ) then
  722.                         SetSelectedRace(id);
  723.                         SetCharacterRace(id);
  724.                         if ( id == TUSKARR_RACE_ID ) then
  725.                                 SetCharacterGender(SEX_MALE);
  726.                         else
  727.                                 SetCharacterGender(GetSelectedSex());
  728.                         end
  729.                         SetCharacterCreateFacing(-15);
  730.                         CharacterCreateEnumerateClasses(GetAvailableClasses());
  731.                         local _,_,classIndex = GetSelectedClass();
  732.                         if ( PAID_SERVICE_TYPE ) then
  733.                                 classIndex = PaidChange_GetCurrentClassIndex();
  734.                                 SetSelectedClass(classIndex);   -- selecting a race would have changed class to default
  735.                         end
  736.                         if (id == 12) then
  737.                                 SetCharacterClass(6)
  738.                         else
  739.                                 SetCharacterClass(classIndex);
  740.                         end
  741.                        
  742.                         -- Hair customization stuff
  743.                         CharacterCreate_UpdateHairCustomization();
  744.                                
  745.                         CharacterChangeFixup();
  746.                 else
  747.                         self:SetChecked(1);
  748.                 end
  749.         else
  750.                 self:SetChecked(0);
  751.         end
  752. end
  753.  
  754. function SetCharacterGender(sex)
  755.         local gender;
  756.        
  757.         if ( sex == SEX_MALE or GetSelectedRace() == TUSKARR_RACE_ID ) then
  758.                 CharCreateMaleButton:SetChecked(1);
  759.                 CharCreateFemaleButton:SetChecked(0);
  760.                 sex = SEX_MALE
  761.         else
  762.                 CharCreateMaleButton:SetChecked(0);
  763.                 CharCreateFemaleButton:SetChecked(1);
  764.         end
  765.         SetSelectedSex(sex);
  766.  
  767.         -- Update race images to reflect gender
  768.         CharacterCreateEnumerateRaces(GetAvailableRaces());
  769.         CharacterCreateEnumerateClasses(GetAvailableClasses());
  770.         SetCharacterRace(GetSelectedRace());
  771.        
  772.         local _,_,classIndex = GetSelectedClass();
  773.         if ( PAID_SERVICE_TYPE ) then
  774.                 classIndex = PaidChange_GetCurrentClassIndex();
  775.                 PandarenFactionButtons_SetTextures();
  776.         end
  777.         SetCharacterClass(classIndex);
  778.  
  779.         CharacterCreate_UpdateHairCustomization();
  780.         CharacterChangeFixup();
  781.  
  782.         -- Update preview models if on customization step
  783.         if ( CharCreatePreviewFrame:IsShown() ) then
  784.                 CharCreateCustomizationFrame_OnShow(); -- buttons may need to reset for dirty Pandarens
  785.                 CharCreate_PrepPreviewModels();
  786.                 CharCreate_ResetFeaturesDisplay();
  787.         end
  788. end
  789.  
  790. function CharacterCustomization_Left(id)
  791.         PlaySound("gsCharacterCreationLook");
  792.         CycleCharCustomization(id, -1);
  793. end
  794.  
  795. function CharacterCustomization_Right(id)
  796.         PlaySound("gsCharacterCreationLook");
  797.         CycleCharCustomization(id, 1);
  798. end
  799.  
  800. function CharacterCreate_GenerateRandomName(button)
  801.         button:Disable();
  802.         CharacterCreateNameEdit:SetText("...");
  803.         RequestRandomName();
  804. end
  805.  
  806. function CharacterCreate_Randomize()
  807.         PlaySound("gsCharacterCreationLook");
  808.         RandomizeCharCustomization();
  809.         CharCreate_ResetFeaturesDisplay();
  810. end
  811.  
  812. function CharacterCreateRotateRight_OnUpdate(self)
  813.         if ( self:GetButtonState() == "PUSHED" ) then
  814.                 SetCharacterCreateFacing(GetCharacterCreateFacing() + CHARACTER_FACING_INCREMENT);
  815.                 CharCreate_RotatePreviews();
  816.         end
  817. end
  818.  
  819. function CharacterCreateRotateLeft_OnUpdate(self)
  820.         if ( self:GetButtonState() == "PUSHED" ) then
  821.                 SetCharacterCreateFacing(GetCharacterCreateFacing() - CHARACTER_FACING_INCREMENT);
  822.                 CharCreate_RotatePreviews();
  823.         end
  824. end
  825.  
  826. function CharacterCreate_UpdateHairCustomization()
  827.         CharCreateCustomizationButton3.text:SetText(_G["HAIR_"..GetHairCustomization().."_STYLE"]);
  828.         CharCreateCustomizationButton4.text:SetText(_G["HAIR_"..GetHairCustomization().."_COLOR"]);
  829.         CharCreateCustomizationButton5.text:SetText(_G["FACIAL_HAIR_"..GetFacialHairCustomization()]);
  830. end
  831.  
  832. function SetButtonDesaturated(button, desaturated)
  833.         if ( not button ) then
  834.                 return;
  835.         end
  836.         local icon = button:GetNormalTexture();
  837.         if ( not icon ) then
  838.                 return;
  839.         end
  840.        
  841.         icon:SetDesaturated(desaturated);
  842. end
  843.  
  844. function GetFlavorText(tagname, sex)
  845.         local primary, secondary;
  846.         if ( sex == SEX_MALE ) then
  847.                 primary = "";
  848.                 secondary = "_FEMALE";
  849.         else
  850.                 primary = "_FEMALE";
  851.                 secondary = "";
  852.         end
  853.         local text = _G[tagname..primary];
  854.         if ( (text == nil) or (text == "") ) then
  855.                 text = _G[tagname..secondary];
  856.         end
  857.         return text;
  858. end
  859.  
  860. function CharacterCreate_DeathKnightSwap(self)
  861.         local _, classFilename = GetSelectedClass();
  862.         if ( classFilename == "DEATHKNIGHT" ) then
  863.                 if (self.currentModel ~= "DEATHKNIGHT") then
  864.                         self.currentModel = "DEATHKNIGHT";
  865.                         self:SetNormalTexture("Interface\\Glues\\Common\\Glue-Panel-Button-Up-Blue");
  866.                         self:SetPushedTexture("Interface\\Glues\\Common\\Glue-Panel-Button-Down-Blue");
  867.                         self:SetHighlightTexture("Interface\\Glues\\Common\\Glue-Panel-Button-Highlight-Blue");
  868.                 end
  869.         else
  870.                 if (self.currentModel == "DEATHKNIGHT") then
  871.                         self.currentModel = nil;
  872.                         self:SetNormalTexture("Interface\\Glues\\Common\\Glue-Panel-Button-Up");
  873.                         self:SetPushedTexture("Interface\\Glues\\Common\\Glue-Panel-Button-Down");
  874.                         self:SetHighlightTexture("Interface\\Glues\\Common\\Glue-Panel-Button-Highlight");
  875.                 end
  876.         end
  877. end
  878.  
  879. function CharacterChangeFixup()
  880.         if ( PAID_SERVICE_TYPE ) then
  881.                 -- no class changing as a paid service
  882.                 CharCreateClassFrame:SetAlpha(0.5);
  883.                 for i=1, MAX_CLASSES_PER_RACE, 1 do
  884.                         if (CharacterCreate.selectedClass ~= i) then
  885.                                 local button = _G["CharCreateClassButton"..i];
  886.                                 button:Disable();
  887.                                 SetButtonDesaturated(button, true);
  888.                         end
  889.                 end
  890.  
  891.                 local numAllowedRaces = 0;
  892.                 for i=1, MAX_RACES, 1 do
  893.                         local allow = false;
  894.                         if ( PAID_SERVICE_TYPE == PAID_FACTION_CHANGE ) then
  895.                                 --[[local faction = PaidChange_GetCurrentFaction();
  896.                                 if ( (i == PaidChange_GetCurrentRaceIndex()) or ((GetFactionForRace(i) ~= faction) and (IsRaceClassValid(i,CharacterCreate.selectedClass))) ) then
  897.                                         allow = true;
  898.                                 end]]
  899.                                 if ( i == CharacterCreate.selectedRace ) then
  900.                                         allow = true
  901.                                 end
  902.                         elseif ( PAID_SERVICE_TYPE == PAID_RACE_CHANGE ) then
  903.                                 --[[local faction = PaidChange_GetCurrentFaction();
  904.                                 if ( (i == PaidChange_GetCurrentRaceIndex()) or ((GetFactionForRace(i) == faction or IsNeutralRace(i)) and (IsRaceClassValid(i,CharacterCreate.selectedClass))) ) then
  905.                                         allow = true
  906.                                 end]]
  907.                                 if ( i == CharacterCreate.selectedRace ) then
  908.                                         allow = true
  909.                                 end
  910.                         elseif ( PAID_SERVICE_TYPE == PAID_CHARACTER_CUSTOMIZATION ) then
  911.                                 if ( i == CharacterCreate.selectedRace ) then
  912.                                         allow = true
  913.                                 end
  914.                         end
  915.                         if (not allow) then
  916.                                 local button = _G["CharCreateRaceButton"..i];
  917.                                 button:Disable();
  918.                                 SetButtonDesaturated(button, true);
  919.                         else
  920.                                 numAllowedRaces = numAllowedRaces + 1;
  921.                         end
  922.                 end
  923.                 if ( numAllowedRaces > 1 ) then
  924.                         CharCreateRaceButtonsFrame:SetAlpha(1);
  925.                 else
  926.                         CharCreateRaceButtonsFrame:SetAlpha(0.5);
  927.                 end
  928.         else
  929.                 CharCreateRaceButtonsFrame:SetAlpha(1);
  930.                 CharCreateClassFrame:SetAlpha(1);
  931.         end
  932. end
  933.  
  934. function CharCreateSelectCustomizationType(newType)
  935.         -- deselect previous type selection
  936.         if ( CharacterCreateFrame.customizationType and CharacterCreateFrame.customizationType ~= newType ) then
  937.                 --_G["CharCreateCustomizationButton"..CharacterCreateFrame.customizationType]:SetChecked(0);
  938.         end
  939.         --_G["CharCreateCustomizationButton"..newType]:SetChecked(1);
  940.         CharacterCreateFrame.customizationType = newType;
  941.         CharCreate_ResetFeaturesDisplay();
  942.  
  943.         --[[if (newType > 1) then
  944.                 SetFaceCustomizeCamera(true);
  945.         else
  946.                 SetFaceCustomizeCamera(false);
  947.         end]]
  948. end
  949.  
  950. function CharCreate_ResetFeaturesDisplay()
  951.         --SetPreviewFramesFeature(CharacterCreateFrame.customizationType);
  952.         -- set the previews scrollframe container height
  953.         -- since the first and the last previews need to be in the center position when scrolled all the way
  954.         -- to the top or to the bottom, there will be gaps of height equal to 2 previews on each side
  955.         local numTotalButtons = 4--GetNumFeatureVariations() + 4;
  956.         CharCreatePreviewFrame.scrollFrame.container:SetHeight(numTotalButtons * PREVIEW_FRAME_HEIGHT - PREVIEW_FRAME_Y_OFFSET);      
  957.  
  958.         for _, previewFrame in pairs(CharCreatePreviewFrame.previews) do
  959.                 previewFrame.featureType = 0;
  960.         end
  961.  
  962.         CharCreate_DisplayPreviewModels();
  963. end
  964.  
  965. function CharCreate_PrepPreviewModels(reloadModels)
  966.         local displayFrame = CharCreatePreviewFrame;
  967.  
  968.         -- clear models if rebuildPreviews got flagged
  969.         local rebuildPreviews = displayFrame.rebuildPreviews;
  970.         displayFrame.rebuildPreviews = nil;
  971.  
  972.         -- need to reload models class was swapped to or from DK
  973.         local classSwap = false;
  974.         local _, class = GetSelectedClass();
  975.         if ( class == "DEATHKNIGHT" or displayFrame.lastClass == "DEATHKNIGHT" ) and ( class ~= displayFrame.lastClass ) then
  976.                 classSwap = true;
  977.         end
  978.  
  979.         -- always clear the featureType
  980.         for index, previewFrame in pairs(displayFrame.previews) do
  981.                 previewFrame.featureType = 0;
  982.                 -- force model reload if class changed
  983.                 if ( classSwap ) then
  984.                         previewFrame.race = nil;
  985.                         previewFrame.gender = nil;
  986.                 end
  987.                 if ( rebuildPreviews ) then
  988.                         --SetPreviewFrame(previewFrame.model:GetName(), index);
  989.                 end
  990.         end
  991. end
  992.  
  993. function CharCreate_DisplayPreviewModels(selectionIndex)
  994.         if ( not selectionIndex ) then
  995.                 selectionIndex = featureIndex--GetSelectedFeatureVariation();
  996.         end
  997.  
  998.         local displayFrame = CharCreatePreviewFrame;
  999.         local previews = displayFrame.previews;
  1000.         local numVariations = 8--GetNumFeatureVariations();
  1001.         local currentFeatureType = CharacterCreateFrame.customizationType;
  1002.  
  1003.         local race = GetSelectedRace();
  1004.         local gender = GetSelectedSex();
  1005.  
  1006.         -- get data for target/camera/light
  1007.         local _, raceFileName = GetNameForRace();
  1008.         --[[if ( IsViewingAlteredForm() ) then
  1009.                 raceFileName = raceFileName.."Alt";
  1010.         end]]
  1011.         local config = MODEL_CAMERA_CONFIG[gender][raceFileName];
  1012.  
  1013.         -- selection index is the center preview
  1014.         -- there are 2 previews above and 2 below, and will pad it out to 1 more on each side, for a total of 7 previews to set up
  1015.         for index = selectionIndex - 3, selectionIndex + 3 do
  1016.                 -- there is empty space both at the beginning and at end of the list, each gap the height of 2 previews
  1017.                 if ( index > 0 and index <= numVariations ) then
  1018.                         local previewFrame = previews[index];
  1019.                         -- create button if we don't have it yet
  1020.                         if ( not previewFrame ) then
  1021.                                 previewFrame = CreateFrame("BUTTON", "PreviewFrame"..index, displayFrame.scrollFrame.container, "CharCreatePreviewFrameTemplate");
  1022.                                 -- index + 1 because of 2 gaps at the top and -1 for the current preview
  1023.                                 previewFrame:SetPoint("TOPLEFT", PREVIEW_FRAME_X_OFFSET, (index + 1) * -PREVIEW_FRAME_HEIGHT + PREVIEW_FRAME_Y_OFFSET);
  1024.                                 previewFrame.button.index = index;
  1025.                                 previews[index] = previewFrame;
  1026.                                 --SetPreviewFrame(previewFrame.model:GetName(), index);
  1027.                                 -- no texture as of yet
  1028.                                 --previewFrame:SetNormalTexture("Interface\\Glues\\CharacterCreate\\UI-CharacterCreate-Classes")
  1029.                         end
  1030.                         -- load model if needed, may have been cleared by different race/gender selection
  1031.                         if ( previewFrame.race ~= race or previewFrame.gender ~= gender ) then
  1032.                                 --SetPreviewFrameModel(index);
  1033.                                 previewFrame.race = race;
  1034.                                 previewFrame.gender = gender;
  1035.                                 -- apply settings
  1036.                                 local model = previewFrame.model;
  1037.                                 --model:SetCustomCamera(cameraID);
  1038.                                 local scale = 1--model:GetWorldScale();
  1039.                                 --model:SetCameraTarget(config.tx * scale, config.ty * scale, config.tz * scale);
  1040.                                 --model:SetCameraDistance(config.distance * scale);
  1041.                                 local cx, cy, cz = model:GetPosition()
  1042.                                 --model:SetCameraPosition(cx, cy, config.cz * scale);
  1043.                                 model:SetLight(1, 0, 0, 0, 0, config.light, 1.0, 1.0, 1.0);
  1044.                         end
  1045.                         -- need to reset the model if it was last used to preview a different feature
  1046.                         if ( previewFrame.featureType ~= currentFeatureType ) then
  1047.                                 --ResetPreviewFrameModel(index);
  1048.                                 --ShowPreviewFrameVariation(index);
  1049.                                 previewFrame.featureType = currentFeatureType;
  1050.                         end
  1051.                         previewFrame:Show();
  1052.                 else
  1053.                         -- need to hide tail previews when going to features with fewer styles
  1054.                         if ( previews[index] ) then
  1055.                                 previews[index]:Hide();
  1056.                         end
  1057.                 end
  1058.         end
  1059.         displayFrame.border.number:SetText("Option "..selectionIndex.."                     ");
  1060.         displayFrame.selectionIndex = selectionIndex;
  1061.         CharCreate_RotatePreviews();
  1062.         CharCreatePreviewFrame_UpdateStyleButtons();
  1063.         -- scroll to center the selection
  1064.         if ( not displayFrame.animating ) then
  1065.                 displayFrame.scrollFrame:SetVerticalScroll((selectionIndex - 1) * PREVIEW_FRAME_HEIGHT);
  1066.         end
  1067. end
  1068.  
  1069.  
  1070. function CharCreate_RotatePreviews()
  1071.         if ( CharCreatePreviewFrame:IsShown() ) then
  1072.                 local facing = ((GetCharacterCreateFacing())/ -180) * math.pi;
  1073.                 local previews = CharCreatePreviewFrame.previews;
  1074.                 --CharCreatePreviewFrame.selectionIndex = 0;
  1075.                 for index = CharCreatePreviewFrame.selectionIndex - 3, CharCreatePreviewFrame.selectionIndex + 3 do
  1076.                         local previewFrame = previews[index];
  1077.                         if ( previewFrame ) then -- and previewFrame.model:HasCustomCamera()
  1078.                                 --previewFrame.model:SetCameraFacing(facing);
  1079.                         end
  1080.                 end
  1081.         end
  1082. end
  1083.  
  1084. function CharCreate_ChangeFeatureVariation(delta)
  1085.         local numVariations = 8--GetNumFeatureVariations();
  1086.         local startIndex = featureIndex--GetSelectedFeatureVariation();
  1087.         local endIndex = startIndex + delta;
  1088.         if ( endIndex < 1 or endIndex > numVariations ) then
  1089.                 return;
  1090.         end
  1091.         PlaySound("gsCharacterCreationClass");
  1092.         featureIndex = endIndex
  1093.         CharCreatePreviewFrame_SelectFeatureVariation(endIndex);
  1094. end
  1095.  
  1096. function CharCreatePreviewFrameButton_OnClick(self)
  1097.         PlaySound("gsCharacterCreationClass");
  1098.         CharCreatePreviewFrame_SelectFeatureVariation(self.index);
  1099. end
  1100.  
  1101. function CharCreatePreviewFrame_SelectFeatureVariation(endIndex)
  1102.         local self = CharCreatePreviewFrame;
  1103.         if ( self.animating ) then
  1104.                 if ( not self.queuedIndex ) then
  1105.                         self.queuedIndex = endIndex;
  1106.                 end
  1107.         else
  1108.                 local startIndex = featureIndex--GetSelectedFeatureVariation();
  1109.                 --SelectFeatureVariation(endIndex);
  1110.                 for i=1,endIndex do
  1111.                         CycleCharCustomization(FeatureType, 1);
  1112.                 end
  1113.                 CharCreatePreviewFrame_UpdateStyleButtons();
  1114.                 featureIndex = endIndex
  1115.                 CharCreatePreviewFrame_StartAnimating(startIndex, endIndex);
  1116.         end
  1117. end
  1118.  
  1119. function CharCreatePreviewFrame_StartAnimating(startIndex, endIndex)
  1120.         local self = CharCreatePreviewFrame;
  1121.         if ( self.animating ) then
  1122.                 return;
  1123.         else
  1124.                 self.startIndex = startIndex;
  1125.                 self.currentIndex = startIndex;
  1126.                 self.endIndex = endIndex;
  1127.                 self.queuedIndex = nil;
  1128.                 self.direction = 1;
  1129.                 if ( self.startIndex > self.endIndex ) then
  1130.                         self.direction = -1;
  1131.                 end
  1132.                 self.movedTotal = 0;
  1133.                 self.moveUntilUpdate = PREVIEW_FRAME_HEIGHT;
  1134.                 self.animating = true;
  1135.         end
  1136. end
  1137.  
  1138. function CharCreatePreviewFrame_StopAnimating()
  1139.         local self = CharCreatePreviewFrame;
  1140.         if ( self.animating ) then
  1141.                 self.animating = false;
  1142.         end
  1143. end
  1144.  
  1145. local ANIMATION_SPEED = 5;
  1146. function CharCreatePreviewFrame_OnUpdate(self, elapsed)
  1147.         if ( self.animating ) then
  1148.                 local moveIncrement = PREVIEW_FRAME_HEIGHT * elapsed * ANIMATION_SPEED;
  1149.                 self.movedTotal = self.movedTotal + moveIncrement;
  1150.                 self.scrollFrame:SetVerticalScroll((self.startIndex - 1) * PREVIEW_FRAME_HEIGHT + self.movedTotal * self.direction);          
  1151.                 self.moveUntilUpdate = self.moveUntilUpdate - moveIncrement;
  1152.                 if ( self.moveUntilUpdate <= 0 ) then
  1153.                         self.currentIndex = self.currentIndex + self.direction;
  1154.                         self.moveUntilUpdate = PREVIEW_FRAME_HEIGHT;
  1155.                         -- reset movedTotal to account for rounding errors
  1156.                         self.movedTotal = abs(self.startIndex - self.currentIndex) * PREVIEW_FRAME_HEIGHT;
  1157.                         CharCreate_DisplayPreviewModels(self.currentIndex);
  1158.                 end
  1159.                 if ( self.currentIndex == self.endIndex ) then
  1160.                         self.animating = false;
  1161.                         CharCreate_DisplayPreviewModels();
  1162.                         if ( self.queuedIndex ) then
  1163.                                 local newIndex = self.queuedIndex;
  1164.                                 self.queuedIndex = nil;
  1165.                                 --SelectFeatureVariation(newIndex);
  1166.                                 featureIndex = newIndex
  1167.                                 CycleCharCustomization(FeatureType, featureIndex);
  1168.                                 CharCreatePreviewFrame_UpdateStyleButtons();
  1169.                                 CharCreatePreviewFrame_StartAnimating(self.endIndex, newIndex);
  1170.                         end
  1171.                 end
  1172.         end
  1173. end
  1174.  
  1175. function CharCreatePreviewFrame_UpdateStyleButtons()
  1176.         local selectionIndex = math.random(1,5)--GetSelectedFeatureVariation();
  1177.         local numVariations = 8--GetNumFeatureVariations();
  1178.         if ( selectionIndex == 1 ) then
  1179.                 CharCreateStyleUpButton:Enable();
  1180.                 CharCreateStyleUpButton.arrow:SetDesaturated(true);
  1181.         else
  1182.                 CharCreateStyleUpButton:Enable();
  1183.                 CharCreateStyleUpButton.arrow:SetDesaturated(false);
  1184.         end
  1185.         if ( selectionIndex == numVariations ) then
  1186.                 CharCreateStyleDownButton:Disable();
  1187.                 CharCreateStyleDownButton.arrow:SetDesaturated(true);
  1188.         else
  1189.                 CharCreateStyleDownButton:Disable(true);
  1190.                 CharCreateStyleDownButton.arrow:SetDesaturated(false);
  1191.         end
  1192. end
  1193.  
  1194. local TotalTime = 0;
  1195. local KeepScrolling = nil;
  1196. local TIME_TO_SCROLL = 0.5;
  1197. function CharacterCreateWhileMouseDown_OnMouseDown(direction)
  1198.         TIME_TO_SCROLL = 0.5;
  1199.         TotalTime = 0;
  1200.         KeepScrolling = direction;
  1201. end
  1202. function CharacterCreateWhileMouseDown_OnMouseUp()
  1203.         KeepScrolling = nil;
  1204. end
  1205. function CharacterCreateWhileMouseDown_Update(elapsed)
  1206.         if ( KeepScrolling ) then
  1207.                 TotalTime = TotalTime + elapsed;
  1208.                 if ( TotalTime >= TIME_TO_SCROLL ) then
  1209.                         CharCreate_ChangeFeatureVariation(KeepScrolling);
  1210.                         TIME_TO_SCROLL = 0.25;
  1211.                         TotalTime = 0;
  1212.                 end
  1213.         end
  1214. end
  1215.  
  1216. -- pandaren stuff related to faction change
  1217. function CharCreate_EnableNextButton(enabled)
  1218.         local button = CharCreateOkayButton;
  1219.         if enabled then
  1220.                 button:Enable();
  1221.         else
  1222.                 button:Disable();
  1223.         end
  1224.         button.Arrow:SetDesaturated(not enabled);
  1225.         if enabled then
  1226.                 button.TopGlow:Hide();
  1227.                 button.BottomGlow:Hide();
  1228.         else
  1229.                 button.TopGlow:Show();
  1230.                 button.BottomGlow:Show();
  1231.         end
  1232. end
  1233.  
  1234. function PandarenFactionButtons_OnLoad(self)
  1235.         self.PandarenButton = CharCreateRaceButton6;
  1236. end
  1237.  
  1238. function PandarenFactionButtons_Show()
  1239.         local frame = CharCreatePandarenFactionFrame;
  1240.         -- set the name
  1241.         local raceName = GetNameForRace();
  1242.         frame.AllianceButton.nameFrame.text:SetText(raceName);
  1243.         frame.AllianceButton.tooltip = raceName;
  1244.         frame.HordeButton.nameFrame.text:SetText(raceName);
  1245.         frame.HordeButton.tooltip = raceName;
  1246.         -- set the texture
  1247.         PandarenFactionButtons_SetTextures();
  1248.         -- set selected button
  1249.         local faction = PaidChange_GetCurrentFaction();
  1250.         -- deselect first in case of multiple pandaren faction changes
  1251.         PandarenFactionButtons_ClearSelection();
  1252.         frame[faction.."Button"]:SetChecked(1);
  1253.         -- show the frame on top of the normal pandaren button
  1254.         frame:Show();
  1255.         frame:SetFrameLevel(frame.PandarenButton:GetFrameLevel() + 2);
  1256.         CharCreate_EnableNextButton(false);
  1257. end
  1258.  
  1259. function PandarenFactionButtons_Hide()
  1260.         CharCreatePandarenFactionFrame:Hide();
  1261.         CharCreate_EnableNextButton(true);
  1262. end
  1263.  
  1264. function PandarenFactionButtons_SetTextures()
  1265.         local gender = "MALE";
  1266.         local coords = RACE_ICON_TCOORDS["TUSKARR_"..gender];
  1267.         CharCreatePandarenFactionFrameAllianceButtonNormalTexture:SetTexCoord(coords[1], coords[2], coords[3], coords[4]);
  1268.         CharCreatePandarenFactionFrameAllianceButtonPushedTexture:SetTexCoord(coords[1], coords[2], coords[3], coords[4]);
  1269.         CharCreatePandarenFactionFrameHordeButtonNormalTexture:SetTexCoord(coords[1], coords[2], coords[3], coords[4]);
  1270.         CharCreatePandarenFactionFrameHordeButtonPushedTexture:SetTexCoord(coords[1], coords[2], coords[3], coords[4]);
  1271. end
  1272.  
  1273. function PandarenFactionButtons_ClearSelection()
  1274.         CharCreatePandarenFactionFrame.AllianceButton:SetChecked(0);
  1275.         CharCreatePandarenFactionFrame.HordeButton:SetChecked(0);
  1276. end
  1277.  
  1278. function PandarenFactionButtons_GetSelectedFaction()
  1279.         if ( CharCreatePandarenFactionFrame.AllianceButton:GetChecked() ) then
  1280.                 return "Alliance";
  1281.         elseif ( CharCreatePandarenFactionFrame.HordeButton:GetChecked() ) then
  1282.                 return "Horde";
  1283.         end
  1284. end
  1285.  
  1286. function PandarenFactionButton_OnClick(self)
  1287.         PandarenFactionButtons_ClearSelection();
  1288.         self:SetChecked(1);
  1289.         CharacterRace_OnClick(CharCreatePandarenFactionFrame.PandarenButton, CharCreatePandarenFactionFrame.PandarenButton:GetID(), true);
  1290. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement