-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNewGame.gd
79 lines (60 loc) · 2.36 KB
/
NewGame.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
extends Control
@onready var _browse: Button = get_node("PanelContainer/CenterContainer/VBoxContainer/Browse")
var _changed_image_path: bool = false
@onready var _image: Image
@onready var _image_path: String
@onready var _image_texture: ImageTexture
@onready var _tiles_image: TextureRect = get_node("PanelContainer/CenterContainer/VBoxContainer/TilesImage")
@onready var _tiles_image_dialog:FileDialog = get_node("TileImageDialog")
var _tiles_image_dialog_used: bool = false
@onready var _tree: SceneTree = get_tree()
@onready var _use_image: CheckButton = get_node("PanelContainer/CenterContainer/VBoxContainer/HBoxContainer/UseImage")
func _on_browse_pressed() -> void:
if _tiles_image_dialog_used:
_tiles_image_dialog.popup()
else:
_tiles_image_dialog_used = true;
if Globals.preferences.last_image != "":
_tiles_image_dialog.current_path = Globals.preferences.last_image
_tiles_image_dialog.popup_centered()
func _on_cancel_pressed() -> void:
var _x = _tree.change_scene_to_file("res://Main.tscn")
func _on_start_pressed() -> void:
if _use_image.pressed:
Globals.tiles_use_image = true
if _changed_image_path:
Globals.tiles_default_image = false
Globals.preferences.last_image = _image_path
Globals.preferences.save(Preferences.P_PREFS)
else:
Globals.tiles_use_image = false
var _x = _tree.change_scene_to_file("res://Game.tscn")
func _on_tile_image_dialog_file_selected(path: String) -> void:
_image_path = path
_image = load_image(_image_path)
_changed_image_path = true
update_image()
func _on_use_image_pressed() -> void:
_browse.disabled = not _use_image.button_pressed
func _ready() -> void:
# Update variables from globals
_use_image.button_pressed = Globals.tiles_use_image
_browse.disabled = !Globals.tiles_use_image
if Globals.tiles_default_image:
_image_path = Globals.preferences.default_image
else:
_image_path = Globals.preferences.last_image
_image = load_image(_image_path)
# Resize image and set as texture
call_deferred("update_image")
func load_image(path: String) -> Image:
if path.substr(0, 4) == "res:":
return ResourceLoader.load(path, "Image") as Image
else:
var i: Image = Image.new()
var _x = i.load(path)
return i
func update_image() -> void:
_image.resize(_tiles_image.size.x as int, _tiles_image.size.y as int)
_image_texture = ImageTexture.create_from_image(_image)
_tiles_image.texture = _image_texture