-
Notifications
You must be signed in to change notification settings - Fork 1
/
obj.gd
86 lines (68 loc) · 1.78 KB
/
obj.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
extends TextureButton
onready var main = get_node("/root/main")
var pos = Vector2(0,0)
var obj_name = "Object"
var obj_id = "0"
var obj_type = "static"
var obj_is_group = false
var obj_group = ""
var obj_anim = "default"
var obj_frame = 1
var insert_into_list = false
var inserted = false
var dragging = false
var selected = false
var tile = ImageTexture.new()
var icon = ImageTexture.new()
var location = ""
var custom_prop = {}
var anims = ['default']
var created_on_start = true
func _ready():
if not inserted:
var id = str(main.objs.get_child_count()) # TODO repleace by proper ID
obj_id = "obj_"+id
obj_name += " "+id
set_name(obj_id)
else:
obj_id = get_name()
update_anim()
if insert_into_list:
icon.load(location+"/icon_24.png")
main.get_node("obj_list").add_item(obj_name,icon)
main.newevent.get_node("list_1").add_item(obj_name,icon)
main.newevent.get_node("list_3").add_item(obj_name,icon)
main.obj_unique_list.append(obj_id)
set_process(true)
func init_prop(json):
custom_prop = json
func _on_obj_button_down():
print(obj_id)
pos = main.pos - get_position()
dragging = true
if not selected:
selected()
func _on_obj_button_up():
dragging = false
func _process(delta):
if dragging:
set_position(main.pos-pos)
func selected():
main.selection_clear()
main.toolbox.get_node("obj_name").set_text(obj_name)
main.obj_selected = get_name()
$selection.set_visible(true)
selected = true
main.selection_obj()
func unselect():
$selection.set_visible(false)
selected = false
func update_anim():
tile = load(location+"/frames/"+obj_anim+"/frame_"+str(obj_frame)+".png")
$tile.set_texture(tile)
var size = tile.get_size()
self.set_size(size)
$selection.set_size(size)
func created_on_start(state):
created_on_start = state
set_visible(created_on_start)