2019-08-04 09:57:42 +02:00
|
|
|
tool
|
|
|
|
extends Control
|
|
|
|
|
2019-11-23 12:33:43 +01:00
|
|
|
var navbar_storage = {
|
2019-11-24 20:12:55 +01:00
|
|
|
"File": {
|
|
|
|
"items": ["New", "Load", "Save", "Quit"],
|
|
|
|
"export_only": ["Quit"]
|
|
|
|
},
|
|
|
|
"Editor": {
|
|
|
|
"items": ["Settings", "Toggle Grid", "Reset Camera Position"],
|
|
|
|
},
|
|
|
|
"Image": {
|
|
|
|
"items": ["Resize"]
|
|
|
|
}
|
2019-11-23 12:33:43 +01:00
|
|
|
}
|
|
|
|
|
2019-11-27 06:09:09 +01:00
|
|
|
onready var dialogs = get_parent().get_node("Dialogs")
|
|
|
|
|
2019-08-04 09:57:42 +02:00
|
|
|
func _ready():
|
2019-11-24 20:12:55 +01:00
|
|
|
var x_to_add = 0
|
|
|
|
var menu_button_script = load("res://addons/graphics_editor/MenuButtonExtended.gd")
|
|
|
|
for i in navbar_storage:
|
|
|
|
var menu_button = MenuButton.new()
|
|
|
|
menu_button.name = i
|
|
|
|
menu_button.rect_size = Vector2(90, 20)
|
|
|
|
menu_button.rect_position = Vector2(x_to_add, 0)
|
|
|
|
x_to_add += menu_button.rect_size.x
|
|
|
|
menu_button.switch_on_hover = true
|
|
|
|
menu_button.flat = false
|
|
|
|
menu_button.text = i
|
|
|
|
menu_button.set_script(menu_button_script)
|
|
|
|
var items_to_remove = []
|
|
|
|
if Engine.editor_hint:
|
|
|
|
if navbar_storage[i].get("export_only"):
|
|
|
|
for j in navbar_storage[i]["export_only"]:
|
|
|
|
items_to_remove.append(j)
|
|
|
|
if navbar_storage[i].get("items"):
|
|
|
|
for j in navbar_storage[i]["items"]:
|
|
|
|
var item_index = items_to_remove.find(j)
|
|
|
|
if item_index == -1:
|
|
|
|
menu_button.get_popup().add_item(j)
|
|
|
|
get_node("Buttons").add_child(menu_button)
|
2019-08-04 09:57:42 +02:00
|
|
|
for i in get_node("Buttons").get_children():
|
|
|
|
i.connect("item_pressed", self, "button_pressed")
|
|
|
|
|
|
|
|
func button_pressed(button_name, button_item):
|
|
|
|
if button_name == "File":
|
2019-11-23 12:33:43 +01:00
|
|
|
if button_item == "New":
|
2019-11-27 06:09:09 +01:00
|
|
|
dialogs.show_dialog("NewImage")
|
2019-11-23 12:33:43 +01:00
|
|
|
if button_item == "Load":
|
2019-11-27 06:09:09 +01:00
|
|
|
dialogs.show_dialog("LoadFileDialog")
|
2019-08-04 09:57:42 +02:00
|
|
|
if button_item == "Save":
|
2019-11-27 06:09:09 +01:00
|
|
|
dialogs.show_dialog("SaveFileDialog")
|
2019-08-04 09:57:42 +02:00
|
|
|
if button_item == "Quit":
|
|
|
|
get_tree().quit()
|
|
|
|
elif button_name == "Editor":
|
|
|
|
if button_item == "Settings":
|
2019-11-27 06:09:09 +01:00
|
|
|
dialogs.show_dialog("Settings")
|
2019-08-04 09:57:42 +02:00
|
|
|
elif button_item == "Toggle Grid":
|
2019-11-23 12:33:43 +01:00
|
|
|
var grids_node = get_parent().get_node("PaintCanvasContainer/ViewportContainer/Viewport/PaintCanvas/Grids")
|
2019-08-04 09:57:42 +02:00
|
|
|
grids_node.visible = !grids_node.visible
|
2019-11-23 12:33:43 +01:00
|
|
|
elif button_item == "Reset Camera Position":
|
|
|
|
get_parent().camera.position = Vector2(0, 0)
|
|
|
|
elif button_name == "Image":
|
|
|
|
if button_item == "Resize":
|
2019-11-27 06:09:09 +01:00
|
|
|
dialogs.show_dialog("ExpandCanvas")
|