Advertisement
Guest User

Untitled

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