You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
96 lines
2.9 KiB
GDScript
96 lines
2.9 KiB
GDScript
@tool
|
|
extends EditorPlugin
|
|
|
|
var menu_parent: Node
|
|
var skill_popup: PopupMenu
|
|
var short_cut_popup: PopupMenu
|
|
var skill_cfg_list: Array[SkillCfg]
|
|
var short_cut_path_list: Array[String]
|
|
var selected_skill_file: String
|
|
|
|
|
|
func _enter_tree():
|
|
var root: Node = EditorInterface.get_editor_main_screen()
|
|
while root.get_parent() != null:
|
|
root = root.get_parent()
|
|
menu_parent = root.get_child(0).get_child(4).get_child(0).get_child(0).get_child(0)
|
|
if not menu_parent:
|
|
print("menu_parent is null")
|
|
return
|
|
|
|
## 技能配置
|
|
skill_popup = PopupMenu.new()
|
|
skill_popup.name = "技能配置"
|
|
menu_parent.add_child(skill_popup)
|
|
skill_popup.about_to_popup.connect(skill_popup_about_to_popup)
|
|
skill_popup.index_pressed.connect(skill_popup_index_pressed)
|
|
|
|
## 快捷方式
|
|
short_cut_popup = PopupMenu.new()
|
|
short_cut_popup.name = "快捷方式"
|
|
menu_parent.add_child(short_cut_popup)
|
|
short_cut_popup.index_pressed.connect(short_cut_index_pressed)
|
|
|
|
add_short_cut("配置-角色", "res://config/character")
|
|
add_short_cut("配置-武器技能", "res://config/skill_player_weapon")
|
|
add_short_cut("资产-技能特效", "res://scene/effect/particle")
|
|
add_short_cut("资产-AI", "res://scene/ai")
|
|
|
|
|
|
func add_short_cut(target_name: String, path: String):
|
|
short_cut_popup.add_item(target_name)
|
|
short_cut_path_list.append(path)
|
|
|
|
|
|
func skill_popup_about_to_popup():
|
|
skill_cfg_list.clear()
|
|
skill_popup.set_item_count(0)
|
|
skill_cfg_list = Util.get_all_skill()
|
|
for skill_cfg in skill_cfg_list:
|
|
skill_popup.add_item(skill_cfg.get_res_name())
|
|
|
|
|
|
func skill_popup_index_pressed(index: int):
|
|
EditorInterface.select_file(skill_cfg_list[index].resource_path)
|
|
|
|
|
|
func short_cut_index_pressed(index: int):
|
|
EditorInterface.select_file(short_cut_path_list[index])
|
|
|
|
|
|
func _process(delta: float) -> void:
|
|
var selected_paths: PackedStringArray = EditorInterface.get_selected_paths()
|
|
if len(selected_paths) != 1:
|
|
return
|
|
var selected_path: String = selected_paths[0]
|
|
if selected_skill_file == selected_path:
|
|
return
|
|
selected_skill_file = selected_path
|
|
if not selected_path.ends_with(".tres"):
|
|
return
|
|
var res := ResourceLoader.load(selected_path)
|
|
if not res is SkillCfg:
|
|
return
|
|
var skill_cfg: SkillCfg = res as SkillCfg
|
|
|
|
if not skill_cfg.skill_animation:
|
|
return
|
|
|
|
EditorInterface.open_scene_from_path("res://scene/character/character.tscn")
|
|
var root: Node = EditorInterface.get_edited_scene_root()
|
|
var character_skill: AnimationPlayer = root.find_child("Skill") as AnimationPlayer
|
|
var animation_name: String = "animation_library/%s" % Util.get_resource_name(res)
|
|
if not character_skill.has_animation(animation_name):
|
|
print("技能动画不存在:", animation_name)
|
|
return
|
|
|
|
character_skill.current_animation = animation_name
|
|
EditorInterface.edit_node(character_skill)
|
|
EditorInterface.edit_resource(res)
|
|
|
|
|
|
func _exit_tree():
|
|
remove_tool_menu_item("Test")
|
|
if skill_popup: skill_popup.queue_free()
|
|
if short_cut_popup: short_cut_popup.queue_free()
|