-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainForm.cs
More file actions
1291 lines (1216 loc) · 61.2 KB
/
Copy pathMainForm.cs
File metadata and controls
1291 lines (1216 loc) · 61.2 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.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using FC2Editor.Core;
using FC2Editor.Core.Nomad;
using FC2Editor.Parameters;
using FC2Editor.Properties;
using FC2Editor.Tools;
using FC2Editor.UI;
using FC2Editor.Utils;
using Microsoft.Win32;
using TD.SandBar;
using TD.SandDock;
namespace FC2Editor
{
internal class MainForm : Form, IInputSink
{
private List<ButtonItem> m_toolItemList = new List<ButtonItem>();
private Dictionary<Keys, ButtonItem> m_toolShortcuts = new Dictionary<Keys, ButtonItem>();
private string m_helpString;
private static ITool m_currentTool;
private bool m_closeSaveConfirmed;
private float m_lastUpdate;
private bool m_isLoading;
private float m_currentMemoryUsage;
private float m_currentObjectUsage;
private Vec3 m_currentCameraPos;
private bool m_currentCursorValid;
private Vec3 m_currentCursorPos;
private bool m_cursorPhysics = true;
private float m_currentFps;
private string m_documentPath;
private static MainForm s_instance;
private IContainer components;
private SandBarManager sandBarManager;
private ToolBarContainer leftSandBarDock;
private ToolBarContainer rightSandBarDock;
private ToolBarContainer bottomSandBarDock;
private ToolBarContainer topSandBarDock;
private MenuBar menuBar;
private MenuBarItem menuBarItem1;
private TD.SandBar.ToolBar toolBarMain;
private MenuButtonItem menuItem_newMap;
private MenuButtonItem menuItem_loadMap;
private MenuButtonItem menuItem_saveMap;
private MenuButtonItem menuItem_exit;
private ButtonItem buttonItem1;
private ButtonItem buttonItem2;
private ButtonItem buttonItem3;
internal ViewportControl viewport;
private SandDockManager sandDockManager;
private ToolParametersDock toolParametersDock;
private ToolTip toolTip;
private MenuBarItem menuBarItem2;
private MenuButtonItem menuItem_viewToolParameters;
private MenuButtonItem menuItem_viewEditorSettings;
private OpenFileDialog openMapDialog;
private SaveFileDialog saveMapDialog;
private MenuButtonItem menuItem_saveMapAs;
private MenuBarItem menuBarItem3;
private MenuButtonItem menuItem_Undo;
private MenuButtonItem menuItem_Redo;
private ButtonItem buttonItem4;
private ButtonItem buttonItem5;
private Timer timerUIUpdate;
private MenuBarItem menuBarItem4;
private MenuButtonItem menuItem_TestIngame;
private EditorSettingsDock editorSettingsDock;
private ContextHelpDock contextHelpDock;
private MenuButtonItem menuItem_viewContextHelp;
private StatusStrip statusBar;
private ToolStripStatusLabel statusCaption;
private ToolStripStatusLabel statusBarFpsItem;
private ToolStripStatusLabel statusBarCameraPos;
private ToolStripStatusLabel statusBarCursorPos;
private ToolStripDropDownButton statusBarCameraSpeed;
private ContextMenuStrip cameraSpeedStrip;
private MenuBarItem menuBarItem5;
private MenuButtonItem menuItem_OpenCodeEditor;
private MenuButtonItem menuItem_FlushCache;
private MenuButtonItem menuItem_ExportToConsole;
private FolderBrowserDialog folderBrowserDialog;
private ToolStripStatusLabel statusBarObjectUsage;
private ToolStripStatusLabel statusBarMemoryUsage;
private MenuButtonItem menuItem_ResetLayout;
private ContextMenuStrip statusBarContextMenu;
private ToolStripMenuItem whatsThisToolStripMenuItem;
private MenuButtonItem menuItem_newWilderness;
private MenuBarItem menuBarItem6;
private MenuButtonItem menuItem_visitWebsite;
private MenuButtonItem menuItem_about;
private MenuButtonItem menuItem_ExportToPC;
public bool EnableShortcuts
{
get { return this.menuBar.ShortcutListener.Listening; }
set
{
this.menuBar.ShortcutListener.Listening = value;
if (value)
{
this.viewport.BlockNextKeyRepeats = true;
}
}
}
public ITool CurrentTool
{
get { return m_currentTool; }
set
{
if (m_currentTool != null)
{
m_currentTool.Deactivate();
if (m_currentTool is IInputSink sink)
Editor.PopInput(sink);
}
m_currentTool = value;
if (m_currentTool != null)
{
if (m_currentTool is IInputSink sink)
Editor.PushInput(sink);
m_currentTool.Activate();
}
this.UpdateCurrentTool();
if (m_currentTool != null)
{
this.toolParametersDock.Open();
}
}
}
public bool CursorPhysics
{
get { return this.m_cursorPhysics; }
set { this.m_cursorPhysics = value; }
}
public string DocumentPath
{
get { return this.m_documentPath; }
set { this.m_documentPath = value; }
}
public ViewportControl Viewport { get { return this.viewport; } }
public ToolTip ToolTip { get { return this.toolTip; } }
public static bool IsActive
{
get
{
IntPtr activeWindow = Win32.GetActiveWindow();
while (activeWindow != IntPtr.Zero)
{
if (activeWindow == MainForm.Instance.Handle)
return true;
activeWindow = Win32.GetParent(activeWindow);
}
return false;
}
}
public static MainForm Instance { get { return s_instance; } }
public MainForm()
{
MainForm.s_instance = this;
this.InitializeComponent();
byte[] iconBytes = (byte[])Resources.ResourceManager.GetObject("appIcon");
using (System.IO.MemoryStream ms = new System.IO.MemoryStream(iconBytes))
{
base.Icon = new System.Drawing.Icon(ms);
}
Editor.PushInput((IInputSink)this);
base.HandleCreated += new EventHandler(this.MainForm_HandleCreated);
base.HandleDestroyed += new EventHandler(this.MainForm_HandleDestroyed);
bool flag = false;
foreach (string str in Environment.GetCommandLineArgs())
{
if (str == "-wilderness")
flag = true;
}
this.menuItem_OpenCodeEditor.Visible = flag;
this.menuItem_ExportToPC.Visible = false;
this.menuItem_ExportToConsole.Visible = false;
}
private void DisposeInternal()
{
Editor.PopInput((IInputSink)this);
}
public void InitializeDocks()
{
this.toolParametersDock = new ToolParametersDock();
this.toolParametersDock.Guid = new Guid("3b44d7d6-f472-4373-9bac-a5d4cc471425");
this.toolParametersDock.Manager = this.sandDockManager;
this.contextHelpDock = new ContextHelpDock();
this.contextHelpDock.Guid = new Guid("4a3bcfd3-d4b0-44a0-bac0-bfd030fbc69b");
this.contextHelpDock.Manager = this.sandDockManager;
this.editorSettingsDock = new EditorSettingsDock();
this.editorSettingsDock.Guid = new Guid("ad8a4d52-f3ba-4463-9ce3-4cbed143ec05");
this.editorSettingsDock.Manager = this.sandDockManager;
}
public void EnableUI(bool enable)
{
foreach (Control control in base.Controls)
{
control.Enabled = enable;
}
}
private TD.SandBar.ToolBar CreateToolbar(string id, string text, int row, int column)
{
TD.SandBar.ToolBar toolBar = new TD.SandBar.ToolBar();
toolBar.Guid = new Guid(id.GetHashCode(), (short)0, (short)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0);
toolBar.DockLine = row;
toolBar.DockOffset = column;
this.sandBarManager.AddToolbar(toolBar);
toolBar.Redock(this.sandBarManager.FindSuitableContainer(DockStyle.Top));
toolBar.Text = text;
toolBar.EnterMenuLoop += new EventHandler(this.menuBar_EnterMenuLoop);
toolBar.ExitMenuLoop += new EventHandler(this.menuBar_ExitMenuLoop);
return toolBar;
}
private void AddTool(TD.SandBar.ToolBar toolbar, IToolBase tool, Keys shortcut)
{
ButtonItem buttonItem = new ButtonItem();
buttonItem.Image = tool.GetToolImage();
buttonItem.ToolTipText = StringUtils.EscapeUIString(tool.GetToolName()) + (shortcut != Keys.None ? " (" + shortcut.ToString() + ")" : "");
buttonItem.Tag = (object)tool;
if (tool is ITool)
buttonItem.Activate += new EventHandler(this.tool_Activate);
else if (tool is IToolAction)
buttonItem.Activate += new EventHandler(this.toolBase_Activate);
toolbar.Items.Add((ToolbarItemBase)buttonItem);
this.m_toolItemList.Add(buttonItem);
if (shortcut == Keys.None)
return;
this.m_toolShortcuts.Add(shortcut, buttonItem);
}
public void InitializeTools()
{
TD.SandBar.ToolBar toolbar1 = this.CreateToolbar("Terrain", Localizer.Localize("TOOLBAR_TERRAIN"), 1, 1);
this.AddTool(toolbar1, (IToolBase)new ToolTerrainBump(), Keys.F1);
this.AddTool(toolbar1, (IToolBase)new ToolTerrainRaiseLower(), Keys.F2);
this.AddTool(toolbar1, (IToolBase)new ToolTerrainSetHeight(), Keys.F3);
this.AddTool(toolbar1, (IToolBase)new ToolTerrainSmooth(), Keys.F4);
this.AddTool(toolbar1, (IToolBase)new ToolTerrainRamp(), Keys.F5);
this.AddTool(toolbar1, (IToolBase)new ToolTerrainNoise(), Keys.F6);
this.AddTool(toolbar1, (IToolBase)new ToolTerrainErosion(), Keys.F7);
this.AddTool(toolbar1, (IToolBase)new ToolTexture(), Keys.F8);
TD.SandBar.ToolBar toolbar2 = this.CreateToolbar("Objects", Localizer.Localize("TOOLBAR_OBJECTS"), 1, 2);
this.AddTool(toolbar2, (IToolBase)new ToolObject(), Keys.F9);
this.AddTool(toolbar2, (IToolBase)new ToolCollection(), Keys.F10);
this.AddTool(toolbar2, (IToolBase)new ToolRoad(), Keys.F11);
this.AddTool(toolbar2, (IToolBase)new ToolPlayableZone(), Keys.F12);
TD.SandBar.ToolBar toolbar3 = this.CreateToolbar("Miscellaneous", Localizer.Localize("TOOLBAR_MISCELLANEOUS"), 1, 3);
this.AddTool(toolbar3, (IToolBase)new ToolEnvironment(), Keys.None);
this.AddTool(toolbar3, (IToolBase)new ToolValidation(), Keys.None);
this.AddTool(toolbar3, (IToolBase)new ToolProperties(), Keys.None);
this.AddTool(toolbar3, (IToolBase)new ToolFinalize(), Keys.None);
}
private void toolBase_Activate(object sender, EventArgs e)
{
((IToolAction)((ButtonItem)sender).Tag).Fire();
}
private void tool_Activate(object sender, EventArgs e)
{
ITool tag = (ITool)((ButtonItem)sender).Tag;
this.CurrentTool = this.CurrentTool != tag ? tag : (ITool)null;
}
private void UpdateToolbar()
{
foreach (ButtonItem toolItem in this.m_toolItemList)
{
if (toolItem.Tag == this.CurrentTool)
{
if (!toolItem.Checked)
toolItem.Checked = true;
}
else if (toolItem.Checked)
toolItem.Checked = false;
}
}
public void ClearMapPath()
{
this.m_documentPath = (string)null;
this.UpdateTitleBar();
}
private bool PromptSave(EditorDocument.SaveCompletedCallback callback)
{
switch (MessageBox.Show((IWin32Window)MainForm.Instance, Localizer.Localize("EDITOR_CHANGE_MAP_PROMPT"), Localizer.Localize("EDITOR_CONFIRMATION"), MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation))
{
case DialogResult.Yes:
this.SaveMap(false, true, callback);
return false;
case DialogResult.No:
return true;
case DialogResult.Cancel:
return false;
default:
return false;
}
}
private void NewMap()
{
if (!this.PromptSave((EditorDocument.SaveCompletedCallback)(success =>
{
if (!success)
return;
this.NewMapInternal();
})))
return;
this.NewMapInternal();
}
private void NewMapInternal()
{
this.CurrentTool = (ITool)null;
EditorDocument.Reset();
this.m_documentPath = (string)null;
this.UpdateTitleBar();
}
private void LoadMap(string fileName, EditorDocument.LoadCompletedCallback callback)
{
if (!this.PromptSave((EditorDocument.SaveCompletedCallback)(success =>
{
if (!success)
return;
this.LoadMapInternal((string)null, callback);
})))
return;
this.LoadMapInternal(fileName, callback);
}
private void LoadMapInternal(string fileName, EditorDocument.LoadCompletedCallback callback)
{
if (fileName == null)
{
if (this.openMapDialog.ShowDialog((IWin32Window)this) != DialogResult.OK)
return;
fileName = this.openMapDialog.FileName;
}
this.m_documentPath = fileName;
this.CurrentTool = (ITool)null;
EditorDocument.Load(this.m_documentPath, callback);
this.UpdateTitleBar();
}
private bool SaveMap(bool saveAs, bool silent, EditorDocument.SaveCompletedCallback callback)
{
if (!EditorDocument.Validate() && MessageBox.Show(Localizer.Localize("ERROR_VALIDATION_FAILED"), Localizer.Localize("ERROR"), MessageBoxButtons.YesNo, MessageBoxIcon.Hand) == DialogResult.No)
return false;
string fileName = this.m_documentPath;
if (saveAs || this.m_documentPath == null)
{
this.saveMapDialog.FileName = fileName;
if (this.saveMapDialog.ShowDialog((IWin32Window)this) != DialogResult.OK)
return false;
fileName = this.saveMapDialog.FileName;
}
string str = (string)null;
if (string.IsNullOrEmpty(EditorDocument.CreatorName))
{
using (PromptForm promptForm = new PromptForm(Localizer.Localize("PROMPT_CREATOR_TEXT")))
{
promptForm.Text = Localizer.Localize("PROMPT_CREATOR_TITLE");
promptForm.Input = EditorDocument.AuthorName;
if (promptForm.ShowDialog((IWin32Window)this) != DialogResult.OK)
return false;
str = promptForm.Input;
}
}
if (str != null)
EditorDocument.CreatorName = str;
this.m_documentPath = fileName;
EditorDocument.Save(this.m_documentPath, callback);
this.UpdateTitleBar();
return true;
}
private void ExportMap(bool toConsole)
{
if (this.openMapDialog.ShowDialog((IWin32Window)this) != DialogResult.OK || this.folderBrowserDialog.ShowDialog((IWin32Window)this) != DialogResult.OK)
return;
EditorDocument.Export(this.openMapDialog.FileName, this.folderBrowserDialog.SelectedPath, toConsole);
}
public void ToggleIngame()
{
bool isIngame = Editor.IsIngame;
if (isIngame)
{
this.CurrentTool = (ITool)null;
this.statusCaption.Text = Localizer.Localize("EDITOR_STATUS_INGAME");
}
else
this.statusCaption.Text = Localizer.Localize("EDITOR_STATUS_READY");
this.Viewport.CaptureMouse = isIngame;
foreach (Control control in base.Controls)
{
if (control != this.Viewport && control != this.statusBar)
{
control.Enabled = !isIngame;
control.Visible = !isIngame;
}
}
this.Viewport.Focus();
}
private void menuItem_newMap_Activate(object sender, EventArgs e)
{
this.NewMap();
}
private void menuItem_newWilderness_Activate(object sender, EventArgs e)
{
this.NewMap();
using (PromptInventory promptInventory = new PromptInventory())
{
promptInventory.Root = WildernessInventory.Instance.Root;
if (promptInventory.ShowDialog((IWin32Window)this) == DialogResult.OK)
Wilderness.RunScriptEntry((WildernessInventory.Entry)promptInventory.Value);
}
}
private void menuItem_loadMap_Activate(object sender, EventArgs e)
{
this.LoadMap((string)null, (EditorDocument.LoadCompletedCallback)null);
}
private void menuItem_saveMap_Activate(object sender, EventArgs e)
{
this.SaveMap(false, false, (EditorDocument.SaveCompletedCallback)null);
}
private void menuItem_saveMapAs_Activate(object sender, EventArgs e)
{
this.SaveMap(true, false, (EditorDocument.SaveCompletedCallback)null);
}
private void menuItem_exit_Activate(object sender, EventArgs e)
{
this.Close();
}
private void menuItem_Undo_Activate(object sender, EventArgs e)
{
UndoManager.Undo();
}
private void menuItem_Redo_Activate(object sender, EventArgs e)
{
UndoManager.Redo();
}
private void menuItem_viewToolParameters_Activate(object sender, EventArgs e)
{
this.toolParametersDock.Open();
}
private void menuItem_viewEditorSettings_Activate(object sender, EventArgs e)
{
this.editorSettingsDock.Open();
}
private void menuItem_viewContextHelp_Activate(object sender, EventArgs e)
{
this.contextHelpDock.Open();
}
private void menuItem_TestIngame_Activate(object sender, EventArgs e)
{
Editor.ToggleIngame();
}
private void menuItem_OpenCodeEditor_Activate(object sender, EventArgs e)
{
if (CodeEditor.Instance == null)
new CodeEditor();
CodeEditor.Instance.Show();
}
private void menuItem_FlushCache_Activate(object sender, EventArgs e)
{
ObjectRenderer.ClearCache();
}
private void menuItem_ResetLayout_Activate(object sender, EventArgs e)
{
try
{
this.sandDockManager.SetLayout(Resources.DefaultSandDockLayout);
}
catch (Exception ex)
{
}
try
{
this.sandBarManager.SetLayout(Resources.DefaultSandBarLayout);
}
catch (Exception ex)
{
}
}
private void menuItem_ExportToPC_Activate(object sender, EventArgs e)
{
this.ExportMap(false);
}
private void menuItem_ExportToConsole_Activate(object sender, EventArgs e)
{
this.ExportMap(true);
}
private void menuItem_visitWebsite_Activate(object sender, EventArgs e)
{
try
{
Process.Start("http://www.farcrygame.com");
}
catch (Exception ex)
{
}
}
private void menuItem_about_Activate(object sender, EventArgs e)
{
using (SplashForm splashForm = new SplashForm())
{
splashForm.AboutMode = true;
int num = (int)splashForm.ShowDialog((IWin32Window)this);
}
}
private void statusBarContextMenu_Opening(object sender, CancelEventArgs e)
{
Point position = Cursor.Position;
this.m_helpString = (string)null;
if (this.statusBar.RectangleToScreen(this.statusBarFpsItem.Bounds).Contains(position))
this.m_helpString = Localizer.Localize("HELP_STATUSBAR_PERFORMANCE");
else if (this.statusBar.RectangleToScreen(this.statusBarObjectUsage.Bounds).Contains(position))
this.m_helpString = Localizer.Localize("HELP_STATUSBAR_OBJECT_COST");
else if (this.statusBar.RectangleToScreen(this.statusBarMemoryUsage.Bounds).Contains(position))
this.m_helpString = Localizer.Localize("HELP_STATUSBAR_MEMORY_USAGE");
else if (this.statusBar.RectangleToScreen(this.statusBarCursorPos.Bounds).Contains(position))
this.m_helpString = Localizer.Localize("HELP_STATUSBAR_CURSOR_POS");
else if (this.statusBar.RectangleToScreen(this.statusBarCameraPos.Bounds).Contains(position))
this.m_helpString = Localizer.Localize("HELP_STATUSBAR_CAMERA_POS");
else if (this.statusBar.RectangleToScreen(this.statusBarCameraSpeed.Bounds).Contains(position))
this.m_helpString = Localizer.Localize("HELP_STATUSBAR_CAMERA_SPEED");
else if (this.statusBar.RectangleToScreen(this.statusCaption.Bounds).Contains(position))
this.m_helpString = Localizer.Localize("HELP_STATUSBAR_STATE");
}
private void whatsThisToolStripMenuItem_Click(object sender, EventArgs e)
{
if (this.m_helpString != null)
{
int num1 = (int)MessageBox.Show((IWin32Window)this, this.m_helpString, Localizer.Localize("HELP_WHATS_THIS"), MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else
{
int num2 = (int)MessageBox.Show((IWin32Window)this, "Help text not defined.", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
private void LoadSettings()
{
using (RegistryKey registrySettings = Editor.GetRegistrySettings())
{
Rectangle rectangle = new Rectangle()
{
X = Editor.GetRegistryInt(registrySettings, "MainFormX", this.Bounds.X),
Y = Editor.GetRegistryInt(registrySettings, "MainFormY", this.Bounds.Y),
Width = Editor.GetRegistryInt(registrySettings, "MainFormW", this.Bounds.Width),
Height = Editor.GetRegistryInt(registrySettings, "MainFormH", this.Bounds.Height)
};
foreach (Screen allScreen in Screen.AllScreens)
{
if (allScreen.Bounds.IntersectsWith(rectangle))
{
this.Bounds = rectangle;
this.StartPosition = FormStartPosition.Manual;
break;
}
}
try
{
this.sandDockManager.SetLayout(Editor.GetRegistryString(registrySettings, "SandDock", Resources.DefaultSandDockLayout));
}
catch (Exception ex)
{
}
try
{
this.sandBarManager.SetLayout(Editor.GetRegistryString(registrySettings, "SandBar", Resources.DefaultSandBarLayout));
}
catch (Exception ex)
{
}
foreach (TD.SandBar.ToolBar toolBar in this.sandBarManager.GetToolBars())
{
if (toolBar.Parent != null)
toolBar.Parent.Visible = true;
}
if (this.menuBar.Visible)
return;
foreach (TD.SandBar.ToolBar toolBar in this.sandBarManager.GetToolBars())
toolBar.Visible = true;
}
}
private void SaveSettings()
{
using (RegistryKey registrySettings = Editor.GetRegistrySettings())
{
registrySettings.SetValue("MainFormX", (object)this.Bounds.X);
registrySettings.SetValue("MainFormY", (object)this.Bounds.Y);
registrySettings.SetValue("MainFormW", (object)this.Bounds.Width);
registrySettings.SetValue("MainFormH", (object)this.Bounds.Height);
registrySettings.SetValue("SandDock", (object)this.sandDockManager.GetLayout());
registrySettings.SetValue("SandBar", (object)this.sandBarManager.GetLayout());
}
}
private void UpdateCurrentTool()
{
this.toolParametersDock.Tool = this.CurrentTool;
this.contextHelpDock.Tool = this.CurrentTool;
this.UpdateToolbar();
}
private void UpdateTitleBar()
{
this.Text = (this.m_documentPath != null ? Path.GetFileNameWithoutExtension(this.m_documentPath) : Localizer.Localize("EDITOR_UNTITLED")) + " - " + Localizer.Localize("EDITOR_NAME");
}
private void Localize()
{
Localizer.Localize(this.menuBar);
this.toolBarMain.Text = Localizer.Localize(this.toolBarMain.Text);
this.whatsThisToolStripMenuItem.Text = Localizer.Localize(this.whatsThisToolStripMenuItem.Text);
SandBarLanguage.AddRemoveButtonsText = Localizer.Localize("SANDBAR_ADDREMOVEBUTTONSTEXT");
SandBarLanguage.CloseMenuText = Localizer.Localize("SANDBAR_CLOSEMENUTEXT");
SandBarLanguage.CloseWindowText = Localizer.Localize("SANDBAR_CLOSEWINDOWTEXT");
SandBarLanguage.MaximizeMenuText = Localizer.Localize("SANDBAR_MAXIMIZEMENUTEXT");
SandBarLanguage.MinimizeMenuText = Localizer.Localize("SANDBAR_MINIMIZEMENUTEXT");
SandBarLanguage.MinimizeWindowText = Localizer.Localize("SANDBAR_MINIMIZEWINDOWTEXT");
SandBarLanguage.MoveMenuText = Localizer.Localize("SANDBAR_MOVEMENUTEXT");
SandBarLanguage.RestoreMenuText = Localizer.Localize("SANDBAR_RESTOREMENUTEXT");
SandBarLanguage.RestoreWindowText = Localizer.Localize("SANDBAR_RESTOREWINDOWTEXT");
SandBarLanguage.SizeMenuText = Localizer.Localize("SANDBAR_SIZEMENUTEXT");
SandBarLanguage.ToolbarOptionsText = Localizer.Localize("SANDBAR_TOOLBAROPTIONSTEXT");
SandDockLanguage.AutoHideText = Localizer.Localize("SANDDOCK_AUTOHIDETEXT");
SandDockLanguage.CloseText = Localizer.Localize("SANDDOCK_CLOSETEXT");
SandDockLanguage.ScrollLeftText = Localizer.Localize("SANDDOCK_SCROLLLEFTTEXT");
SandDockLanguage.ScrollRightText = Localizer.Localize("SANDDOCK_SCROLLRIGHTTEXT");
SandDockLanguage.WindowPositionText = Localizer.Localize("SANDDOCK_WINDOWPOSITIONTEXT");
}
private void MainForm_Load(object sender, EventArgs e)
{
this.Localize();
this.InitCameraSpeed();
this.InitializeDocks();
this.InitializeTools();
this.LoadSettings();
this.UpdateCurrentTool();
this.UpdateTitleBar();
this.openMapDialog.InitialDirectory = Engine.PersonalPath;
this.saveMapDialog.InitialDirectory = Engine.PersonalPath;
EditorDocument.Reset();
}
public void PostLoad()
{
if (Program.GetMapArgument() == null)
return;
this.LoadMapInternal(Program.GetMapArgument(), (EditorDocument.LoadCompletedCallback)null);
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (Editor.IsIngame)
Editor.ToggleIngame();
if (this.m_closeSaveConfirmed || this.PromptSave((EditorDocument.SaveCompletedCallback)(success =>
{
if (!success)
return;
this.m_closeSaveConfirmed = true;
this.Close();
})))
this.SaveSettings();
else
e.Cancel = true;
}
private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
{
Engine.Close();
}
private void MainForm_HandleCreated(object sender, EventArgs e)
{
Win32.SetProp(this.Handle, Program.programGuid, this.Handle);
}
private void MainForm_HandleDestroyed(object sender, EventArgs e)
{
Win32.RemoveProp(this.Handle, Program.programGuid);
}
private void MainForm_Activated(object sender, EventArgs e)
{
this.Viewport.UpdateFocus();
}
private void MainForm_Deactivate(object sender, EventArgs e)
{
this.Viewport.UpdateFocus();
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.F10 && Editor.Viewport.Focused)
{
this.OnKeyEvent(Editor.KeyEvent.KeyDown, new KeyEventArgs(Keys.F10));
this.OnKeyEvent(Editor.KeyEvent.KeyUp, new KeyEventArgs(Keys.F10));
return true;
}
return Editor.IsIngame || base.ProcessCmdKey(ref msg, keyData);
}
protected override void WndProc(ref Message m)
{
if (m.Msg == 74 && Engine.Initialized)
{
string stringUni = Marshal.PtrToStringUni(((Win32.COPYDATASTRUCT)Marshal.PtrToStructure(m.LParam, typeof(Win32.COPYDATASTRUCT))).lpData);
this.LoadMap(stringUni, (EditorDocument.LoadCompletedCallback)null);
}
base.WndProc(ref m);
}
private void menuBar_EnterMenuLoop(object sender, EventArgs e)
{
this.viewport.ForceRefresh = true;
}
private void menuBar_ExitMenuLoop(object sender, EventArgs e)
{
this.viewport.ForceRefresh = false;
}
private void timerUIUpdate_Tick(object sender, EventArgs e)
{
if (!Engine.Initialized)
return;
bool flag1 = UndoManager.UndoCount > 0;
bool flag2 = UndoManager.RedoCount > 0;
if (this.menuItem_Undo.Enabled != flag1)
this.menuItem_Undo.Enabled = flag1;
if (this.menuItem_Redo.Enabled == flag2)
return;
this.menuItem_Redo.Enabled = flag2;
}
private void InitCameraSpeed()
{
Camera.Speed = 16f;
float num1 = 2f;
for (int index = 0; index < 6; ++index)
{
ToolStripItem toolStripItem = this.cameraSpeedStrip.Items.Add(num1.ToString());
toolStripItem.Tag = (object)num1;
toolStripItem.Click += new EventHandler(this.cameraSpeedItem_Click);
num1 *= 2f;
}
this.cameraSpeedStrip.Items.Add(Localizer.Localize("EDITOR_CAMERA_SPEED_CUSTOM")).Click += new EventHandler(this.cameraSpeedItem_Click);
this.UpdateCameraSpeed();
}
private void UpdateCameraSpeed()
{
this.statusBarCameraSpeed.Text = Camera.Speed.ToString();
}
private void cameraSpeedItem_Click(object sender, EventArgs e)
{
object tag = ((ToolStripItem)sender).Tag;
float num;
if (tag != null)
{
num = (float)tag;
}
else
{
using (PromptForm promptForm = new PromptForm(Localizer.Localize("EDITOR_CAMERA_SPEED_PROMPT"), Localizer.Localize("EDITOR_CAMERA_SPEED_PROMPT_TITLE")))
{
promptForm.Validation = PromptForm.GetFloatValidation(1f / 1000f, 50f);
if (promptForm.ShowDialog((IWin32Window)this) != DialogResult.OK)
return;
num = float.Parse(promptForm.Input);
}
}
Camera.Speed = num;
this.UpdateCameraSpeed();
}
public void OnInputAcquire()
{
}
public void OnInputRelease()
{
}
public bool OnMouseEvent(Editor.MouseEvent mouseEvent, MouseEventArgs mouseEventArgs)
{
return false;
}
public bool OnKeyEvent(Editor.KeyEvent keyEvent, KeyEventArgs keyEventArgs)
{
if (keyEvent == Editor.KeyEvent.KeyDown)
{
if (keyEventArgs.KeyCode == Keys.Escape)
{
this.CurrentTool = (ITool)null;
return true;
}
ButtonItem buttonItem;
if (this.m_toolShortcuts.TryGetValue(keyEventArgs.KeyCode, out buttonItem))
{
this.CurrentTool = (ITool)buttonItem.Tag;
return true;
}
}
return false;
}
public void OnEditorEvent(uint eventType, IntPtr eventPtr)
{
}
public void Update(float dt)
{
this.m_lastUpdate += dt;
if ((double)this.m_lastUpdate >= 0.1)
{
this.m_lastUpdate = 0.0f;
bool isLoadPending = Editor.IsLoadPending;
if (this.m_isLoading != isLoadPending)
{
this.m_isLoading = isLoadPending;
if (isLoadPending)
{
this.statusCaption.Image = (Image)Resources.hourglass;
this.statusCaption.Text = Localizer.Localize("EDITOR_STATUS_LOADING");
}
else
{
this.statusCaption.Image = (Image)null;
this.statusCaption.Text = Localizer.Localize("EDITOR_STATUS_READY");
}
}
float num1 = (float)BudgetManager.MemoryUsage / 1048576f;
if ((double)Math.Abs(this.m_currentMemoryUsage - num1) >= 0.1)
{
this.m_currentMemoryUsage = num1;
this.statusBarMemoryUsage.Text = num1.ToString("F1");
}
float objectUsage = BudgetManager.ObjectUsage;
if ((double)Math.Abs(this.m_currentObjectUsage - objectUsage) >= 0.1)
{
this.m_currentObjectUsage = objectUsage;
this.statusBarObjectUsage.Text = objectUsage.ToString("F0");
}
float num2 = 1f / Editor.FrameTime;
if ((double)num2 != (double)this.m_currentFps)
{
this.m_currentFps = num2;
this.statusBarFpsItem.Text = num2.ToString("F1") + " fps";
}
Vec3 position = Camera.Position;
if (position != this.m_currentCameraPos)
{
this.m_currentCameraPos = position;
this.statusBarCameraPos.Text = position.ToString("F2");
}
Vec3 hitPos;
bool flag = this.m_cursorPhysics ? Editor.RayCastPhysicsFromMouse(out hitPos) : Editor.RayCastTerrainFromMouse(out hitPos);
if (this.m_currentCursorValid != flag || hitPos != this.m_currentCursorPos)
{
this.m_currentCursorPos = hitPos;
this.m_currentCursorValid = flag;
if (flag)
this.statusBarCursorPos.Text = hitPos.ToString("F2");
else
this.statusBarCursorPos.Text = Localizer.Localize("PARAM_NA");
}
}
ObjectRenderer.Update(dt);
}
protected override void Dispose(bool disposing)
{
this.DisposeInternal();
if (disposing && this.components != null)
this.components.Dispose();
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.sandDockManager = new TD.SandDock.SandDockManager();
this.sandBarManager = new TD.SandBar.SandBarManager(this.components);
this.leftSandBarDock = new TD.SandBar.ToolBarContainer();
this.rightSandBarDock = new TD.SandBar.ToolBarContainer();
this.bottomSandBarDock = new TD.SandBar.ToolBarContainer();
this.topSandBarDock = new TD.SandBar.ToolBarContainer();
this.menuBar = new TD.SandBar.MenuBar();
this.menuBarItem1 = new TD.SandBar.MenuBarItem();
this.menuItem_newMap = new TD.SandBar.MenuButtonItem();
this.menuItem_newWilderness = new TD.SandBar.MenuButtonItem();
this.menuItem_loadMap = new TD.SandBar.MenuButtonItem();
this.menuItem_saveMap = new TD.SandBar.MenuButtonItem();
this.menuItem_saveMapAs = new TD.SandBar.MenuButtonItem();
this.menuItem_exit = new TD.SandBar.MenuButtonItem();
this.menuBarItem3 = new TD.SandBar.MenuBarItem();
this.menuItem_Undo = new TD.SandBar.MenuButtonItem();
this.menuItem_Redo = new TD.SandBar.MenuButtonItem();
this.menuBarItem2 = new TD.SandBar.MenuBarItem();
this.menuItem_viewToolParameters = new TD.SandBar.MenuButtonItem();
this.menuItem_viewEditorSettings = new TD.SandBar.MenuButtonItem();
this.menuItem_viewContextHelp = new TD.SandBar.MenuButtonItem();
this.menuBarItem4 = new TD.SandBar.MenuBarItem();
this.menuItem_TestIngame = new TD.SandBar.MenuButtonItem();
this.menuBarItem5 = new TD.SandBar.MenuBarItem();
this.menuItem_OpenCodeEditor = new TD.SandBar.MenuButtonItem();
this.menuItem_ExportToPC = new TD.SandBar.MenuButtonItem();
this.menuItem_ExportToConsole = new TD.SandBar.MenuButtonItem();
this.menuItem_FlushCache = new TD.SandBar.MenuButtonItem();
this.menuItem_ResetLayout = new TD.SandBar.MenuButtonItem();
this.menuBarItem6 = new TD.SandBar.MenuBarItem();
this.menuItem_visitWebsite = new TD.SandBar.MenuButtonItem();
this.menuItem_about = new TD.SandBar.MenuButtonItem();
this.toolBarMain = new TD.SandBar.ToolBar();
this.buttonItem1 = new TD.SandBar.ButtonItem();
this.buttonItem2 = new TD.SandBar.ButtonItem();
this.buttonItem3 = new TD.SandBar.ButtonItem();
this.buttonItem4 = new TD.SandBar.ButtonItem();
this.buttonItem5 = new TD.SandBar.ButtonItem();
this.toolTip = new System.Windows.Forms.ToolTip(this.components);
this.openMapDialog = new System.Windows.Forms.OpenFileDialog();
this.saveMapDialog = new System.Windows.Forms.SaveFileDialog();
this.timerUIUpdate = new System.Windows.Forms.Timer(this.components);
this.statusBar = new System.Windows.Forms.StatusStrip();
this.statusBarContextMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
this.whatsThisToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.statusCaption = new System.Windows.Forms.ToolStripStatusLabel();
this.statusBarCameraSpeed = new System.Windows.Forms.ToolStripDropDownButton();
this.cameraSpeedStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
this.statusBarCameraPos = new System.Windows.Forms.ToolStripStatusLabel();
this.statusBarCursorPos = new System.Windows.Forms.ToolStripStatusLabel();
this.statusBarMemoryUsage = new System.Windows.Forms.ToolStripStatusLabel();
this.statusBarObjectUsage = new System.Windows.Forms.ToolStripStatusLabel();
this.statusBarFpsItem = new System.Windows.Forms.ToolStripStatusLabel();
this.folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog();
this.viewport = new FC2Editor.UI.ViewportControl();
this.topSandBarDock.SuspendLayout();
this.statusBar.SuspendLayout();
this.statusBarContextMenu.SuspendLayout();
this.SuspendLayout();
this.sandDockManager.DockSystemContainer = (System.Windows.Forms.Control)this;
this.sandDockManager.OwnerForm = this;
this.sandBarManager.OwnerForm = this;
this.sandBarManager.Renderer = new TD.SandBar.WhidbeyRenderer();
this.leftSandBarDock.Dock = System.Windows.Forms.DockStyle.Left;
this.leftSandBarDock.Guid = new System.Guid("5af42533-b4bf-4ff9-b113-19c06ff822ad");
this.leftSandBarDock.Location = new System.Drawing.Point(0, 49);
this.leftSandBarDock.Manager = this.sandBarManager;
this.leftSandBarDock.Name = "leftSandBarDock";