Guest User

Untitled

a guest
Jun 4th, 2025
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 28.06 KB | None | 0 0
  1. class MissionEndRewardStep
  2. {
  3.     string m_name;
  4.  
  5.     int m_gold;
  6.     int m_wood;
  7.     int m_stone;
  8.     int m_iron;
  9.     int m_crystals;
  10.     int m_dust;
  11.     int m_fragments;
  12.  
  13.     array<ScriptSprite@>@ m_sprites;
  14.     int m_delayAfter;
  15.     int m_countTm;
  16.     int m_countC;
  17.  
  18.     MissionEndRewardStep() {}
  19.  
  20.     MissionEndRewardStep(string &in name, int displayTime, int delayAfter, int gold, int wood, int stone, int iron, int crystals, int dust, int fragments, PlayerRecord@ materialModder = null, array<ScriptSprite@>@ sprites = null)
  21.     {
  22.         m_name = name;
  23.         @m_sprites = sprites;
  24.         m_countTm = displayTime;
  25.         m_countC = 0;
  26.         m_delayAfter = delayAfter;
  27.  
  28.         m_gold = gold;
  29.         m_wood = wood;
  30.         m_stone = stone;
  31.         m_iron = iron;
  32.         m_crystals = crystals;
  33.         m_dust = dust;
  34.         m_fragments = fragments;
  35.  
  36.         if (materialModder !is null)
  37.         {
  38.             auto@ mods = materialModder.GetModifiers();
  39.             m_gold = roll_round(m_gold * (mods.MaterialGainMul(materialModder, MaterialType::Gold) + (g_ngp * Tweak::NGPMaterialGain)));
  40.             m_wood = roll_round(m_wood * (mods.MaterialGainMul(materialModder, MaterialType::Wood) + (g_ngp * Tweak::NGPMaterialGain)));
  41.             m_stone = roll_round(m_stone * (mods.MaterialGainMul(materialModder, MaterialType::Stone) + (g_ngp * Tweak::NGPMaterialGain)));
  42.             m_iron = roll_round(m_iron * (mods.MaterialGainMul(materialModder, MaterialType::Iron) + (g_ngp * Tweak::NGPMaterialGain)));
  43.             m_crystals = roll_round(m_crystals * (mods.MaterialGainMul(materialModder, MaterialType::Crystals) + (g_ngp * Tweak::NGPEnchantMaterialGain)));
  44.             m_dust = roll_round(m_dust * (mods.MaterialGainMul(materialModder, MaterialType::Dust) + (g_ngp * Tweak::NGPEnchantMaterialGain)));
  45.             m_fragments = roll_round(m_fragments * (mods.MaterialGainMul(materialModder, MaterialType::Fragments)));
  46.         }
  47.     }
  48. }
  49.  
  50. MissionEndRewardStep@ SumRewardSteps(array<MissionEndRewardStep@> rewardSteps)
  51. {
  52.     MissionEndRewardStep step;
  53.    
  54.     for (uint i = 0; i < rewardSteps.length(); i++)
  55.     {
  56.         step.m_gold += rewardSteps[i].m_gold;
  57.         step.m_wood += rewardSteps[i].m_wood;
  58.         step.m_stone += rewardSteps[i].m_stone;
  59.         step.m_iron += rewardSteps[i].m_iron;
  60.         step.m_crystals += rewardSteps[i].m_crystals;
  61.         step.m_dust += rewardSteps[i].m_dust;
  62.         step.m_fragments += rewardSteps[i].m_fragments;
  63.     }
  64.    
  65.     return step;
  66. }
  67.  
  68.  
  69.  
  70. class MissionEndMenu : AWindowObject
  71. {
  72.     int m_disabledCounter;
  73.  
  74.     Widget@ m_contentW;
  75.     Widget@ m_rewardContent;
  76.  
  77.     array<MissionEndRewardStep@> m_rewardSteps;
  78.  
  79.     int m_countGold;
  80.     int m_countWood;
  81.     int m_countStone;
  82.     int m_countIron;
  83.     int m_countCrystals;
  84.     int m_countDust;
  85.     int m_countFragments;
  86.  
  87.     bool m_showCongratulation;
  88.  
  89.     Widget@ m_addGroup;
  90.  
  91.     TextWidget@ m_currGold;
  92.     TextWidget@ m_currWood;
  93.     TextWidget@ m_currStone;
  94.     TextWidget@ m_currIron;
  95.     TextWidget@ m_currCrystals;
  96.     TextWidget@ m_currDust;
  97.     TextWidget@ m_currFragments;
  98.  
  99.     TextWidget@ m_addGold;
  100.     TextWidget@ m_addWood;
  101.     TextWidget@ m_addStone;
  102.     TextWidget@ m_addIron;
  103.     TextWidget@ m_addCrystals;
  104.     TextWidget@ m_addDust;
  105.     TextWidget@ m_addFragments;
  106.  
  107.     CheckBoxGroupWidget@ m_checkboxGroup;
  108.     CheckBoxWidget@ m_materialCheckbox;
  109.     CheckBoxWidget@ m_statCheckbox;
  110.  
  111.     ScrollbarWidget@ m_statGroup;
  112.     TextWidget@ m_statCategoryTemplate;
  113.     Widget@ m_statSeparatorTemplate;
  114.     Widget@ m_statValuePair;
  115.  
  116.     BindingDisplayWidget@ m_bindingSubTabP;
  117.     BindingDisplayWidget@ m_bindingSubTabN;
  118.  
  119.     int m_delayC;
  120.  
  121.     MissionEndMenu(GUIBuilder@ b, PlayerRecord@ plr, bool dontClearMission = false)
  122.     {
  123.         super(b, "gui/mission_end.gui");
  124.  
  125.         m_disabledCounter = 1500;
  126.  
  127.         @m_checkboxGroup = cast<CheckBoxGroupWidget>(m_widget.GetWidgetById("checkbox-group"));
  128.         @m_materialCheckbox = cast<CheckBoxWidget>(m_checkboxGroup.GetWidgetById("material"));
  129.         @m_statCheckbox = cast<CheckBoxWidget>(m_checkboxGroup.GetWidgetById("stats"));
  130.  
  131.         @m_addGroup = m_widget.GetWidgetById("add-group");
  132.  
  133.         @m_currGold = cast<TextWidget>(m_widget.GetWidgetById("curr-gold"));
  134.         @m_currWood = cast<TextWidget>(m_widget.GetWidgetById("curr-wood"));
  135.         @m_currStone = cast<TextWidget>(m_widget.GetWidgetById("curr-stone"));
  136.         @m_currIron = cast<TextWidget>(m_widget.GetWidgetById("curr-iron"));
  137.         @m_currCrystals = cast<TextWidget>(m_widget.GetWidgetById("curr-crystal"));
  138.         @m_currDust = cast<TextWidget>(m_widget.GetWidgetById("curr-dust"));
  139.         @m_currFragments = cast<TextWidget>(m_widget.GetWidgetById("curr-fragment"));
  140.  
  141.         @m_addGold = cast<TextWidget>(m_widget.GetWidgetById("add-gold"));
  142.         @m_addWood = cast<TextWidget>(m_widget.GetWidgetById("add-wood"));
  143.         @m_addStone = cast<TextWidget>(m_widget.GetWidgetById("add-stone"));
  144.         @m_addIron = cast<TextWidget>(m_widget.GetWidgetById("add-iron"));
  145.         @m_addCrystals = cast<TextWidget>(m_widget.GetWidgetById("add-crystal"));
  146.         @m_addDust = cast<TextWidget>(m_widget.GetWidgetById("add-dust"));
  147.         @m_addFragments = cast<TextWidget>(m_widget.GetWidgetById("add-fragment"));
  148.  
  149.         @m_bindingSubTabP = cast<BindingDisplayWidget>(m_widget.GetWidgetById("binding-subtab-p"));
  150.         @m_bindingSubTabN = cast<BindingDisplayWidget>(m_widget.GetWidgetById("binding-subtab-n"));
  151.  
  152.         m_currGold.SetText(Resources::GetString(".tab.overlay.player.gold", {{ "amount", 0 }}));
  153.         m_currWood.SetText(Resources::GetString(".tab.overlay.player.wood", {{ "amount", 0 }}));
  154.         m_currStone.SetText(Resources::GetString(".tab.overlay.player.stone", {{ "amount", 0 }}));
  155.         m_currIron.SetText(Resources::GetString(".tab.overlay.player.iron", {{ "amount", 0 }}));
  156.         m_currCrystals.SetText(Resources::GetString(".tab.overlay.player.crys", {{ "amount", 0 }}));
  157.         m_currDust.SetText(Resources::GetString(".tab.overlay.player.dust", {{ "amount", 0 }}));
  158.         m_currFragments.SetText(Resources::GetString(".tab.overlay.player.frag", {{ "amount", 0 }}));
  159.  
  160.         m_addGold.SetText("");
  161.         m_addWood.SetText("");
  162.         m_addStone.SetText("");
  163.         m_addIron.SetText("");
  164.         m_addCrystals.SetText("");
  165.         m_addDust.SetText("");
  166.         m_addFragments.SetText("");
  167.  
  168.         @m_statGroup = cast<ScrollbarWidget>(m_widget.GetWidgetById("stat-group"));
  169.         @m_statCategoryTemplate = cast<TextWidget>(m_widget.GetWidgetById("stat-category-template"));
  170.         @m_statSeparatorTemplate = m_widget.GetWidgetById("stat-separator");
  171.         @m_statValuePair = m_widget.GetWidgetById("stat-value-template");
  172.  
  173.         @m_contentW = m_widget.GetWidgetById("stat-content");
  174.         @m_rewardContent = m_widget.GetWidgetById("reward-content");
  175.  
  176.         m_contentW.m_visible = false;
  177.         m_rewardContent.m_visible = true;
  178.  
  179.         auto missionDef = MissionDef::Get(plr.currMission);
  180.         if (missionDef is null)
  181.         {
  182.             PrintError("Failed to find ended mission.");
  183.             return;
  184.         }
  185.  
  186.         auto sentBack = MissionEndRewardStep(Resources::GetString(".menu.mission_end.step.sent_back"), 1000, 750,
  187.             plr.statsRun.GetStatCurr(HashString("sent-back-gold")),
  188.             plr.statsRun.GetStatCurr(HashString("sent-back-wood")),
  189.             plr.statsRun.GetStatCurr(HashString("sent-back-stone")),
  190.             plr.statsRun.GetStatCurr(HashString("sent-back-iron")),
  191.             plr.statsRun.GetStatCurr(HashString("sent-back-crystals")),
  192.             plr.statsRun.GetStatCurr(HashString("sent-back-dust")),
  193.             plr.statsRun.GetStatCurr(HashString("sent-back-fragments"))
  194.         );
  195.  
  196.         m_rewardSteps.insertLast(MissionEndRewardStep(Resources::GetString(".menu.mission_end.step.picked_up"), 750, 750,
  197.             max(0, plr.materials[int(MaterialType::Gold)] - plr.valuableInventory.m_totValue), max(0, plr.materials[int(MaterialType::Wood)]), max(0, plr.materials[int(MaterialType::Stone)]), max(0, plr.materials[int(MaterialType::Iron)]), max(0, plr.materials[int(MaterialType::Crystals)]), max(0, plr.materials[int(MaterialType::Dust)]), max(0, plr.materials[int(MaterialType::Fragments)])));
  198.  
  199.         if (plr.valuableInventory.m_valuables.length() > 0)
  200.         {
  201.             array<ScriptSprite@> sprites;
  202.             for (uint i = 0; i < plr.valuableInventory.m_valuables.length(); i++)
  203.             {
  204.                 auto icon = plr.valuableInventory.m_valuables[i].GetIcon();
  205.                 if (icon !is null)
  206.                     sprites.insertLast(icon);
  207.             }
  208.  
  209.             m_rewardSteps.insertLast(MissionEndRewardStep(Resources::GetString(".menu.mission_end.step.valuables"), 500 + 100 * min(30, plr.valuableInventory.m_valuables.length()), 750, plr.valuableInventory.m_totValue, 0, 0, 0, 0, 0, 0, null, sprites));
  210.         }
  211.  
  212.  
  213.         if (g_currTownRecord.GetVariationOnBuilding(HashString("magic_shop")) >= 0)
  214.         {
  215.             array<ScriptSprite@> commonSprites;
  216.             array<ScriptSprite@> uncommonSprites;
  217.             array<ScriptSprite@> rareSprites;
  218.             array<ScriptSprite@> epicSprites;
  219.  
  220.             for (uint i = 0; i < plr.trinketInventory.m_items.length(); i++)
  221.             {
  222.                 auto trinket = plr.trinketInventory.m_items[i];
  223.                 if (trinket.m_quality == Item::Quality::Common)
  224.                     commonSprites.insertLast(trinket.GetIcon());
  225.                 else if (trinket.m_quality == Item::Quality::Uncommon)
  226.                     uncommonSprites.insertLast(trinket.GetIcon());
  227.                 else if (trinket.m_quality == Item::Quality::Rare)
  228.                     rareSprites.insertLast(trinket.GetIcon());
  229.                 else if (trinket.m_quality == Item::Quality::Epic)
  230.                     epicSprites.insertLast(trinket.GetIcon());
  231.             }
  232.  
  233.             const int trinketDelayTime = 350;
  234.  
  235.             if (commonSprites.length() > 0)
  236.             {
  237.                 int num = commonSprites.length();
  238.                 auto step = MissionEndRewardStep(Resources::GetString(".menu.mission_end.step.trinkets.common"), 500 + 100 * min(30, commonSprites.length()), trinketDelayTime, 0, 0, 0, 0, num, 0, 0, plr, commonSprites);
  239.                 m_rewardSteps.insertLast(step);
  240.                 %STAT Add collected-crystals step.m_crystals plr
  241.             }
  242.             if (uncommonSprites.length() > 0)
  243.             {
  244.                 int num = uncommonSprites.length() * 3;
  245.                 auto step = MissionEndRewardStep(Resources::GetString(".menu.mission_end.step.trinkets.uncommon"), 500 + 100 * min(30, uncommonSprites.length()), trinketDelayTime, 0, 0, 0, 0, num, 0, 0, plr, uncommonSprites);
  246.                 m_rewardSteps.insertLast(step);
  247.                 %STAT Add collected-crystals step.m_crystals plr
  248.             }
  249.             if (rareSprites.length() > 0)
  250.             {
  251.                 int num = rareSprites.length();
  252.                 auto step = MissionEndRewardStep(Resources::GetString(".menu.mission_end.step.trinkets.rare"), 500 + 100 * min(30, rareSprites.length()), trinketDelayTime, 0, 0, 0, 0, 0, num, 0, plr, rareSprites);
  253.                 m_rewardSteps.insertLast(step);
  254.                 %STAT Add collected-dust step.m_dust plr
  255.             }
  256.             if (epicSprites.length() > 0)
  257.             {
  258.                 int num = epicSprites.length() * 3;
  259.                 auto step = MissionEndRewardStep(Resources::GetString(".menu.mission_end.step.trinkets.epic"), 500 + 100 * min(30, epicSprites.length()), trinketDelayTime, 0, 0, 0, 0, 0, num, 0, plr, epicSprites);
  260.                 m_rewardSteps.insertLast(step);
  261.                 %STAT Add collected-dust step.m_dust plr
  262.             }
  263.         }
  264.  
  265.         if (plr.currMissionState != MissionManager::MissionState::Succeeded)
  266.         {
  267.             float costMul = -1.0f * (1.0f - ((1.0f - plr.GetModifiers().ReviveCostMul(plr)) + (1.0f - Tweak::BaseReviveCost)));
  268.             auto total = SumRewardSteps(m_rewardSteps);
  269.            
  270.             auto costStep = MissionEndRewardStep(Resources::GetString(".menu.mission_end.step.revive", {{ "rate", int(costMul * -100.0f + 0.5f) }}), 1000, 750,
  271.                 int(total.m_gold * costMul),
  272.                 int(total.m_wood * costMul),
  273.                 int(total.m_stone * costMul),
  274.                 int(total.m_iron * costMul),
  275.                 int(total.m_crystals * costMul),
  276.                 int(total.m_dust * costMul),
  277.                 int(total.m_fragments * costMul)
  278.             );
  279.            
  280.             %STAT Add chapel-revive-gold -costStep.m_gold plr
  281.             %STAT Add chapel-revive-wood -costStep.m_wood plr
  282.             %STAT Add chapel-revive-stone -costStep.m_stone plr
  283.             %STAT Add chapel-revive-iron -costStep.m_iron plr
  284.             %STAT Add chapel-revive-crystals -costStep.m_crystals plr
  285.             %STAT Add chapel-revive-dust -costStep.m_dust plr
  286.             %STAT Add chapel-revive-fragments -costStep.m_fragments plr
  287.            
  288.             m_rewardSteps.insertLast(costStep);
  289.         }
  290.  
  291.  
  292.  
  293.         // Bonus??
  294.  
  295.         if (plr.currMissionState == MissionManager::MissionState::Succeeded)
  296.         {
  297.             auto reward = missionDef.GetReward(MissionManager::g_module.m_missionRewardSeed);
  298.             bool givesReward = reward !is null && (reward.m_gold.x != 0 || reward.m_wood.x != 0 || reward.m_stone.x != 0 || reward.m_iron.x != 0 || reward.m_crystals.x != 0 || reward.m_dust.x != 0 || reward.m_fragments.x != 0);
  299.             if (givesReward)
  300.                 m_rewardSteps.insertLast(MissionEndRewardStep(Resources::GetString(".menu.mission_end.step.reward"), 2000, 500, reward.m_gold.x, reward.m_wood.x, reward.m_stone.x, reward.m_iron.x, reward.m_crystals.x, reward.m_dust.x, reward.m_fragments.x, plr));
  301.            
  302.             if (missionDef.m_id == "dark_citadel")
  303.             {
  304.                 auto ingp = int(g_ngp + 0.5f);
  305.                
  306.                 if (ingp >= 5)
  307.                     Platform::Service.UnlockAchievement("beat_dark_citadel_ngp5");
  308.                 if (ingp >= 4)
  309.                     Platform::Service.UnlockAchievement("beat_dark_citadel_ngp4");
  310.                 if (ingp >= 3)
  311.                     Platform::Service.UnlockAchievement("beat_dark_citadel_ngp3");
  312.                 if (ingp >= 2)
  313.                     Platform::Service.UnlockAchievement("beat_dark_citadel_ngp2");
  314.                 if (ingp >= 1)
  315.                     Platform::Service.UnlockAchievement("beat_dark_citadel_ngp1");
  316.                
  317.                 Platform::Service.UnlockAchievement("beat_dark_citadel");
  318.                
  319.                 if (!g_myTownRecord.HasTownFlag(HashString("beat_dark_citadel")))
  320.                     m_showCongratulation = true;
  321.                
  322.                 g_myTownRecord.SetTownFlag(HashString("beat_dark_citadel"), true, false);
  323.                 %STAT Max highest-ngp ingp+1 plr
  324.             }
  325.         }
  326.  
  327.         m_delayC = 1000;
  328.        
  329.         if (plr.currMissionState == MissionManager::MissionState::Succeeded)
  330.         {
  331.             cast<TextWidget>(m_widget.GetWidgetById("mission-state")).SetText(Resources::GetString(".menu.mission_end.completed"));
  332.             cast<TextWidget>(m_widget.GetWidgetById("mission-title")).SetText(missionDef.m_name);
  333.         }
  334.         else if (plr.currMissionState == MissionManager::MissionState::Failed)
  335.         {
  336.             cast<TextWidget>(m_widget.GetWidgetById("mission-state")).SetText(Resources::GetString(".menu.mission_end.failed"));
  337.             cast<TextWidget>(m_widget.GetWidgetById("mission-title")).SetText(missionDef.m_name);
  338.  
  339.         }
  340.         else if (plr.currMissionState == MissionManager::MissionState::Aborted)
  341.         {
  342.             cast<TextWidget>(m_widget.GetWidgetById("mission-state")).SetText(Resources::GetString(".menu.mission_end.aborted"));
  343.             cast<TextWidget>(m_widget.GetWidgetById("mission-title")).SetText(missionDef.m_name);
  344.         }
  345.  
  346.  
  347.         auto plrBase = cast<PlayerBase>(plr.actor);
  348.         if (plrBase !is null)
  349.         {
  350.             Widget@ categoryGroup;
  351.             for (uint i = 0; i < plrBase.m_skills.length(); i++)
  352.             {
  353.                 auto val = plr.statsRun.GetStatCurr(HashString("damage-dealt-" + plrBase.m_skills[i].m_skillId));
  354.                 if (val == 0)
  355.                     continue;
  356.                
  357.                 if (categoryGroup is null)
  358.                     @categoryGroup = AddStatGroup("skill_dmg");
  359.                
  360.                 AddStatValue(categoryGroup, plrBase.m_skills[i].m_name, formatThousands(val, true));
  361.             }
  362.         }
  363.  
  364.         for (uint i = 0; i < Stats::StatDef::Instances.length(); i++)
  365.         {
  366.             auto currStat = Stats::StatDef::Instances[i];
  367.             if (currStat.m_hidden)
  368.                 continue;
  369.            
  370.             if (currStat.m_category.isEmpty())
  371.                 continue;
  372.            
  373.             auto val = plr.statsRun.GetStatCurr(currStat.m_idHash);
  374.             if (val == 0)
  375.                 continue;
  376.            
  377.             auto categoryGroup = m_statGroup.GetWidgetByIdImpl(currStat.m_categoryHash);
  378.             if (categoryGroup is null)
  379.                 @categoryGroup = AddStatGroup(currStat.m_category);
  380.            
  381.             AddStatValue(categoryGroup, Resources::GetString(currStat.m_name), currStat.GetStatFormatted(val));
  382.         }
  383.  
  384.  
  385.  
  386.         if (!dontClearMission)
  387.         {
  388.             MissionManager::g_module.SetMission(0, 0);
  389.             plr.currMission = 0;
  390.             plr.currMissionState = MissionManager::MissionState::None;
  391.             plr.currMissionRewardSeed = 0;
  392.         }
  393.  
  394.         plr.ResetForNewMission();
  395.         g_flags.ClearFlags(FlagState::Run);
  396.  
  397.         for (uint i = 0; i < plr.materials.length(); i++)
  398.             plr.materials[i] = 0;
  399.  
  400.         {
  401.             auto total = SumRewardSteps(m_rewardSteps);
  402.             g_myTownRecord.GiveMaterial(MaterialType::Gold, max(0, total.m_gold));
  403.             g_myTownRecord.GiveMaterial(MaterialType::Wood, max(0, total.m_wood));
  404.             g_myTownRecord.GiveMaterial(MaterialType::Stone, max(0, total.m_stone));
  405.             g_myTownRecord.GiveMaterial(MaterialType::Iron, max(0, total.m_iron));
  406.             g_myTownRecord.GiveMaterial(MaterialType::Crystals, max(0, total.m_crystals));
  407.             g_myTownRecord.GiveMaterial(MaterialType::Dust, max(0, total.m_dust));
  408.             g_myTownRecord.GiveMaterial(MaterialType::Fragments, max(0, total.m_fragments));
  409.         }
  410.  
  411.         if (sentBack.m_gold > 0 || sentBack.m_wood > 0 || sentBack.m_stone > 0 || sentBack.m_iron > 0 || sentBack.m_crystals > 0 || sentBack.m_dust > 0 || sentBack.m_fragments > 0)
  412.             m_rewardSteps.insertAt(0, sentBack);
  413.  
  414.         TabIncome();
  415.  
  416.         g_myTownRecord.RefreshDonationTitles();
  417.         plr.RefreshModifiers();
  418.     }
  419.  
  420.     void RefreshKeybinds(ControlMap@ currMap) override
  421.     {
  422.         m_bindingSubTabP.SetBinding("MenuPreviousSubTab");
  423.         m_bindingSubTabN.SetBinding("MenuNextSubTab");
  424.  
  425.         AWindowObject::RefreshKeybinds(currMap);
  426.     }
  427.  
  428.     void OnInteractableIndexChanged() override
  429.     {
  430.         auto currInteractable = m_input.GetCurrentInteractable();
  431.         if (currInteractable is null)
  432.         {
  433.             m_navigationBar.BuildBar({}, this);
  434.             return;
  435.         }
  436.  
  437.         array<string>@ rawTexts = currInteractable.NavigationBarText();
  438.         array<KeyNavigationText@> navTexts;
  439.         for (uint i = 0; i < rawTexts.length(); i++)
  440.             navTexts.insertLast(KeyNavigationText(m_navigationBar.m_font.BuildText(rawTexts[i])));
  441.  
  442.         m_navigationBar.BuildBar(navTexts, this);
  443.     }
  444.  
  445.     void TabIncome()
  446.     {
  447.         if (m_statGroup.m_visible)
  448.         {
  449.             m_statGroup.m_visible = false;
  450.             m_contentW.m_visible = false;
  451.             m_rewardContent.m_visible = true;
  452.             RefreshInteractableWidgets(m_widget);
  453.             OnInteractableIndexChanged();
  454.  
  455.             m_materialCheckbox.SetChecked(true);
  456.             m_statCheckbox.SetChecked(false);
  457.         }
  458.     }
  459.     void TabStats()
  460.     {
  461.         if (!m_statGroup.m_visible)
  462.         {
  463.             m_statGroup.m_visible = true;
  464.             m_contentW.m_visible = true;
  465.             m_rewardContent.m_visible = false;
  466.             RefreshInteractableWidgets(m_widget);
  467.             OnInteractableIndexChanged();
  468.            
  469.             m_materialCheckbox.SetChecked(false);
  470.             m_statCheckbox.SetChecked(true);
  471.         }
  472.     }
  473.  
  474.     Widget@ AddStatGroup(const string &in group)
  475.     {
  476.         auto newCategory = cast<TextWidget>(m_statCategoryTemplate.Clone());
  477.         newCategory.m_id = group;
  478.         newCategory.m_idHash = HashString(group);
  479.         newCategory.m_visible = true;
  480.  
  481.         newCategory.SetText(Resources::GetString(".menu.stats.cat." + group));
  482.  
  483.         if (m_statGroup.m_children.length() > 0)
  484.             newCategory.m_offset.y += m_statValuePair.m_height;
  485.  
  486.         m_statGroup.AddChild(newCategory);
  487.         return newCategory;
  488.     }
  489.  
  490.     void AddStatValue(Widget@ group, const string &in title, const string &in text)
  491.     {
  492.         auto newStatPair = m_statValuePair.Clone();
  493.         newStatPair.SetID("");
  494.         newStatPair.m_visible = true;
  495.  
  496.         auto statTitle = cast<TextWidget>(newStatPair.GetWidgetById("stat-title"));
  497.         statTitle.SetText(title);
  498.  
  499.         auto statText = cast<TextWidget>(newStatPair.GetWidgetById("stat-text"));
  500.         statText.SetText(text);
  501.  
  502.         int i = 0;
  503.         int placeIndex = m_statGroup.m_children.findByRef(group) + 1;
  504.         for (; placeIndex < int(m_statGroup.m_children.length()); placeIndex++, i++)
  505.         {
  506.             if (!m_statGroup.m_children[placeIndex].m_id.isEmpty())
  507.                 break;
  508.         }
  509.  
  510.         if (i % 2 == 0)
  511.             newStatPair.GetWidgetById("stat-bg").m_visible = true;
  512.  
  513.         m_statGroup.AddChild(newStatPair, placeIndex);
  514.     }
  515.  
  516.  
  517.     void Draw(SpriteBatch& sb, int idt) override
  518.     {
  519.         AWindowObject::Draw(sb, idt);
  520.  
  521.         if (!m_statGroup.m_visible)
  522.         {
  523.             auto font = Resources::GetBitmapFont("gui/fonts/hw8.fnt");
  524.             vec2 offset = m_origin + vec2(5, 5);
  525.  
  526.             for (int r = 0; r <= m_rewardStepCurrId; r++)
  527.             {
  528.                 if (r >= int(m_rewardSteps.length()))
  529.                     break;
  530.                
  531.                 float step = clamp(m_rewardSteps[r].m_countC / float(m_rewardSteps[r].m_countTm), 0.0f, 1.0f);
  532.                 if (r < m_rewardStepCurrId)
  533.                     step = 1.0f;
  534.                
  535.                 StringBuilder cost;
  536.                 cost.Append(m_rewardSteps[r].m_name);
  537.                 cost.Append(": ");
  538.                
  539.                 if (m_rewardSteps[r].m_gold != 0)
  540.                     AddStepCountingText(cost, m_rewardSteps[r].m_gold, ".tab.overlay.player.gold", step);
  541.                 if (m_rewardSteps[r].m_wood != 0)
  542.                     AddStepCountingText(cost, m_rewardSteps[r].m_wood, ".tab.overlay.player.wood", step);
  543.                 if (m_rewardSteps[r].m_stone != 0)
  544.                     AddStepCountingText(cost, m_rewardSteps[r].m_stone, ".tab.overlay.player.stone", step);
  545.                 if (m_rewardSteps[r].m_iron != 0)
  546.                     AddStepCountingText(cost, m_rewardSteps[r].m_iron, ".tab.overlay.player.iron", step);
  547.                 if (m_rewardSteps[r].m_crystals != 0)
  548.                     AddStepCountingText(cost, m_rewardSteps[r].m_crystals, ".tab.overlay.player.crys", step);
  549.                 if (m_rewardSteps[r].m_dust != 0)
  550.                     AddStepCountingText(cost, m_rewardSteps[r].m_dust, ".tab.overlay.player.dust", step);
  551.                 if (m_rewardSteps[r].m_fragments != 0)
  552.                     AddStepCountingText(cost, m_rewardSteps[r].m_fragments, ".tab.overlay.player.frag", step);
  553.                
  554.                 sb.DrawString(m_rewardContent.m_origin + offset, font, cost.String(), vec4(1,1,1,1), TextAlignment::Left);
  555.                
  556.                 offset.y += font.GetLineHeight() + 1;
  557.                
  558.                
  559.                 auto@ sprites = m_rewardSteps[r].m_sprites;
  560.                 if (sprites !is null && sprites.length() > 0)
  561.                 {
  562.                     auto pos = m_rewardContent.m_origin + offset;
  563.                     float height = 0;
  564.                    
  565.                     auto drawSprites = Modifiers::lerp(vec2(0, sprites.length()), step);
  566.                     float xIncr = float(m_rewardContent.m_width - sprites[0].GetWidth() - offset.x * 2) / max(1.0f, float(sprites.length() - 1));
  567.                     xIncr = min(sprites[0].GetWidth() * 1.5f, xIncr);
  568.                    
  569.                     for (int i = 0; i < drawSprites; i++)
  570.                     {
  571.                         sprites[i].Draw(sb, pos + vec2(int(xIncr * i + 0.5f), 0), g_menuTime);
  572.                         height = max(height, sprites[i].GetHeight());
  573.                     }
  574.                    
  575.                     offset.y += height + 3;
  576.                 }
  577.             }
  578.         }
  579.     }
  580.  
  581.     void AddStepCountingText(StringBuilder@ sb, int value, const string &in str, float step)
  582.     {
  583.         if (value != 0)
  584.         {
  585.             sb.Append(Resources::GetString(str, {{ "amount", lerp(0, value, step) }}));
  586.             sb.Append("  ");
  587.         }
  588.         /*
  589.         if (value < 0)
  590.             widget.SetColor(vec4(1,0,0,1));
  591.         else
  592.             widget.SetColor(vec4(0,1,0,1));
  593.         */
  594.     }
  595.  
  596.     void SetRewardStepCountingText(TextWidget@ widget, int value, float step)
  597.     {
  598.         if (value != 0)
  599.             widget.SetText("+" + lerp(value, 0, step));
  600.        
  601.         if (value < 0)
  602.             widget.SetColor(vec4(1,0,0,1));
  603.         else
  604.             widget.SetColor(vec4(0,1,0,1));
  605.     }
  606.  
  607.     int m_rewardStepCurrId;
  608.     bool Update(int ms, GameInput& gameInput, MenuInput& menuInput) override
  609.     {
  610. %if GAME
  611.         if (menuInput.MenuPreviousSubTab.Pressed)
  612.             TabIncome();
  613.         if (menuInput.MenuNextSubTab.Pressed)
  614.             TabStats();
  615. %endif
  616.  
  617.         if (m_disabledCounter > 0)
  618.             m_disabledCounter -= ms;
  619.  
  620.         if (m_delayC > 0)
  621.             m_delayC -= ms;
  622.         else if (int(m_rewardSteps.length()) > m_rewardStepCurrId)
  623.         {
  624.             m_rewardSteps[m_rewardStepCurrId].m_countC += ms;
  625.  
  626.             float step = m_rewardSteps[m_rewardStepCurrId].m_countC / float(m_rewardSteps[m_rewardStepCurrId].m_countTm);
  627.             if (step >= 1.0f)
  628.             {
  629.                 m_countGold += m_rewardSteps[m_rewardStepCurrId].m_gold;
  630.                 m_countWood += m_rewardSteps[m_rewardStepCurrId].m_wood;
  631.                 m_countStone += m_rewardSteps[m_rewardStepCurrId].m_stone;
  632.                 m_countIron += m_rewardSteps[m_rewardStepCurrId].m_iron;
  633.                 m_countCrystals += m_rewardSteps[m_rewardStepCurrId].m_crystals;
  634.                 m_countDust += m_rewardSteps[m_rewardStepCurrId].m_dust;
  635.                 m_countFragments += m_rewardSteps[m_rewardStepCurrId].m_fragments;
  636.  
  637.                 if (m_countGold != 0)
  638.                     m_currGold.SetText(Resources::GetString(".tab.overlay.player.gold", {{ "amount", m_countGold }}));
  639.                 if (m_countWood != 0)
  640.                     m_currWood.SetText(Resources::GetString(".tab.overlay.player.wood", {{ "amount", m_countWood }}));
  641.                 if (m_countStone != 0)
  642.                     m_currStone.SetText(Resources::GetString(".tab.overlay.player.stone", {{ "amount", m_countStone }}));
  643.                 if (m_countIron != 0)
  644.                     m_currIron.SetText(Resources::GetString(".tab.overlay.player.iron", {{ "amount", m_countIron }}));
  645.                 if (m_countCrystals != 0)
  646.                     m_currCrystals.SetText(Resources::GetString(".tab.overlay.player.crys", {{ "amount", m_countCrystals }}));
  647.                 if (m_countDust != 0)
  648.                     m_currDust.SetText(Resources::GetString(".tab.overlay.player.dust", {{ "amount", m_countDust }}));
  649.                 if (m_countFragments != 0)
  650.                     m_currFragments.SetText(Resources::GetString(".tab.overlay.player.frag", {{ "amount", m_countFragments }}));
  651.  
  652.                 m_addGold.SetText("");
  653.                 m_addWood.SetText("");
  654.                 m_addStone.SetText("");
  655.                 m_addIron.SetText("");
  656.                 m_addCrystals.SetText("");
  657.                 m_addDust.SetText("");
  658.                 m_addFragments.SetText("");
  659.  
  660.                 m_delayC = m_rewardSteps[m_rewardStepCurrId].m_delayAfter;
  661.                 m_rewardStepCurrId++;
  662.             }
  663.             else
  664.             {
  665.                 {
  666.                     if (m_countGold != 0 || m_rewardSteps[m_rewardStepCurrId].m_gold != 0)
  667.                         m_currGold.SetText(Resources::GetString(".tab.overlay.player.gold", {{ "amount", m_countGold + lerp(0, m_rewardSteps[m_rewardStepCurrId].m_gold, step) }}));
  668.                     if (m_countWood != 0 || m_rewardSteps[m_rewardStepCurrId].m_wood != 0)
  669.                         m_currWood.SetText(Resources::GetString(".tab.overlay.player.wood", {{ "amount", m_countWood + lerp(0, m_rewardSteps[m_rewardStepCurrId].m_wood, step) }}));
  670.                     if (m_countStone != 0 || m_rewardSteps[m_rewardStepCurrId].m_stone != 0)
  671.                         m_currStone.SetText(Resources::GetString(".tab.overlay.player.stone", {{ "amount", m_countStone + lerp(0, m_rewardSteps[m_rewardStepCurrId].m_stone, step) }}));
  672.                     if (m_countIron != 0 || m_rewardSteps[m_rewardStepCurrId].m_iron != 0)
  673.                         m_currIron.SetText(Resources::GetString(".tab.overlay.player.iron", {{ "amount", m_countIron + lerp(0, m_rewardSteps[m_rewardStepCurrId].m_iron, step) }}));
  674.                     if (m_countCrystals != 0 || m_rewardSteps[m_rewardStepCurrId].m_crystals != 0)
  675.                         m_currCrystals.SetText(Resources::GetString(".tab.overlay.player.crys", {{ "amount", m_countCrystals + lerp(0, m_rewardSteps[m_rewardStepCurrId].m_crystals, step) }}));
  676.                     if (m_countDust != 0 || m_rewardSteps[m_rewardStepCurrId].m_dust != 0)
  677.                         m_currDust.SetText(Resources::GetString(".tab.overlay.player.dust", {{ "amount", m_countDust + lerp(0, m_rewardSteps[m_rewardStepCurrId].m_dust, step) }}));
  678.                     if (m_countFragments != 0 || m_rewardSteps[m_rewardStepCurrId].m_fragments != 0)
  679.                         m_currFragments.SetText(Resources::GetString(".tab.overlay.player.frag", {{ "amount", m_countFragments + lerp(0, m_rewardSteps[m_rewardStepCurrId].m_fragments, step) }}));
  680.                 }
  681.  
  682.                 {
  683.                     if (m_countGold != 0 || m_rewardSteps[m_rewardStepCurrId].m_gold != 0)
  684.                         SetRewardStepCountingText(m_addGold, m_rewardSteps[m_rewardStepCurrId].m_gold, step);
  685.  
  686.                     if (m_countWood != 0 || m_rewardSteps[m_rewardStepCurrId].m_wood != 0)
  687.                         SetRewardStepCountingText(m_addWood, m_rewardSteps[m_rewardStepCurrId].m_wood, step);
  688.  
  689.                     if (m_countStone != 0 || m_rewardSteps[m_rewardStepCurrId].m_stone != 0)
  690.                         SetRewardStepCountingText(m_addStone, m_rewardSteps[m_rewardStepCurrId].m_stone, step);
  691.  
  692.                     if (m_countIron != 0 || m_rewardSteps[m_rewardStepCurrId].m_iron != 0)
  693.                         SetRewardStepCountingText(m_addIron, m_rewardSteps[m_rewardStepCurrId].m_iron, step);
  694.  
  695.                     if (m_countCrystals != 0 || m_rewardSteps[m_rewardStepCurrId].m_crystals != 0)
  696.                         SetRewardStepCountingText(m_addCrystals, m_rewardSteps[m_rewardStepCurrId].m_crystals, step);
  697.  
  698.                     if (m_countDust != 0 || m_rewardSteps[m_rewardStepCurrId].m_dust != 0)
  699.                         SetRewardStepCountingText(m_addDust, m_rewardSteps[m_rewardStepCurrId].m_dust, step);
  700.  
  701.                     if (m_countFragments != 0 || m_rewardSteps[m_rewardStepCurrId].m_fragments != 0)
  702.                         SetRewardStepCountingText(m_addFragments, m_rewardSteps[m_rewardStepCurrId].m_fragments, step);
  703.                 }
  704.             }
  705.         }
  706.  
  707.         return AWindowObject::Update(ms, gameInput, menuInput);
  708.     }
  709.  
  710.     void OnFunc(Widget@ sender, const string &in name) override
  711.     {
  712.         auto parse = name.split(" ");
  713.         if (parse[0] == "close")
  714.         {
  715.             destroyPlayer();
  716.            
  717.             if (m_disabledCounter > 0)
  718.                 return;
  719.  
  720.             cast<AGameplayGameMode>(g_gameMode).SavePlayerAndTown();
  721.  
  722.             m_manager.CloseWindow(this);
  723.         }
  724.         else if (parse[0] == "set-tab")
  725.         {
  726.             if (parse[1] == "materials")
  727.                 TabIncome();
  728.             else if (parse[1] == "stats")
  729.                 TabStats();
  730.         }
  731.     }
  732.  
  733.     void OnClose() override
  734.     {
  735.         destroyPlayer();
  736.         if (m_showCongratulation)
  737.             g_gameMode.ShowDialog("a", Resources::GetString(".menu.mission_end.new_game_plus"), Resources::GetString(".menu.ok"), this);
  738.     }
  739.    
  740.     void destroyPlayer()
  741.     {
  742.         auto plr = GetLocalPlayerRecord();
  743.         uint m_deletingCharKey = plr.uniqueKey;
  744.         @plr = null;
  745.         auto gm = cast<BaseGameMode>(g_gameMode);
  746.         if (gm !is null)
  747.             gm.m_windowManager.AddWindowObject(PickCharacterWindow(gm.m_guiBuilder));
  748.         if (m_deletingCharKey != 0)
  749.         {
  750.             PersistentSaves::SetCharacter(m_deletingCharKey, null, "");
  751.         }
  752.     }
  753. }
Add Comment
Please, Sign In to add comment