stoneharry

Untitled

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