gfolf2/addons/terrain_3d/src/terrain_menu.gd

82 lines
3.1 KiB
GDScript3
Raw Normal View History

2024-10-20 15:47:57 -06:00
extends HBoxContainer
2024-11-17 12:47:37 -07:00
const DirectoryWizard: Script = preload("res://addons/terrain_3d/src/directory_setup.gd")
2024-10-20 15:47:57 -06:00
const Packer: Script = preload("res://addons/terrain_3d/src/channel_packer.gd")
2024-11-17 12:47:37 -07:00
const Baker: Script = preload("res://addons/terrain_3d/src/baker.gd")
2024-10-20 15:47:57 -06:00
var plugin: EditorPlugin
var menu_button: MenuButton = MenuButton.new()
2024-11-17 12:47:37 -07:00
var directory_setup: DirectoryWizard = DirectoryWizard.new()
2024-10-20 15:47:57 -06:00
var packer: Packer = Packer.new()
2024-11-17 12:47:37 -07:00
var baker: Baker = Baker.new()
2024-10-20 15:47:57 -06:00
2024-11-17 12:47:37 -07:00
# These are IDs and order must be consistent with add_item and set_disabled IDs
2024-10-20 15:47:57 -06:00
enum {
2024-11-17 12:47:37 -07:00
MENU_DIRECTORY_SETUP,
MENU_PACK_TEXTURES,
MENU_SEPARATOR,
2024-10-20 15:47:57 -06:00
MENU_BAKE_ARRAY_MESH,
MENU_BAKE_OCCLUDER,
2024-11-17 12:47:37 -07:00
MENU_SEPARATOR2,
2024-10-20 15:47:57 -06:00
MENU_SET_UP_NAVIGATION,
2024-11-17 12:47:37 -07:00
MENU_BAKE_NAV_MESH,
2024-10-20 15:47:57 -06:00
}
func _enter_tree() -> void:
2024-11-17 12:47:37 -07:00
directory_setup.plugin = plugin
2024-10-20 15:47:57 -06:00
packer.plugin = plugin
2024-11-17 12:47:37 -07:00
baker.plugin = plugin
add_child(directory_setup)
2024-10-20 15:47:57 -06:00
add_child(baker)
menu_button.text = "Terrain3D Tools"
2024-11-17 12:47:37 -07:00
menu_button.get_popup().add_item("Directory Setup...", MENU_DIRECTORY_SETUP)
menu_button.get_popup().add_item("Pack Textures...", MENU_PACK_TEXTURES)
2024-10-20 15:47:57 -06:00
menu_button.get_popup().add_separator("", MENU_SEPARATOR)
2024-11-17 12:47:37 -07:00
menu_button.get_popup().add_item("Bake ArrayMesh...", MENU_BAKE_ARRAY_MESH)
menu_button.get_popup().add_item("Bake Occluder3D...", MENU_BAKE_OCCLUDER)
menu_button.get_popup().add_separator("", MENU_SEPARATOR2)
menu_button.get_popup().add_item("Set up Navigation...", MENU_SET_UP_NAVIGATION)
menu_button.get_popup().add_item("Bake NavMesh...", MENU_BAKE_NAV_MESH)
2024-10-20 15:47:57 -06:00
menu_button.get_popup().id_pressed.connect(_on_menu_pressed)
menu_button.about_to_popup.connect(_on_menu_about_to_popup)
add_child(menu_button)
func _on_menu_pressed(p_id: int) -> void:
match p_id:
2024-11-17 12:47:37 -07:00
MENU_DIRECTORY_SETUP:
directory_setup.directory_setup_popup()
MENU_PACK_TEXTURES:
packer.pack_textures_popup()
2024-10-20 15:47:57 -06:00
MENU_BAKE_ARRAY_MESH:
baker.bake_mesh_popup()
MENU_BAKE_OCCLUDER:
baker.bake_occluder_popup()
MENU_SET_UP_NAVIGATION:
baker.set_up_navigation_popup()
2024-11-17 12:47:37 -07:00
MENU_BAKE_NAV_MESH:
baker.bake_nav_mesh()
2024-10-20 15:47:57 -06:00
func _on_menu_about_to_popup() -> void:
2024-11-17 12:47:37 -07:00
menu_button.get_popup().set_item_disabled(MENU_DIRECTORY_SETUP, not plugin.terrain)
menu_button.get_popup().set_item_disabled(MENU_PACK_TEXTURES, not plugin.terrain)
2024-10-20 15:47:57 -06:00
menu_button.get_popup().set_item_disabled(MENU_BAKE_ARRAY_MESH, not plugin.terrain)
menu_button.get_popup().set_item_disabled(MENU_BAKE_OCCLUDER, not plugin.terrain)
if plugin.terrain:
var nav_regions: Array[NavigationRegion3D] = baker.find_terrain_nav_regions(plugin.terrain)
menu_button.get_popup().set_item_disabled(MENU_BAKE_NAV_MESH, nav_regions.size() == 0)
menu_button.get_popup().set_item_disabled(MENU_SET_UP_NAVIGATION, nav_regions.size() != 0)
elif plugin.nav_region:
var terrains: Array[Terrain3D] = baker.find_nav_region_terrains(plugin.nav_region)
menu_button.get_popup().set_item_disabled(MENU_BAKE_NAV_MESH, terrains.size() == 0)
menu_button.get_popup().set_item_disabled(MENU_SET_UP_NAVIGATION, true)
else:
menu_button.get_popup().set_item_disabled(MENU_BAKE_NAV_MESH, true)
menu_button.get_popup().set_item_disabled(MENU_SET_UP_NAVIGATION, true)