Skip to content

Commit

Permalink
Quick use fix (JavidPack#5)
Browse files Browse the repository at this point in the history
* fix mod compiling on latest tml

* fix quick use item 20 being stuck if repeatedly used again

* fix other quick use actions
  • Loading branch information
direwolf420 authored Jan 30, 2020
1 parent 9ed7848 commit 311cd16
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 24 deletions.
8 changes: 4 additions & 4 deletions HelpfulHotkeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ public override object Call(params object[] args)
RecallItems.Add(Convert.ToInt32(args[1]));
return "Success";
default:
ErrorLogger.Log("HelpfulHotkeys: Unknown Message type: " + messageType);
Logger.Warn("Unknown Message type: " + messageType);
return "Failure";
}
}
catch (Exception e)
{
ErrorLogger.Log("HelpfulHotkeys Call Error: " + e.StackTrace + e.Message);
Logger.Warn("Call Error: " + e.StackTrace + e.Message);
}
return "Failure";
}
Expand Down Expand Up @@ -168,7 +168,7 @@ private void DrawSmartStackButton(SpriteBatch spriteBatch)
if (Main.mouseLeft && Main.mouseLeftRelease)
{
Main.mouseLeftRelease = false;
HelpfulHotkeysPlayer modPlayer = Main.LocalPlayer.GetModPlayer<HelpfulHotkeysPlayer>(this);
HelpfulHotkeysPlayer modPlayer = Main.LocalPlayer.GetModPlayer<HelpfulHotkeysPlayer>();
modPlayer.smartQuickStack();
Recipe.FindRecipes();
}
Expand Down Expand Up @@ -216,7 +216,7 @@ private void DrawSmartStackButton(SpriteBatch spriteBatch)
{
return;
}
HelpfulHotkeysPlayer modPlayer = player.GetModPlayer<HelpfulHotkeysPlayer>(this);
HelpfulHotkeysPlayer modPlayer = player.GetModPlayer<HelpfulHotkeysPlayer>();
modPlayer.smartQuickStack();
Recipe.FindRecipes();
}
Expand Down
33 changes: 13 additions & 20 deletions HelpfulHotkeysPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace HelpfulHotkeys
{
public class HelpfulHotkeysPlayer : ModPlayer
{
internal const int ITEM20 = 19;
internal int originalSelectedItem;
internal bool autoRevertSelectedItem = false;
internal bool autoCycleAmmo = false;
Expand Down Expand Up @@ -66,7 +67,7 @@ public override void ProcessTriggers(TriggersSet triggersSet)
}
if (HelpfulHotkeys.QuickUseItem20Hotkey.JustPressed)
{
QuickUseItem20();
QuickUseItemAt(ITEM20);
}
if (HelpfulHotkeys.QuickUseConfigItemHotkey.JustPressed) {
QuickUseConfigItem();
Expand Down Expand Up @@ -220,7 +221,7 @@ private void CyclingQuickMount()
public Item QuickMountCycle_GetItemToUse(int lastMount)
{
bool lastMountFound = false;
bool lastMountPassed = false;
//bool lastMountPassed = false;
Item item = null;
if (item == null && player.miscEquips[3].mountType != -1 && !MountID.Sets.Cart[player.miscEquips[3].mountType] && ItemLoader.CanUseItem(player.miscEquips[3], player))
{
Expand Down Expand Up @@ -552,15 +553,18 @@ public void ToggleAutoPause()
Main.NewText("Autopause turned " + (Main.autoPause ? "on" : "off"));
}

public void QuickUseItem20()
public void QuickUseItemAt(int index, bool use = true)
{
if (player.inventory[19].type != 0)
if (!autoRevertSelectedItem && player.selectedItem != index && player.inventory[index].type != 0)
{
originalSelectedItem = player.selectedItem;
autoRevertSelectedItem = true;
player.selectedItem = 19;
player.selectedItem = index;
player.controlUseItem = true;
player.ItemCheck(Main.myPlayer);
if (use)
{
player.ItemCheck(Main.myPlayer);
}
}
}

Expand All @@ -575,11 +579,7 @@ public void QuickUseConfigItem() {
Main.NewText($"Quick Use Config Item \"{Lang.GetItemNameValue(type)}\" not found in inventory.");
return;
}
originalSelectedItem = player.selectedItem;
autoRevertSelectedItem = true;
player.selectedItem = index;
player.controlUseItem = true;
player.ItemCheck(Main.myPlayer);
QuickUseItemAt(index);
}

public void SmartQuickStackToChests()
Expand Down Expand Up @@ -630,10 +630,7 @@ public void AutoTorch()
{
if (TileLoader.IsTorch(player.inventory[i].createTile))
{
originalSelectedItem = player.selectedItem;
autoRevertSelectedItem = true;
player.selectedItem = i;
player.controlUseItem = true;
QuickUseItemAt(i, use: false);
Player.tileTargetX = (int)(player.Center.X / 16);
Player.tileTargetY = (int)(player.Center.Y / 16);
int oldstack = player.inventory[player.selectedItem].stack;
Expand Down Expand Up @@ -681,11 +678,7 @@ public void AutoRecall()
{
if (HelpfulHotkeys.RecallItems.Contains(player.inventory[i].type))
{
originalSelectedItem = player.selectedItem;
autoRevertSelectedItem = true;
player.selectedItem = i;
player.controlUseItem = true;
player.ItemCheck(Main.myPlayer);
QuickUseItemAt(i);
break;
}
}
Expand Down

0 comments on commit 311cd16

Please sign in to comment.