class_name LuneModalPanel extends Control ## A window over the field for detail work (hero, recruiting). A light backdrop keeps clicks ## away from the world and closes the window; Esc and the × close it too. The window never ## covers the whole screen, and it only opens on request. signal closed var panel: PanelContainer var body: VBoxContainer var title: Label var _close: Button var _box: Vector2 func _init(window_size: Vector2 = Vector2(980, 600)) -> void: _box = window_size set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) mouse_filter = Control.MOUSE_FILTER_STOP visible = false var backdrop := ColorRect.new() backdrop.color = Color(.01, .015, .025, .38) backdrop.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT) backdrop.mouse_filter = Control.MOUSE_FILTER_STOP backdrop.gui_input.connect(func(event: InputEvent) -> void: if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT: close()) add_child(backdrop) panel = PanelContainer.new() panel.theme_type_variation = "HudModal" panel.mouse_filter = Control.MOUSE_FILTER_STOP add_child(panel) var column := VBoxContainer.new() column.add_theme_constant_override("separation", 12) panel.add_child(column) var head := HBoxContainer.new() column.add_child(head) title = LuneUiTheme.label("", "HudTitle", head) title.size_flags_horizontal = Control.SIZE_EXPAND_FILL _close = LuneUiTheme.button("", "HudIconButton", head) _close.custom_minimum_size = Vector2(36, 34) var cross := LuneGlyph.make("close", LuneUiTheme.MUTED, 14.0, _close) cross.set_anchors_and_offsets_preset(Control.PRESET_CENTER) _close.pressed.connect(close) LuneTooltip.attach(_close, func() -> Dictionary: return {"title": "Schließen", "text": "Esc oder Klick neben das Fenster."}) body = VBoxContainer.new() body.add_theme_constant_override("separation", 10) body.size_flags_vertical = Control.SIZE_EXPAND_FILL column.add_child(body) resized.connect(_layout) func open(heading: String) -> void: title.text = heading visible = true _layout() func close() -> void: if visible: visible = false closed.emit() func _layout() -> void: var edge: Vector2 = Vector2(minf(_box.x, size.x - 40.0), minf(_box.y, size.y - 40.0)) panel.custom_minimum_size = edge panel.size = edge panel.position = ((size - edge) * .5).floor() func _gui_input(event: InputEvent) -> void: if event is InputEventMouseButton: accept_event() func _unhandled_key_input(event: InputEvent) -> void: if visible and event is InputEventKey and event.pressed and event.keycode == KEY_ESCAPE: close() get_viewport().set_input_as_handled()