forked from davidwashere/delegated-scanning-sim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog_panel.gd
68 lines (52 loc) · 1.37 KB
/
log_panel.gd
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
extends Control
class_name LogPanel
const log_entry_scene = preload("res://log_entry.tscn")
@onready var log_entries = $ScrollContainer/LogEntries
func _ready():
SignalManager.clear_log.connect(delAll)
SignalManager.pop_log_entry.connect(del)
SignalManager.push_log_entry.connect(add)
func add(icon_text:String, text:String):
var le = log_entry_scene.instantiate()
le.desc = text
le.icon_text = icon_text
if log_entries.get_child_count() > 0:
var sep = HSeparator.new()
sep.name = "LogPanel-HSeparator"
log_entries.add_child(sep)
log_entries.add_child(le)
func del() -> bool:
var el = log_entries
var statuses:Array[bool] = []
var c = _get_last_child(el)
if c == null:
return false
if c is HSeparator:
return _remove_last(el)
# assume we have a sparator and another node
statuses.append(_remove_last(el))
statuses.append(_remove_last(el))
for s in statuses:
if s:
SignalManager.log_entry_popped.emit()
return true
return false
func delAll():
while del():
pass
SignalManager.log_cleared.emit()
func _get_last_child(el:Node) -> Node:
var cnt = el.get_child_count()
if cnt == 0:
return null
return el.get_child(cnt-1)
func _remove_last(el:Node) -> bool:
var cnt = el.get_child_count()
if cnt == 0:
return false
var c = el.get_child(cnt-1)
el.remove_child(c)
c.queue_free()
return true
func get_all() -> Array[LogEntry]:
return []