Skip to content

Commit 3ce86bb

Browse files
0.21.8
1 parent c3a11d2 commit 3ce86bb

File tree

5 files changed

+70
-187
lines changed

5 files changed

+70
-187
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.vs/
2-
obj/
2+
obj/
3+
bin/

Merchants/Shop.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace MerchantsPlus.Merchants;
55

66
internal abstract class Shop
77
{
8+
public int CycleIndex { get; set; }
89
public List<string> Shops;
910
public List<string> Quests;
1011

@@ -26,7 +27,7 @@ public Shop(params string[] shops)
2627
}
2728

2829
/// <summary>
29-
/// Initalizes the merchants particular shop.
30+
/// Opens the merchants shop.
3031
/// </summary>
3132
/// <param name="shop">The current shop we are in.</param>
3233
/// <param name="nextSlot">The nextSlot of the item to sell.</param>

UI/ShopUI.cs

Lines changed: 56 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,54 @@
11
using MerchantsPlus.Merchants;
22
using Terraria.GameContent.UI.Elements;
3+
using Terraria.ID;
34

45
namespace MerchantsPlus.UI;
56

7+
// This UI will appear when a new dialog is opened with a merchant
68
internal class ShopUI : UIState
79
{
8-
public const int ANGLER = 0;
9-
public const int ARMSDEALER = 1;
10-
public const int CLOTHIER = 2;
11-
public const int CYBORG = 3;
12-
public const int DEMOLITIONIST = 4;
13-
public const int DRYAD = 5;
14-
public const int DYETRADER = 6;
15-
public const int GOBLINTINKERER = 7;
16-
public const int GUIDE = 8;
17-
public const int MECHANIC = 9;
18-
public const int MERCHANT = 10;
19-
public const int NURSE = 11;
20-
public const int PAINTER = 12;
21-
public const int PARTYGIRL = 13;
22-
public const int PIRATE = 14;
23-
public const int SANTACLAUS = 15;
24-
public const int SKELETONMERCHANT = 16;
25-
public const int STEAMPUNKER = 17;
26-
public const int STYLIST = 18;
27-
public const int TAVERNKEEP = 19;
28-
public const int TAXCOLLECTOR = 20;
29-
public const int TRAVELLINGMERCHANT = 21;
30-
public const int TRUFFLE = 22;
31-
public const int WITCHDOCTOR = 23;
32-
public const int WIZARD = 24;
33-
3410
static readonly Dictionary<int, Shop> shops = new() {
3511
// DO NOT CHANGE THESE NAMES WITHOUT CHECKING THAT THEY MATCH
3612
// CORRECTLY INSIDE THEIR RESPECTIVE SHOP CLASSES!
37-
{ ANGLER, new ShopAngler("Bait", "Buffs", "Crates") },
38-
{ ARMSDEALER, new ShopArmsDealer("Guns") },
39-
{ CLOTHIER, new ShopClothier("Clothing", "Boss Masks", "Vanity I", "Vanity II", "Vanity III", "Vanity IV") },
40-
{ CYBORG, new ShopCyborg("Robotics", "Buffs") },
41-
{ DEMOLITIONIST, new ShopDemolitionist("Explosives", "Potions") },
42-
{ DRYAD, new ShopDryad("Seeds", "Potions") },
43-
{ DYETRADER, new ShopDyeTrader("Basic", "Bright", "Gradient", "Compound", "Strange", "Lunar") },
44-
{ GOBLINTINKERER, new ShopGoblinTinkerer("Movement", "Informational", "Combat", "Health and Mana",
13+
{ NPCID.Angler, new ShopAngler("Bait", "Buffs", "Crates") },
14+
{ NPCID.ArmsDealer, new ShopArmsDealer("Guns") },
15+
{ NPCID.Clothier, new ShopClothier("Clothing", "Boss Masks", "Vanity I", "Vanity II", "Vanity III", "Vanity IV") },
16+
{ NPCID.Cyborg, new ShopCyborg("Robotics", "Buffs") },
17+
{ NPCID.Demolitionist, new ShopDemolitionist("Explosives", "Potions") },
18+
{ NPCID.Dryad, new ShopDryad("Seeds", "Potions") },
19+
{ NPCID.DyeTrader, new ShopDyeTrader("Basic", "Bright", "Gradient", "Compound", "Strange", "Lunar") },
20+
{ NPCID.GoblinTinkerer, new ShopGoblinTinkerer("Movement", "Informational", "Combat", "Health and Mana",
4521
"Immunity", "Defensive", "Special", "Miscellaneous") },
46-
{ MECHANIC, new ShopMechanic("Mechanics", "Materials") },
47-
{ MERCHANT, new ShopMerchant("Gear", "Ores", "Pets", "Mounts") },
48-
{ NURSE, new ShopNurse("Potions") },
49-
{ PAINTER, new ShopPainter("Tools", "Paint", "Wallpaper", "Paintings I", "Paintings II") },
50-
{ PARTYGIRL, new ShopPartyGirl("Party Stuff") },
51-
{ PIRATE, new ShopPirate("Arrr", "Potions") },
52-
{ SANTACLAUS, new ShopSantaClaus("Decor", "Bulbs", "Lights", "Potions") },
53-
{ SKELETONMERCHANT, new ShopSkeletonMerchant("Gear", "Music Boxes") },
54-
{ STEAMPUNKER, new ShopSteampunker("Gear", "Solutions", "Logic") },
55-
{ STYLIST, new ShopStylist("Hair Dyes", "Overworld", "Underworld", "Desert", "Snow", "Jungle", "Ocean",
22+
{ NPCID.Mechanic, new ShopMechanic("Mechanics", "Materials") },
23+
{ NPCID.Merchant, new ShopMerchant("Gear", "Ores", "Pets", "Mounts") },
24+
{ NPCID.Nurse, new ShopNurse("Potions") },
25+
{ NPCID.Painter, new ShopPainter("Tools", "Paint", "Wallpaper", "Paintings I", "Paintings II") },
26+
{ NPCID.PartyGirl, new ShopPartyGirl("Party Stuff") },
27+
{ NPCID.Pirate, new ShopPirate("Arrr", "Potions") },
28+
{ NPCID.SantaClaus, new ShopSantaClaus("Decor", "Bulbs", "Lights", "Potions") },
29+
{ NPCID.SkeletonMerchant, new ShopSkeletonMerchant("Gear", "Music Boxes") },
30+
{ NPCID.Steampunker, new ShopSteampunker("Gear", "Solutions", "Logic") },
31+
{ NPCID.Stylist, new ShopStylist("Hair Dyes", "Overworld", "Underworld", "Desert", "Snow", "Jungle", "Ocean",
5632
"Corruption", "Crimson", "Hallow", "Space", "Mushroom", "Dungeon", "Bloodmoon", "Eclipse", "Goblin Army",
5733
"Old Ones Army", "Frost Legion", "Pumpkin Moon", "Frost Moon", "Pirate Invasion", "Martian Madness",
5834
"Solar Zone", "Vortex Zone", "Nebula Zone", "Stardust Zone") },
59-
{ TAVERNKEEP, new ShopTavernkeep("Gear") },
60-
{ TAXCOLLECTOR, new ShopTaxCollector() },
61-
{ TRAVELLINGMERCHANT, new ShopTravellingMerchant("Gear") },
62-
{ TRUFFLE, new ShopTruffle("Gear") },
63-
{ WITCHDOCTOR, new ShopWitchDoctor("Gear", "Flasks", "Wings") },
64-
{ WIZARD, new ShopWizard("Gear") },
65-
{ GUIDE, new ShopGuide("Gear") }
35+
{ NPCID.DD2Bartender, new ShopTavernkeep("Gear") },
36+
{ NPCID.TaxCollector, new ShopTaxCollector() },
37+
{ NPCID.TravellingMerchant, new ShopTravellingMerchant("Gear") },
38+
{ NPCID.Truffle, new ShopTruffle("Gear") },
39+
{ NPCID.WitchDoctor, new ShopWitchDoctor("Gear", "Flasks", "Wings") },
40+
{ NPCID.Wizard, new ShopWizard("Gear") },
41+
{ NPCID.Guide, new ShopGuide("Gear") }
6642
};
6743

6844
public static bool Visible { get; set; }
69-
public static int CurrentShopIndex { get; set; }
70-
public static int[] ShopCycleIndexes { get; private set; }
45+
public static int CurrentMerchantID { get; set; }
7146

72-
string[] shopNames;
7347
UIText currentShopName;
7448
UIPanel shopPanel;
7549

7650
public override void OnInitialize()
7751
{
78-
ShopCycleIndexes = new int[shops.Count];
79-
shopNames = new string[shops.Count];
80-
81-
// This is the first shop name the player will see (for all shops)
82-
// before pressing cycle shop button
83-
for (int i = 0; i < shops.Count; i++)
84-
shopNames[i] = shops[i].ToString();
85-
86-
//for (int i = 0; i < ShopNames.Length; i++)
87-
// ShopNames[i] = "Shop";
88-
8952
shopPanel = new UIPanel();
9053
shopPanel.SetPadding(0);
9154
shopPanel.Left.Set(200f, 0f);
@@ -94,7 +57,7 @@ public override void OnInitialize()
9457
shopPanel.Height.Set(35f, 0f);
9558
shopPanel.BackgroundColor = new Color(0, 0, 0, 0.6f);
9659

97-
currentShopName = new UIText(shopNames[CurrentShopIndex], 0.9f);
60+
currentShopName = new UIText("Shop Name", 0.9f);
9861
currentShopName.Left.Set(10, 0f);
9962
currentShopName.Top.Set(8, 0f);
10063
currentShopName.OnLeftClick += new MouseEvent(ShopButtonClicked);
@@ -109,33 +72,49 @@ public override void OnInitialize()
10972
Append(shopPanel);
11073
}
11174

112-
public void UpdateShopName() =>
113-
currentShopName.SetText(shopNames[CurrentShopIndex]);
75+
public void UpdateShopName()
76+
{
77+
if (shops[CurrentMerchantID].Shops.Count == 0)
78+
{
79+
currentShopName.SetText("Shop");
80+
return;
81+
}
82+
83+
int shopIndex = shops[CurrentMerchantID].CycleIndex;
84+
85+
currentShopName.SetText(shops[CurrentMerchantID].Shops[shopIndex]);
86+
}
11487

11588
void CycleShopButtonClicked(UIMouseEvent evt, UIElement listeningElement)
11689
{
11790
ShiftShop();
11891
UpdateShopName();
119-
OpenShop();
92+
OpenShop(shops[CurrentMerchantID].CycleIndex);
12093
}
12194

12295
void ShiftShop()
12396
{
124-
if (shops[CurrentShopIndex].Shops.Count == 0) return; // Safe Guard
125-
if (ShopCycleIndexes[CurrentShopIndex] >= shops[CurrentShopIndex].Shops.Count - 1)
97+
if (shops[CurrentMerchantID].Shops.Count == 0) return; // Safe Guard
98+
if (shops[CurrentMerchantID].CycleIndex >= shops[CurrentMerchantID].Shops.Count - 1)
12699
{
127-
shopNames[CurrentShopIndex] = shops[CurrentShopIndex].Shops[0];
128-
ShopCycleIndexes[CurrentShopIndex] = 0;
100+
shops[CurrentMerchantID].CycleIndex = 0;
129101
}
130102
else
131103
{
132-
shopNames[CurrentShopIndex] = shops[CurrentShopIndex].Shops[++ShopCycleIndexes[CurrentShopIndex]];
104+
shops[CurrentMerchantID].CycleIndex++;
133105
}
134106
}
135107

136108
void ShopButtonClicked(UIMouseEvent evt, UIElement listeningElement) =>
137-
OpenShop();
109+
OpenShop(0);
138110

139-
void OpenShop() =>
140-
shops[CurrentShopIndex].OpenShop(shopNames[CurrentShopIndex]);
111+
void OpenShop(int shopIndex)
112+
{
113+
string shopToOpen = "";
114+
115+
if (shops[CurrentMerchantID].Shops.Count != 0)
116+
shopToOpen = shops[CurrentMerchantID].Shops[shopIndex];
117+
118+
shops[CurrentMerchantID].OpenShop(shopToOpen);
119+
}
141120
}

UI/UIEvents.cs

Lines changed: 9 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,26 @@ namespace MerchantsPlus.UI;
44

55
internal class UIEvents : GlobalNPC
66
{
7-
static NPC currentNPC;
7+
static NPC currentNPC = null;
88

99
public override void GetChat(NPC npc, ref string chat)
1010
{
1111
// Do not change shop if the player is talking to the same NPC
12+
bool sameNPC = npc.type == currentNPC?.type;
13+
1214
// Do not change shop if not talking to a NPC
15+
bool notTalkingToNPC = !Utils.TalkingToNPC();
16+
1317
// Do not change shop if this is not a shop NPC
14-
if (npc == currentNPC || !Utils.TalkingToNPC() || !IsShopNPC(npc))
18+
bool notShopNPC = !IsShopNPC(npc);
19+
20+
if (sameNPC || notTalkingToNPC || notShopNPC)
1521
return;
1622

1723
currentNPC = npc;
1824
SetShopIndex(npc);
1925
//Main.NewText("Showing shop ui for " + npc.FullName);
2026
ModContent.GetInstance<ModifyUI>().ShowShopUI();
21-
22-
// Reset shop category index
23-
ShopUI.ShopCycleIndexes[ShopUI.CurrentShopIndex] = 0;
2427
}
2528

2629
static bool IsShopNPC(NPC npc) => npc.type switch
@@ -55,107 +58,6 @@ NPCID.WitchDoctor or
5558

5659
static void SetShopIndex(NPC npc)
5760
{
58-
switch (npc.type)
59-
{
60-
case NPCID.Angler:
61-
ShopUI.CurrentShopIndex = ShopUI.ANGLER;
62-
break;
63-
64-
case NPCID.ArmsDealer:
65-
ShopUI.CurrentShopIndex = ShopUI.ARMSDEALER;
66-
break;
67-
68-
case NPCID.Clothier:
69-
ShopUI.CurrentShopIndex = ShopUI.CLOTHIER;
70-
break;
71-
72-
case NPCID.Cyborg:
73-
ShopUI.CurrentShopIndex = ShopUI.CYBORG;
74-
break;
75-
76-
case NPCID.Demolitionist:
77-
ShopUI.CurrentShopIndex = ShopUI.DEMOLITIONIST;
78-
break;
79-
80-
case NPCID.Dryad:
81-
ShopUI.CurrentShopIndex = ShopUI.DRYAD;
82-
break;
83-
84-
case NPCID.DyeTrader:
85-
ShopUI.CurrentShopIndex = ShopUI.DYETRADER;
86-
break;
87-
88-
case NPCID.GoblinTinkerer:
89-
ShopUI.CurrentShopIndex = ShopUI.GOBLINTINKERER;
90-
break;
91-
92-
case NPCID.Guide:
93-
ShopUI.CurrentShopIndex = ShopUI.GUIDE;
94-
break;
95-
96-
case NPCID.Mechanic:
97-
ShopUI.CurrentShopIndex = ShopUI.MECHANIC;
98-
break;
99-
100-
case NPCID.Merchant:
101-
ShopUI.CurrentShopIndex = ShopUI.MERCHANT;
102-
break;
103-
104-
case NPCID.Nurse:
105-
ShopUI.CurrentShopIndex = ShopUI.NURSE;
106-
break;
107-
108-
case NPCID.Painter:
109-
ShopUI.CurrentShopIndex = ShopUI.PAINTER;
110-
break;
111-
112-
case NPCID.PartyGirl:
113-
ShopUI.CurrentShopIndex = ShopUI.PARTYGIRL;
114-
break;
115-
116-
case NPCID.Pirate:
117-
ShopUI.CurrentShopIndex = ShopUI.PIRATE;
118-
break;
119-
120-
case NPCID.SantaClaus:
121-
ShopUI.CurrentShopIndex = ShopUI.SANTACLAUS;
122-
break;
123-
124-
case NPCID.SkeletonMerchant:
125-
ShopUI.CurrentShopIndex = ShopUI.SKELETONMERCHANT;
126-
break;
127-
128-
case NPCID.Steampunker:
129-
ShopUI.CurrentShopIndex = ShopUI.STEAMPUNKER;
130-
break;
131-
132-
case NPCID.Stylist:
133-
ShopUI.CurrentShopIndex = ShopUI.STYLIST;
134-
break;
135-
136-
case NPCID.DD2Bartender:
137-
ShopUI.CurrentShopIndex = ShopUI.TAVERNKEEP;
138-
break;
139-
140-
case NPCID.TaxCollector:
141-
ShopUI.CurrentShopIndex = ShopUI.TAXCOLLECTOR;
142-
break;
143-
144-
case NPCID.TravellingMerchant:
145-
ShopUI.CurrentShopIndex = ShopUI.TRAVELLINGMERCHANT;
146-
break;
147-
148-
case NPCID.Truffle:
149-
ShopUI.CurrentShopIndex = ShopUI.TRUFFLE;
150-
break;
151-
152-
case NPCID.WitchDoctor:
153-
ShopUI.CurrentShopIndex = ShopUI.WITCHDOCTOR;
154-
break;
155-
156-
case NPCID.Wizard:
157-
ShopUI.CurrentShopIndex = ShopUI.WIZARD;
158-
break;
159-
}
61+
ShopUI.CurrentMerchantID = npc.type;
16062
}
16163
}

build.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
author = valkyrienyanko
2-
version = 0.21.7
2+
version = 0.21.8
33
displayName = MerchantsPlus
44
homepage = https://discord.gg/866cg8yfxZ
55
buildIgnore = *.csproj, *.user, obj\*, bin\*, .vs\*

0 commit comments

Comments
 (0)