47 lines
1.6 KiB
GDScript3
47 lines
1.6 KiB
GDScript3
|
# MIT License
|
||
|
#
|
||
|
# Copyright (c) 2023 Mark McKay
|
||
|
# https://github.com/blackears/cyclopsLevelBuilder
|
||
|
#
|
||
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||
|
# of this software and associated documentation files (the "Software"), to deal
|
||
|
# in the Software without restriction, including without limitation the rights
|
||
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||
|
# copies of the Software, and to permit persons to whom the Software is
|
||
|
# furnished to do so, subject to the following conditions:
|
||
|
#
|
||
|
# The above copyright notice and this permission notice shall be included in all
|
||
|
# copies or substantial portions of the Software.
|
||
|
#
|
||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||
|
# SOFTWARE.
|
||
|
|
||
|
@tool
|
||
|
extends PopupMenu
|
||
|
class_name ActionPopupMenu
|
||
|
|
||
|
var action_map:Dictionary = {}
|
||
|
|
||
|
func _ready():
|
||
|
id_pressed.connect(on_id_pressed)
|
||
|
|
||
|
func add_action_item(action:CyclopsAction):
|
||
|
# var id:int = action_map.size()
|
||
|
var id:int = action_map.size() + 1000
|
||
|
add_item(action.name, id, action.accellerator)
|
||
|
action_map[id] = action
|
||
|
|
||
|
#func add_separator(label:String, id:int = -1):
|
||
|
# pass
|
||
|
|
||
|
func on_id_pressed(id:int):
|
||
|
var action:CyclopsAction = action_map[id]
|
||
|
action._execute()
|
||
|
|
||
|
|