|
| 1 | +class_name ReplayInputDisplay |
| 2 | +extends HBoxContainer |
| 3 | + |
| 4 | +const ACTIVE_BG := Color(0.94, 0.93, 0.89, 1.0) |
| 5 | +const ACTIVE_BORDER := Color(0.18, 0.18, 0.18, 1.0) |
| 6 | +const ACTIVE_FONT := Color(0.10, 0.10, 0.10, 1.0) |
| 7 | +const INACTIVE_BG := Color(0.12, 0.14, 0.17, 1.0) |
| 8 | +const INACTIVE_BORDER := Color(0.30, 0.33, 0.37, 1.0) |
| 9 | +const INACTIVE_FONT := Color(0.78, 0.81, 0.84, 1.0) |
| 10 | + |
| 11 | +var _input_states := { |
| 12 | + &"forward": false, |
| 13 | + &"back": false, |
| 14 | + &"left": false, |
| 15 | + &"right": false, |
| 16 | + &"shoot": false, |
| 17 | + &"ads": false, |
| 18 | + &"reload": false, |
| 19 | +} |
| 20 | + |
| 21 | +var _key_panels: Dictionary = { } |
| 22 | +var _key_labels: Dictionary = { } |
| 23 | +var _active_panel_style: StyleBoxFlat |
| 24 | +var _inactive_panel_style: StyleBoxFlat |
| 25 | + |
| 26 | +func _ready() -> void: |
| 27 | + _active_panel_style = _create_panel_style(ACTIVE_BG, ACTIVE_BORDER) |
| 28 | + _inactive_panel_style = _create_panel_style(INACTIVE_BG, INACTIVE_BORDER) |
| 29 | + |
| 30 | + _register_decorative_panel($"Movement/TopLeftSpacer") |
| 31 | + _register_key(&"forward", $"Movement/W") |
| 32 | + _register_decorative_panel($"Movement/TopRightSpacer") |
| 33 | + _register_key(&"back", $"Movement/S") |
| 34 | + _register_key(&"left", $"Movement/A") |
| 35 | + _register_key(&"right", $"Movement/D") |
| 36 | + _register_key(&"shoot", $"Combat/Shoot") |
| 37 | + _register_key(&"ads", $"Combat/Ads") |
| 38 | + _register_key(&"reload", $"Combat/Reload") |
| 39 | + |
| 40 | + reset() |
| 41 | + |
| 42 | +func set_inputs( |
| 43 | + forward_input: bool, |
| 44 | + back_input: bool, |
| 45 | + left_input: bool, |
| 46 | + right_input: bool, |
| 47 | + shoot_input: bool, |
| 48 | + ads_input: bool, |
| 49 | + reload_input: bool, |
| 50 | +) -> void: |
| 51 | + _input_states[&"forward"] = forward_input |
| 52 | + _input_states[&"back"] = back_input |
| 53 | + _input_states[&"left"] = left_input |
| 54 | + _input_states[&"right"] = right_input |
| 55 | + _input_states[&"shoot"] = shoot_input |
| 56 | + _input_states[&"ads"] = ads_input |
| 57 | + _input_states[&"reload"] = reload_input |
| 58 | + _apply_visual_state() |
| 59 | + |
| 60 | +func reset() -> void: |
| 61 | + set_inputs(false, false, false, false, false, false, false) |
| 62 | + |
| 63 | +func is_input_active(input_name: StringName) -> bool: |
| 64 | + return _input_states.get(input_name, false) |
| 65 | + |
| 66 | +func _register_key(action_name: StringName, panel: PanelContainer) -> void: |
| 67 | + var label := panel.get_node_or_null("Label") as Label |
| 68 | + _key_panels[action_name] = panel |
| 69 | + _key_labels[action_name] = label |
| 70 | + |
| 71 | +func _register_decorative_panel(panel: PanelContainer) -> void: |
| 72 | + if panel != null: |
| 73 | + panel.add_theme_stylebox_override("panel", _inactive_panel_style) |
| 74 | + |
| 75 | +func _apply_visual_state() -> void: |
| 76 | + for action_name in _key_panels.keys(): |
| 77 | + var panel := _key_panels[action_name] as PanelContainer |
| 78 | + var label := _key_labels.get(action_name) as Label |
| 79 | + var active := _input_states.get(action_name, false) |
| 80 | + |
| 81 | + if panel != null: |
| 82 | + panel.add_theme_stylebox_override("panel", _active_panel_style if active else _inactive_panel_style) |
| 83 | + if label != null: |
| 84 | + label.add_theme_color_override("font_color", ACTIVE_FONT if active else INACTIVE_FONT) |
| 85 | + |
| 86 | +func _create_panel_style(bg_color: Color, border_color: Color) -> StyleBoxFlat: |
| 87 | + var style := StyleBoxFlat.new() |
| 88 | + style.bg_color = bg_color |
| 89 | + style.border_color = border_color |
| 90 | + style.border_width_left = 1 |
| 91 | + style.border_width_top = 1 |
| 92 | + style.border_width_right = 1 |
| 93 | + style.border_width_bottom = 1 |
| 94 | + style.content_margin_left = 5 |
| 95 | + style.content_margin_top = 3 |
| 96 | + style.content_margin_right = 5 |
| 97 | + style.content_margin_bottom = 3 |
| 98 | + return style |
0 commit comments