mirror of
https://github.com/HarmonyHoney/tiny_crate.git
synced 2026-01-23 02:34:53 +00:00
rebinding in effect! TODO: cleanup & combine menu scripts (:
This commit is contained in:
parent
428b7c0c1e
commit
0e2e927e9f
7 changed files with 161 additions and 60 deletions
|
|
@ -180,30 +180,6 @@ ui_focus_prev={
|
|||
"deadzone": 0.5,
|
||||
"events": [ ]
|
||||
}
|
||||
ui_left={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777231,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
ui_right={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
ui_up={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777232,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
ui_down={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
ui_page_up={
|
||||
"deadzone": 0.5,
|
||||
"events": [ ]
|
||||
|
|
@ -221,6 +197,30 @@ ui_end={
|
|||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777224,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
ui_up={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777232,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
ui_down={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
ui_left={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777231,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
ui_right={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
ui_yes={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":75,"physical_scancode":0,"unicode":0,"echo":false,"script":null)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
extends Node2D
|
||||
|
||||
onready var control := $Control
|
||||
onready var main_menu := $Control/Main
|
||||
onready var quit_menu := $Control/Quit
|
||||
onready var slot_menu := $Control/Slot
|
||||
|
|
@ -118,7 +119,8 @@ func menu_select(tag : String = menu_items[cursor].to_lower()):
|
|||
OptionsMenu.open(true, self)
|
||||
is_input = false
|
||||
Audio.play("menu_options", 0.9, 1.1)
|
||||
Shared.cam.pos_target += Vector2(228, 0)
|
||||
Shared.cam.pos_target += Vector2(24, -4)
|
||||
control.visible = false
|
||||
"credits":
|
||||
Shared.wipe_scene(Shared.credits_path)
|
||||
Audio.play("menu_pick", 0.9, 1.1)
|
||||
|
|
@ -157,6 +159,8 @@ func menu_select(tag : String = menu_items[cursor].to_lower()):
|
|||
func resume():
|
||||
is_input = true
|
||||
Shared.cam.pos_target = Vector2(90, 76)
|
||||
UI.keys(false)
|
||||
control.visible = true
|
||||
|
||||
func switch_menu(arg, silent := false, _cursor := 0):
|
||||
var s = ["quit", "main", "slot", "open", "erase"]
|
||||
|
|
|
|||
|
|
@ -6,10 +6,18 @@ onready var default_keys := {}
|
|||
export var is_gamepad := false
|
||||
|
||||
onready var control := $Control
|
||||
onready var popup := $PopUp
|
||||
var is_rebind := false
|
||||
|
||||
onready var list_node := $Control/VBox
|
||||
onready var row_node := $Control/VBox/Row
|
||||
|
||||
var cursor := 0 setget set_cursor
|
||||
onready var cursor_node := $Control/Cursor
|
||||
export var cursor_expand := Vector2.ZERO
|
||||
var list := []
|
||||
var actions := []
|
||||
|
||||
export var keys_action := {
|
||||
"up" : "up",
|
||||
"down" : "down",
|
||||
|
|
@ -29,6 +37,7 @@ export var keys_action := {
|
|||
|
||||
func _ready():
|
||||
open(false)
|
||||
popup.visible = false
|
||||
|
||||
# get default key binds
|
||||
for i in InputMap.get_actions():
|
||||
|
|
@ -40,33 +49,85 @@ func _ready():
|
|||
var r = row_node.duplicate()
|
||||
r.get_node("Label").text = keys_action[i]
|
||||
list_node.add_child(r)
|
||||
list.append(r)
|
||||
actions.append(i)
|
||||
|
||||
var a = InputMap.get_action_list(i)
|
||||
var k := []
|
||||
|
||||
for y in a:
|
||||
if Key.is_type(y, is_gamepad):
|
||||
k.append(y.as_text())
|
||||
|
||||
var keys = r.get_node("Keys").get_children()
|
||||
for x in keys.size():
|
||||
var less = x < k.size()
|
||||
keys[x].visible = less
|
||||
if less:
|
||||
keys[x].text = k[x]
|
||||
|
||||
fill_row(r, i)
|
||||
|
||||
row_node.queue_free()
|
||||
|
||||
|
||||
set_cursor()
|
||||
|
||||
func fill_row(row, action):
|
||||
var a = InputMap.get_action_list(action)
|
||||
var k := []
|
||||
|
||||
for y in a:
|
||||
if Key.is_type(y, is_gamepad):
|
||||
k.append(y.as_text())
|
||||
|
||||
var keys = row.get_node("Keys").get_children()
|
||||
for x in keys.size():
|
||||
var less = x < k.size()
|
||||
keys[x].visible = less
|
||||
if less:
|
||||
keys[x].text = k[x]
|
||||
|
||||
func _input(event):
|
||||
if !is_open or Wipe.is_wipe: return
|
||||
|
||||
if event.is_action_pressed("ui_no"):
|
||||
open(false)
|
||||
OptionsMenu.open(true)
|
||||
if is_rebind:
|
||||
if event.is_action_pressed("ui_end"):
|
||||
is_rebind = false
|
||||
popup.visible = false
|
||||
elif event.is_pressed() and !event.is_echo() and Key.is_type(event):
|
||||
assign_key(actions[cursor], event)
|
||||
is_rebind = false
|
||||
popup.visible = false
|
||||
get_tree().set_input_as_handled()
|
||||
else:
|
||||
var btny = btn.p("ui_down") - btn.p("ui_up")
|
||||
|
||||
if event.is_action_pressed("ui_no"):
|
||||
open(false)
|
||||
OptionsMenu.open(true)
|
||||
elif event.is_action_pressed("ui_yes"):
|
||||
popup.visible = true
|
||||
is_rebind = true
|
||||
elif btny != 0:
|
||||
self.cursor += btny
|
||||
|
||||
func open(arg := false):
|
||||
is_open = arg
|
||||
control.visible = is_open
|
||||
visible = is_open
|
||||
|
||||
func set_cursor(arg := cursor):
|
||||
cursor = clamp(arg, 0, list.size() - 1)
|
||||
|
||||
cursor_node.rect_size = list[cursor].rect_size + cursor_expand
|
||||
cursor_node.rect_global_position = list[cursor].rect_global_position - (cursor_expand * 0.5)
|
||||
|
||||
control.rect_position.y = 64 - cursor_node.rect_position.y
|
||||
|
||||
func assign_key(action, event):
|
||||
# remove event if present
|
||||
if InputMap.action_has_event(action, event):
|
||||
InputMap.action_erase_event(action, event)
|
||||
# add event to action, will bring to front of list if present
|
||||
InputMap.action_add_event(action, event)
|
||||
|
||||
# keep action size to 4 events of type
|
||||
var e = []
|
||||
for i in InputMap.get_action_list(action):
|
||||
if Key.is_type(i):
|
||||
e.append(i)
|
||||
|
||||
if e.size() > 4:
|
||||
InputMap.action_erase_event(action, e[0])
|
||||
|
||||
fill_row(list[cursor], actions[cursor])
|
||||
|
||||
#create_keys(cursor)
|
||||
|
||||
#emit_gamepad()
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
[gd_scene load_steps=5 format=2]
|
||||
[gd_scene load_steps=6 format=2]
|
||||
|
||||
[ext_resource path="res://media/font/QuinqueFive.ttf" type="DynamicFontData" id=1]
|
||||
[ext_resource path="res://src/menu/options/Key.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://src/menu/options/KeyMenu.gd" type="Script" id=3]
|
||||
[ext_resource path="res://src/menu/Blink.gd" type="Script" id=4]
|
||||
|
||||
[sub_resource type="DynamicFont" id=1]
|
||||
size = 5
|
||||
|
|
@ -13,21 +14,29 @@ font_data = ExtResource( 1 )
|
|||
|
||||
[node name="KeyMenu" type="CanvasLayer"]
|
||||
script = ExtResource( 3 )
|
||||
cursor_expand = Vector2( 4, 4 )
|
||||
|
||||
[node name="Back" type="ColorRect" parent="."]
|
||||
modulate = Color( 0, 0, 0, 0.5 )
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
|
||||
[node name="Control" type="Control" parent="."]
|
||||
margin_right = 228.0
|
||||
margin_bottom = 128.0
|
||||
|
||||
[node name="Back" type="ColorRect" parent="Control"]
|
||||
modulate = Color( 0, 0, 0, 0.5 )
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
[node name="Cursor" type="ColorRect" parent="Control"]
|
||||
modulate = Color( 1, 0, 0.301961, 1 )
|
||||
margin_left = 5.0
|
||||
margin_top = 37.0
|
||||
margin_right = 47.0
|
||||
margin_bottom = 47.0
|
||||
script = ExtResource( 4 )
|
||||
|
||||
[node name="VBox" type="VBoxContainer" parent="Control"]
|
||||
margin_left = 48.0
|
||||
margin_top = 25.0
|
||||
margin_right = 175.0
|
||||
margin_bottom = 95.0
|
||||
margin_bottom = 73.0
|
||||
|
||||
[node name="Guide" type="HBoxContainer" parent="Control/VBox"]
|
||||
margin_right = 127.0
|
||||
|
|
@ -52,7 +61,7 @@ margin_bottom = 5.0
|
|||
custom_fonts/font = SubResource( 1 )
|
||||
text = "keys"
|
||||
|
||||
[node name="Row" type="HBoxContainer" parent="Control/VBox"]
|
||||
[node name="Row" type="HBoxContainer" parent="Control/VBox" groups=["menu_item"]]
|
||||
margin_top = 9.0
|
||||
margin_right = 127.0
|
||||
margin_bottom = 16.0
|
||||
|
|
@ -98,3 +107,23 @@ margin_right = 76.0
|
|||
rect_min_size = Vector2( 19, 7 )
|
||||
action = ""
|
||||
text = "del"
|
||||
|
||||
[node name="PopUp" type="CenterContainer" parent="."]
|
||||
margin_right = 228.0
|
||||
margin_bottom = 128.0
|
||||
|
||||
[node name="Back" type="ColorRect" parent="PopUp"]
|
||||
modulate = Color( 0, 0, 1, 1 )
|
||||
margin_left = 74.0
|
||||
margin_top = 58.0
|
||||
margin_right = 154.0
|
||||
margin_bottom = 70.0
|
||||
rect_min_size = Vector2( 80, 12 )
|
||||
|
||||
[node name="Label" type="Label" parent="PopUp"]
|
||||
margin_left = 75.0
|
||||
margin_top = 61.0
|
||||
margin_right = 153.0
|
||||
margin_bottom = 66.0
|
||||
custom_fonts/font = SubResource( 1 )
|
||||
text = "press any key"
|
||||
|
|
|
|||
|
|
@ -2,5 +2,6 @@ extends CanvasItem
|
|||
|
||||
func act():
|
||||
OptionsMenu.is_open = false
|
||||
OptionsMenu.visible = false
|
||||
KeyMenu.open(true)
|
||||
Audio.play("menu_pause", 0.9, 1.1)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
extends Node
|
||||
extends CanvasLayer
|
||||
|
||||
onready var center := $Center
|
||||
onready var node_cursor : ColorRect = $Center/Control/Cursor
|
||||
onready var menu_items : Array = $Center/Control/MenuItems.get_children()
|
||||
var cursor := 0
|
||||
|
|
@ -10,7 +9,7 @@ export var input_cooldown := 0.1
|
|||
var last_menu = null
|
||||
|
||||
func _ready():
|
||||
center.visible = false
|
||||
visible = false
|
||||
select_item(0)
|
||||
|
||||
func _input(event):
|
||||
|
|
@ -56,10 +55,13 @@ func open(arg := is_open, _last = null):
|
|||
if is_instance_valid(_last):
|
||||
last_menu = _last
|
||||
|
||||
center.visible = is_open
|
||||
visible = is_open
|
||||
input_clock = input_cooldown
|
||||
|
||||
select_item()
|
||||
if is_open:
|
||||
UI.keys(true)
|
||||
|
||||
if !is_open and is_instance_valid(last_menu) and last_menu.has_method("resume"):
|
||||
last_menu.resume()
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,11 @@ font_data = ExtResource( 8 )
|
|||
pause_mode = 2
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="Back" type="ColorRect" parent="."]
|
||||
modulate = Color( 0, 0, 0, 0.5 )
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
|
||||
[node name="Center" type="CenterContainer" parent="."]
|
||||
margin_right = 40.0
|
||||
margin_bottom = 40.0
|
||||
|
|
@ -38,9 +43,8 @@ script = ExtResource( 4 )
|
|||
color_blink = PoolColorArray( 0, 0, 1, 1, 0, 0.482353, 1, 1 )
|
||||
|
||||
[node name="Header" type="Label" parent="Center/Control"]
|
||||
margin_left = 14.0
|
||||
margin_top = 7.0
|
||||
margin_right = 242.0
|
||||
margin_right = 228.0
|
||||
margin_bottom = 20.0
|
||||
custom_colors/font_color_shadow = Color( 0, 0, 0, 1 )
|
||||
custom_constants/shadow_as_outline = 1
|
||||
|
|
@ -49,10 +53,10 @@ text = "OPTIONS"
|
|||
align = 1
|
||||
|
||||
[node name="MenuItems" type="VBoxContainer" parent="Center/Control"]
|
||||
margin_left = 72.0
|
||||
margin_left = 58.0
|
||||
margin_top = 40.0
|
||||
margin_right = 188.0
|
||||
margin_bottom = 100.0
|
||||
margin_right = 174.0
|
||||
margin_bottom = 108.0
|
||||
|
||||
[node name="Keyboard" type="HBoxContainer" parent="Center/Control/MenuItems"]
|
||||
margin_right = 116.0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue