11using MerchantsPlus . Merchants ;
22using Terraria . GameContent . UI . Elements ;
3+ using Terraria . ID ;
34
45namespace MerchantsPlus . UI ;
56
7+ // This UI will appear when a new dialog is opened with a merchant
68internal 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}
0 commit comments