-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cs
More file actions
331 lines (302 loc) · 14.5 KB
/
Main.cs
File metadata and controls
331 lines (302 loc) · 14.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
using Life;
using Life.BizSystem;
using Life.Network;
using Life.UI;
using Mirror;
using ModKit.Helper;
using ModKit.Interfaces;
using ModKit.Internal;
using ModKit.ORM;
using JobBus.Classes;
using JobBus.Functions;
using Newtonsoft.Json;
using SQLite;
using System.Collections.Generic;
using System.IO;
using _menu = AAMenu.Menu;
namespace JobBus.Main
{
class Main : ModKit.ModKit
{
public LineCreator LineCreator = new LineCreator();
public LinePlayable LinePlayable = new LinePlayable();
public DataManager DataManager = new DataManager();
public LineViewer LineViewer = new LineViewer();
public static string ConfigDirectoryPath;
public static string ConfigJobBusPath;
public static JobBusConfig _JobBusConfig;
public Main(IGameAPI api) : base(api)
{
PluginInformations = new PluginInformations(AssemblyHelper.GetName(), "1.0.0", "Loicsmith");
LineCreator.Context = this;
LinePlayable.Context = this;
DataManager.Context = this;
LineViewer.Context = this;
}
public override void OnPluginInit()
{
base.OnPluginInit();
Logger.LogSuccess($"{PluginInformations.SourceName} v{PluginInformations.Version}", "initialisé");
InitAAmenu();
Orm.RegisterTable<OrmManager.JobBus_LineManager>();
Orm.RegisterTable<OrmManager.JobBus_BusStopManager>();
InitConfig();
_JobBusConfig = LoadConfigFile(ConfigJobBusPath);
Nova.server.OnPlayerDisconnectEvent += (NetworkConnection conn) =>
{
LinePlayable.RemoveNetIDFromList(conn.connectionId);
};
}
private void InitConfig()
{
try
{
ConfigDirectoryPath = DirectoryPath + "/JobBus";
ConfigJobBusPath = Path.Combine(ConfigDirectoryPath, "JobBusConfig.json");
if (!Directory.Exists(ConfigDirectoryPath)) Directory.CreateDirectory(ConfigDirectoryPath);
if (!File.Exists(ConfigJobBusPath)) InitBusJobConfig();
}
catch (IOException ex)
{
Logger.LogError("InitDirectory", ex.Message);
}
}
private void InitBusJobConfig()
{
JobBusConfig JobBusConfig = new JobBusConfig();
string json = JsonConvert.SerializeObject(JobBusConfig, Formatting.Indented);
File.WriteAllText(ConfigJobBusPath, json);
}
private JobBusConfig LoadConfigFile(string path)
{
if (File.Exists(path))
{
string jsonContent = File.ReadAllText(path);
JobBusConfig JobBusConfig = JsonConvert.DeserializeObject<JobBusConfig>(jsonContent);
return JobBusConfig;
}
else return null;
}
private void SaveConfig(string path)
{
string json = JsonConvert.SerializeObject(_JobBusConfig, Formatting.Indented);
File.WriteAllText(path, json);
}
public void ConfigEditor(Player player)
{
Panel panel = PanelHelper.Create("JobBus | Config JSON", UIPanel.PanelType.TabPrice, player, () => ConfigEditor(player));
panel.AddTabLine($"{TextFormattingHelper.Color("CityHallId : ", TextFormattingHelper.Colors.Info)}" + $"{TextFormattingHelper.Color($"{_JobBusConfig.CityHallId}", TextFormattingHelper.Colors.Verbose)}", _ =>
{
EditLineInConfig(player, "CityHallId");
});
panel.AddTabLine($"{TextFormattingHelper.Color("TaxPercentage : ", TextFormattingHelper.Colors.Info)}" + $"{TextFormattingHelper.Color($"{_JobBusConfig.TaxPercentage}", TextFormattingHelper.Colors.Verbose)}", _ =>
{
EditLineInConfig(player, "TaxPercentage");
});
panel.AddTabLine($"{TextFormattingHelper.Color("PlayerReceivePercentage : ", TextFormattingHelper.Colors.Info)}" + $"{TextFormattingHelper.Color($"{_JobBusConfig.PlayerReceivePercentage}", TextFormattingHelper.Colors.Verbose)}", _ =>
{
EditLineInConfig(player, "PlayerReceivePercentage");
});
panel.AddTabLine($"{TextFormattingHelper.Color("MinCustomerPerBusStop : ", TextFormattingHelper.Colors.Info)}" + $"{TextFormattingHelper.Color($"{_JobBusConfig.MinCustomerPerBusStop}", TextFormattingHelper.Colors.Verbose)}", _ =>
{
EditLineInConfig(player, "MinCustomerPerBusStop");
});
panel.AddTabLine($"{TextFormattingHelper.Color("MaxCustomerPerBusStop : ", TextFormattingHelper.Colors.Info)}" + $"{TextFormattingHelper.Color($"{_JobBusConfig.MaxCustomerPerBusStop}", TextFormattingHelper.Colors.Verbose)}", _ =>
{
EditLineInConfig(player, "MaxCustomerPerBusStop");
});
panel.AddTabLine($"{TextFormattingHelper.Color("MinMoneyPerCustomer : ", TextFormattingHelper.Colors.Info)}" + $"{TextFormattingHelper.Color($"{_JobBusConfig.MinMoneyPerCustomer}", TextFormattingHelper.Colors.Verbose)}", _ =>
{
EditLineInConfig(player, "MinMoneyPerCustomer");
});
panel.AddTabLine($"{TextFormattingHelper.Color("MaxMoneyPerCustomer : ", TextFormattingHelper.Colors.Info)}" + $"{TextFormattingHelper.Color($"{_JobBusConfig.MaxMoneyPerCustomer}", TextFormattingHelper.Colors.Verbose)}", _ =>
{
EditLineInConfig(player, "MaxMoneyPerCustomer");
});
panel.AddTabLine($"{TextFormattingHelper.Color("TicketHeure : ", TextFormattingHelper.Colors.Info)}" + $"{TextFormattingHelper.Color($"{_JobBusConfig.TicketHeure}", TextFormattingHelper.Colors.Verbose)}", _ =>
{
EditLineInConfig(player, "TicketHeure");
});
panel.AddTabLine($"{TextFormattingHelper.Color("TicketJournée : ", TextFormattingHelper.Colors.Info)}" + $"{TextFormattingHelper.Color($"{_JobBusConfig.TicketJournée}", TextFormattingHelper.Colors.Verbose)}", _ =>
{
EditLineInConfig(player, "TicketJournée");
});
panel.AddTabLine($"{TextFormattingHelper.Color("TicketMensuel : ", TextFormattingHelper.Colors.Info)}" + $"{TextFormattingHelper.Color($"{_JobBusConfig.TicketMensuel}", TextFormattingHelper.Colors.Verbose)}", _ =>
{
EditLineInConfig(player, "TicketMensuel");
});
panel.AddTabLine($"{TextFormattingHelper.Color("UrlWebhookForNotifyService (prochaine maj)", TextFormattingHelper.Colors.Info)}", _ =>
{
EditLineInConfig(player, "UrlWebhookForNotifyService");
});
panel.AddTabLine($"{TextFormattingHelper.Color("Appliquer la configuration", TextFormattingHelper.Colors.Success)}", _ =>
{
SaveConfig(ConfigJobBusPath);
panel.Refresh();
});
panel.NextButton("Sélectionner", () => panel.SelectTab());
panel.AddButton("Retour", _ => AAMenu.AAMenu.menu.AdminPluginPanel(player));
panel.CloseButton();
panel.Display();
}
public void EditLineInConfig(Player player, string Param)
{
Panel panel = PanelHelper.Create("JobBus | Edit JSON", UIPanel.PanelType.Input, player, () => EditLineInConfig(player, Param));
panel.TextLines.Add($"Modification de la valeur de : \"{Param}\"");
panel.SetInputPlaceholder("Veuillez saisir une valeur");
panel.AddButton("Valider", (ui) =>
{
string input = ui.inputText;
switch (Param)
{
case "CityHallId":
// int
if (int.TryParse(input, out int valueCity))
{
_JobBusConfig.CityHallId = valueCity;
}
else
{
player.Notify("JobBus", "Veuillez saisir un nombre entier.", NotificationManager.Type.Error);
}
break;
case "TaxPercentage":
// double
if (float.TryParse(input, out float valueTax))
{
_JobBusConfig.TaxPercentage = valueTax;
}
else
{
player.Notify("JobBus", "Veuillez saisir un nombre valide.", NotificationManager.Type.Error);
}
break;
case "PlayerReceivePercentage":
// double
if (float.TryParse(input, out float valueTaxPlayer))
{
_JobBusConfig.PlayerReceivePercentage = valueTaxPlayer;
}
else
{
player.Notify("JobBus", "Veuillez saisir un nombre valide.", NotificationManager.Type.Error);
}
break;
case "MinCustomerPerBusStop":
// int
if (int.TryParse(input, out int valueMinCustomer))
{
_JobBusConfig.MinCustomerPerBusStop = valueMinCustomer;
}
else
{
player.Notify("JobBus", "Veuillez saisir un nombre entier.", NotificationManager.Type.Error);
}
break;
case "MaxCustomerPerBusStop":
// int
if (int.TryParse(input, out int valueMaxCustomer))
{
_JobBusConfig.MaxCustomerPerBusStop = valueMaxCustomer;
}
else
{
player.Notify("JobBus", "Veuillez saisir un nombre entier.", NotificationManager.Type.Error);
}
_JobBusConfig.MaxCustomerPerBusStop = int.Parse(input);
break;
case "MinMoneyPerCustomer":
//float
if (float.TryParse(input, out float valueMinMoney))
{
_JobBusConfig.MinMoneyPerCustomer = valueMinMoney;
}
else
{
player.Notify("JobBus", "Veuillez saisir un nombre valide .", NotificationManager.Type.Error);
}
break;
case "MaxMoneyPerCustomer":
//float
if (float.TryParse(input, out float valueMaxMoney))
{
_JobBusConfig.MaxMoneyPerCustomer = valueMaxMoney;
}
else
{
player.Notify("JobBus", "Veuillez saisir un nombre valide.", NotificationManager.Type.Error);
}
break;
case "TicketHeure":
//float
if (double.TryParse(input, out double valueTicketHeure))
{
_JobBusConfig.TicketHeure = valueTicketHeure;
}
else
{
player.Notify("JobBus", "Veuillez saisir un nombre valide.", NotificationManager.Type.Error);
}
break;
case "TicketJournée":
//float
if (double.TryParse(input, out double valueTicketJournée))
{
_JobBusConfig.TicketJournée = valueTicketJournée;
}
else
{
player.Notify("JobBus", "Veuillez saisir un nombre valide.", NotificationManager.Type.Error);
}
break;
case "TicketMensuel":
//float
if (double.TryParse(input, out double valueTicketMensuel))
{
_JobBusConfig.TicketMensuel = valueTicketMensuel;
}
else
{
player.Notify("JobBus", "Veuillez saisir un nombre valide.", NotificationManager.Type.Error);
}
break;
case "UrlWebhookForNotifyService":
_JobBusConfig.UrlWebhookForNotifyService = input;
break;
}
panel.Previous();
});
panel.PreviousButton();
panel.CloseButton();
panel.Display();
}
public void InitAAmenu()
{
_menu.AddAdminPluginTabLine(PluginInformations, 0, "JobBus", (ui) =>
{
Player player = PanelHelper.ReturnPlayerFromPanel(ui);
ConfigEditor(player);
});
_menu.AddBizTabLine(PluginInformations, new List<Activity.Type> { Activity.Type.Bus }, null, "Utiliser SAE", (ui) =>
{
Player player = PanelHelper.ReturnPlayerFromPanel(ui);
LinePlayable.MainPanel(player);
});
_menu.AddAdminTabLine(PluginInformations, 5, $"{TextFormattingHelper.Color("LineCreator - JobBus", TextFormattingHelper.Colors.Grey)}", (ui) =>
{
Player player = PanelHelper.ReturnPlayerFromPanel(ui);
LineCreator.MainPanel(player);
});
_menu.AddProximityTabLine(PluginInformations, 1012, "Arrêt de bus - Informations voyageurs", (ui) =>
{
Player player = PanelHelper.ReturnPlayerFromPanel(ui);
LineViewer.MainPanel(player);
});
_menu.AddProximityTabLine(PluginInformations, 1172, "Arrêt de bus - Informations voyageurs", (ui) =>
{
Player player = PanelHelper.ReturnPlayerFromPanel(ui);
LineViewer.MainPanel(player);
});
}
}
}