Skip to content

Commit

Permalink
Added sorting code to SellMenu
Browse files Browse the repository at this point in the history
  • Loading branch information
435THz committed May 5, 2024
1 parent 6999d05 commit 270462c
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion RogueEssence/Menu/Items/SellMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,53 @@ public override void Draw(SpriteBatch spriteBatch)

public IEnumerator<YieldInstruction> SortCommand()
{
//generate list of selected items
List<int> equip_selected = new List<int>();
List<int> selected = new List<int>();
int eqIndex = 0;
for (int ii = 0; ii < DataManager.Instance.Save.ActiveTeam.Players.Count; ii++)
{
Character activeChar = DataManager.Instance.Save.ActiveTeam.Players[ii];
if (!String.IsNullOrEmpty(activeChar.EquippedItem.ID))
{
if (GetTotalChoiceAtIndex(eqIndex).Selected)
equip_selected.Add(eqIndex);
eqIndex++;
}
}
int pos = eqIndex;
for (int ii = 0; ii < DataManager.Instance.Save.ActiveTeam.GetInvCount(); ii++)
{
if (GetTotalChoiceAtIndex(pos).Selected)
selected.Add(ii);
pos++;
}

// get mapping
Dictionary<int, int> mapping = DataManager.Instance.Save.ActiveTeam.GetSortMapping(true);

// reorder the inventory
yield return CoroutineManager.Instance.StartCoroutine(GroundScene.Instance.ProcessInput(new GameAction(GameAction.ActionType.SortItems, Dir8.None)));
MenuManager.Instance.ReplaceMenu(new SellMenu(CurrentChoiceTotal, action));
// create the new menu
SellMenu menu = new SellMenu(CurrentChoiceTotal, action);

// reselect equip slots
for (int ii = 0; ii < equip_selected.Count; ii++)
{
int slot = equip_selected[ii];
((MenuChoice)menu.GetTotalChoiceAtIndex(slot)).SilentSelect(true);
}
// reselect the rest of the inventory
for (int ii = selected.Count - 1; ii >= 0; ii--)
{
int oldPos = selected[ii];
int newPos = mapping[oldPos];
int index = newPos + eqIndex;
((MenuChoice)menu.GetTotalChoiceAtIndex(index)).SilentSelect(true);
}

//replace the menu
MenuManager.Instance.ReplaceMenu(menu);
}
}
}

0 comments on commit 270462c

Please sign in to comment.