Skip to content

Commit 5b8cf60

Browse files
authored
Merge pull request #2 from 435THz/ui-mod-nonchoice
More robust label lookup system and SummaryMenus list in all InteractableMenus
2 parents a1ed454 + 8d8e0f9 commit 5b8cf60

39 files changed

Lines changed: 349 additions & 304 deletions

RogueEssence/Dungeon/DSceneMap.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ public IEnumerator<YieldInstruction> AskToSendHome()
991991
else
992992
{
993993
yield return CoroutineManager.Instance.StartCoroutine(MenuManager.Instance.SetDialogue(Text.FormatKey("DLG_TEAM_FULL")));
994-
yield return CoroutineManager.Instance.StartCoroutine(MenuManager.Instance.ProcessMenuCoroutine(new TeamMenu(MenuLabel.TEAM_SENDHOME, true)));
994+
yield return CoroutineManager.Instance.StartCoroutine(MenuManager.Instance.ProcessMenuCoroutine(new TeamMenu(MenuLabel.TEAM_MENU_SENDHOME, true)));
995995
}
996996
}
997997

RogueEssence/Lua/LuaEngine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1934,7 +1934,7 @@ public void OnAddMenu(IInteractable menu)
19341934
{
19351935
DiagManager.Instance.LogInfo("LuaEngine.OnAddMenu()...");
19361936
m_scrsvc.Publish(EServiceEvents.AddMenu.ToString(), menu);
1937-
if (menu is InteractableMenu interactable && ((ILabeled)interactable).HasLabel())
1937+
if (menu is InteractableMenu interactable && interactable.HasLabel())
19381938
DiagManager.Instance.LogInfo("Menu label is: " + interactable.Label);
19391939
}
19401940

RogueEssence/Menu/ChoiceMenu.cs

Lines changed: 18 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,44 @@
11
using System.Collections.Generic;
22
using RogueElements;
3-
using Microsoft.Xna.Framework;
4-
using Microsoft.Xna.Framework.Graphics;
5-
using RogueEssence.Content;
63
using System.Linq;
74

85
namespace RogueEssence.Menu
96
{
107
public abstract class ChoiceMenu : InteractableMenu
118
{
9+
public override List<IMenuElement> Elements {
10+
get => NonChoices.Concat(Choices).ToList();
11+
protected set { NonChoices = value; Choices = new(); } //Realistically only affects initialization
12+
}
1213
public List<IMenuElement> NonChoices;
1314
public List<IChoosable> Choices;
1415

15-
//TODO: add this into the non-choices list?
1616
protected MenuCursor cursor;
1717

1818
public ChoiceMenu()
1919
{
20-
cursor = new MenuCursor(this, Dir4.Right);
21-
NonChoices = new List<IMenuElement>();
20+
cursor = new MenuCursor(MenuLabel.CURSOR, this, Dir4.Right);
21+
NonChoices = new List<IMenuElement> {cursor};
2222
Choices = new List<IChoosable>();
2323
}
2424

25-
public virtual int GetChoiceIndexByLabel(string label)
26-
{
27-
return GetChoiceIndexesByLabel(label)[label];
28-
}
29-
public virtual Dictionary<string, int> GetChoiceIndexesByLabel(params string[] labels)
30-
{
31-
Dictionary<string, int> poss = new();
32-
List<string> labelList = labels.ToList();
33-
foreach (string label in labels)
34-
poss.Add(label, -1);
25+
public override Dictionary<string, int> GetElementIndexesByLabel(params string[] labels)
26+
=> SearchLabels(labels, Elements);
3527

36-
for (int ii = 0; ii < Choices.Count; ii++)
37-
{
38-
bool found = false;
39-
IChoosable choice = Choices[ii];
40-
if (choice.HasLabel())
41-
{
42-
for (int kk = 0; kk < labelList.Count; kk++)
43-
{
44-
string label = labelList[kk];
45-
if (choice.Label == label)
46-
{
47-
found = true;
48-
poss[label] = ii;
49-
labelList.RemoveAt(kk);
50-
break;
51-
}
52-
}
53-
}
54-
if (found && labelList.Count == 0) break;
55-
}
56-
return poss;
57-
}
58-
59-
public override IEnumerable<IMenuElement> GetElements()
28+
public int GetChoiceIndexByLabel(string label)
6029
{
61-
yield return cursor;
62-
foreach (IChoosable choice in Choices)
63-
yield return choice;
64-
foreach (IMenuElement nonChoice in NonChoices)
65-
yield return nonChoice;
30+
if (GetChoiceIndexesByLabel(label).TryGetValue(label, out int ret)) return ret;
31+
return -1;
6632
}
33+
public virtual Dictionary<string, int> GetChoiceIndexesByLabel(params string[] labels)
34+
=> SearchLabels(labels, Choices);
6735

68-
69-
public override void Draw(SpriteBatch spriteBatch)
36+
public int GetNonChoiceIndexByLabel(string label)
7037
{
71-
if (!Visible)
72-
return;
73-
base.Draw(spriteBatch);
38+
if (GetElementIndexesByLabel(label).TryGetValue(label, out int ret)) return ret;
39+
return -1;
7440
}
41+
public virtual Dictionary<string, int> GetNonChoiceIndexesByLabel(params string[] labels)
42+
=> SearchLabels(labels, Choices);
7543
}
7644
}

RogueEssence/Menu/Dialogue/InfoMenu.cs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
32
using RogueElements;
43
using RogueEssence.Content;
54

@@ -14,25 +13,23 @@ public class InfoMenu : InteractableMenu
1413

1514
private Action action;
1615

17-
public InfoMenu(string title, string message, Action action)
16+
public InfoMenu(string title, string message, Action action) : this(MenuLabel.INFO_MENU, title, message, action) { }
17+
public InfoMenu(string label, string title, string message, Action action)
1818
{
19+
Label = label;
1920
this.action = action;
2021

2122
Bounds = new Rect(new Loc(40, 32), new Loc(240, 176));
2223

23-
Title = new MenuText(title, new Loc(GraphicsManager.MenuBG.TileWidth + 8, GraphicsManager.MenuBG.TileHeight));
24-
Div = new MenuDivider(new Loc(GraphicsManager.MenuBG.TileWidth, GraphicsManager.MenuBG.TileHeight + LINE_HEIGHT), Bounds.Width - GraphicsManager.MenuBG.TileWidth * 2);
24+
Title = new MenuText(MenuLabel.TITLE, title, new Loc(GraphicsManager.MenuBG.TileWidth + 8, GraphicsManager.MenuBG.TileHeight));
25+
Div = new MenuDivider(MenuLabel.DIV, new Loc(GraphicsManager.MenuBG.TileWidth, GraphicsManager.MenuBG.TileHeight + LINE_HEIGHT), Bounds.Width - GraphicsManager.MenuBG.TileWidth * 2);
2526

26-
Info = new DialogueText(message, new Rect(new Loc(GraphicsManager.MenuBG.TileWidth * 2, GraphicsManager.MenuBG.TileHeight + TitledStripMenu.TITLE_OFFSET),
27+
Info = new DialogueText(MenuLabel.MESSAGE, message, new Rect(new Loc(GraphicsManager.MenuBG.TileWidth * 2, GraphicsManager.MenuBG.TileHeight + TitledStripMenu.TITLE_OFFSET),
2728
new Loc(Bounds.Width - GraphicsManager.MenuBG.TileWidth * 3, Bounds.Height - GraphicsManager.MenuBG.TileHeight * 3)), LINE_HEIGHT);
28-
}
29-
30-
public override IEnumerable<IMenuElement> GetElements()
31-
{
32-
yield return Title;
33-
yield return Div;
3429

35-
yield return Info;
30+
Elements.Add(Title);
31+
Elements.Add(Div);
32+
Elements.Add(Info);
3633
}
3734

3835
public override void Update(InputManager input)

RogueEssence/Menu/Dialogue/SpeakerPortrait.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ public class SpeakerPortrait : IMenuElement
1414
public EmoteStyle SpeakerEmotion;
1515
public bool Bordered;
1616

17+
public bool HasLabel()
18+
{
19+
return !string.IsNullOrEmpty(Label);
20+
}
21+
public bool LabelContains(string substr)
22+
{
23+
return HasLabel() && Label.Contains(substr);
24+
}
25+
1726
public SpeakerPortrait(MonsterID speaker, EmoteStyle emotion, Loc loc, bool bordered)
1827
{
1928
Speaker = speaker;

RogueEssence/Menu/ILabeled.cs

Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,63 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
71
namespace RogueEssence.Menu
82
{
93
public interface ILabeled
104
{
115
public string Label { get; }
12-
public bool HasLabel()
13-
{
14-
return !string.IsNullOrEmpty(Label);
15-
}
16-
17-
public bool LabelContains(string substr)
18-
{
19-
return HasLabel() && Label.Contains(substr);
20-
}
6+
public bool HasLabel();
7+
public bool LabelContains(string substr);
218
}
229

2310
public abstract class MenuLabel
2411
{
25-
public const string MAIN = "MAIN";
26-
public const string SKILLS = "SKILLS";
27-
public const string INVENTORY = "INVENTORY";
28-
public const string INVENTORY_REPLACE = "INVENTORY_REPLACE";
29-
public const string TACTICS = "TACTICS";
30-
public const string TEAM = "TEAM";
31-
public const string TEAM_SWITCH = "TEAM_SWITCH";
32-
public const string TEAM_SENDHOME = "TEAM_SENDHOME";
33-
public const string GROUND = "GROUND";
34-
public const string GROUND_ITEM = "GROUND_ITEM";
35-
public const string GROUND_TILE = "GROUND_TILE";
36-
public const string OTHERS = "OTHERS";
37-
public const string REST = "REST";
38-
public const string SAVE = "SAVE";
39-
public const string MSG_LOG = "MSG_LOG";
40-
public const string SETTINGS = "SETTINGS";
41-
public const string KEYBOARD = "KEYBOARD";
42-
public const string GAMEPAD = "GAMEPAD";
12+
//MENU_LABELS
13+
public const string TOP_MENU = "TOP_MENU";
14+
public const string MAIN_MENU = "MAIN_MENU";
15+
public const string INFO_MENU = "INFO_MENU";
16+
public const string SKILLS_MENU = "SKILLS_MENU";
17+
public const string INVENTORY_MENU = "INVENTORY_MENU";
18+
public const string INVENTORY_MENU_REPLACE = "INVENTORY_MENU_REPLACE";
19+
public const string TACTICS_MENU = "TACTICS_MENU";
20+
public const string TEAM_MENU = "TEAM_MENU";
21+
public const string TEAM_MENU_SWITCH = "TEAM_MENU_SWITCH";
22+
public const string TEAM_MENU_SENDHOME = "TEAM_MENU_SENDHOME";
23+
public const string GROUND_MENU_ITEM = "GROUND_MENU_ITEM";
24+
public const string GROUND_MENU_TILE = "GROUND_MENU_TILE";
25+
public const string OTHERS_MENU = "OTHERS_MENU";
26+
public const string SETTINGS_MENU = "SETTINGS_MENU";
27+
28+
//USED IN MULTIPLE MENUS
29+
public const string TITLE = "TITLE";
30+
public const string DIV = "DIV";
31+
public const string MESSAGE = "MESSAGE";
32+
public const string CURSOR = "CURSOR";
33+
34+
//TOP MENU OPTIONS
35+
public const string TOP_TITLE_SUMMARY = "TOP_TITLE_SUMMARY";
36+
public const string TOP_RESCUE = "TOP_RESCUE";
37+
public const string TOP_CONTINUE = "TOP_CONTINUE";
38+
public const string TOP_NEW = "TOP_NEW";
39+
public const string TOP_ROGUE = "TOP_ROGUE";
40+
public const string TOP_RECORD = "TOP_RECORD";
41+
public const string TOP_OPTIONS = "TOP_OPTIONS";
42+
public const string TOP_QUEST = "TOP_QUEST";
43+
public const string TOP_QUEST_EXIT = "TOP_QUEST_EXIT";
44+
public const string TOP_MODS = "TOP_MODS";
45+
public const string TOP_QUIT = "TOP_QUIT";
46+
47+
//MAIN MENU OPTIONS
48+
public const string MAIN_SKILLS = "MAIN_SKILLS";
49+
public const string MAIN_INVENTORY = "MAIN_INVENTORY";
50+
public const string MAIN_TACTICS = "MAIN_TACTICS";
51+
public const string MAIN_TEAM = "MAIN_TEAM";
52+
public const string MAIN_GROUND = "MAIN_GROUND";
53+
public const string MAIN_OTHERS = "MAIN_OTHERS";
54+
public const string MAIN_REST = "MAIN_REST";
55+
public const string MAIN_SAVE = "MAIN_SAVE";
56+
57+
//OTHERS MENU OPTIONS
58+
public const string OTH_MSG_LOG = "OTH_MSG_LOG";
59+
public const string OTH_SETTINGS = "OTH_SETTINGS";
60+
public const string OTH_KEYBOARD = "OTH_KEYBOARD";
61+
public const string OTH_GAMEPAD = "OTH_GAMEPAD";
4362
}
4463
}

RogueEssence/Menu/InteractableMenu.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
using RogueElements;
2-
using RogueEssence.Content;
1+
using Microsoft.Xna.Framework.Graphics;
2+
using RogueElements;
3+
using System.Collections.Generic;
34

45
namespace RogueEssence.Menu
56
{
6-
public abstract class InteractableMenu : MenuBase, IInteractable, ILabeled
7+
public abstract class InteractableMenu : MenuBase, IInteractable
78
{
89
const int INPUT_WAIT = 30;
910
const int INPUT_GAP = 6;
@@ -15,7 +16,7 @@ public bool Inactive {
1516
}
1617
public bool BlockPrevious { get; set; }
1718

18-
public virtual string Label { get; protected set; } = "";
19+
public List<SummaryMenu> SummaryMenus { get; set; } = new();
1920

2021
public abstract void Update(InputManager input);
2122

@@ -42,5 +43,22 @@ public static bool IsInputting(InputManager input, params Dir8[] dirs)
4243
return (choseDir && (!prevDir || atAdd));
4344
}
4445

46+
public override void Draw(SpriteBatch spriteBatch)
47+
{
48+
if (!Visible)
49+
return;
50+
base.Draw(spriteBatch);
51+
52+
foreach (SummaryMenu menu in SummaryMenus)
53+
menu.Draw(spriteBatch);
54+
}
55+
56+
public int GetSummaryIndexByLabel(string label)
57+
{
58+
if (GetSummaryIndexesByLabel(label).TryGetValue(label, out int ret)) return ret;
59+
return new int();
60+
}
61+
public virtual Dictionary<string, int> GetSummaryIndexesByLabel(params string[] labels)
62+
=> SearchLabels(labels, SummaryMenus);
4563
}
4664
}

RogueEssence/Menu/Items/ItemChosenMenu.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ private void PutBackAction()
236236

237237
private void SwapAction()
238238
{
239-
MenuManager.Instance.AddMenu(new ItemMenu(MenuLabel.INVENTORY_REPLACE, slot), false);
239+
MenuManager.Instance.AddMenu(new ItemMenu(MenuLabel.INVENTORY_MENU_REPLACE, slot), false);
240240
}
241241
private void GiveAction()
242242
{

RogueEssence/Menu/Items/ItemMenu.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class ItemMenu : MultiPageMenu
2323

2424
//-2 for no replace slot, -1 for replace with ground, positive numbers for replace held team index's item
2525
public ItemMenu() : this(-2) { }
26-
public ItemMenu(int replaceSlot) : this(MenuLabel.INVENTORY, replaceSlot) { }
26+
public ItemMenu(int replaceSlot) : this(MenuLabel.INVENTORY_MENU, replaceSlot) { }
2727
public ItemMenu(string label) : this(label, -2) { }
2828
public ItemMenu(string label, int replaceSlot)
2929
{

0 commit comments

Comments
 (0)