forked from jadaradix/dsgamemaker
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFoundInScripts.cs
More file actions
131 lines (122 loc) · 5.45 KB
/
FoundInScripts.cs
File metadata and controls
131 lines (122 loc) · 5.45 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
namespace DS_Game_Maker
{
public partial class FoundInScripts
{
public List<string> ScriptNames = new List<string>();
public List<short> ScriptLines = new List<short>();
public List<short> ScriptPositions = new List<short>();
public string Term = string.Empty;
public FoundInScripts()
{
InitializeComponent();
}
private void FoundInScripts_Load(object sender, EventArgs e)
{
MainToolStrip.Renderer = new clsToolstripRenderer();
if (Term.Length == 0)
return;
FindInScriptsDoIt();
}
public void FindInScriptsDoIt()
{
short TermLength = (short)Term.Length;
MainListBox.Items.Clear();
ScriptNames.Clear();
ScriptLines.Clear();
ScriptPositions.Clear();
short DOn = 0;
foreach (string X in DSGMlib.GetXDSFilter("SCRIPT "))
{
DOn = 0;
string ScriptName = X.Substring(7);
ScriptName = ScriptName.Substring(0, ScriptName.LastIndexOf(","));
foreach (string ThisLine in DSGMlib.StringToLines(DSGMlib.PathToString(SessionsLib.SessionPath + "Scripts/" + ScriptName + ".dbas")))
{
short FullLength = (short)ThisLine.Length;
// MsgError("Line: " + ThisLine + vbcrlf + vbcrlf + "Length: " + FullLength.ToString)
if (TermLength > FullLength)
{
DOn = (short)(DOn + 1);
continue;
}
if (ThisLine == Term)
{
ScriptNames.Add(ScriptName);
ScriptLines.Add((short)(DOn + 1));
ScriptPositions.Add(0);
DOn = (short)(DOn + 1);
// MsgError("Term equal to line length")
continue;
}
// MsgError("Loop from 0 to " + (FullLength - TermLength).ToString)
for (short i = 0, loopTo = (short)(FullLength - TermLength); i <= loopTo; i++)
{
// MsgError(i.ToString + ": Observing: " + ThisLine.Substring(i))
if (ThisLine.Substring(i).StartsWith(Term))
{
DSGMlib.MsgError(i.ToString() + " - '" + ThisLine.Substring(i) + "' starts with '" + Term + "' so I'm addin' it");
ScriptNames.Add(ScriptName);
ScriptLines.Add((short)(DOn + 1));
ScriptPositions.Add(i);
// MsgError("Added line " + (DOn + 1).ToString)
// MsgError("Added pos " + i.ToString)
}
}
DOn = (short)(DOn + 1);
}
}
for (short i = 0, loopTo1 = (short)(ScriptNames.Count - 1); i <= loopTo1; i++)
MainListBox.Items.Add(ScriptNames[i]);
}
private void RefreshButton_Click(object sender, EventArgs e)
{
FindInScriptsDoIt();
}
private void MainListBox_MeasureItem(object sender, MeasureItemEventArgs e)
{
e.ItemHeight = 22;
}
private void MainListBox_DrawItem(object sender, DrawItemEventArgs e)
{
short i = (short)e.Index;
if (e.Index < 0)
return;
bool IsSelected = false;
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
IsSelected = true;
e.Graphics.FillRectangle(Brushes.White, new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height));
if (IsSelected)
e.Graphics.DrawImage(Properties.Resources.BarBG, new Rectangle(0, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height));
e.Graphics.DrawImageUnscaled(Properties.Resources.ScriptIcon, new Point(e.Bounds.X + 4, e.Bounds.Y + 3));
e.Graphics.DrawString(ScriptNames[i] + ": Line " + ScriptLines[i].ToString() + ", Pos: " + ScriptPositions[i].ToString(), new Font("Tahoma", 8f), Brushes.Black, e.Bounds.X + 21, e.Bounds.Y + 4);
}
private void CloseButton_Click(object sender, EventArgs e)
{
Close();
}
private void MainListBox_SelectedIndexChanged(object sender, EventArgs e)
{
string ScriptName = ScriptNames[MainListBox.SelectedIndex];
bool HasDone = false;
foreach (Form X in Program.Forms.main_Form.MdiChildren)
{
if ((X.Name == "Script") && (X.Text == ScriptName))
{
((Script)X).GoToLine((short)(ScriptLines[MainListBox.SelectedIndex] - 1), ScriptPositions[MainListBox.SelectedIndex], (short)Term.Length);
X.BringToFront();
HasDone = true;
}
}
if (!HasDone)
{
var P = new Script();
P.ScriptName = ScriptName;
object argInstance = (object)P;
DSGMlib.ShowInternalForm(ref argInstance);
P = (Script)argInstance;
P.GoToLine((short)(ScriptLines[MainListBox.SelectedIndex] - 1), ScriptPositions[MainListBox.SelectedIndex], (short)Term.Length);
}
}
}
}