forked from Oonej/ChaosHelper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPluginCore.cs
More file actions
1165 lines (961 loc) · 49.7 KB
/
PluginCore.cs
File metadata and controls
1165 lines (961 loc) · 49.7 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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.IO;
using System.Collections.Generic;
using System.Collections;
using Decal.Adapter;
using Decal.Adapter.Wrappers;
using MyClasses.MetaViewWrappers;
using VirindiViewService.Controls;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Text.RegularExpressions;
using ChaosHelper.VirindiControlExtensions;
/*
* Created by Mag-nus. 8/19/2011, VVS added by Virindi-Inquisitor.
*
* No license applied, feel free to use as you wish. H4CK TH3 PL4N3T? TR45H1NG 0UR R1GHT5? Y0U D3C1D3!
*
* Notice how I use try/catch on every function that is called or raised by decal (by base events or user initiated events like buttons, etc...).
* This is very important. Don't crash out your users!
*
* In 2.9.6.4+ Host and Core both have Actions objects in them. They are essentially the same thing.
* You sould use Host.Actions though so that your code compiles against 2.9.6.0 (even though I reference 2.9.6.5 in this project)
*
* If you add this plugin to decal and then also create another plugin off of this sample, you will need to change the guid in
* Properties/AssemblyInfo.cs to have both plugins in decal at the same time.
*
* If you have issues compiling, remove the Decal.Adapater and VirindiViewService references and add the ones you have locally.
* Decal.Adapter should be in C:\Games\Decal 3.0\
* VirindiViewService should be in C:\Games\VirindiPlugins\VirindiViewService\
*/
namespace ChaosHelper
{
//Attaches events from core
[WireUpBaseEvents]
// FriendlyName is the name that will show up in the plugins list of the decal agent (the one in windows, not in-game)
// View is the path to the xml file that contains info on how to draw our in-game plugin. The xml contains the name and icon our plugin shows in-game.
// The view here is SamplePlugin.mainView.xml because our projects default namespace is SamplePlugin, and the file name is mainView.xml.
// The other key here is that mainView.xml must be included as an embeded resource. If its not, your plugin will not show up in-game.
[FriendlyName("ChaosHelper")]
public class PluginCore : PluginBase
{
private static PluginCore _Instance = null;
public static PluginCore Instance { get { return _Instance; } }
private VirindiViewService.ViewProperties properties;
private VirindiViewService.ControlGroup controls;
private VirindiViewService.HudView view;
private string chatLoc = "";
public HudTextBox ChatCommand { get; private set; }
public HudStaticText VersionLbl { get; private set; }
public HudCombo ConfigChoice { get; private set; }
public HudButton SetChatBtn { get; private set; }
public HudButton LoadConfigBtn { get; private set; }
public HudButton SaveDefaultsBtn { get; private set; }
public HudList popoutList { get; private set; }
public HudTabView TabView { get; private set; }
public int currentConfig = 0;
public int locx = 50, locy = 50;
public int startingW = 335, startingH = 200;
//Registered Dictionary of events
private Dictionary<string, EventHandler> popoutEvents = new Dictionary<string, EventHandler>();
private ArrayList sizes = new ArrayList();
private ArrayList locations = new ArrayList();
private Dictionary<string, PopoutWindow> popoutWindows = new Dictionary<string, PopoutWindow>();
/// <summary>
/// This is called when the plugin is started up. This happens only once.
/// </summary>
protected override void Startup()
{
try
{
_Instance = this;
Globals.Init("Chaos-Helper", Host, Core);
LoadWindow();
CommandLineText += new EventHandler<ChatParserInterceptEventArgs>(FilterCore_CommandLineText);
}
catch (Exception ex) { Util.LogError(ex); Util.WriteToChat(ex.Message); }
}
[BaseEvent("LoginComplete", "CharacterFilter")]
private void CharacterFilter_LoginComplete(object sender, EventArgs e)
{
try
{
LoadBaseXML(true, "");
LoadIni();
}
catch (Exception ex) { Util.LogError(ex); }
}
/// <summary>
/// This is called when the plugin is shut down. This happens only once.
/// </summary>
protected override void Shutdown()
{
try
{
CommandLineText -= new EventHandler<ChatParserInterceptEventArgs>(FilterCore_CommandLineText);
}
catch (Exception ex) { Util.LogError(ex); Util.WriteToChat(ex.Message); }
}
void LoadBaseXML(bool firstLoad, string configtoload)
{
if (firstLoad)
{
LoadListOfConfigs();
}
else
{
locx = view.Location.X;
locy = view.Location.Y;
currentConfig = ConfigChoice.Current;
chatLoc = ChatCommand.Text;
if (properties != null)
{
properties.Dispose();
}
if (controls != null)
{
controls.Dispose();
}
if (view != null)
{
view.Dispose();
}
foreach (string p in popoutWindows.Keys)
popoutWindows[p].Dispose();
popoutWindows.Clear();
sizes.Clear();
locations.Clear();
LoadWindow();
LoadListOfConfigs();
if(configtoload == "")
{
LoadConfig(((HudStaticText)ConfigChoice[currentConfig]).Text);
}
else
{
for (int i = 0; i < ConfigChoice.Count; i++)
{
if (((HudStaticText)ConfigChoice[i]).Text.Trim() == configtoload.Trim())
{
ConfigChoice.Current = i;
LoadConfig(((HudStaticText)ConfigChoice[i]).Text);
}
}
}
}
}
void LoadIni()
{
string[] ini = Util.GetIni();
foreach(string line in ini)
{
string[] col = line.Split(':');
if(line.Contains("default config"))
{
for (int i = 0; i < ConfigChoice.Count; i++)
{
if (((HudStaticText)ConfigChoice[i]).Text.Trim() == col[1].Trim())
{
ConfigChoice.Current = i;
LoadConfig(((HudStaticText)ConfigChoice[i]).Text);
}
}
}
else if(line.Contains("sendchatcommand"))
{
chatLoc = col[1];
ChatCommand.Text = col[1];
}
}
}
void LoadWindow()
{
// Create the view
VirindiViewService.XMLParsers.Decal3XMLParser parser = new VirindiViewService.XMLParsers.Decal3XMLParser();
parser.ParseFromResource("ChaosHelper.mainView.xml", out properties, out controls);
// Display the view
view = new VirindiViewService.HudView(properties, controls);
TabView = view != null ? (HudTabView)view["nbMain"] : new HudTabView();
ChatCommand = view != null ? (HudTextBox)view["ChatCommand"] : new HudTextBox();
ConfigChoice = view != null ? (HudCombo)view["ConfigFiles"] : new HudCombo(controls);
VersionLbl = view != null ? (HudStaticText)view["VersionLbl"] : new HudStaticText();
SetChatBtn = view != null ? (HudButton)view["ChatCommandSet"] : new HudButton();
LoadConfigBtn = view != null ? (HudButton)view["ReloadConfig"] : new HudButton();
SaveDefaultsBtn = view != null ? (HudButton)view["SaveIni"] : new HudButton();
popoutList = view != null ? (HudList)view["PopoutList"] : new HudList();
SetChatBtn.Hit += new EventHandler(ChatCommandSet_Click);
LoadConfigBtn.Hit += new EventHandler(ReloadConfig_Click);
SaveDefaultsBtn.Hit += new EventHandler(SaveIni_Click);
view.Location = new System.Drawing.Point(locx, locy);
TabView.OpenTabChange += new EventHandler(TabChanged);
VersionLbl.Text = "Version 2.2.6.1";
ChatCommand.Text = chatLoc;
}
void GenerateLayout(string layoutStyle)
{
string[] layout = Util.LoadLayout(layoutStyle);
try
{
int currentRow = 1;
int currentCol = 1;
int padding = 0;
int width = 0;
int height = 0;
int cols = 0;
int rows = 0;
HudFixedLayout tempLayout = new HudFixedLayout();
PopoutWindow tempPopoutwindow = new PopoutWindow();
int buttonWidth = 0;
int buttonHeight = 0;
string currentTab = "";
int button_count = 1;
startingW = 335;
startingH = 200;
view.ClientArea = new System.Drawing.Size(startingW, startingH);
foreach (string _line in layout)
{
string line = _line.Trim();
if (string.IsNullOrEmpty(line))
continue;
// trim comment
int commentIndex = line.IndexOf("~~");
if (commentIndex == -1)
commentIndex = line.IndexOf("//");
if (commentIndex != -1)
line = line.Substring(0, commentIndex).Trim();
// replace first colon (if exist) with whitespace (make it optional)
int colonIndex = line.IndexOf(':');
if (colonIndex != -1)
{
line = line.Remove(colonIndex, 1);
line = line.Insert(colonIndex, " ");
}
string directive;
string content;
// split directive out based on first whitespace
int sepIndex = line.IndexOfAny(new char[] { ' ', '\t' });
if (sepIndex == -1)
{
// only directive and no values?
directive = line;
content = string.Empty;
}
else
{
// isolate directive and content
directive = line.Substring(0, sepIndex).Trim();
content = line.Substring(sepIndex + 1).Trim();
}
// make sure we really landed on something
if (string.IsNullOrEmpty(directive))
continue;
// for simple [directive] [value] lines just compare a pre-lowercased version `simpleDirective`
// for complex directives where values are introduced in the first string (eg. Button_01) then parse using `directive`
string simpleDirective = directive.ToLowerInvariant();
if (simpleDirective == "windowposition")
{
string[] split = content.Split(',');
view.Location = new System.Drawing.Point(int.Parse(split[0]), int.Parse(split[1]));
}
else if (simpleDirective == "windowsize")
{
string[] split = content.Split(',');
startingW = int.Parse(split[0]);
startingH = int.Parse(split[1]);
view.ClientArea = new System.Drawing.Size(startingW, startingH);
}
else if (simpleDirective == "windowstartopen")
{
view.Visible = bool.Parse(content);
}
else if (simpleDirective == "buttonpadding")
{
padding = int.Parse(content);
}
else if (simpleDirective == "tab")
{
button_count = 1;
currentRow = 1;
currentCol = 1;
cols = 0;
rows = 0;
tempLayout = new HudFixedLayout();
tempPopoutwindow = new PopoutWindow();
tempLayout.InternalName = content;
currentTab = content;
popoutWindows.Add(content, tempPopoutwindow);
TabView.AddTab(tempLayout, content);
}
else if (simpleDirective == "tabvisible")
{
if (bool.Parse(content))
{
tempPopoutwindow.toggleVisibility();
}
}
else if (simpleDirective == "tabsize")
{
string[] split = content.Split(',');
width = int.Parse(split[0].Trim());
height = int.Parse(split[1].Trim());
sizes.Add(new System.Drawing.Size(width, height));
tempPopoutwindow.SetWindowSize(new System.Drawing.Size(width, height - 25));
}
else if (simpleDirective == "tabposition")
{
string[] split = content.Split(',');
int tabx = int.Parse(split[0].Trim());
int taby = int.Parse(split[1].Trim());
locations.Add(new System.Drawing.Point(tabx, taby));
tempPopoutwindow.SetWindowPos(new System.Drawing.Point(tabx, taby));
}
else if (simpleDirective == "cols")
{
cols = int.Parse(content.Trim());
buttonWidth = (int)((width - (padding * (1 + cols))) / cols);
}
else if (simpleDirective == "rows")
{
rows = int.Parse(content);
buttonHeight = (int)((height - (padding * (3 + rows))) / rows);
}
else
{
// OK doesnt seem like simple directive.. so either its totally bad, or its one we have to interpret
int span;// we will still have a span value.. so the following (optional) comma-seperated columns will just try to take place of .txt
// we may have columns of data
List<string> datCols = new List<string>(content.Split(','));
// if not, then make sure to put original value in here
if (datCols.Count == 0)
span = int.Parse(content);
else
{
// we have to put 1st entry into span, then condense the rest of the arguments list to be zero-based
span = int.Parse(datCols[0]);
datCols.RemoveAt(0);
}
// lets see what we have...
IChaosHudControl newMainControl = null;//only track main form control; when we register later we will use .Mirror
if (directive.IndexOf("ToggleButton", StringComparison.InvariantCultureIgnoreCase) != -1)//must check before regular Button
{
string defTextOff = null;
string defTextOn = null;
string defCommandOn = null;
string defCommandOff = null;
if (datCols.Count == 3)
{
defTextOff = datCols[0];
defCommandOn = datCols[1];
defCommandOff = datCols[2];
} else if(datCols.Count == 4)
{
defTextOff = datCols[0];
defTextOn = datCols[1];
defCommandOn = datCols[2];
defCommandOff = datCols[3];
}
if (string.IsNullOrEmpty(defTextOff))
defTextOff = currentTab + "_" + button_count.ToString("D2");
//Creates Button
ChaosHudToggleButton tempBtn = new ChaosHudToggleButton(defTextOff, defTextOn, defCommandOn, defCommandOff);
ChaosHudToggleButton tempPopBtn = new ChaosHudToggleButton(defTextOff, defTextOn, defCommandOn, defCommandOff);
tempBtn.MirrorToggleButton = tempPopBtn;
tempPopBtn.MirrorToggleButton = tempBtn;
tempBtn.InternalName = currentTab + "_ToggleButton_" + button_count.ToString("D2");
tempPopBtn.InternalName = currentTab + "_ToggleButton_" + button_count.ToString("D2");
newMainControl = tempBtn;
}
else if (directive.IndexOf("Button", StringComparison.InvariantCultureIgnoreCase) != -1)
{
string defText = null;
string defCommand = null;
string defParam = null;
if (datCols.Count > 0)
defText = datCols[0];
if (datCols.Count > 1)
defCommand = datCols[1];
if (datCols.Count > 2)
defParam = datCols[2];
if (string.IsNullOrEmpty(defText))
defText = currentTab + "_" + button_count.ToString("D2");
//Creates Button
ChaosHudButton tempBtn = new ChaosHudButton(defText, defCommand, defParam);
ChaosHudButton tempPopBtn = new ChaosHudButton(defText, defCommand, defParam);
tempBtn.MirrorButton = tempPopBtn;
tempPopBtn.MirrorButton = tempBtn;
tempBtn.InternalName = currentTab + "_Button_" + button_count.ToString("D2");
tempPopBtn.InternalName = currentTab + "_Button_" + button_count.ToString("D2");
newMainControl = tempBtn;
}
else if (directive.IndexOf("StaticText", StringComparison.InvariantCultureIgnoreCase) != -1)
{
string defText = null;
if (datCols.Count > 0)
defText = datCols[0];
if (string.IsNullOrEmpty(defText))
defText = currentTab + "_" + button_count.ToString("D2");
//Creates Button
ChaosHudStaticText tempBtn = new ChaosHudStaticText(defText);
ChaosHudStaticText tempPopBtn = new ChaosHudStaticText(defText);
tempBtn.MirrorStaticText = tempPopBtn;
tempPopBtn.MirrorStaticText = tempBtn;
tempBtn.TextAlignment = VirindiViewService.WriteTextFormats.Center | VirindiViewService.WriteTextFormats.VerticalCenter;
tempPopBtn.TextAlignment = VirindiViewService.WriteTextFormats.Center | VirindiViewService.WriteTextFormats.VerticalCenter;
tempBtn.InternalName = currentTab + "_StaticText_" + button_count.ToString("D2");
tempPopBtn.InternalName = currentTab + "_StaticText_" + button_count.ToString("D2");
newMainControl = tempBtn;
} else if (directive.IndexOf("CheckBox", StringComparison.InvariantCultureIgnoreCase) != -1)
{
string defText = null;
string defCommandOn = null;
string defCommandOff = null;
if (datCols.Count > 0)
defText = datCols[0];
if (datCols.Count > 1)
defCommandOn = datCols[1];
if (datCols.Count > 2)
defCommandOff = datCols[2];
if (string.IsNullOrEmpty(defText))
defText = currentTab + "_" + button_count.ToString("D2");
//Creates Button
ChaosHudCheckBox tempBtn = new ChaosHudCheckBox(defText, defCommandOn, defCommandOff);
ChaosHudCheckBox tempPopBtn = new ChaosHudCheckBox(defText, defCommandOn, defCommandOff);
tempBtn.MirrorCheckBox = tempPopBtn;
tempPopBtn.MirrorCheckBox = tempBtn;
tempBtn.InternalName = currentTab + "_CheckBox_" + button_count.ToString("D2");
tempPopBtn.InternalName = currentTab + "_CheckBox_" + button_count.ToString("D2");
newMainControl = tempBtn;
}
// if we generated a control, finalize it by performing layout and registration
if (newMainControl != null || /*haxx to allow "Spacer" as a noop*/directive.IndexOf("Spacer", StringComparison.InvariantCultureIgnoreCase) != -1)
{
// do we REAALLY have a control?
if (newMainControl != null)
{
int x = (padding * (currentCol)) + (buttonWidth * (currentCol - 1));
int y = (padding * (currentRow)) + (buttonHeight * (currentRow - 1));
int btnW = (buttonWidth * span) + (padding * (span - 1));
int btnH = buttonHeight;
tempLayout.AddControl(newMainControl.AsHudControl, new System.Drawing.Rectangle(x, y, btnW, btnH));
popoutWindows[currentTab].AddControl(newMainControl.Mirror, new System.Drawing.Rectangle(x, y, btnW, btnH));
}
// handle layout update
currentCol += span;
if (currentCol > cols)
{
currentCol = 1;
currentRow++;
}
button_count++;
} else
{
Util.WriteToChat($"Failed to parse layout line: {line}");
}
}
}
CreatePopoutList();
}
catch(Exception ex)
{
Util.WriteToChat("Error Loading Layout: " + ex.Message + "\n" + ex.StackTrace);
}
}
void LoadListOfConfigs()
{
string[] configs = Util.GetListofConfigs();
if(ConfigChoice.Count > 0)
ConfigChoice.Clear();
for(int i = 0; i < configs.Length; i++)
{
HudStaticText temp = new HudStaticText();
temp.Text = configs[i];
ConfigChoice.AddItem(temp, configs[i]);
}
}
/// <summary>
/// Dynamically generates the final command string from provided values and dispatches message to game.
/// </summary>
public static void DispatchCommand(string command, string param)
{
PluginCore.DispatchChatToBoxWithPluginIntercept(Instance.GenerateFinalCommandString(command, param));
}
private string GenerateFinalCommandString(string command, string param)
{
if (string.IsNullOrEmpty(command))
return null;
if (command.Contains("[player]"))
{
command = command.Replace("[player]", Core.CharacterFilter.Name);
}
if (command.Contains("[loc]"))
{
command = command.Replace("[loc]", Core.WorldFilter.GetByName(Core.CharacterFilter.Name).First.Coordinates().ToString());
}
if (command.Contains("[chatloc]"))
{
command = command.Replace("[chatloc]", chatLoc);
}
var regexItem = new Regex("^[a-zA-Z0-9 ]*$");
if (command.StartsWith("/") || regexItem.IsMatch(command))
{
//if is a /tell command
if (!string.IsNullOrEmpty(param) && command.StartsWith("/"))
{
return command + "," + param;
}
//Handle / commands
else if (command.StartsWith("/"))
{
return command;
}
//Handle raw text
else
{
return chatLoc + " " + command;
}
}
else
{
return chatLoc + " " + command;
}
}
void LoadConfig(string configName)
{
for (int i = 0; i < ConfigChoice.Count; i++)
{
if (((HudStaticText)ConfigChoice[i]).Text == configName.Trim())
{
ConfigChoice.Current = i;
}
}
string[] configInfo = Util.GetConfig(configName.Trim());
if(configInfo != null)
{
foreach(string _line in configInfo)
{
string line = _line.Trim();
// trim comment
int commentIndex = line.IndexOf("~~");
if (commentIndex == -1)
commentIndex = line.IndexOf("//");
if (commentIndex != -1)
line = line.Substring(0, commentIndex).Trim();
try
{
if(line.StartsWith("LAYOUT:", StringComparison.InvariantCultureIgnoreCase))
{
string[] parts = line.Split(':');
if (parts.Length < 2)
continue;
GenerateLayout(parts[1].Trim());
}
else
{
string[] col = line.Split(',');
// perhaps we have a single-column control declaration like a break/spacer; so make a "fake" array with just the control name
if (col.Length == 0)
col = new string[] { line };
// isolate control name and control object
string ctrlName = col[0];
if (string.IsNullOrEmpty(ctrlName))// might be a blank line.. skip
continue;
IChaosHudControl ctrl;
try
{
ctrl = view[ctrlName] as IChaosHudControl;
}
catch
{
Util.WriteToChat($"Cannot find {ctrlName} when parsing {configName.Trim()}; check your .layout file!");
continue;
}
if(ctrl is ChaosHudButton)
{
ChaosHudButton temp = (ChaosHudButton)ctrl;
string currentTabName = ctrlName.Substring(0, ctrlName.IndexOf('_'));
//check if button exists
if (temp != null)
{
//Check if button should be set to visible
if (col[1].Contains("NOTSET"))
{
temp.Visible = false;
temp.Mirror.Visible = false;
}
//If button is an image button
// Register the button event handler and make visible
else
{
if (col[1].Contains("[") && col[1].Contains("]"))
{
//Remove button, replace with image button and register bindings
//temp.Visible = false;
string clean = col[1].Replace("[", "");
clean = clean.Replace("]", "");
//Format : [<icon id>|<text>]
int iconImage = 0;
if(!clean.Contains("|"))
{
iconImage = int.Parse(clean);
VirindiViewService.ACImage tempImage = new VirindiViewService.ACImage(iconImage);
popoutWindows[currentTabName].SetImage(ctrlName, tempImage);
temp.Image = tempImage;
temp.Text = "";
temp.Mirror.Text = "";
}
else
{
string[] imageSettings = clean.Split('|');
iconImage = int.Parse(imageSettings[0]);
int iconBG = 0;
if(imageSettings.Length > 1)
{
if(int.TryParse(imageSettings[1], out iconBG))
{
popoutWindows[currentTabName].SetImage(ctrlName, new VirindiViewService.ACImage(iconImage));
temp.Image = new VirindiViewService.ACImage(iconImage);
temp.Image = new VirindiViewService.ACImage(iconBG);
Util.WriteToChat("Adding Double Image");
if (imageSettings.Length == 3)
{
temp.Text = imageSettings[2];
temp.Mirror.Text = imageSettings[2];
}
}
else
{
VirindiViewService.ACImage tempImage = new VirindiViewService.ACImage(iconImage);
popoutWindows[currentTabName].SetImage(ctrlName, tempImage);
temp.Image = tempImage;
if(imageSettings.Length == 2)
{
temp.Text = imageSettings[1];
temp.Mirror.Text = imageSettings[1];
}
}
}
}
}
else
{
temp.Text = col[1];
temp.Mirror.Text = col[1];
}
temp.Visible = true;
temp.Mirror.Visible = true;
//Creates the event handler for each button
string strCommand = null;
if (col.Length > 2)
strCommand = col[2];
string strParam = null;
if (col.Length > 3)
strParam = col[3];
// override command for main form
temp.Command = strCommand;
temp.Param = strParam;
// override command for popup form
temp.MirrorButton.Command = strCommand;
temp.MirrorButton.Param = strParam;
}
}
} else if (ctrl is ChaosHudStaticText)
{
ChaosHudStaticText temp = (ChaosHudStaticText)ctrl;
//check if button exists
if (temp != null)
{
//Check if button should be set to visible
if (col[1].Contains("NOTSET"))
{
temp.Visible = false;
temp.Mirror.Visible = false;
}
//If button is an image button
// Register the button event handler and make visible
else
{
temp.Text = col[1];
temp.Mirror.Text = col[1];
temp.Visible = true;
temp.Mirror.Visible = true;
}
}
}
else if (ctrl is ChaosHudCheckBox)
{
ChaosHudCheckBox temp = (ChaosHudCheckBox)ctrl;
//check if button exists
if (temp != null)
{
//Check if button should be set to visible
if (col[1].Contains("NOTSET"))
{
temp.Visible = false;
temp.Mirror.Visible = false;
}
//If button is an image button
// Register the button event handler and make visible
else
{
string text = null;
string commandOn = null;
string commandOff = null;
if (col.Length > 1)
text = col[1];
if (col.Length > 2)
commandOn = col[2];
if (col.Length > 3)
commandOff = col[3];
temp.Text = text;
temp.Mirror.Text = text;
temp.Visible = true;
temp.Mirror.Visible = true;
// override command for main form
temp.OnCommand = commandOn;
temp.OffCommand = commandOff;
// override command for popout form
temp.MirrorCheckBox.OnCommand = commandOn;
temp.MirrorCheckBox.OffCommand = commandOff;
}
}
} else if (ctrl is ChaosHudToggleButton)
{
ChaosHudToggleButton temp = (ChaosHudToggleButton)ctrl;
//check if button exists
if (temp != null)
{
//Check if button should be set to visible
if (col[1].Contains("NOTSET"))
{
temp.Visible = false;
temp.Mirror.Visible = false;
}
//If button is an image button
// Register the button event handler and make visible
else
{
string textOff = null;
string textOn = null;
string commandOn = null;
string commandOff = null;
if(col.Length == 4)
{
textOff = col[1];
commandOn = col[2];
commandOff = col[3];
} else if(col.Length == 5)
{
textOff = col[1];
textOn = col[2];
commandOn = col[3];
commandOff = col[4];
}
temp.Text = textOff;
temp.TextAlt = textOn;
temp.Mirror.Text = textOff;
(temp.Mirror as ChaosHudToggleButton).TextAlt = textOn;
temp.Visible = true;
temp.Mirror.Visible = true;
// override command for main form
temp.OnCommand = commandOn;
temp.OffCommand = commandOff;
// override command for popout form
temp.MirrorToggleButton.OnCommand = commandOn;
temp.MirrorToggleButton.OffCommand = commandOff;
}
}
}
}
}
catch(Exception ex)
{
Util.WriteToChat("Error Loading Config at :" + line + "\n : Error: " + ex.Message + "\n" + ex.StackTrace);
}
}
}
else
{
Util.WriteToChat("Error Loading Config!");
}
}
//
// ? Tab
//
private void ChatCommandSet_Click(object sender, EventArgs e)
{
//Set the specified chat command text
chatLoc = ChatCommand.Text;
LoadBaseXML(false, "");
view.Visible = true;
Util.WriteToChat("Changing chat command to : " + chatLoc);
}
private void ReloadConfig_Click(object sender, EventArgs e)
{
//Load the specified config file
LoadBaseXML(false, "");
view.Visible = true;
Util.WriteToChat("Reloading Config...");
}
private void SaveIni_Click(object sender, EventArgs e)
{
//Save the ini so it can be used later
Util.SaveIni(ChatCommand.Text, ((HudStaticText)ConfigChoice[ConfigChoice.Current]).Text);
Util.WriteToChat("Saving Defaults...");
}
private void TabChanged(object sender, EventArgs e)
{
if(TabView.CurrentTab == 0)
{
view.ClientArea = new System.Drawing.Size(startingW, startingH);
}
else
{
view.Width = ((System.Drawing.Size)sizes[TabView.CurrentTab - 1]).Width;
view.Height = ((System.Drawing.Size)sizes[TabView.CurrentTab - 1]).Height;
}
}
private void FilterCore_CommandLineText(object sender, ChatParserInterceptEventArgs e)
{
if(e.Text.ToLower().StartsWith("/ch"))
{