-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plugin.cs
1353 lines (1260 loc) · 60.3 KB
/
Plugin.cs
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 GeniePlugin.Interfaces;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.Layout;
using System.Xml;
using System.Linq;
using System.Text.RegularExpressions;
using Microsoft.VisualBasic.Devices;
namespace DynamicWindows
{
public class Plugin : IPlugin
{
public ArrayList forms = new ArrayList();
public Hashtable documents = new Hashtable();
public Color formback = Color.Black;
public Color formfore = Color.White;
public bool bPluginEnabled = true;
public ArrayList ignorelist = new ArrayList();
public Dictionary<string, Point> positionList = new Dictionary<string, Point>();
public bool bStowContainer;
public Form pForm;
public IHost ghost;
private string configPath;
public bool Enabled
{
get
{
return this.bPluginEnabled;
}
set
{
if (value)
this.bPluginEnabled = true;
else
this.bPluginEnabled = false;
}
}
public string Name => "Dynamic Windows";
public string Version => "2.1.5";
public string Author => "Multiple Developers";
public string Description => "Displays content windows specified through the XML stream from the game.";
public void Initialize(IHost Host)
{
try
{
this.ghost = Host;
this.pForm = Host.ParentForm;
this.configPath = Host.get_Variable("PluginPath");
this.LoadConfig();
}
catch
{
}
}
public void SaveConfig()
{
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.CreateXmlDeclaration("1.0", "utf-8", (string)null);
XmlElement element1 = xmlDocument.CreateElement("DynamicWindows");
xmlDocument.AppendChild((XmlNode)element1);
XmlElement element2 = xmlDocument.CreateElement("Config");
element2.SetAttribute("id", "foreground");
element2.SetAttribute("color", ColorTranslator.ToHtml(this.formfore));
element1.AppendChild((XmlNode)element2);
XmlElement element3 = xmlDocument.CreateElement("Config");
element3.SetAttribute("id", "background");
element3.SetAttribute("color", ColorTranslator.ToHtml(this.formback));
element1.AppendChild((XmlNode)element3);
XmlElement element4 = xmlDocument.CreateElement("Config");
element4.SetAttribute("id", "stowcontainer");
element4.SetAttribute("enabled", this.bStowContainer.ToString());
element1.AppendChild((XmlNode)element4);
XmlElement element5 = xmlDocument.CreateElement("Config");
element5.SetAttribute("id", "plugin");
element5.SetAttribute("pluginenabled", this.bPluginEnabled.ToString());
element1.AppendChild((XmlNode)element5);
foreach (string str in this.ignorelist)
{
XmlElement element6 = xmlDocument.CreateElement("Ignore");
element6.SetAttribute("id", str);
element1.AppendChild((XmlNode)element6);
}
foreach (SkinnedMDIChild skinnedMdiChild in this.forms)
{
if (this.positionList.ContainsKey(skinnedMdiChild.Name))
this.positionList.Remove(skinnedMdiChild.Name);
this.positionList.Add(skinnedMdiChild.Name, skinnedMdiChild.Location);
}
foreach (KeyValuePair<string, Point> keyValuePair in this.positionList)
{
XmlElement element6 = xmlDocument.CreateElement("Position");
element6.SetAttribute("id", keyValuePair.Key);
element6.SetAttribute("X", keyValuePair.Value.X.ToString());
element6.SetAttribute("Y", keyValuePair.Value.Y.ToString());
element1.AppendChild((XmlNode)element6);
}
xmlDocument.Save(this.configPath + "/DynamicWindows.xml");
}
private void LoadConfig()
{
XmlDocument xmlDocument = new XmlDocument();
try
{
xmlDocument.Load(this.configPath + "/DynamicWindows.xml");
}
catch (Exception ex)
{
this.ghost.EchoText("Could not load Dynamic Windows Config File, It will be created when you change your options and hit OK: " + ex.Message);
return;
}
foreach (XmlElement xmlElement in xmlDocument.GetElementsByTagName("Config"))
{
if (xmlElement.GetAttribute("id") == "foreground")
this.formfore = ColorTranslator.FromHtml(xmlElement.GetAttribute("color"));
else if (xmlElement.GetAttribute("id") == "background")
this.formback = ColorTranslator.FromHtml(xmlElement.GetAttribute("color"));
else if (xmlElement.GetAttribute("id") == "stowcontainer")
{
bool.TryParse(xmlElement.GetAttribute("enabled"), out bool result);
this.bStowContainer = result;
}
else if (xmlElement.GetAttribute("id") == "plugin")
{
bool.TryParse(xmlElement.GetAttribute("pluginenabled"), out bool result);
this.bPluginEnabled = result;
}
}
foreach (XmlElement xmlElement in xmlDocument.GetElementsByTagName("Ignore"))
this.ignorelist.Add((object)xmlElement.GetAttribute("id"));
foreach (XmlElement xmlElement in xmlDocument.GetElementsByTagName("Position"))
this.positionList.Add(xmlElement.GetAttribute("id"), new Point(int.Parse(xmlElement.GetAttribute("X")), int.Parse(xmlElement.GetAttribute("Y"))));
}
public string ParseInput(string Text)
{
if (!Text.StartsWith("/debugwindows"))
return Text;
this.ghost.EchoText("Form Count: " + this.forms.Count.ToString());
foreach (Control control in this.forms)
this.ghost.EchoText(" Form: " + control.Name);
foreach (string str in (IEnumerable)this.documents.Keys)
this.ghost.EchoText(string.Concat(new object[4]
{
(object) "Variable: ",
(object) str,
(object) " - ",
this.documents[(object) str]
}));
return "";
}
public string ParseText(string Text, string Window)
{
if (Window.Trim().ToLower() == "main" || Window.Trim() == string.Empty)
return this.ParseText(Text);
else
return Text;
}
public string ParseText(string Text)
{
return Text;
}
public void ParseXML(string XML)
{
if (!this.bPluginEnabled)
return;
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml("<?xml version='1.0'?><root>" + XML + "</root>");
foreach (XmlElement xmlElement in xmlDocument.DocumentElement.ChildNodes)
{
switch (xmlElement.Name)
{
//case "exposeStream":
// this.Parse_xml_exposestream(xmlElement);
// continue;
//case "pushStream":
// this.Parse_xml_pushstream(xmlElement);
// continue;
//case "popStream":
// this.Parse_xml_popStream(xmlElement);
// continue;
case "streamWindow":
this.Parse_xml_streamwindow(xmlElement);
continue;
case "openDialog":
this.Parse_xml_openwindow(xmlElement);
continue;
case "dialogData":
this.Parse_xml_updatewindow(xmlElement);
continue;
case "closeDialog":
this.Parse_xml_closewindow(xmlElement);
continue;
case "exposeDialog":
this.Parse_xml_exposewindow(xmlElement);
continue;
case "dynaStream":
this.Parse_set_stream(xmlElement);
continue;
case "clearDynaStream":
Parse_clear_stream(xmlElement);
continue;
case "clearStream":
this.Parse_clear_stream(xmlElement);
continue;
case "clearContainer":
this.Parse_container(xmlElement);
continue;
case "inv":
this.Parse_inventory(xmlElement);
continue;
default:
continue;
}
}
}
public void Show()
{
FormOptionWindow formOptionWindow = new FormOptionWindow(this)
{
MdiParent = this.pForm,
TopMost = true
};
((Control)formOptionWindow).Show();
}
public void VariableChanged(string Variable)
{
}
public void ParentClosing()
{
this.SaveConfig();
}
private void Parse_xml_streamwindow(XmlElement elem)
{
// Check if the id attribute is "profileHelp"
if (elem.GetAttribute("id") != "profileHelp")
return;
// Use default values for the width and height if they are not specified in the element
int width = elem.HasAttribute("width") ? int.Parse(elem.GetAttribute("width")) : 375;
int height = elem.HasAttribute("height") ? int.Parse(elem.GetAttribute("height")) : 350;
// Check if the stream window is already open
SkinnedMDIChild existingWindow = null;
foreach (SkinnedMDIChild window in this.forms)
{
if (window.Name == elem.GetAttribute("id"))
{
existingWindow = window;
break;
}
}
if (existingWindow != null)
{
// Close the existing window
this.forms.Remove(existingWindow);
existingWindow.Close();
}
// Create a new SkinnedMDIChild object for the stream window
SkinnedMDIChild streamWindow = new SkinnedMDIChild(this.ghost, this)
{
MdiParent = this.pForm,
Text = elem.GetAttribute("title"),
ForeColor = this.formfore
};
streamWindow.formBody.ForeColor = this.formfore;
streamWindow.Name = elem.GetAttribute("id");
streamWindow.ClientSize = new Size(width, height + 22);
if (this.positionList.ContainsKey(elem.GetAttribute("id")))
streamWindow.Location = this.positionList[elem.GetAttribute("id")];
streamWindow.StartPosition = FormStartPosition.CenterScreen;
// Show the stream window
streamWindow.formBody.Visible = true;
streamWindow.formBody.AutoScroll = true;
streamWindow.formBody.AutoSize = true;
if (elem.HasAttribute("resident") && elem.GetAttribute("resident").Equals("false") && !elem.GetAttribute("location").Equals("center"))
return;
// Create a new instance of the HelpWindows class
helpWindows helpWindows = new helpWindows();
// Create a new RichTextBox control
RichTextBox contentBox = new RichTextBox
{
ForeColor = this.formfore,
BackColor = this.formback,
ReadOnly = true,
BorderStyle = BorderStyle.None
};
if (streamWindow.Text == "Profile RP Help")
contentBox.Text = helpWindows.RPHelp;
if (streamWindow.Text == "Profile PVP Help")
contentBox.Text = helpWindows.PVPHelp;
if (streamWindow.Text == "Profile SPOUSE Help")
contentBox.Text = helpWindows.SPOUSEHelp;
// this removes the window in genie that these create
this.ghost.SendText("#window remove profileHelp");
contentBox.Dock = DockStyle.Fill;
// Add the RichTextBox control to the formBody property of the streamWindow object
streamWindow.formBody.Controls.Add(contentBox);
streamWindow.ShowForm();
}
// Define a new method to find a window with a specific name
private SkinnedMDIChild FindWindowByName(string name)
{
// Search for the window in the forms list
foreach (SkinnedMDIChild window in this.forms)
{
if (window.Name == name)
{
// Return the window if it is found
return window;
}
}
// Return null if the window is not found
return null;
}
// Define a new method to find a window with a specific name
private SkinnedMDIChild FindLabelByName(string name)
{
// Search for the window in the forms list
foreach (SkinnedMDIChild label in this.forms)
{
if (label.Name == name)
{
// Return the window if it is found
return label;
}
}
// Return null if the window is not found
return null;
}
private void Parse_xml_exposestream(XmlElement elem)
{
// Find the stream window with the specified id
SkinnedMDIChild streamWindow = null;
foreach (SkinnedMDIChild window in this.forms)
{
if (window.Name == elem.GetAttribute("id"))
{
streamWindow = window;
break;
}
}
// Check if the stream window was found
// Show the stream window
streamWindow?.Show();
}
private void Parse_xml_pushstream(XmlElement elem)
{
// Find the stream window with the specified id
SkinnedMDIChild streamWindow = null;
foreach (SkinnedMDIChild window in this.forms)
{
if (window.Name == elem.GetAttribute("id"))
{
streamWindow = window;
break;
}
}
// Check if the stream window was found
if (streamWindow != null)
{
// Update the content of the stream window
string content = elem.InnerText;
streamWindow.Text = content;
}
}
private void Parse_xml_exposewindow(XmlElement elem)
{
foreach (SkinnedMDIChild skinnedMdiChild in this.forms)
{
if (skinnedMdiChild.Name.Equals(elem.GetAttribute("id")))
{
skinnedMdiChild.TopMost = true;
skinnedMdiChild.Update();
skinnedMdiChild.ShowForm();
}
}
}
private void Parse_xml_closewindow(XmlElement elem)
{
SkinnedMDIChild skinnedMdiChild1 = (SkinnedMDIChild)null;
foreach (SkinnedMDIChild skinnedMdiChild2 in this.forms)
{
if (skinnedMdiChild2.Name.Equals(elem.GetAttribute("id")))
skinnedMdiChild1 = skinnedMdiChild2;
}
if (skinnedMdiChild1 == null)
return;
this.forms.Remove((object)skinnedMdiChild1);
skinnedMdiChild1.Close();
}
private void Parse_xml_updatewindow(XmlElement xelem)
{
SkinnedMDIChild dyndialog = (SkinnedMDIChild)null;
foreach (SkinnedMDIChild skinnedMdiChild in this.forms)
{
if (skinnedMdiChild.Name.Equals(xelem.GetAttribute("id")))
dyndialog = skinnedMdiChild;
}
if (dyndialog == null)
return;
dyndialog.formBody.Visible = false;
foreach (XmlElement cbx in xelem.ChildNodes)
{
switch (cbx.Name)
{
case "label":
this.Parse_labels(cbx, dyndialog);
continue;
case "cmdButton":
this.Parse_command_buttons(cbx, dyndialog);
continue;
case "closeButton":
this.Parse_close_button(cbx, dyndialog);
continue;
case "checkBox":
this.Parse_check_box(cbx, dyndialog);
continue;
case "radio":
this.Parse_radio_button(cbx, dyndialog);
continue;
case "streamBox":
this.Parse_stream_box(cbx, dyndialog);
continue;
case "dropDownBox":
this.Parse_drop_down(cbx, dyndialog);
continue;
case "upDownEditBox":
this.Parse_numericupdown(cbx, dyndialog);
continue;
case "editBox":
this.Parse_edit_box(cbx, dyndialog);
continue;
case "progressBar":
this.Parse_progress_bar(cbx, dyndialog);
continue;
default:
continue;
}
}
dyndialog.formBody.Visible = true;
dyndialog.formBody.AutoScroll = true;
dyndialog.formBody.AutoSize = true;
dyndialog.TopMost = true;
dyndialog.Update();
dyndialog.ShowForm();
}
public void Parse_xml_openwindow(XmlElement xelem)
{
if (!xelem.GetAttribute("type").Equals("dynamic") || !xelem.HasAttribute("width") || !xelem.HasAttribute("height"))
return;
SkinnedMDIChild skinnedMdiChild1 = (SkinnedMDIChild)null;
if (this.ignorelist.Contains((object)xelem.GetAttribute("id")))
return;
foreach (SkinnedMDIChild skinnedMdiChild2 in this.forms)
{
if (skinnedMdiChild2.Name.Equals(xelem.GetAttribute("id")))
skinnedMdiChild1 = skinnedMdiChild2;
}
if (skinnedMdiChild1 != null)
{
this.forms.Remove((object)skinnedMdiChild1);
skinnedMdiChild1.Close();
}
SkinnedMDIChild dyndialog = new SkinnedMDIChild(this.ghost, this)
{
MdiParent = this.pForm,
Text = xelem.GetAttribute("title")
};
dyndialog.formBody.ForeColor = this.formfore;
dyndialog.formBody.BackColor = this.formback;
dyndialog.formBody.AutoSize = false;
dyndialog.formBody.BorderStyle = BorderStyle.None;
this.forms.Add((object)dyndialog);
dyndialog.Name = xelem.GetAttribute("id");
if (xelem.GetAttribute("id") == "spellChoose")
{
dyndialog.ClientSize = new Size(480, int.Parse(xelem.GetAttribute("height")) + 22);
}
else
dyndialog.ClientSize = new Size(int.Parse(xelem.GetAttribute("width")), int.Parse(xelem.GetAttribute("height")) + 22);
if (this.positionList.ContainsKey(xelem.GetAttribute("id")))
dyndialog.Location = this.positionList[xelem.GetAttribute("id")];
dyndialog.formBody.Visible = false;
dyndialog.StartPosition = FormStartPosition.CenterScreen;
foreach (XmlElement xmlElement in xelem.FirstChild.ChildNodes)
{
switch (xmlElement.Name)
{
case "label":
this.Parse_labels(xmlElement, dyndialog);
continue;
case "cmdButton":
this.Parse_command_buttons(xmlElement, dyndialog);
continue;
case "closeButton":
this.Parse_close_button(xmlElement, dyndialog);
continue;
case "radio":
this.Parse_radio_button(xmlElement, dyndialog);
continue;
case "streamBox":
this.Parse_stream_box(xmlElement, dyndialog);
continue;
case "dropDownBox":
this.Parse_drop_down(xmlElement, dyndialog);
continue;
case "editBox":
this.Parse_edit_box(xmlElement, dyndialog);
continue;
case "upDownEditBox":
this.Parse_numericupdown(xmlElement, dyndialog);
continue;
case "clearContainer":
this.Parse_container(xmlElement);
continue;
case "progressBar":
this.Parse_progress_bar(xmlElement, dyndialog);
continue;
default:
continue;
}
}
dyndialog.formBody.Visible = true;
dyndialog.formBody.AutoScroll = true;
if (xelem.HasAttribute("resident") && xelem.GetAttribute("resident").Equals("false") && !xelem.GetAttribute("location").Equals("detach"))
return;
dyndialog.TopMost = true;
dyndialog.ShowForm();
}
private void Parse_container(XmlElement elem)
{
if (!this.bStowContainer)
return;
this.ghost.SendText("#clear " + elem.GetAttribute("id"));
}
private void Parse_inventory(XmlElement elem)
{
if (!this.bStowContainer)
return;
this.ghost.SendText("#echo >" + elem.GetAttribute("id") + " " + elem.InnerText);
}
private void Parse_clear_stream(XmlElement xelem)
{
foreach (SkinnedMDIChild skinnedMdiChild in this.forms)
{
foreach (Control control in (ArrangedElementCollection)skinnedMdiChild.formBody.Controls)
{
if (control.Name.Equals(xelem.GetAttribute("id")))
control.Text = "";
}
}
this.documents.Remove((object)xelem.GetAttribute("id"));
}
public void Parse_set_stream(XmlElement xmlElement)
{
string id = xmlElement.GetAttribute("id");
string value = xmlElement.InnerXml;
this.documents[(object)id] = (object)value;
foreach (SkinnedMDIChild skinnedMdiChild in this.forms)
{
foreach (Control control in (ArrangedElementCollection)skinnedMdiChild.formBody.Controls)
{
if (control.Name.Equals(id))
{
switch (id)
{
case "spells":
// Create a specific element for the "spells" stream
if (control is Panel panel)
{
if (panel.Controls.Count == 0)
{
// Only clear the panel and add the title label when it is first called
panel.Controls.Clear();
panel.SuspendLayout();
//panel.Size = this.Build_size(xmlElement, 200, 380);
panel.Height = 380;
panel.Width = 200;
panel.BackColor = this.formback;
Label label = new Label
{
Text = "",
AutoSize = true,
Location = new Point(0, 0)
};
panel.Controls.Add(label);
}
int y = panel.Controls[panel.Controls.Count - 1].Bottom + 5;
if (!xmlElement.HasChildNodes || xmlElement.GetElementsByTagName("d").Count == 0)
{
// Add a label for the spell book name
Label bookLabel = new Label
{
Text = xmlElement.InnerXml,
AutoSize = true,
Location = new Point(0, y)
};
//bookLabel.Font = new Font(bookLabel.Font, FontStyle.Regular | FontStyle.Underline);
bookLabel.Font = new Font(bookLabel.Font.FontFamily, 10, FontStyle.Bold);
bookLabel.ForeColor = this.formfore;
bookLabel.Click -= SpellLabel_Click;
panel.Controls.Add(bookLabel);
y += bookLabel.Height + 5;
}
else
{
// Add labels for the spells
foreach (XmlNode node in xmlElement.ChildNodes)
{
if (node is XmlElement elem && elem.Name == "d")
{
Label spellLabel = new Label
{
Text = elem.InnerText,
AutoSize = true,
Location = new Point(15, y),
ForeColor = this.formfore
};
spellLabel.Font = new Font(spellLabel.Font.FontFamily, 9, FontStyle.Underline);
spellLabel.Tag = elem.GetAttribute("cmd");
spellLabel.Click += SpellLabel_Click;
panel.Controls.Add(spellLabel);
y += spellLabel.Height + 5;
}
}
}
panel.ResumeLayout();
}
break;
case "spellInfo":
// Handle the "spellInfo" stream
if (control is RichTextBox spellInfoBox)
{
spellInfoBox.AppendText(xmlElement.InnerText + Environment.NewLine);
spellInfoBox.Width = 250;
spellInfoBox.Location = new Point(215, 40);
spellInfoBox.BackColor = this.formback;
}
break;
default:
value = Regex.Replace(value, "(<pushBold />|<popBold />)", "");
//control.Text = value;
string attribute = xmlElement.GetAttribute("id");
string innerText = xmlElement.InnerText;
this.documents[(object)attribute] = (object)innerText;
foreach (Control control1 in (ArrangedElementCollection)skinnedMdiChild.formBody.Controls)
{
if (control1.Name.Equals(attribute))
control1.Text = innerText;
}
break;
}
}
}
}
}
private void SpellLabel_Click(object sender, EventArgs e)
{
Label label = (Label)sender;
string cmd = (string)label.Tag;
ghost.SendText(cmd);
// Find the form that contains the spell labels
Form form = label.FindForm();
// Find the "spells" panel control
Control spellsPanel = form.Controls.Find("spells", true).FirstOrDefault();
// Check if the "spells" panel was found
if (spellsPanel != null)
{
// Find all spell labels in the "spells" panel
var spellLabels = spellsPanel.Controls.OfType<Label>();
// Reset the ForeColor of all spell labels to their default color
foreach (var spellLabel in spellLabels)
{
spellLabel.ForeColor = this.formfore;
}
}
// Change the ForeColor of the clicked label to the desired color
label.ForeColor = Color.Blue;
// Find the choose button control
Control chooseButton = form.Controls.Find("chooseSpell", true).FirstOrDefault();
// Check if the choose button was found
if (chooseButton != null)
{
// Update the text and command of the choose button
chooseButton.Text = "Choose " + label.Text;
((CmdButton)chooseButton).cmd_string = cmd;
}
}
private void Parse_stream_box(XmlElement cbx, SkinnedMDIChild dyndialog)
{
string id = cbx.GetAttribute("id");
switch (id)
{
case "spells":
// Create a Panel control for the "spells" stream
Panel panel = !dyndialog.formBody.Controls.ContainsKey(cbx.GetAttribute("id")) ? new Panel() : (Panel)dyndialog.formBody.Controls[cbx.GetAttribute("id")];
if (panel == null)
return;
panel.Name = cbx.GetAttribute("id");
panel.Size = Build_size(cbx, int.Parse(cbx.GetAttribute("width")), int.Parse(cbx.GetAttribute("height")));
// Spells background color
panel.BackColor = this.formback;
panel.Location = Set_location(cbx, (Control)panel, dyndialog);
panel.AutoScroll = true;
//panel.AutoSize = true;
dyndialog.formBody.Controls.Add((Control)panel);
// Add a Label control for each spell
int y = 0;
foreach (XmlNode node in cbx.ChildNodes)
{
if (node is XmlElement elem && elem.Name == "d")
{
Label spellLabel = new Label
{
Text = elem.InnerText,
AutoSize = true,
Location = new Point(0, y),
ForeColor = this.formfore
};
spellLabel.Font = new Font(spellLabel.Font, FontStyle.Underline);
spellLabel.Tag = elem.GetAttribute("cmd");
spellLabel.Click += SpellLabel_Click;
panel.Controls.Add(spellLabel);
y += spellLabel.Height + 5;
}
}
break;
case "spellInfo":
// Create a RichTextBox control for other streams
RichTextBox spellInfo = !dyndialog.formBody.Controls.ContainsKey(cbx.GetAttribute("id")) ? new RichTextBox() : (RichTextBox)dyndialog.formBody.Controls[cbx.GetAttribute("id")];
if (spellInfo == null)
return;
spellInfo.Name = cbx.GetAttribute("id");
spellInfo.Rtf = cbx.GetAttribute("value");
//spellInfo.Size = Build_size(cbx, int.Parse(cbx.GetAttribute("width")), int.Parse(cbx.GetAttribute("height")));
//spellInfo.Size = dyndialog.ClientSize = new Size(300, 380);
// spell info colors
spellInfo.BackColor = this.formback;
spellInfo.ForeColor = this.formfore;
//spellInfo.Location = Set_location(cbx, (Control)spellInfo, dyndialog);
spellInfo.Width = 300;
spellInfo.Height = 380;
spellInfo.Location = new Point(215, 40);
spellInfo.Anchor = AnchorStyles.Top | AnchorStyles.Right;
spellInfo.BorderStyle = BorderStyle.None;
spellInfo.Multiline = true;
spellInfo.ScrollBars = RichTextBoxScrollBars.Vertical;
spellInfo.ReadOnly = true;
spellInfo.LinkClicked += Rtb_LinkClicked;
spellInfo.DetectUrls = false;
dyndialog.formBody.Controls.Add((Control)spellInfo);
break;
default:
TextBox textBox = !dyndialog.formBody.Controls.ContainsKey(cbx.GetAttribute("id")) ? new TextBox() : (TextBox)dyndialog.formBody.Controls[cbx.GetAttribute("id")];
if (textBox == null)
return;
textBox.Name = cbx.GetAttribute("id");
textBox.Text = cbx.GetAttribute("value");
textBox.Size = this.Build_size(cbx, 200, 75);
textBox.Location = this.Set_location(cbx, (Control)textBox, dyndialog);
textBox.Multiline = true;
textBox.ScrollBars = ScrollBars.Vertical;
dyndialog.formBody.Controls.Add((Control)textBox);
break;
}
}
private void Rtb_LinkClicked(object sender, LinkClickedEventArgs e)
{
RichTextBox richTextBox = (RichTextBox)sender;
Point mousePos = richTextBox.PointToClient(Cursor.Position);
int index = richTextBox.GetCharIndexFromPosition(mousePos);
int start = richTextBox.Text.LastIndexOf("<d", index);
int end = richTextBox.Text.IndexOf("</d>", index) + 4;
string linkText = richTextBox.Text.Substring(start, end - start);
XmlDocument doc = new XmlDocument();
doc.LoadXml("<root>" + linkText + "</root>");
if (doc.DocumentElement.FirstChild is XmlElement elem && elem.Name == "d" && elem.HasAttribute("cmd"))
{
ghost.SendText(elem.GetAttribute("cmd"));
}
}
private void Parse_numericupdown(XmlElement cbx, SkinnedMDIChild dyndialog)
{
NumericUpDown numericUpDown = !dyndialog.formBody.Controls.ContainsKey(cbx.GetAttribute("id")) ? new NumericUpDown() : (NumericUpDown)dyndialog.formBody.Controls[cbx.GetAttribute("id")];
if (numericUpDown == null)
return;
if (cbx.HasAttribute("max"))
numericUpDown.Maximum = (Decimal)int.Parse(cbx.GetAttribute("max"));
if (cbx.HasAttribute("min"))
numericUpDown.Minimum = (Decimal)int.Parse(cbx.GetAttribute("min"));
numericUpDown.Name = cbx.GetAttribute("id");
numericUpDown.Text = cbx.GetAttribute("value");
numericUpDown.Value = (Decimal)int.Parse(cbx.GetAttribute("value"));
numericUpDown.Size = this.Build_size(cbx, 200, 75);
numericUpDown.Location = this.Set_location(cbx, (Control)numericUpDown, dyndialog);
dyndialog.formBody.Controls.Add((Control)numericUpDown);
}
private void Parse_edit_box(XmlElement cbx, SkinnedMDIChild dyndialog)
{
TextBox textBox = !dyndialog.formBody.Controls.ContainsKey(cbx.GetAttribute("id")) ? new TextBox() : (TextBox)dyndialog.formBody.Controls[cbx.GetAttribute("id")];
if (textBox == null)
return;
textBox.Name = cbx.GetAttribute("id");
textBox.Text = cbx.GetAttribute("value");
SkinnedMDIChild window = FindWindowByName("bugDialogBox");
if (window != null)
{
textBox.TextChanged += (sender, e) => TextBox_TextChanged(sender, e, dyndialog);
}
textBox.Size = this.Build_size(cbx, 200, 75);
textBox.Location = this.Set_location(cbx, (Control)textBox, dyndialog);
if (cbx.HasAttribute("maxChars"))
textBox.MaxLength = int.Parse(cbx.GetAttribute("maxChars"));
textBox.Multiline = false;
textBox.WordWrap = true;
dyndialog.formBody.Controls.Add((Control)textBox);
}
private void TextBox_TextChanged(object sender, EventArgs e, SkinnedMDIChild dyndialog)
{
if (e is null)
{
throw new ArgumentNullException(nameof(e));
}
SkinnedMDIChild window = FindWindowByName("bugDialogBox");
if (window != null)
{
// Get a reference to the TextBox control
TextBox textBox = sender as TextBox;
// Calculate the current character count
int charCount = textBox.Text.Length;
// Find the Label control that corresponds to the TextBox control
Label label;
int maxChars;
string labelText;
if (textBox.Name == "title")
{
label = dyndialog.formBody.Controls["titleLabel"] as Label;
label.Location = new Point(0, 105);
maxChars = 128;
labelText = "Title";
}
else if (textBox.Name == "details")
{
label = dyndialog.formBody.Controls["detailsLabel"] as Label;
label.Location = new Point(0, 135);
maxChars = 875;
labelText = "Details";
}
else
{
return;
}
// Update the label with the current character count and maximum character count
label.Text = $"{labelText} {charCount}/{maxChars}";
label.AutoSize = true;
// Add the Label control to the form
dyndialog.formBody.Controls.Add(label);
}
}
private void Parse_check_box(XmlElement cbx, SkinnedMDIChild dyndialog)
{
cbCheckBox cbCheckBox = !dyndialog.formBody.Controls.ContainsKey(cbx.GetAttribute("id")) ? new cbCheckBox() : (cbCheckBox)dyndialog.formBody.Controls[cbx.GetAttribute("id")];
if (cbCheckBox == null)
return;
cbCheckBox.Name = cbx.GetAttribute("id");
cbCheckBox.Text = cbx.GetAttribute("text");
cbCheckBox.checked_value = cbx.GetAttribute("checked_value");
cbCheckBox.unchecked_value = cbx.GetAttribute("unchecked_value");
cbCheckBox.Checked = cbx.HasAttribute("checked");
cbCheckBox.Size = this.Build_size(cbx, 200, 20);
cbCheckBox.Location = this.Set_location(cbx, (Control)cbCheckBox, dyndialog);
dyndialog.formBody.Controls.Add((Control)cbCheckBox);
}
private void Parse_radio_button(XmlElement cbx, SkinnedMDIChild dyndialog)
{
cbRadio cbRadio = !dyndialog.formBody.Controls.ContainsKey(cbx.GetAttribute("id")) ? new cbRadio() : (cbRadio)dyndialog.formBody.Controls[cbx.GetAttribute("id")];
if (cbRadio == null)
return;
cbRadio.Name = cbx.GetAttribute("id");
cbRadio.Text = cbx.GetAttribute("text");
cbRadio.command = cbx.GetAttribute("cmd");
cbRadio.group = cbx.GetAttribute("group");
if (cbx.GetAttribute("value").Contains("0"))
cbRadio.Checked = false;
else
cbRadio.Checked = true;
cbRadio.Size = this.Build_size(cbx, 200, 20);
cbRadio.Location = this.Set_location(cbx, (Control)cbRadio, dyndialog);
cbRadio.Click += new EventHandler(this.CbRadioSelect);
dyndialog.formBody.Controls.Add((Control)cbRadio);
}
private void Parse_progress_bar(XmlElement cbx, SkinnedMDIChild dyndialog)
{
ProgressBar progressBar = !dyndialog.formBody.Controls.ContainsKey(cbx.GetAttribute("id")) ? new ProgressBar() : (ProgressBar)dyndialog.formBody.Controls[cbx.GetAttribute("id")];
if (progressBar == null)
return;
progressBar.Name = cbx.GetAttribute("id");
progressBar.Text = cbx.GetAttribute("text");
progressBar.Style = ProgressBarStyle.Continuous;
int.TryParse(cbx.GetAttribute("value"), out int result);
progressBar.Value = result;
progressBar.Size = this.Build_size(cbx, 200, 20);
progressBar.Location = this.Set_location(cbx, (Control)progressBar, dyndialog);
dyndialog.formBody.Controls.Add((Control)progressBar);
}
private void Parse_close_button(XmlElement cbx, SkinnedMDIChild dyndialog)
{
// Find the existing choose button control
Control chooseButton = dyndialog.formBody.Controls.Find("chooseSpell", true).FirstOrDefault();
// Check if the choose button was found
if (chooseButton != null)
{
// Update the text and command of the choose button
chooseButton.Text = cbx.GetAttribute("value");
((CmdButton)chooseButton).cmd_string = !cbx.HasAttribute("cmd") ? "" : cbx.GetAttribute("cmd");
// Redraw the choose button
chooseButton.Invalidate();
}
else
{
// Create a new closeButton if it doesn't exist
CmdButton closeButton = new CmdButton