-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathItemList.gd
62 lines (50 loc) · 1.42 KB
/
ItemList.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
extends ItemList
onready var context_menu = $ContextMenu
#onready var data = get_node("/root/Data")
#
#onready var dict = data.poses
var from = null
var to = null
var selected = null
var pose_icon = load("res://art/sliders.svg")
enum Action {MOVE, DELETE, NONE = -1}
var current_action = Action.NONE
func _ready():
load_data()
func _on_ItemList_item_activated(index):
if current_action == Action.MOVE:
to = index
move_item(from, to)
current_action = Action.NONE
update_poses()
func _on_ItemList_item_rmb_selected(index, at_position):
selected = index
# print("selected: ", selected)
var mouse_position = get_viewport().get_mouse_position()
context_menu.rect_position = mouse_position
context_menu.show()
func _on_ContextMenu_index_pressed(index):
if index == Action.MOVE:
current_action = Action.MOVE
from = selected
elif index == Action.DELETE and selected !=null:
current_action = Action.DELETE
remove_item(selected)
selected = null
current_action = Action.NONE
update_poses()
func _on_ContextMenu_focus_exited():
context_menu.hide()
func update_poses():
Data.poses.pose.clear()
for i in get_item_count():
Data.poses.pose.append(get_item_metadata(i))
for i in Data.poses.pose.size():
print(Data.poses.pose[i])
func load_data():
# print("Clearing")
clear()
for i in Data.poses.pose.size():
add_item("Pose: " + str(i), pose_icon)
set_item_metadata(i, Data.poses.pose[i])
# print("adding items")