Skip to content

Commit

Permalink
Wire up upgrade tuning to the menu
Browse files Browse the repository at this point in the history
  • Loading branch information
ToxicFrog committed Dec 25, 2023
1 parent 3ee2d97 commit e2432a9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 10 deletions.
6 changes: 6 additions & 0 deletions gun-bonsai/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
- A `Service` is now included to make it easier to write integrations with
other mods. It supports RPCs for adding XP or upgrades to players and weapons.
See `MODDING.md` for details.
- You can now change the effective level of an upgrade by pressing left and
right on the status screen, to any level between 1 and its max level. (You
cannot set an upgrade to level 0; to turn it off, press enter). The tooltip
will update to show the current effects of the upgrade. The level change may
not take effect immediately for all upgrades, e.g. new elemental debuffs you
inflict will use the new level but existing ones will use the old level.
- Change:
- `Indestructable` integration updated to support Indestructable 0.3.x. If you
use the integration, you must update both mods for it to function properly.
Expand Down
2 changes: 2 additions & 0 deletions gun-bonsai/LANGUAGE.en-menu
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ TFLV_MENU_STATUS_TITLE = "Status";
TFLV_MENU_HEADER_PLAYER_STATUS = "Player Status";
TFLV_MENU_HEADER_WEAPON_STATUS = "Weapon Status";
TFLV_MENU_HEADER_WEAPON_LD_EFFECTS = "LegenDoom Effects";
// Displayed at the bottom of the status menu.
TFLV_MENU_UPGRADE_CONTROLS_HELP = "↵ Toggle upgrade\n⬅➡ Adjust upgrade level";
// headers for player/weapon levelup menus
TFLV_MENU_PLAYER_LEVELUP_TITLE = "Player Level Up!";
TFLV_MENU_WEAPON_LEVELUP_TITLE = "Weapon Level Up!";
Expand Down
43 changes: 33 additions & 10 deletions gun-bonsai/ca.ancilla.bonsai/menu/GenericMenu.zs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ class ::GenericMenu : TFLV::TooltipOptionMenu {
}

void PushUpgradeToggle(TFLV::Upgrade::BaseUpgrade upgrade, uint bag_index, uint index) {
mDesc.mItems.Push(new("::UpgradeToggle").Init(upgrade, bag_index, index));
PushTooltip(upgrade.GetTooltip(upgrade.level));
let toggle = new("::UpgradeToggle").Init(upgrade, bag_index, index);
mDesc.mItems.Push(toggle);
toggle.tt = PushTooltip(upgrade.GetTooltip(upgrade.level));
}

override bool MenuEvent(int key, bool fromController) {
Expand Down Expand Up @@ -84,6 +85,7 @@ class ::UpgradeToggle : ::KeyValueText {
TFLV::Upgrade::BaseUpgrade upgrade;
uint bag_index;
uint index;
TFLV::Tooltip tt;

::UpgradeToggle Init(TFLV::Upgrade::BaseUpgrade upgrade, uint bag_index, uint index) {
self.upgrade = upgrade;
Expand All @@ -96,26 +98,47 @@ class ::UpgradeToggle : ::KeyValueText {
return self;
}

string GetLabel() {
if (upgrade.level == upgrade.max_level) {
return string.format("%s (%d)", upgrade.GetName(), upgrade.level);
} else {
return string.format("%s \c[DARKGREY](%d/%d)\c-",
upgrade.GetName(), upgrade.level, upgrade.max_level);
}
}

override bool Selectable() { return true; }

override int Draw(OptionMenuDescriptor d, int y, int indent, bool selected) {
if (upgrade.enabled) {
drawLabel(indent, y, font.CR_DARKRED);
drawValue(indent, y, selected ? font.CR_RED : font.CR_DARKRED, self.value);
} else {
// Update the tooltip, since it's going to change if the user has wiggled
// the effective upgrade level.
tt.text = upgrade.GetTooltip(upgrade.level);
self.mLabel = GetLabel();

if (!upgrade.enabled) {
drawLabel(indent, y, font.CR_DARKRED);
drawValue(indent, y, selected ? font.CR_DARKGRAY : font.CR_BLACK,
string.format("\c[BLACK][OFF]\c- %s", self.value));
} else {
drawLabel(indent, y, font.CR_DARKRED);
drawValue(indent, y, selected ? font.CR_RED : font.CR_DARKRED, self.value);
}
return indent;
}

override bool MenuEvent(int key, bool fromController) {
if (key != Menu.MKey_Enter)
if (key == Menu.MKey_Left) {
Menu.MenuSound("menu/change");
EventHandler.SendNetworkEvent("bonsai-tune-upgrade", bag_index, index, -1);
} else if (key == Menu.MKey_Right) {
Menu.MenuSound("menu/change");
EventHandler.SendNetworkEvent("bonsai-tune-upgrade", bag_index, index, 1);
} else if (key == Menu.MKey_Enter) {
Menu.MenuSound("menu/choose");
EventHandler.SendNetworkEvent("bonsai-toggle-upgrade", bag_index, index);
} else {
return super.MenuEvent(key, fromController);

Menu.MenuSound("menu/choose");
EventHandler.SendNetworkEvent("bonsai-toggle-upgrade", bag_index, index);
}
return true;
}
}
Expand Down
3 changes: 3 additions & 0 deletions gun-bonsai/ca.ancilla.bonsai/menu/StatusDisplay.zs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class ::StatusDisplay : ::GenericMenu {
string.format(StringTable.Localize("$TFLV_MENU_LEVEL"), stats.wlvl),
string.format(StringTable.Localize("$TFLV_MENU_XP"), stats.wxp, stats.wmax));
stats.wupgrades.DumpInteractableToMenu(self, 1);
PushText(" ", Font.CR_RED);
PushText("―――――", Font.CR_WHITE);
PushText("$TFLV_MENU_UPGRADE_CONTROLS_HELP", Font.CR_WHITE);

mDesc.mSelectedItem = -1;
let ld_info = stats.winfo.ld_info;
Expand Down

0 comments on commit e2432a9

Please sign in to comment.