summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2023-12-25 13:10:22 +0100
committerDaniel Weipert <git@mail.dweipert.de>2023-12-25 13:10:22 +0100
commitc1f30a2905d7a44439c2c0797ddd87b58f79d724 (patch)
treeae973c30d87c3f24b0e778206a501a8dcd12ff73
parentd74263a17e98159b2e3176a5f8e1ff361909c210 (diff)
level select input supportv2.1.0
-rw-r--r--Global.gd9
-rw-r--r--UI/HUD/CancelButton.gd5
-rw-r--r--UI/LevelSelect.gd35
-rw-r--r--UI/LevelSelectCell.gd17
-rw-r--r--UI/LevelSelectCell.tscn3
-rw-r--r--project.godot30
6 files changed, 89 insertions, 10 deletions
diff --git a/Global.gd b/Global.gd
index 9cb1001..4ff6114 100644
--- a/Global.gd
+++ b/Global.gd
@@ -7,7 +7,7 @@ signal game_ended()
signal game_won()
-var Levels = [
+var Levels = [ # should be 9
"Level_0001",
"Level_0002",
"Level_0003",
@@ -15,7 +15,6 @@ var Levels = [
"Level_0005",
"Level_0005",
"Level_0004",
- "Level_0003",
"Level_0002",
"Level_0001",
]
@@ -85,7 +84,7 @@ func end_level(instance_level):
for id in Network.players:
rpc_id(id, "_update_level_map", instance_level.idx, global_level)
- get_tree().change_scene_to_file("res://UI/LevelSelect.tscn")
+ (func(): get_tree().change_scene_to_file("res://UI/LevelSelect.tscn")).call_deferred()
self.check_win()
@@ -112,7 +111,7 @@ func end_game():
func _on_Network_game_ended():
- get_tree().change_scene_to_file("res://UI/GameOver.tscn")
+ (func(): get_tree().change_scene_to_file("res://UI/GameOver.tscn")).call_deferred()
self.Level_Map = []
self.init()
@@ -168,7 +167,7 @@ func check_win():
func check_win_timer():
var has_won = self.has_won()
- if has_won:
+ if self.has_won():
emit_signal("game_won", Network.player)
diff --git a/UI/HUD/CancelButton.gd b/UI/HUD/CancelButton.gd
index 51b146b..a40d594 100644
--- a/UI/HUD/CancelButton.gd
+++ b/UI/HUD/CancelButton.gd
@@ -3,3 +3,8 @@ extends Button
func _on_CancelButton_pressed():
Global.cancel_level()
+
+
+func _input(event):
+ if event.is_action_pressed("BACK"):
+ Global.cancel_level()
diff --git a/UI/LevelSelect.gd b/UI/LevelSelect.gd
index 368d338..dae69bb 100644
--- a/UI/LevelSelect.gd
+++ b/UI/LevelSelect.gd
@@ -1,29 +1,64 @@
extends Control
+var selected_idx = 0
+
+
func _ready():
Global.connect("level_map_updated", Callable(self, "draw"))
draw()
+func _input(event):
+ if event.is_action_pressed("DIRECTION_LEFT") and event.get_action_strength("DIRECTION_LEFT") == 1.0:
+ selected_idx = max(selected_idx - 1, 0)
+ set_cell_selected()
+ elif event.is_action_pressed("DIRECTION_RIGHT") and event.get_action_strength("DIRECTION_RIGHT") == 1.0:
+ selected_idx = min(selected_idx + 1, Global.Level_Map.size() - 1)
+ set_cell_selected()
+ elif event.is_action_pressed("UP") and (selected_idx - 3 >= 0) and event.get_action_strength("UP") == 1.0:
+ selected_idx = max(selected_idx - 3, 0)
+ set_cell_selected()
+ elif event.is_action_pressed("DOWN") and (selected_idx + 3 <= Global.Level_Map.size() - 1) and event.get_action_strength("DOWN") == 1.0:
+ selected_idx = min(selected_idx + 3, Global.Level_Map.size() - 1)
+ set_cell_selected()
+ elif event.is_action_pressed("ACCEPT"):
+ Global.start_level(selected_idx)
+
+
func draw():
var Cell = load("res://UI/LevelSelectCell.tscn")
for idx in range(Global.Level_Map.size()): # size = 9
var cell = Cell.instantiate()
cell.level_idx = idx
+
+ if idx == selected_idx:
+ cell.set_selected(true)
+
cell.set_rect_size(
get_viewport_rect().size.x/3,
get_viewport_rect().size.y/3
)
+
var column = idx % 3
var row = idx / 3
cell.position.x = cell.size.x*column
cell.position.y = cell.size.y*row
+
cell.connect("gui_input", Callable(self, '_button_pressed').bind(idx))
+
self.add_child(cell)
+func set_cell_selected():
+ var cells = get_children()
+ for cell in cells:
+ cell.set_selected(false)
+
+ cells[selected_idx].set_selected(true)
+
+
func _button_pressed(event, idx):
if event is InputEventMouseButton or event is InputEventKey:
if event.pressed:
diff --git a/UI/LevelSelectCell.gd b/UI/LevelSelectCell.gd
index a756210..cd59593 100644
--- a/UI/LevelSelectCell.gd
+++ b/UI/LevelSelectCell.gd
@@ -3,10 +3,16 @@ extends Panel
var level_idx = 0
+var stylebox = StyleBoxFlat.new()
+var background_color = "#225f30"
+var background_color_selected = "#3c9f54"
+
func _ready():
var level = Global.get_level(self.level_idx)
+ stylebox = self.get("theme_override_styles/panel")
+
$ClearMark.text = ""
if level.cleared_by.idx == Enum.PLAYER.FIRST:
$ClearMark.text = "X"
@@ -31,3 +37,14 @@ func set_rect_size(x, y):
$Time.position = Vector2(3, 3)
$Name.position = Vector2(3, y - $Name.size.y)
+
+
+func set_selected(is_selected = true):
+ if is_selected:
+ var box = stylebox.duplicate()
+ box.bg_color = Color.from_string(self.background_color_selected, self.background_color)
+ self.set("theme_override_styles/panel", box)
+ else:
+ var box = stylebox.duplicate()
+ box.bg_color = Color.from_string(self.background_color, self.background_color)
+ self.set("theme_override_styles/panel", box)
diff --git a/UI/LevelSelectCell.tscn b/UI/LevelSelectCell.tscn
index b76111b..2d26c47 100644
--- a/UI/LevelSelectCell.tscn
+++ b/UI/LevelSelectCell.tscn
@@ -13,9 +13,6 @@ border_width_bottom = 1
[sub_resource type="FontFile" id="3"]
fallbacks = Array[Font]([ExtResource("2")])
-face_index = null
-embolden = null
-transform = null
cache/0/16/0/ascent = 0.0
cache/0/16/0/descent = 0.0
cache/0/16/0/underline_position = 0.0
diff --git a/project.godot b/project.godot
index f41802a..c8ba050 100644
--- a/project.godot
+++ b/project.godot
@@ -59,15 +59,15 @@ ui_down={
DIRECTION_LEFT={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194319,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null)
-, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null)
+, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":13,"pressure":0.0,"pressed":true,"script":null)
]
}
DIRECTION_RIGHT={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194321,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null)
-, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":15,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null)
+, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":14,"pressure":0.0,"pressed":true,"script":null)
]
}
JUMP={
@@ -83,6 +83,32 @@ RUN={
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":5,"axis_value":1.0,"script":null)
]
}
+DOWN={
+"deadzone": 0.5,
+"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"echo":false,"script":null)
+, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":1.0,"script":null)
+, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":12,"pressure":0.0,"pressed":true,"script":null)
+]
+}
+UP={
+"deadzone": 0.5,
+"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"echo":false,"script":null)
+, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":-1.0,"script":null)
+, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":11,"pressure":0.0,"pressed":true,"script":null)
+]
+}
+ACCEPT={
+"deadzone": 0.5,
+"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194309,"key_label":0,"unicode":0,"echo":false,"script":null)
+, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":true,"script":null)
+]
+}
+BACK={
+"deadzone": 0.5,
+"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194308,"key_label":0,"unicode":0,"echo":false,"script":null)
+, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":4,"pressure":0.0,"pressed":true,"script":null)
+]
+}
[layer_names]