Materials UI Fix + No Death Penalty

This commit is contained in:
mikx
2026-06-01 05:08:36 -04:00
parent db005c33bd
commit 1afa3266d5
2 changed files with 737 additions and 1 deletions

View File

@@ -83,7 +83,7 @@
</group>
<!-- MxHoH2 - Mission Materials Display -->
<rect offset="265 30" width="10" height="14">
<rect offset="-272 30" width="10" height="14">
<sprite src="icon-gold" offset="-10 0" anchor="0.5 0" />
<text id="mission-gold" font="gui/fonts/hw8.fnt" anchor="0 1" offset="3 -2" text="100/100" color="#DAA520" />

View File

@@ -0,0 +1,736 @@
class MissionEndRewardStep
{
string m_name;
int m_gold;
int m_wood;
int m_stone;
int m_iron;
int m_crystals;
int m_dust;
int m_ore;
array<ScriptSprite@>@ m_sprites;
int m_delayAfter;
int m_countTm;
int m_countC;
MissionEndRewardStep() {}
MissionEndRewardStep(string &in name, int displayTime, int delayAfter, int gold, int wood, int stone, int iron, int crystals, int dust, int ore, PlayerRecord@ materialModder = null, array<ScriptSprite@>@ sprites = null)
{
m_name = name;
@m_sprites = sprites;
m_countTm = displayTime;
m_countC = 0;
m_delayAfter = delayAfter;
m_gold = gold;
m_wood = wood;
m_stone = stone;
m_iron = iron;
m_crystals = crystals;
m_dust = dust;
m_ore = ore;
if (materialModder !is null)
{
//auto@ mods = materialModder.GetModifiers();
m_gold = roll_round(m_gold * materialModder.GetMaterialModifier(MaterialType::Gold));
m_wood = roll_round(m_wood * materialModder.GetMaterialModifier(MaterialType::Wood));
m_stone = roll_round(m_stone * materialModder.GetMaterialModifier(MaterialType::Stone));
m_iron = roll_round(m_iron * materialModder.GetMaterialModifier(MaterialType::Iron));
m_crystals = roll_round(m_crystals * materialModder.GetMaterialModifier(MaterialType::Crystals));
m_dust = roll_round(m_dust * materialModder.GetMaterialModifier(MaterialType::Dust));
m_ore = roll_round(m_ore * materialModder.GetMaterialModifier(MaterialType::Ore));
}
}
}
MissionEndRewardStep@ SumRewardSteps(array<MissionEndRewardStep@> rewardSteps)
{
MissionEndRewardStep step;
for (uint i = 0; i < rewardSteps.length(); i++)
{
step.m_gold += rewardSteps[i].m_gold;
step.m_wood += rewardSteps[i].m_wood;
step.m_stone += rewardSteps[i].m_stone;
step.m_iron += rewardSteps[i].m_iron;
step.m_crystals += rewardSteps[i].m_crystals;
step.m_dust += rewardSteps[i].m_dust;
step.m_ore += rewardSteps[i].m_ore;
}
return step;
}
class MissionEndMenu : AWindowObject
{
int m_disabledCounter;
Widget@ m_contentW;
Widget@ m_rewardContent;
array<MissionEndRewardStep@> m_rewardSteps;
int m_countGold;
int m_countWood;
int m_countStone;
int m_countIron;
int m_countCrystals;
int m_countDust;
int m_countOre;
bool m_showCongratulation;
Widget@ m_addGroup;
TextWidget@ m_currGold;
TextWidget@ m_currWood;
TextWidget@ m_currStone;
TextWidget@ m_currIron;
TextWidget@ m_currCrystals;
TextWidget@ m_currDust;
TextWidget@ m_currOre;
TextWidget@ m_addGold;
TextWidget@ m_addWood;
TextWidget@ m_addStone;
TextWidget@ m_addIron;
TextWidget@ m_addCrystals;
TextWidget@ m_addDust;
TextWidget@ m_addOre;
CheckBoxGroupWidget@ m_checkboxGroup;
CheckBoxWidget@ m_materialCheckbox;
CheckBoxWidget@ m_statCheckbox;
ScrollbarWidget@ m_statGroup;
TextWidget@ m_statCategoryTemplate;
Widget@ m_statSeparatorTemplate;
Widget@ m_statValuePair;
BindingDisplayWidget@ m_bindingSubTabP;
BindingDisplayWidget@ m_bindingSubTabN;
int m_delayC;
MissionEndMenu(GUIBuilder@ b, PlayerRecord@ plr, bool dontClearMission = false)
{
super(b, "gui/mission_end.gui");
m_disabledCounter = 1500;
@m_checkboxGroup = cast<CheckBoxGroupWidget>(m_widget.GetWidgetById("checkbox-group"));
@m_materialCheckbox = cast<CheckBoxWidget>(m_checkboxGroup.GetWidgetById("material"));
@m_statCheckbox = cast<CheckBoxWidget>(m_checkboxGroup.GetWidgetById("stats"));
@m_addGroup = m_widget.GetWidgetById("add-group");
@m_currGold = cast<TextWidget>(m_widget.GetWidgetById("curr-gold"));
@m_currWood = cast<TextWidget>(m_widget.GetWidgetById("curr-wood"));
@m_currStone = cast<TextWidget>(m_widget.GetWidgetById("curr-stone"));
@m_currIron = cast<TextWidget>(m_widget.GetWidgetById("curr-iron"));
@m_currCrystals = cast<TextWidget>(m_widget.GetWidgetById("curr-crystal"));
@m_currDust = cast<TextWidget>(m_widget.GetWidgetById("curr-dust"));
@m_currOre = cast<TextWidget>(m_widget.GetWidgetById("curr-ore"));
@m_addGold = cast<TextWidget>(m_widget.GetWidgetById("add-gold"));
@m_addWood = cast<TextWidget>(m_widget.GetWidgetById("add-wood"));
@m_addStone = cast<TextWidget>(m_widget.GetWidgetById("add-stone"));
@m_addIron = cast<TextWidget>(m_widget.GetWidgetById("add-iron"));
@m_addCrystals = cast<TextWidget>(m_widget.GetWidgetById("add-crystal"));
@m_addDust = cast<TextWidget>(m_widget.GetWidgetById("add-dust"));
@m_addOre = cast<TextWidget>(m_widget.GetWidgetById("add-ore"));
@m_bindingSubTabP = cast<BindingDisplayWidget>(m_widget.GetWidgetById("binding-subtab-p"));
@m_bindingSubTabN = cast<BindingDisplayWidget>(m_widget.GetWidgetById("binding-subtab-n"));
m_currGold.SetText(Resources::GetString(".tab.overlay.player.gold", {{ "amount", 0 }}));
m_currWood.SetText(Resources::GetString(".tab.overlay.player.wood", {{ "amount", 0 }}));
m_currStone.SetText(Resources::GetString(".tab.overlay.player.stone", {{ "amount", 0 }}));
m_currIron.SetText(Resources::GetString(".tab.overlay.player.iron", {{ "amount", 0 }}));
m_currCrystals.SetText(Resources::GetString(".tab.overlay.player.crys", {{ "amount", 0 }}));
m_currDust.SetText(Resources::GetString(".tab.overlay.player.dust", {{ "amount", 0 }}));
m_currOre.SetText(Resources::GetString(".tab.overlay.player.ore", {{ "amount", 0 }}));
m_addGold.SetText("");
m_addWood.SetText("");
m_addStone.SetText("");
m_addIron.SetText("");
m_addCrystals.SetText("");
m_addDust.SetText("");
m_addOre.SetText("");
@m_statGroup = cast<ScrollbarWidget>(m_widget.GetWidgetById("stat-group"));
@m_statCategoryTemplate = cast<TextWidget>(m_widget.GetWidgetById("stat-category-template"));
@m_statSeparatorTemplate = m_widget.GetWidgetById("stat-separator");
@m_statValuePair = m_widget.GetWidgetById("stat-value-template");
@m_contentW = m_widget.GetWidgetById("stat-content");
@m_rewardContent = m_widget.GetWidgetById("reward-content");
m_contentW.m_visible = false;
m_rewardContent.m_visible = true;
auto missionDef = MissionDef::Get(plr.currMission);
if (missionDef is null)
{
PrintError("Failed to find ended mission.");
return;
}
auto sentBack = MissionEndRewardStep(Resources::GetString(".menu.mission_end.step.sent_back"), 1000, 750,
plr.statsRun.GetStatCurr(HashString("sent-back-gold")),
plr.statsRun.GetStatCurr(HashString("sent-back-wood")),
plr.statsRun.GetStatCurr(HashString("sent-back-stone")),
plr.statsRun.GetStatCurr(HashString("sent-back-iron")),
plr.statsRun.GetStatCurr(HashString("sent-back-crystals")),
plr.statsRun.GetStatCurr(HashString("sent-back-dust")),
plr.statsRun.GetStatCurr(HashString("sent-back-ore"))
);
m_rewardSteps.insertLast(MissionEndRewardStep(Resources::GetString(".menu.mission_end.step.picked_up"), 750, 750,
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::Ore)])));
if (plr.valuableInventory.m_valuables.length() > 0)
{
array<ScriptSprite@> sprites;
for (uint i = 0; i < plr.valuableInventory.m_valuables.length(); i++)
{
auto icon = plr.valuableInventory.m_valuables[i].GetIcon();
if (icon !is null)
sprites.insertLast(icon);
}
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));
}
if (g_currTownRecord.GetVariationOnBuilding(HashString("magic_shop")) >= 0)
{
array<ScriptSprite@> commonSprites;
array<ScriptSprite@> uncommonSprites;
array<ScriptSprite@> rareSprites;
array<ScriptSprite@> epicSprites;
for (uint i = 0; i < plr.trinketInventory.m_items.length(); i++)
{
auto trinket = plr.trinketInventory.m_items[i];
if (trinket.m_quality == Item::Quality::Common)
commonSprites.insertLast(trinket.GetIcon());
else if (trinket.m_quality == Item::Quality::Uncommon)
uncommonSprites.insertLast(trinket.GetIcon());
else if (trinket.m_quality == Item::Quality::Rare)
rareSprites.insertLast(trinket.GetIcon());
else if (trinket.m_quality == Item::Quality::Epic)
epicSprites.insertLast(trinket.GetIcon());
}
const int trinketDelayTime = 350;
if (commonSprites.length() > 0)
{
int num = commonSprites.length();
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);
m_rewardSteps.insertLast(step);
%STAT Add collected-crystals step.m_crystals plr
}
if (uncommonSprites.length() > 0)
{
int num = uncommonSprites.length() * 3;
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);
m_rewardSteps.insertLast(step);
%STAT Add collected-crystals step.m_crystals plr
}
if (rareSprites.length() > 0)
{
int num = rareSprites.length();
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);
m_rewardSteps.insertLast(step);
%STAT Add collected-dust step.m_dust plr
}
if (epicSprites.length() > 0)
{
int num = epicSprites.length() * 3;
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);
m_rewardSteps.insertLast(step);
%STAT Add collected-dust step.m_dust plr
}
}
if (false) // plr.currMissionState != MissionManager::MissionState::Succeeded
{
float costMul = -1.0f * (1.0f - ((1.0f - plr.GetModifiers().ReviveCostMul(plr)) + (1.0f - Tweak::BaseReviveCost)));
auto total = SumRewardSteps(m_rewardSteps);
auto costStep = MissionEndRewardStep(Resources::GetString(".menu.mission_end.step.revive", {{ "rate", int(costMul * -100.0f + 0.5f) }}), 1000, 750,
int(total.m_gold * costMul),
int(total.m_wood * costMul),
int(total.m_stone * costMul),
int(total.m_iron * costMul),
int(total.m_crystals * costMul),
int(total.m_dust * costMul),
int(total.m_ore * costMul)
);
%STAT Add chapel-revive-gold -costStep.m_gold plr
%STAT Add chapel-revive-wood -costStep.m_wood plr
%STAT Add chapel-revive-stone -costStep.m_stone plr
%STAT Add chapel-revive-iron -costStep.m_iron plr
%STAT Add chapel-revive-crystals -costStep.m_crystals plr
%STAT Add chapel-revive-dust -costStep.m_dust plr
%STAT Add chapel-revive-ore -costStep.m_ore plr
m_rewardSteps.insertLast(costStep);
}
// Bonus??
if (plr.currMissionState == MissionManager::MissionState::Succeeded)
{
auto reward = missionDef.GetReward(MissionManager::g_module.m_missionRewardSeed);
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_ore.x != 0);
if (givesReward)
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_ore.x, plr));
if (missionDef.m_id == "dark_citadel")
{
auto ingp = int(g_ngp + 0.5f);
if (ingp >= 5)
Platform::Service.UnlockAchievement("beat_dark_citadel_ngp5");
if (ingp >= 4)
Platform::Service.UnlockAchievement("beat_dark_citadel_ngp4");
if (ingp >= 3)
Platform::Service.UnlockAchievement("beat_dark_citadel_ngp3");
if (ingp >= 2)
Platform::Service.UnlockAchievement("beat_dark_citadel_ngp2");
if (ingp >= 1)
Platform::Service.UnlockAchievement("beat_dark_citadel_ngp1");
Platform::Service.UnlockAchievement("beat_dark_citadel");
if (!g_myTownRecord.HasTownFlag(HashString("beat_dark_citadel")))
m_showCongratulation = true;
g_myTownRecord.SetTownFlag(HashString("beat_dark_citadel"), true, false);
%STAT Max highest-ngp ingp+1 plr
}
}
m_delayC = 1000;
if (plr.currMissionState == MissionManager::MissionState::Succeeded)
{
cast<TextWidget>(m_widget.GetWidgetById("mission-state")).SetText(Resources::GetString(".menu.mission_end.completed"));
cast<TextWidget>(m_widget.GetWidgetById("mission-title")).SetText(missionDef.m_name);
}
else if (plr.currMissionState == MissionManager::MissionState::Failed)
{
cast<TextWidget>(m_widget.GetWidgetById("mission-state")).SetText(Resources::GetString(".menu.mission_end.failed"));
cast<TextWidget>(m_widget.GetWidgetById("mission-title")).SetText(missionDef.m_name);
}
else if (plr.currMissionState == MissionManager::MissionState::Aborted)
{
cast<TextWidget>(m_widget.GetWidgetById("mission-state")).SetText(Resources::GetString(".menu.mission_end.aborted"));
cast<TextWidget>(m_widget.GetWidgetById("mission-title")).SetText(missionDef.m_name);
}
auto plrBase = cast<PlayerBase>(plr.actor);
if (plrBase !is null)
{
Widget@ categoryGroup;
for (uint i = 0; i < plrBase.m_skills.length(); i++)
{
auto val = plr.statsRun.GetStatCurr(HashString("damage-dealt-" + plrBase.m_skills[i].m_skillId));
if (val == 0)
continue;
if (categoryGroup is null)
@categoryGroup = AddStatGroup("skill_dmg");
AddStatValue(categoryGroup, plrBase.m_skills[i].m_name, formatThousands(val, true));
}
}
for (uint i = 0; i < Stats::StatDef::Instances.length(); i++)
{
auto currStat = Stats::StatDef::Instances[i];
if (currStat.m_hidden)
continue;
if (currStat.m_category.isEmpty())
continue;
auto val = plr.statsRun.GetStatCurr(currStat.m_idHash);
if (val == 0)
continue;
auto categoryGroup = m_statGroup.GetWidgetByIdImpl(currStat.m_categoryHash);
if (categoryGroup is null)
@categoryGroup = AddStatGroup(currStat.m_category);
AddStatValue(categoryGroup, Resources::GetString(currStat.m_name), currStat.GetStatFormatted(val));
}
if (!dontClearMission)
{
MissionManager::g_module.SetMission(0, 0);
plr.currMission = 0;
plr.currMissionState = MissionManager::MissionState::None;
plr.currMissionRewardSeed = 0;
}
plr.ResetForNewMission();
g_flags.ClearFlags(FlagState::Run);
for (uint i = 0; i < plr.materials.length(); i++)
plr.materials[i] = 0;
{
auto total = SumRewardSteps(m_rewardSteps);
g_myTownRecord.GiveMaterial(MaterialType::Gold, max(0, total.m_gold));
g_myTownRecord.GiveMaterial(MaterialType::Wood, max(0, total.m_wood));
g_myTownRecord.GiveMaterial(MaterialType::Stone, max(0, total.m_stone));
g_myTownRecord.GiveMaterial(MaterialType::Iron, max(0, total.m_iron));
g_myTownRecord.GiveMaterial(MaterialType::Crystals, max(0, total.m_crystals));
g_myTownRecord.GiveMaterial(MaterialType::Dust, max(0, total.m_dust));
g_myTownRecord.GiveMaterial(MaterialType::Ore, max(0, total.m_ore));
}
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_ore > 0)
m_rewardSteps.insertAt(0, sentBack);
TabIncome();
g_myTownRecord.RefreshDonationTitles();
plr.RefreshModifiers();
}
void RefreshKeybinds(ControlMap@ currMap) override
{
m_bindingSubTabP.SetBinding("MenuPreviousSubTab");
m_bindingSubTabN.SetBinding("MenuNextSubTab");
AWindowObject::RefreshKeybinds(currMap);
}
void OnInteractableIndexChanged() override
{
auto currInteractable = m_input.GetCurrentInteractable();
if (currInteractable is null)
{
m_navigationBar.BuildBar({}, this);
return;
}
array<string>@ rawTexts = currInteractable.NavigationBarText();
array<KeyNavigationText@> navTexts;
for (uint i = 0; i < rawTexts.length(); i++)
navTexts.insertLast(KeyNavigationText(m_navigationBar.m_font.BuildText(rawTexts[i])));
m_navigationBar.BuildBar(navTexts, this);
}
void TabIncome()
{
if (m_statGroup.m_visible)
{
m_statGroup.m_visible = false;
m_contentW.m_visible = false;
m_rewardContent.m_visible = true;
RefreshInteractableWidgets(m_widget);
OnInteractableIndexChanged();
m_materialCheckbox.SetChecked(true);
m_statCheckbox.SetChecked(false);
}
}
void TabStats()
{
if (!m_statGroup.m_visible)
{
m_statGroup.m_visible = true;
m_contentW.m_visible = true;
m_rewardContent.m_visible = false;
RefreshInteractableWidgets(m_widget);
OnInteractableIndexChanged();
m_materialCheckbox.SetChecked(false);
m_statCheckbox.SetChecked(true);
}
}
Widget@ AddStatGroup(const string &in group)
{
auto newCategory = cast<TextWidget>(m_statCategoryTemplate.Clone());
newCategory.m_id = group;
newCategory.m_idHash = HashString(group);
newCategory.m_visible = true;
newCategory.SetText(Resources::GetString(".menu.stats.cat." + group));
if (m_statGroup.m_children.length() > 0)
newCategory.m_offset.y += m_statValuePair.m_height;
m_statGroup.AddChild(newCategory);
return newCategory;
}
void AddStatValue(Widget@ group, const string &in title, const string &in text)
{
auto newStatPair = m_statValuePair.Clone();
newStatPair.SetID("");
newStatPair.m_visible = true;
auto statTitle = cast<TextWidget>(newStatPair.GetWidgetById("stat-title"));
statTitle.SetText(title);
auto statText = cast<TextWidget>(newStatPair.GetWidgetById("stat-text"));
statText.SetText(text);
int i = 0;
int placeIndex = m_statGroup.m_children.findByRef(group) + 1;
for (; placeIndex < int(m_statGroup.m_children.length()); placeIndex++, i++)
{
if (!m_statGroup.m_children[placeIndex].m_id.isEmpty())
break;
}
if (i % 2 == 0)
newStatPair.GetWidgetById("stat-bg").m_visible = true;
m_statGroup.AddChild(newStatPair, placeIndex);
}
void Draw(SpriteBatch& sb, int idt) override
{
AWindowObject::Draw(sb, idt);
if (!m_statGroup.m_visible)
{
auto font = Resources::GetBitmapFont("gui/fonts/hw8.fnt");
vec2 offset = m_origin + vec2(5, 5);
for (int r = 0; r <= m_rewardStepCurrId; r++)
{
if (r >= int(m_rewardSteps.length()))
break;
float step = clamp(m_rewardSteps[r].m_countC / float(m_rewardSteps[r].m_countTm), 0.0f, 1.0f);
if (r < m_rewardStepCurrId)
step = 1.0f;
StringBuilder cost;
cost.Append(m_rewardSteps[r].m_name);
cost.Append(": ");
if (m_rewardSteps[r].m_gold != 0)
AddStepCountingText(cost, m_rewardSteps[r].m_gold, ".tab.overlay.player.gold", step);
if (m_rewardSteps[r].m_wood != 0)
AddStepCountingText(cost, m_rewardSteps[r].m_wood, ".tab.overlay.player.wood", step);
if (m_rewardSteps[r].m_stone != 0)
AddStepCountingText(cost, m_rewardSteps[r].m_stone, ".tab.overlay.player.stone", step);
if (m_rewardSteps[r].m_iron != 0)
AddStepCountingText(cost, m_rewardSteps[r].m_iron, ".tab.overlay.player.iron", step);
if (m_rewardSteps[r].m_crystals != 0)
AddStepCountingText(cost, m_rewardSteps[r].m_crystals, ".tab.overlay.player.crys", step);
if (m_rewardSteps[r].m_dust != 0)
AddStepCountingText(cost, m_rewardSteps[r].m_dust, ".tab.overlay.player.dust", step);
if (m_rewardSteps[r].m_ore != 0)
AddStepCountingText(cost, m_rewardSteps[r].m_ore, ".tab.overlay.player.ore", step);
sb.DrawString(m_rewardContent.m_origin + offset, font, cost.String(), vec4(1,1,1,1), TextAlignment::Left);
offset.y += font.GetLineHeight() + 1;
auto@ sprites = m_rewardSteps[r].m_sprites;
if (sprites !is null && sprites.length() > 0)
{
auto pos = m_rewardContent.m_origin + offset;
float height = 0;
auto drawSprites = Modifiers::lerp(vec2(0, sprites.length()), step);
float xIncr = float(m_rewardContent.m_width - sprites[0].GetWidth() - offset.x * 2) / max(1.0f, float(sprites.length() - 1));
xIncr = min(sprites[0].GetWidth() * 1.5f, xIncr);
for (int i = 0; i < drawSprites; i++)
{
sprites[i].Draw(sb, pos + vec2(int(xIncr * i + 0.5f), 0), g_menuTime);
height = max(height, sprites[i].GetHeight());
}
offset.y += height + 3;
}
}
}
}
void AddStepCountingText(StringBuilder@ sb, int value, const string &in str, float step)
{
if (value != 0)
{
sb.Append(Resources::GetString(str, {{ "amount", lerp(0, value, step) }}));
sb.Append(" ");
}
/*
if (value < 0)
widget.SetColor(vec4(1,0,0,1));
else
widget.SetColor(vec4(0,1,0,1));
*/
}
void SetRewardStepCountingText(TextWidget@ widget, int value, float step)
{
if (value != 0)
widget.SetText("+" + lerp(value, 0, step));
if (value < 0)
widget.SetColor(vec4(1,0,0,1));
else
widget.SetColor(vec4(0,1,0,1));
}
int m_rewardStepCurrId;
bool Update(int ms, GameInput& gameInput, MenuInput& menuInput) override
{
%if GAME
if (menuInput.MenuPreviousSubTab.Pressed)
TabIncome();
if (menuInput.MenuNextSubTab.Pressed)
TabStats();
%endif
if (m_disabledCounter > 0)
m_disabledCounter -= ms;
if (m_delayC > 0)
m_delayC -= ms;
else if (int(m_rewardSteps.length()) > m_rewardStepCurrId)
{
m_rewardSteps[m_rewardStepCurrId].m_countC += ms;
float step = m_rewardSteps[m_rewardStepCurrId].m_countC / float(m_rewardSteps[m_rewardStepCurrId].m_countTm);
if (step >= 1.0f)
{
m_countGold += m_rewardSteps[m_rewardStepCurrId].m_gold;
m_countWood += m_rewardSteps[m_rewardStepCurrId].m_wood;
m_countStone += m_rewardSteps[m_rewardStepCurrId].m_stone;
m_countIron += m_rewardSteps[m_rewardStepCurrId].m_iron;
m_countCrystals += m_rewardSteps[m_rewardStepCurrId].m_crystals;
m_countDust += m_rewardSteps[m_rewardStepCurrId].m_dust;
m_countOre += m_rewardSteps[m_rewardStepCurrId].m_ore;
if (m_countGold != 0)
m_currGold.SetText(Resources::GetString(".tab.overlay.player.gold", {{ "amount", m_countGold }}));
if (m_countWood != 0)
m_currWood.SetText(Resources::GetString(".tab.overlay.player.wood", {{ "amount", m_countWood }}));
if (m_countStone != 0)
m_currStone.SetText(Resources::GetString(".tab.overlay.player.stone", {{ "amount", m_countStone }}));
if (m_countIron != 0)
m_currIron.SetText(Resources::GetString(".tab.overlay.player.iron", {{ "amount", m_countIron }}));
if (m_countCrystals != 0)
m_currCrystals.SetText(Resources::GetString(".tab.overlay.player.crys", {{ "amount", m_countCrystals }}));
if (m_countDust != 0)
m_currDust.SetText(Resources::GetString(".tab.overlay.player.dust", {{ "amount", m_countDust }}));
if (m_countOre != 0)
m_currOre.SetText(Resources::GetString(".tab.overlay.player.ore", {{ "amount", m_countOre }}));
m_addGold.SetText("");
m_addWood.SetText("");
m_addStone.SetText("");
m_addIron.SetText("");
m_addCrystals.SetText("");
m_addDust.SetText("");
m_addOre.SetText("");
m_delayC = m_rewardSteps[m_rewardStepCurrId].m_delayAfter;
m_rewardStepCurrId++;
}
else
{
{
if (m_countGold != 0 || m_rewardSteps[m_rewardStepCurrId].m_gold != 0)
m_currGold.SetText(Resources::GetString(".tab.overlay.player.gold", {{ "amount", m_countGold + lerp(0, m_rewardSteps[m_rewardStepCurrId].m_gold, step) }}));
if (m_countWood != 0 || m_rewardSteps[m_rewardStepCurrId].m_wood != 0)
m_currWood.SetText(Resources::GetString(".tab.overlay.player.wood", {{ "amount", m_countWood + lerp(0, m_rewardSteps[m_rewardStepCurrId].m_wood, step) }}));
if (m_countStone != 0 || m_rewardSteps[m_rewardStepCurrId].m_stone != 0)
m_currStone.SetText(Resources::GetString(".tab.overlay.player.stone", {{ "amount", m_countStone + lerp(0, m_rewardSteps[m_rewardStepCurrId].m_stone, step) }}));
if (m_countIron != 0 || m_rewardSteps[m_rewardStepCurrId].m_iron != 0)
m_currIron.SetText(Resources::GetString(".tab.overlay.player.iron", {{ "amount", m_countIron + lerp(0, m_rewardSteps[m_rewardStepCurrId].m_iron, step) }}));
if (m_countCrystals != 0 || m_rewardSteps[m_rewardStepCurrId].m_crystals != 0)
m_currCrystals.SetText(Resources::GetString(".tab.overlay.player.crys", {{ "amount", m_countCrystals + lerp(0, m_rewardSteps[m_rewardStepCurrId].m_crystals, step) }}));
if (m_countDust != 0 || m_rewardSteps[m_rewardStepCurrId].m_dust != 0)
m_currDust.SetText(Resources::GetString(".tab.overlay.player.dust", {{ "amount", m_countDust + lerp(0, m_rewardSteps[m_rewardStepCurrId].m_dust, step) }}));
if (m_countOre != 0 || m_rewardSteps[m_rewardStepCurrId].m_ore != 0)
m_currOre.SetText(Resources::GetString(".tab.overlay.player.ore", {{ "amount", m_countOre + lerp(0, m_rewardSteps[m_rewardStepCurrId].m_ore, step) }}));
}
{
if (m_countGold != 0 || m_rewardSteps[m_rewardStepCurrId].m_gold != 0)
SetRewardStepCountingText(m_addGold, m_rewardSteps[m_rewardStepCurrId].m_gold, step);
if (m_countWood != 0 || m_rewardSteps[m_rewardStepCurrId].m_wood != 0)
SetRewardStepCountingText(m_addWood, m_rewardSteps[m_rewardStepCurrId].m_wood, step);
if (m_countStone != 0 || m_rewardSteps[m_rewardStepCurrId].m_stone != 0)
SetRewardStepCountingText(m_addStone, m_rewardSteps[m_rewardStepCurrId].m_stone, step);
if (m_countIron != 0 || m_rewardSteps[m_rewardStepCurrId].m_iron != 0)
SetRewardStepCountingText(m_addIron, m_rewardSteps[m_rewardStepCurrId].m_iron, step);
if (m_countCrystals != 0 || m_rewardSteps[m_rewardStepCurrId].m_crystals != 0)
SetRewardStepCountingText(m_addCrystals, m_rewardSteps[m_rewardStepCurrId].m_crystals, step);
if (m_countDust != 0 || m_rewardSteps[m_rewardStepCurrId].m_dust != 0)
SetRewardStepCountingText(m_addDust, m_rewardSteps[m_rewardStepCurrId].m_dust, step);
if (m_countOre != 0 || m_rewardSteps[m_rewardStepCurrId].m_ore != 0)
SetRewardStepCountingText(m_addOre, m_rewardSteps[m_rewardStepCurrId].m_ore, step);
}
}
}
return AWindowObject::Update(ms, gameInput, menuInput);
}
void OnFunc(Widget@ sender, const string &in name) override
{
auto parse = name.split(" ");
if (parse[0] == "close")
{
if (m_disabledCounter > 0)
return;
cast<AGameplayGameMode>(g_gameMode).SavePlayerAndTown();
m_manager.CloseWindow(this);
}
else if (parse[0] == "set-tab")
{
if (parse[1] == "materials")
TabIncome();
else if (parse[1] == "stats")
TabStats();
}
}
void OnClose() override
{
if (m_showCongratulation)
g_gameMode.ShowDialog("a", Resources::GetString(".menu.mission_end.new_game_plus"), Resources::GetString(".menu.ok"), this);
}
}