HammeriteEditorCommands
Editor. Inherits RefCounted
Every command the editor has, what it is bound to, and where it appears.
Hammerite's own, not Godot's InputMap. An InputMap action is global to the project that installs the addon, so putting sixty editor commands there would take sixty names out of the host game's hands - the same collision the class_name prefix exists to avoid, in a second namespace. The cost is that rebinding, saving and conflict detection are ours to write rather than Godot's to provide; rebind() is the first of them. Two kinds live here. Commands happen once, can be listed, drawn in a menu and greyed out. Held bindings are asked "is this down right now" inside a movement update - flying the camera, holding the clip plane - and never appear in a menu.
Methods
| Returns | Method |
|---|---|
HammeriteEditorCommand | add(command: HammeriteEditorCommand) |
HammeriteEditorCommand | register(id: StringName, label: String, menu: StringName, run: Callable) |
void | unregister(id: StringName) |
HammeriteEditorCommand | get_command(id: StringName) |
HammeriteEditorCommand[] | all() |
bool | rebind(id: StringName, events: InputEvent[]) |
StringName[] | menus() |
HammeriteEditorCommand[] | commands_in(menu: StringName) |
HammeriteEditorCommand[] | commands_in_context(context: StringName) |
HammeriteEditorCommand | find_command_for(event: InputEvent) |
bool | is_event_for(id: StringName, event: InputEvent) |
void | bind_held(id: StringName, keycode: int) |
bool | is_held(id: StringName) |
int | held_binding(id: StringName) |
StringName[] | held_ids() |
bool | is_command_held() static |
Signals
changed
signal changed()
A command was added or removed, or rebind() changed what one is bound to. Not emitted for other changes to a command already in the table.
Constants
FILE
const FILE = &"File"
Menu names, for register() and HammeriteEditorCommand.in_menu(). A menu is named by its title, so a command naming any other string makes a new menu with that title.
EDIT
const EDIT = &"Edit"
See FILE.
SELECTION
const SELECTION = &"Selection"
See FILE.
VIEW
const VIEW = &"View"
See FILE.
VIEWPORT_3D
const VIEWPORT_3D = &"3D View"
The dropdown in the corner of the perspective viewport, for what is true of the 3D VIEW rather than of the editor: which visualization it draws, and what it draws over the world. Its own menu name rather than a flag, so ordering, radio groups and separators work as they do anywhere else - the menubar knows to leave this one out.
TOOLS
const TOOLS = &"Tools"
See FILE. Where an addon's tool goes.
HELP
const HELP = &"Help"
Always the last menu, after any an addon adds.
MENU_ORDER
const MENU_ORDER = Array[StringName]([&"File", &"Edit", &"Selection", &"View", &"Tools"])
The order the menus are drawn in. A menu an addon invents lands after these.
CTX_ENTITY
const CTX_ENTITY = &"entity"
Right-click contexts. A command names the ones it belongs to (HammeriteEditorCommand.in_context()) and HammeriteContextMenu draws whichever of them the selection puts in play. Separate from HammeriteEditorCommand.menu because they answer different questions: a menu is where a command LIVES, a context is what it applies TO, and Mirror on X lives under Selection while applying to a brush, an entity and a prefab instance alike.
CTX_INSTANCE
const CTX_INSTANCE = &"instance"
A prefab instance is selected. While one is, CTX_ENTITY, CTX_BRUSH and CTX_FACE are not offered: an instance is acted on as one thing.
CTX_BRUSH
const CTX_BRUSH = &"brush"
A brush is selected. See CTX_ENTITY.
CTX_FACE
const CTX_FACE = &"face"
A face is selected. See CTX_ENTITY.
CTX_SELECTION
const CTX_SELECTION = &"selection"
Anything at all is selected. For what does not care which of the above it is: delete, duplicate, group, focus, narrow.
CTX_VIEW
const CTX_VIEW = &"view"
Always, including a click on empty space. For what is about the VIEW rather than about what was clicked. Nothing of the editor's own is in it yet - the one candidate, picking the working plane, reads the face under the CURSOR, and by the time you have moved the cursor onto a menu item it is not over that face any more.
CONTEXT_ORDER
const CONTEXT_ORDER = Array[StringName]([&"entity", &"instance", &"brush", &"face", &"selection", &"view"])
The order a right-click draws its sections in, most specific first: what you clicked, then what it is part of, then what any selection can do, then the view.
Method descriptions
add()
func add(command: HammeriteEditorCommand) -> HammeriteEditorCommand
Adds command and returns it. An id already registered is an error, and command is returned without being added, so whatever is chained on it changes nobody's command.
register()
func register(id: StringName, label: String, menu: StringName, run: Callable) -> HammeriteEditorCommand
For addons: one call, and the command is in the menu with its key working. The seam that stops every plugin hand-rolling another toolbar button.
unregister()
func unregister(id: StringName) -> void
Removes the command id. Nothing happens when there is none.
get_command()
func get_command(id: StringName) -> HammeriteEditorCommand
The command id, or null.
all()
func all() -> HammeriteEditorCommand[]
Every command, in the order added. A new array.
rebind()
func rebind(id: StringName, events: InputEvent[]) -> bool
Bind id to events alone, replacing what it was bound to; an empty array unbinds it. The menus redraw. False for an id nothing registered.
menus()
func menus() -> StringName[]
The menus that have anything in them, in MENU_ORDER and then whatever an addon added.
commands_in()
func commands_in(menu: StringName) -> HammeriteEditorCommand[]
The commands under menu menu, in the order added. A new array.
commands_in_context()
func commands_in_context(context: StringName) -> HammeriteEditorCommand[]
The commands a right-click on context offers, in table order.
find_command_for()
func find_command_for(event: InputEvent) -> HammeriteEditorCommand
The command event is bound to, or null. Matching is exact, so Cmd+Shift+Z is not Cmd+Z. Skips anything a tool owns: those are asked for by id, by the tool, while it is running.
is_event_for()
func is_event_for(id: StringName, event: InputEvent) -> bool
Whether event runs id, by its keys, its clicks or the character it is typed as - the same rules find_command_for() keeps. For a tool asking about its own bindings.
bind_held()
func bind_held(id: StringName, keycode: int) -> void
Held bindings, which are polled rather than dispatched.
is_held()
func is_held(id: StringName) -> bool
Whether the key bound to held binding id is down now. False for an id nothing bound.
held_binding()
func held_binding(id: StringName) -> int
The key held binding id is bound to, or KEY_NONE.
held_ids()
func held_ids() -> StringName[]
Every held binding's id.
is_command_held()
static func is_command_held() -> bool
Whether Cmd is down on macOS, or Ctrl elsewhere: what a click adds to the selection with.