Skip to content

Commit d7741b0

Browse files
committed
*added an indicator of code execution.
1 parent c533333 commit d7741b0

File tree

9 files changed

+93
-1
lines changed

9 files changed

+93
-1
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
0 Bytes
Binary file not shown.
201 Bytes
Binary file not shown.

prj/Assets/Examples/Scripts/Example.cs

+26-1
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,17 @@ private void Start()
127127
interp.Register("INPUT", discarded);
128128
Register(output);
129129

130+
editor.LineEdited += OnLineEdited;
131+
130132
StartCoroutine(Messaging());
131133

132134
StartCoroutine(FillLastCode());
133135
}
134136

135137
private void OnDestroy()
136138
{
139+
editor.LineEdited -= OnLineEdited;
140+
137141
interp.Stop();
138142

139143
while (!interp.Finished)
@@ -183,6 +187,9 @@ private void OnExecutionFinished()
183187
Debug.Log("OK");
184188

185189
mode = RunMode.Stopped;
190+
191+
editor.SelectionEnabled = true;
192+
editor.Unselect();
186193
}
187194

188195
private void Register(my_basic.mb_func_t func)
@@ -306,6 +313,8 @@ private IEnumerator FillLastCode()
306313

307314
public void OnLoadClicked()
308315
{
316+
OnStopClicked();
317+
309318
if (msgbox.Shown) return;
310319

311320
if (!File.Exists(FilePath))
@@ -351,6 +360,8 @@ public void OnSaveClicked()
351360

352361
public void OnInsertClicked()
353362
{
363+
OnStopClicked();
364+
354365
if (msgbox.Shown) return;
355366

356367
editor.Insert(editor.Selected);
@@ -360,6 +371,8 @@ public void OnInsertClicked()
360371

361372
public void OnDeleteClicked()
362373
{
374+
OnStopClicked();
375+
363376
if (msgbox.Shown) return;
364377

365378
editor.Remove(editor.Selected);
@@ -379,6 +392,8 @@ public void OnRunClicked()
379392

380393
interp.Run(this, code);
381394
}
395+
396+
editor.SelectionEnabled = false;
382397
}
383398

384399
public void OnStepClicked()
@@ -395,6 +410,8 @@ public void OnStepClicked()
395410

396411
interp.Run(this, code);
397412
}
413+
414+
editor.SelectionEnabled = false;
398415
}
399416

400417
public void OnPauseClicked()
@@ -407,13 +424,21 @@ public void OnPauseClicked()
407424

408425
public void OnStopClicked()
409426
{
410-
if (msgbox.Shown) return;
427+
if (msgbox.Shown)
428+
msgbox.Close();
411429

412430
if (mode != RunMode.Stopped)
413431
{
414432
mode = RunMode.Stopped;
415433

416434
interp.Stop();
417435
}
436+
437+
editor.SelectionEnabled = true;
438+
}
439+
440+
private void OnLineEdited(int ln)
441+
{
442+
OnStopClicked();
418443
}
419444
}

prj/Assets/Plugins/MyCodeEditor/MsgBox.cs

+7
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ public void Show(object msg, ClickedEventHandler callback = null)
7575
textMsg.text = msg.ToString();
7676
}
7777

78+
public void Close()
79+
{
80+
stack.Clear();
81+
82+
gameObject.SetActive(false);
83+
}
84+
7885
public void OnOkClicked()
7986
{
8087
if (stack.Peek().callback != null)

prj/Assets/Plugins/MyCodeEditor/MyCodeEditor.cs

+38
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,21 @@ public int LineCount
114114
get { return lines.Count; }
115115
}
116116

117+
private bool selectionEnabled = true;
118+
public bool SelectionEnabled
119+
{
120+
get
121+
{
122+
return selectionEnabled;
123+
}
124+
set
125+
{
126+
selectionEnabled = value;
127+
foreach (MyCodeHead h in heads)
128+
h.SelectionEnabled = selectionEnabled;
129+
}
130+
}
131+
117132
public IEnumerable<int> Selected
118133
{
119134
get
@@ -145,6 +160,8 @@ public IEnumerable<string> SelectedText
145160

146161
public Action<int> HeadClicked = null;
147162

163+
public Action<int> LineEdited = null;
164+
148165
private void Start()
149166
{
150167
fontMaterial.mainTexture.filterMode = FilterMode.Point;
@@ -489,6 +506,15 @@ public void Clear()
489506
lineTextWidth = 0.0f;
490507
}
491508

509+
public void Unselect()
510+
{
511+
for (int i = 0; i < LineCount; ++i)
512+
{
513+
MyCodeHead h = heads[i];
514+
h.toggleSelection.isOn = false;
515+
}
516+
}
517+
492518
public bool Unselect(int index)
493519
{
494520
if (index < 0 || index >= LineCount)
@@ -517,7 +543,10 @@ public void Select(int index)
517543
if (index >= 0 && index < LineCount)
518544
{
519545
MyCodeHead h = heads[index];
546+
bool e = h.SelectionEnabled;
547+
h.SelectionEnabled = true;
520548
h.toggleSelection.isOn = true;
549+
h.SelectionEnabled = e;
521550
}
522551
}
523552

@@ -528,7 +557,10 @@ public void Select(IEnumerable<int> indices)
528557
if (i >= 0 && i < LineCount)
529558
{
530559
MyCodeHead h = heads[i];
560+
bool e = h.SelectionEnabled;
561+
h.SelectionEnabled = true;
531562
h.toggleSelection.isOn = true;
563+
h.SelectionEnabled = e;
532564
}
533565
}
534566
}
@@ -545,6 +577,9 @@ public void ScrollToLine(int index)
545577

546578
float val = 1.0f - (float)index / LineCount;
547579
scrollLineCol.verticalScrollbar.value = val;
580+
581+
Unselect();
582+
Select(index);
548583
}
549584

550585
public void OnScrollLineColValueChanged(Vector2 val)
@@ -571,6 +606,9 @@ public void OnInputEdited()
571606
{
572607
codeInput.Editing.SetText(codeInput.FieldInput.text, Color(codeInput.FieldInput.text));
573608

609+
if (LineEdited != null)
610+
LineEdited(codeInput.Editing.LineNumber);
611+
574612
relayout = codeInput.Editing == lines.Last();
575613
}
576614

prj/Assets/Plugins/MyCodeEditor/MyCodeHead.cs

+22
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,29 @@ public int LineNumberTextWidth
118118
}
119119
}
120120

121+
private bool selfProtecting = false;
122+
123+
public bool SelectionEnabled { get; set; }
124+
121125
public Action<MyCodeHead> HeadClicked = null;
122126

127+
private void Start()
128+
{
129+
SelectionEnabled = true;
130+
}
131+
123132
private void Awake()
124133
{
125134
buttonLineNumber.onClick.AddListener(OnButtonHeadClicked);
135+
136+
toggleSelection.onValueChanged.AddListener(OnSelectionValueChanged);
126137
}
127138

128139
private void OnDestroy()
129140
{
130141
buttonLineNumber.onClick.RemoveListener(OnButtonHeadClicked);
142+
143+
toggleSelection.onValueChanged.RemoveListener(OnSelectionValueChanged);
131144
}
132145

133146
public void Relayout()
@@ -139,6 +152,15 @@ public void Relayout()
139152
buttonLineNumber.Rect().SetLeftPosition(-this.Rect().GetSize().x / 2.0f + toggleSelection.Rect().GetSize().x);
140153
}
141154

155+
private void OnSelectionValueChanged(bool v)
156+
{
157+
if (SelectionEnabled) return;
158+
if (selfProtecting) return;
159+
selfProtecting = true;
160+
toggleSelection.isOn = false;
161+
selfProtecting = false;
162+
}
163+
142164
private void OnButtonHeadClicked()
143165
{
144166
if (HeadClicked != null)

0 commit comments

Comments
 (0)