1
+ using System . Text ;
2
+ using CounterStrikeSharp . API . Core ;
3
+ using CounterStrikeSharp . API . Core . Translations ;
4
+ using CS2ScreenMenuAPI ;
5
+ using CS2ScreenMenuAPI . Interfaces ;
6
+ using CS2ScreenMenuAPI . Internal ;
7
+ using static Store . Config_Config ;
8
+ using static Store . Store ;
9
+ using static StoreApi . Store ;
10
+
11
+ namespace Store ;
12
+
13
+ public static class WorldTextMenu
14
+ {
15
+ public static void AddMenuOption ( CCSPlayerController player , ScreenMenu menu , Action < CCSPlayerController , IMenuOption > onSelect , bool disabled , string display , params object [ ] args )
16
+ {
17
+ using ( new WithTemporaryCulture ( player . GetLanguage ( ) ) )
18
+ {
19
+ StringBuilder builder = new ( ) ;
20
+ builder . AppendFormat ( Instance . Localizer [ display , args ] ) ;
21
+
22
+ menu . AddOption ( builder . ToString ( ) , onSelect , disabled ) ;
23
+ }
24
+ }
25
+
26
+ public static void DisplayStore ( CCSPlayerController player , bool inventory )
27
+ {
28
+ using ( new WithTemporaryCulture ( player . GetLanguage ( ) ) )
29
+ {
30
+ StringBuilder builder = new ( ) ;
31
+ builder . AppendFormat ( Instance . Localizer [ "menu_store<title>" , Credits . Get ( player ) ] ) ;
32
+
33
+ ScreenMenu menu = new ( builder . ToString ( ) , Instance )
34
+ {
35
+ IsSubMenu = false ,
36
+ } ;
37
+
38
+ foreach ( KeyValuePair < string , Dictionary < string , Dictionary < string , string > > > category in Instance . Config . Items )
39
+ {
40
+ if ( inventory && ! category . Value . Values . Any ( item => Item . PlayerHas ( player , item [ "type" ] , item [ "uniqueid" ] , false ) ) )
41
+ {
42
+ continue ;
43
+ }
44
+
45
+ StringBuilder builderkey = new ( ) ;
46
+ builderkey . AppendFormat ( Instance . Localizer [ $ "menu_store<{ category . Key } >"] ) ;
47
+
48
+ menu . AddOption ( builderkey . ToString ( ) , ( CCSPlayerController player , IMenuOption option ) =>
49
+ {
50
+ player . ExecuteClientCommand ( $ "play { Config . Menu . MenuPressSoundYes } ") ;
51
+ DisplayItems ( player , builderkey . ToString ( ) , category . Value , inventory , menu ) ;
52
+ } ) ;
53
+ }
54
+
55
+ MenuAPI . OpenMenu ( Instance , player , menu ) ;
56
+ }
57
+ }
58
+
59
+ public static void DisplayItems ( CCSPlayerController player , string key , Dictionary < string , Dictionary < string , string > > items , bool inventory , ScreenMenu parentMenu )
60
+ {
61
+ Dictionary < string , Dictionary < string , string > > playerSkinItems = items . Where ( p => p . Value [ "type" ] == "playerskin" && p . Value [ "enable" ] == "true" ) . ToDictionary ( p => p . Key , p => p . Value ) ;
62
+
63
+ if ( playerSkinItems . Count != 0 )
64
+ {
65
+ ScreenMenu menu = new ( key , Instance )
66
+ {
67
+ IsSubMenu = true ,
68
+ ParentMenu = parentMenu
69
+ } ;
70
+
71
+ foreach ( int Slot in new [ ] { 1 , 2 , 3 } )
72
+ {
73
+ if ( ! Menu . IsAnyItemExistInPlayerSkins ( player , Slot , inventory , playerSkinItems ) )
74
+ {
75
+ continue ;
76
+ }
77
+
78
+ using ( new WithTemporaryCulture ( player . GetLanguage ( ) ) )
79
+ {
80
+ StringBuilder builder = new ( ) ;
81
+ builder . AppendFormat ( Instance . Localizer [ $ "menu_store<{ ( Slot == 1 ? "all" : Slot == 2 ? "t" : "ct" ) } _title>"] ) ;
82
+
83
+ menu . AddOption ( builder . ToString ( ) , ( CCSPlayerController player , IMenuOption option ) =>
84
+ {
85
+ player . ExecuteClientCommand ( $ "play { Config . Menu . MenuPressSoundYes } ") ;
86
+ DisplayItem ( player , inventory , builder . ToString ( ) , playerSkinItems . Where ( p => p . Value . TryGetValue ( "slot" , out string ? slot ) && ! string . IsNullOrEmpty ( slot ) && int . Parse ( p . Value [ "slot" ] ) == Slot ) . ToDictionary ( p => p . Key , p => p . Value ) , menu ) ;
87
+ } ) ;
88
+ }
89
+ }
90
+ MenuAPI . OpenSubMenu ( Instance , player , menu ) ;
91
+ }
92
+ else
93
+ {
94
+ DisplayItem ( player , inventory , key , items , parentMenu ) ;
95
+ }
96
+ }
97
+
98
+ public static void DisplayItem ( CCSPlayerController player , bool inventory , string key , Dictionary < string , Dictionary < string , string > > items , ScreenMenu parentMenu )
99
+ {
100
+ ScreenMenu menu = new ( key , Instance )
101
+ {
102
+ IsSubMenu = true ,
103
+ ParentMenu = parentMenu
104
+ } ;
105
+
106
+ foreach ( KeyValuePair < string , Dictionary < string , string > > kvp in items )
107
+ {
108
+ Dictionary < string , string > item = kvp . Value ;
109
+
110
+ if ( item [ "enable" ] != "true" || ! Menu . CheckFlag ( player , item ) )
111
+ {
112
+ continue ;
113
+ }
114
+
115
+ if ( inventory && ! Item . PlayerHas ( player , item [ "type" ] , item [ "uniqueid" ] , false ) )
116
+ {
117
+ continue ;
118
+ }
119
+
120
+ if ( Item . PlayerHas ( player , item [ "type" ] , item [ "uniqueid" ] , false ) )
121
+ {
122
+ AddMenuOption ( player , menu , ( player , option ) =>
123
+ {
124
+ player . ExecuteClientCommand ( $ "play { Config . Menu . MenuPressSoundYes } ") ;
125
+ DisplayItemOption ( player , item , parentMenu ) ;
126
+ } , false , item [ "name" ] ) ;
127
+ }
128
+ else if ( ! inventory && ! item . IsHidden ( ) )
129
+ {
130
+ if ( int . Parse ( item [ "price" ] ) <= 0 )
131
+ {
132
+ AddMenuOption ( player , menu , ( player , option ) => SelectPurchase ( player , item , false , parentMenu ) , false , "menu_store<purchase1>" , item [ "name" ] ) ;
133
+ }
134
+ else
135
+ {
136
+ AddMenuOption ( player , menu , ( player , option ) => SelectPurchase ( player , item , true , parentMenu ) , false , "menu_store<purchase>" , item [ "name" ] , item [ "price" ] ) ;
137
+ }
138
+ }
139
+ }
140
+
141
+ MenuAPI . OpenSubMenu ( Instance , player , menu ) ;
142
+ }
143
+
144
+ private static void SelectPurchase ( CCSPlayerController player , Dictionary < string , string > item , bool confirm , ScreenMenu parentMenu )
145
+ {
146
+ if ( confirm && Config . Menu . EnableConfirmMenu )
147
+ {
148
+ player . ExecuteClientCommand ( $ "play { Config . Menu . MenuPressSoundYes } ") ;
149
+ DisplayConfirmationMenu ( player , item , parentMenu ) ;
150
+ }
151
+ else
152
+ {
153
+ if ( Item . Purchase ( player , item ) )
154
+ {
155
+ player . ExecuteClientCommand ( $ "play { Config . Menu . MenuPressSoundYes } ") ;
156
+ DisplayItemOption ( player , item , parentMenu ) ;
157
+ }
158
+ else
159
+ {
160
+ player . ExecuteClientCommand ( $ "play { Config . Menu . MenuPressSoundNo } ") ;
161
+ MenuAPI . CloseActiveMenu ( player ) ;
162
+ }
163
+ }
164
+ }
165
+
166
+ public static void DisplayItemOption ( CCSPlayerController player , Dictionary < string , string > item , ScreenMenu parentMenu )
167
+ {
168
+ ScreenMenu menu = new ( item [ "name" ] , Instance )
169
+ {
170
+ IsSubMenu = true ,
171
+ ParentMenu = parentMenu
172
+ } ;
173
+
174
+ if ( Item . PlayerUsing ( player , item [ "type" ] , item [ "uniqueid" ] ) )
175
+ {
176
+ AddMenuOption ( player , menu , ( player , option ) =>
177
+ {
178
+ player . ExecuteClientCommand ( $ "play { Config . Menu . MenuPressSoundYes } ") ;
179
+ Item . Unequip ( player , item , true ) ;
180
+
181
+ player . PrintToChatMessage ( "Purchase Unequip" , item [ "name" ] ) ;
182
+
183
+ DisplayItemOption ( player , item , parentMenu ) ;
184
+ } , false , "menu_store<unequip>" ) ;
185
+ }
186
+ else
187
+ {
188
+ AddMenuOption ( player , menu , ( player , option ) =>
189
+ {
190
+ player . ExecuteClientCommand ( $ "play { Config . Menu . MenuPressSoundYes } ") ;
191
+ Item . Equip ( player , item ) ;
192
+
193
+ player . PrintToChatMessage ( "Purchase Equip" , item [ "name" ] ) ;
194
+
195
+ DisplayItemOption ( player , item , parentMenu ) ;
196
+ } , false , "menu_store<equip>" ) ;
197
+ }
198
+
199
+ Store_Item ? PlayerItems = Instance . GlobalStorePlayerItems . FirstOrDefault ( p => p . SteamID == player . SteamID && p . Type == item [ "type" ] && p . UniqueId == item [ "uniqueid" ] ) ;
200
+
201
+ if ( Config . Menu . EnableSelling && ! Item . IsPlayerVip ( player ) )
202
+ {
203
+ float sell_ratio = Config . Settings . SellRatio ;
204
+
205
+ int purchase_price = 1 ;
206
+
207
+ bool usePurchaseCredit = Config . Settings . SellUsePurchaseCredit ;
208
+
209
+ if ( usePurchaseCredit && PlayerItems != null )
210
+ {
211
+ purchase_price = PlayerItems . Price ;
212
+ }
213
+
214
+ int sellingPrice = ( int ) ( ( usePurchaseCredit ? purchase_price : int . Parse ( item [ "price" ] ) ) * sell_ratio ) ;
215
+
216
+ if ( sellingPrice > 1 )
217
+ {
218
+ AddMenuOption ( player , menu , ( player , option ) =>
219
+ {
220
+ player . ExecuteClientCommand ( $ "play { Config . Menu . MenuPressSoundYes } ") ;
221
+ Item . Sell ( player , item ) ;
222
+
223
+ player . PrintToChatMessage ( "Item Sell" , item [ "name" ] ) ;
224
+
225
+ MenuAPI . CloseActiveMenu ( player ) ;
226
+ } , false , "menu_store<sell>" , sellingPrice ) ;
227
+ }
228
+ }
229
+
230
+ if ( PlayerItems != null && PlayerItems . DateOfExpiration > DateTime . MinValue )
231
+ {
232
+ menu . AddOption ( PlayerItems . DateOfExpiration . ToString ( ) , ( p , o ) => { } , true ) ;
233
+ }
234
+ MenuAPI . OpenSubMenu ( Instance , player , menu ) ;
235
+ }
236
+
237
+ public static void DisplayConfirmationMenu ( CCSPlayerController player , Dictionary < string , string > item , ScreenMenu parentMenu )
238
+ {
239
+ ScreenMenu menu = new ( Instance . Localizer [ "menu_store<confirm_title>" ] , Instance )
240
+ {
241
+ IsSubMenu = true ,
242
+ ParentMenu = parentMenu
243
+ } ;
244
+
245
+ AddMenuOption ( player , menu , ( p , o ) => { } , true , "menu_store<confirm_item>" , item [ "name" ] , item [ "price" ] ) ;
246
+
247
+ AddMenuOption ( player , menu , ( p , o ) =>
248
+ {
249
+ if ( Item . Purchase ( p , item ) )
250
+ {
251
+ player . ExecuteClientCommand ( $ "play { Config . Menu . MenuPressSoundYes } ") ;
252
+ DisplayItemOption ( p , item , parentMenu ) ;
253
+ }
254
+ else
255
+ {
256
+ MenuAPI . CloseActiveMenu ( player ) ;
257
+ player . ExecuteClientCommand ( $ "play { Config . Menu . MenuPressSoundNo } ") ;
258
+ }
259
+
260
+ } , false , "menu_store<yes>" ) ;
261
+
262
+ AddMenuOption ( player , menu , ( p , o ) =>
263
+ {
264
+ player . ExecuteClientCommand ( $ "play { Config . Menu . MenuPressSoundNo } ") ;
265
+ MenuAPI . CloseActiveMenu ( player ) ;
266
+ } , false , "menu_store<no>" ) ;
267
+
268
+ MenuAPI . OpenSubMenu ( Instance , player , menu ) ;
269
+ }
270
+ }
0 commit comments