addon for remapping inputs
ditch the theme
| -rw-r--r-- | Test.gd | 9 | ||||
| -rw-r--r-- | Test.tscn | 24 | ||||
| -rw-r--r-- | addons/remap/ActionIcons.gd | 13 | ||||
| -rw-r--r-- | addons/remap/ActionLabel.gd | 4 | ||||
| -rw-r--r-- | addons/remap/InteractiveActionLabel.gd | 20 | ||||
| -rw-r--r-- | addons/remap/KeySelector.tscn | 18 | ||||
| -rw-r--r-- | addons/remap/PromptFont.tres | 2 | ||||
| -rw-r--r-- | addons/remap/circle.stylebox | bin | 400 -> 0 bytes | |||
| -rw-r--r-- | addons/remap/main.theme | bin | 766 -> 0 bytes | |||
| -rw-r--r-- | addons/remap/package.json | 2 |
10 files changed, 49 insertions, 43 deletions
@@ -1,7 +1,8 @@ extends Control + func _ready(): - var label = InteractiveActionLabel.new() - label.action = "ui_left" - label._name = "left" - add_child(label)
\ No newline at end of file + var label = InteractiveActionLabel.new() + label.action = "ui_left" + label._name = "left" + add_child(label) @@ -1,21 +1,19 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=3 format=2] -[ext_resource path="res://addons/remap/main.theme" type="Theme" id=1] -[ext_resource path="res://addons/remap/InteractiveActionLabel.gd" type="Script" id=2] [ext_resource path="res://Test.gd" type="Script" id=3] +[ext_resource path="res://addons/remap/ActionLabel.gd" type="Script" id=4] [node name="Test" type="Control"] anchor_right = 1.0 anchor_bottom = 1.0 -theme = ExtResource( 1 ) script = ExtResource( 3 ) -[node name="InteractiveActionLabel" type="HBoxContainer" parent="."] -anchor_top = 0.5 -anchor_right = 1.0 -anchor_bottom = 0.5 -margin_left = 4.0 -margin_bottom = 15.0 -script = ExtResource( 2 ) -_name = "right" -action = "ui_right" +[node name="HBoxContainer" type="HBoxContainer" parent="."] +margin_left = 5.0 +margin_top = 42.0 +margin_right = 316.0 +margin_bottom = 75.0 +script = ExtResource( 4 ) +_name = "lef" +action = "ui_left" +icon_size = Vector2( 10, 10 ) diff --git a/addons/remap/ActionIcons.gd b/addons/remap/ActionIcons.gd index a338b58..21d733c 100644 --- a/addons/remap/ActionIcons.gd +++ b/addons/remap/ActionIcons.gd @@ -1,12 +1,11 @@ extends HBoxContainer class_name ActionIcons -var action: String +export(String) var action: String +export(Vector2) var size := Vector2(30, 30) +export(bool) var override_font := true - -func _ready(): - theme = preload("./main.theme") - add_constant_override("separation", 4) +const font = preload("./PromptFont.tres") func _update(): @@ -18,9 +17,11 @@ func _update(): if icon: var p: PanelContainer = PanelContainer.new() var i: Label = Label.new() + if override_font: + i.add_font_override("font", font) i.text = icon i.align = Label.ALIGN_CENTER i.valign = Label.VALIGN_CENTER p.add_child(i) add_child(p) - i.rect_min_size = Vector2(30, 30) + i.rect_min_size = size diff --git a/addons/remap/ActionLabel.gd b/addons/remap/ActionLabel.gd index ff98108..88338f2 100644 --- a/addons/remap/ActionLabel.gd +++ b/addons/remap/ActionLabel.gd @@ -4,6 +4,8 @@ class_name ActionLabel export(String) var _name: String export(String) var action: String +export(Vector2) var icon_size := Vector2(30, 30) +export(bool) var override_font := true var icons := ActionIcons.new() var name_label := Label.new() @@ -21,4 +23,6 @@ func _ready() -> void: add_child(spacer) add_child(icons) icons.action = action + icons.size = icon_size + icons.override_font = override_font icons._update() diff --git a/addons/remap/InteractiveActionLabel.gd b/addons/remap/InteractiveActionLabel.gd index 9fd313f..d337b59 100644 --- a/addons/remap/InteractiveActionLabel.gd +++ b/addons/remap/InteractiveActionLabel.gd @@ -9,16 +9,20 @@ export(PackedScene) var popup = preload("./KeySelector.tscn") var clear := Button.new() +export(bool) var clear_button := true + func _ready(): - clear.theme = preload("./main.theme") - clear.text = "✗" - clear.connect("pressed", self, "clear") - clear.size_flags_vertical = SIZE_EXPAND_FILL - clear.rect_min_size.x = 30 - add_child(clear) - move_child(clear, 0) - clear.visible = InputMap.get_action_list(action).size() > 0 + if clear_button: + clear.text = "✗" + clear.connect("pressed", self, "clear") + clear.size_flags_vertical = SIZE_EXPAND_FILL + clear.rect_min_size = icon_size + add_child(clear) + move_child(clear, 0) + clear.visible = InputMap.get_action_list(action).size() > 0 + if override_font: + clear.add_font_override("font", preload("./PromptFont.tres")) func _gui_input(event: InputEvent): diff --git a/addons/remap/KeySelector.tscn b/addons/remap/KeySelector.tscn index f46fa55..0dcf4fa 100644 --- a/addons/remap/KeySelector.tscn +++ b/addons/remap/KeySelector.tscn @@ -1,6 +1,5 @@ -[gd_scene load_steps=6 format=2] +[gd_scene load_steps=5 format=2] -[ext_resource path="res://addons/remap/main.theme" type="Theme" id=1] [ext_resource path="res://addons/remap/KeyPromptLabel.gd" type="Script" id=2] [ext_resource path="res://addons/remap/PromptFont.ttf" type="DynamicFontData" id=3] [ext_resource path="res://addons/remap/KeySelector.gd" type="Script" id=4] @@ -15,7 +14,6 @@ script = ExtResource( 4 ) [node name="ColorRect" type="ColorRect" parent="."] anchor_right = 1.0 anchor_bottom = 1.0 -theme = ExtResource( 1 ) color = Color( 0.160156, 0.160156, 0.160156, 0.705882 ) [node name="Center" type="CenterContainer" parent="ColorRect"] @@ -24,9 +22,9 @@ anchor_bottom = 1.0 [node name="V" type="VBoxContainer" parent="ColorRect/Center"] margin_left = 35.0 -margin_top = 51.0 +margin_top = 53.0 margin_right = 285.0 -margin_bottom = 129.0 +margin_bottom = 126.0 [node name="KeyPrompter" type="Label" parent="ColorRect/Center/V"] unique_name_in_owner = true @@ -41,12 +39,12 @@ script = ExtResource( 2 ) [node name="H" type="HBoxContainer" parent="ColorRect/Center/V"] margin_top = 53.0 margin_right = 250.0 -margin_bottom = 78.0 +margin_bottom = 73.0 [node name="ok" type="Button" parent="ColorRect/Center/V/H"] unique_name_in_owner = true -margin_right = 119.0 -margin_bottom = 25.0 +margin_right = 123.0 +margin_bottom = 20.0 rect_min_size = Vector2( 50, 0 ) size_flags_horizontal = 3 disabled = true @@ -54,9 +52,9 @@ text = "ok" [node name="cancel" type="Button" parent="ColorRect/Center/V/H"] unique_name_in_owner = true -margin_left = 130.0 +margin_left = 127.0 margin_right = 250.0 -margin_bottom = 25.0 +margin_bottom = 20.0 rect_min_size = Vector2( 100, 0 ) size_flags_horizontal = 3 text = "cancel" diff --git a/addons/remap/PromptFont.tres b/addons/remap/PromptFont.tres index ca3640f..181c50e 100644 --- a/addons/remap/PromptFont.tres +++ b/addons/remap/PromptFont.tres @@ -3,5 +3,5 @@ [ext_resource path="res://addons/remap/PromptFont.ttf" type="DynamicFontData" id=1] [resource] -size = 20 +size = 15 font_data = ExtResource( 1 ) diff --git a/addons/remap/circle.stylebox b/addons/remap/circle.stylebox Binary files differdeleted file mode 100644 index 259f2ce..0000000 --- a/addons/remap/circle.stylebox +++ /dev/null diff --git a/addons/remap/main.theme b/addons/remap/main.theme Binary files differdeleted file mode 100644 index 361a271..0000000 --- a/addons/remap/main.theme +++ /dev/null diff --git a/addons/remap/package.json b/addons/remap/package.json index 8c6f7a6..934d2b3 100644 --- a/addons/remap/package.json +++ b/addons/remap/package.json @@ -1,6 +1,6 @@ { "name": "@bendn/remap", - "version": "1.0.0", + "version": "1.1.0", "description": "godot input remapping", "main": "InteractiveActionLabel.gd", "scripts": { |