OverviewFilesCommitsIssuesDocsReleasesPeers

hyper-tps / scenes / game / editor_tool_bar.gd

58 lines · gd ref:
extends HFlowContainer
## THE TOOLBAR (editor redesign E1, docs/editor-redesign.md §3): one button per build
## tool, in the left region. Each runs its action through Keymap.run (the same path as
## its key), and its tooltip is GENERATED — label, live key, and what the tool needs —
## so the bar teaches the keys instead of hiding them.
##
## TOOLS lists [action, button text, how to use it]. Adding a tool is one row here (a
## tool registry with icons and per-tool settings is E4).

## An optional 4th column is the KEY HINT for a tool with no Keymap key of its own (keymap
## step 3): how you reach it instead — LMB for select, the add menu for the create tool.
const TOOLS: Array = [
	["builder.select", "Select", "Click a brush or face. Shift+click adds; 1-4 = vertex / edge / face / brush.", "LMB"],
	["builder.create_box", "Box", "Aim at a surface. Tab cycles box / stairs / arch, [ ] size, Enter places.", "Shift+A menu"],
	["builder.knife", "Knife", "Aim at a brush. X / Y / Z pick the cut plane, Enter cuts."],
	["builder.move", "Move", "Moves the selection. X / Y / Z axis, [ ] steps, Enter commits."],
	["builder.rotate", "Rotate", "Turns the selection about its centre. X / Y / Z axis, [ ] steps (Shift 1°), Enter commits."],
	["builder.scale", "Scale", "Resizes the selection (or a model) about its base. X / Y / Z axis, C pivot, [ ] steps, Enter commits."],
	["builder.extrude", "Extrude", "Aim at a face. [ ] push / pull, Enter commits."],
	["builder.carve", "Carve", "Carves a sphere at the crosshair (voxel pocket).", "menu"],
	["builder.texture_apply", "Paint", "Applies the current texture (bottom strip) to the selection."],
	["builder.texture_pick", "Pick", "Eyedropper: the aimed face's texture becomes current."],
]

var map: Node = null
var _buttons: Dictionary = {}   # action -> Button


func setup(map_node: Node) -> void:
	map = map_node
	add_theme_constant_override("h_separation", 4)
	add_theme_constant_override("v_separation", 4)
	for t: Array in TOOLS:
		var action := String(t[0])
		var b := Button.new()
		b.text = String(t[1])
		b.focus_mode = Control.FOCUS_NONE
		b.tooltip_text = "%s (%s)\n%s" % [String(Keymap.binding_of(action).get("label", action)),
			key_text(action), String(t[2])]
		b.pressed.connect(func() -> void: Keymap.run(action))
		add_child(b)
		_buttons[action] = b


func buttons() -> Dictionary:
	return _buttons


## How a tool is reached: its live key, or the row's key hint when it has none.
func key_text(action: String) -> String:
	var k := String(Keymap.describe(action))
	if k != "":
		return k
	for t: Array in TOOLS:
		if String(t[0]) == action and t.size() > 3:
			return String(t[3])
	return "menu"