summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Game/Client.gd9
-rw-r--r--Game/Lobby/Server/index.php7
-rw-r--r--Game/Lobby/game_lobby.gd5
-rw-r--r--Game/Network.gd16
-rw-r--r--Game/Selection/SelectionManager.gd164
-rw-r--r--Game/States/Build/StateBuild.gd5
-rw-r--r--Game/States/Default/StateDefault.gd5
-rw-r--r--Stages/Wintermaul/HUD.gd215
-rw-r--r--Stages/Wintermaul/hud_tower.gd7
-rw-r--r--Towers/Tower.gd18
-rw-r--r--UI/Camera.gd3
-rw-r--r--UI/GameLobby/game_lobby.gd29
-rw-r--r--UI/GameLobby/game_lobby.tscn23
-rw-r--r--UI/GameLobby/lobby_game.gd1
-rw-r--r--UI/PlayerLobby/lobby.gd3
-rw-r--r--project.godot5
16 files changed, 324 insertions, 191 deletions
diff --git a/Game/Client.gd b/Game/Client.gd
index 6e08a58..0af4e9d 100644
--- a/Game/Client.gd
+++ b/Game/Client.gd
@@ -33,10 +33,13 @@ func _notification(what: int) -> void:
func initialize_stage(stage: Stage):
current_stage = stage
+
+ if not selection:
+ selection = preload("res://Game/Selection/SelectionManager.tscn").instantiate()
+ add_child(selection)
func ready_stage(_stage: Stage):
- selection = preload("res://Game/Selection/SelectionManager.tscn").instantiate()
- add_child(selection)
+ pass
func place_tower(tower: Tower):
@@ -118,7 +121,7 @@ func get_config() -> ConfigFile:
config.load("user://config")
if not FileAccess.file_exists("user://config"):
- config.set_value("general", "host_default_port", 1234)
+ config.set_value("general", "host_default_port", 8911)
config.set_value("general", "game_lobby_server_base_url", "http://localhost:8910")
config.save("user://config")
diff --git a/Game/Lobby/Server/index.php b/Game/Lobby/Server/index.php
index ae734a6..1086d24 100644
--- a/Game/Lobby/Server/index.php
+++ b/Game/Lobby/Server/index.php
@@ -36,7 +36,7 @@ if (php_sapi_name() == 'cli') {
return;
}
-$url = parse_url("$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");
+$url = parse_url("http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");
$method = $_SERVER['REQUEST_METHOD'];
if ($method == 'POST') {
@@ -49,7 +49,10 @@ if ($method == 'POST') {
$response = [];
if ($method == 'POST' && $url['path'] == '/host') {
- $ip = filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP);
+ $ip = filter_var(
+ $_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['REMOTE_ADDR'],
+ FILTER_VALIDATE_IP
+ );
if ($ip === false) {
$response = [
diff --git a/Game/Lobby/game_lobby.gd b/Game/Lobby/game_lobby.gd
index 6bfa8be..ffc66f3 100644
--- a/Game/Lobby/game_lobby.gd
+++ b/Game/Lobby/game_lobby.gd
@@ -42,8 +42,8 @@ func request(
get_tree().root.add_child(config.node)
if config.method == HTTPClient.METHOD_POST:
- config.set("id", current_game_id)
- config.set("secret", current_secret)
+ config.data["id"] = current_game_id
+ config.data["secret"] = current_secret
var response = HTTPResponse.new()
config.node.request_completed.connect(
@@ -60,6 +60,7 @@ func request(
get_tree().root.remove_child(config.node)
)
+
config.node.request(
"%s%s" % [server_base_url, url],
config.headers,
diff --git a/Game/Network.gd b/Game/Network.gd
index 2858d98..4413548 100644
--- a/Game/Network.gd
+++ b/Game/Network.gd
@@ -61,13 +61,15 @@ func _on_disconnected_from_server():
func _on_peer_connected(id: int):
print(multiplayer.get_unique_id(), ": peer connected: ", id)
- ask_game_running.rpc_id(id)
- is_game_running.connect(func(is_running: bool):
- if not is_running:
- add_to_players.rpc_id(id, inst_to_dict(Client.player))
- elif is_running:
- get_tree().change_scene_to_file("res://UI/Start.tscn")
- )
+ add_to_players.rpc_id(id, inst_to_dict(Client.player))
+ # TODO: check why bug and adds more players than intended
+ #ask_game_running.rpc_id(id)
+ #is_game_running.connect(func(is_running: bool):
+ #if not is_running:
+ #add_to_players.rpc_id(id, inst_to_dict(Client.player))
+ #elif is_running:
+ #get_tree().change_scene_to_file("res://UI/Start.tscn")
+ #)
func _on_peer_disconnected(id: int):
print(multiplayer.get_unique_id(), ": peer disconnected: ", id)
diff --git a/Game/Selection/SelectionManager.gd b/Game/Selection/SelectionManager.gd
index 49cb319..86f08af 100644
--- a/Game/Selection/SelectionManager.gd
+++ b/Game/Selection/SelectionManager.gd
@@ -2,29 +2,167 @@ class_name SelectionManager
extends Node
+signal added_to_group(nodes: Array[Node], id: String)
+signal removed_from_group(nodes: Array[Node], id: String)
+signal moved_to_group(nodes: Array[Node], previous_id: String, new_id: String)
+
var selection_groups := {}
-signal selected_group_changed
+signal selected_group_changed(previous_id: String, new_id: String)
var selected_group := "":
set(value):
+ var previous_id := selected_group
selected_group = value
- selected_group_changed.emit()
+ selected_group_changed.emit(previous_id, value)
+
+var node_count: int
func _ready() -> void:
- pass
+ Client.multi_select_finished.connect(_on_multi_select_finished)
+ Client.placed_tower.connect(_on_placed_tower)
+
+
+func add_to_selection_group(nodes: Array[Node], id: String) -> void:
+ if id not in selection_groups:
+ selection_groups[id] = []
+
+ selection_groups[id].append_array(nodes)
+ node_count += nodes.size()
+
+ if not selected_group:
+ reset_selected_group()
+
+ added_to_group.emit(nodes, id)
-func change_selection_group_id(towers: Array[Tower], previous_id: String, new_id: String) -> void:
- if new_id not in selection_groups:
- selection_groups[new_id] = []
+func remove_from_selection_group(nodes: Array[Node], id: String, fallback_id: String = "") -> void:
+ for node in nodes:
+ selection_groups[id].erase(node)
+
+ if selection_groups[id].is_empty():
+ selection_groups.erase(id)
+ if id == selected_group:
+ if fallback_id and selection_groups.has(fallback_id):
+ selected_group = fallback_id
+ else:
+ reset_selected_group()
- selection_groups[new_id].append_array(towers)
+ node_count -= nodes.size()
+ removed_from_group.emit(nodes, id)
+
+
+func move_to_selection_group(nodes: Array[Node], previous_id: String, new_id: String) -> void:
+ remove_from_selection_group(nodes, previous_id, new_id)
+ add_to_selection_group(nodes, new_id)
+ moved_to_group.emit(nodes, previous_id, new_id)
+
+
+func get_ordered_group_ids() -> Array:#Array[String]:
+ # TODO: remove bound to Tower
+ # TODO: use static function on Tower get_sort_conditions?
+
+ var keys = selection_groups.keys()
+
+ keys.sort_custom(func(a, b):
+ var group_a = selection_groups[a]
+ var group_b = selection_groups[b]
+
+ return group_a.size() > group_b.size()
+ )
+
+ keys.sort_custom(func(a, b):
+ var group_a = selection_groups[a]
+ var group_b = selection_groups[b]
+ var node_a = group_a[0]
+ var node_b = group_b[0]
+ var level_a = 0
+ var level_b = 0
+
+ for component in node_a.components.values():
+ level_a += component.level
+ for component in node_b.components.values():
+ level_b += component.level
+
+ return level_a > level_b
+ )
+
+ keys.sort_custom(func(a, b):
+ var group_a = selection_groups[a]
+ var group_b = selection_groups[b]
+
+ return group_a[0].components.size() > group_b[0].components.size()
+ )
+
+ return keys
+
+
+func get_selected_nodes() -> Array:
+ if selected_group:
+ return selection_groups[selected_group]
- for tower in towers:
- selection_groups[previous_id].erase(tower)
+ return []
+
+
+func get_nodes() -> Array:
+ var nodes := []
+ for id in selection_groups:
+ nodes.append_array(selection_groups[id])
- if selection_groups[previous_id].is_empty():
- selection_groups.erase(previous_id)
- if previous_id == selected_group:
- selected_group = new_id
+ return nodes
+
+
+func go_to_next():
+ var ids = get_ordered_group_ids()
+ var current_idx = ids.find(selected_group)
+ selected_group = ids[(current_idx + 1) % ids.size()]
+
+
+func go_to_previous():
+ var ids = get_ordered_group_ids()
+ var current_idx = ids.find(selected_group)
+ selected_group = ids[(current_idx - 1) % ids.size()]
+
+
+func has_selection() -> bool:
+ return selection_groups.size() > 0
+
+
+func has_node_in_group(node: Node, id: String) -> bool:
+ return selection_groups.has(id) and selection_groups[id].has(node)
+
+
+func reset_selected_group():
+ var ids = get_ordered_group_ids()
+ if ids.size() > 0:
+ selected_group = ids[0]
+ else:
+ selected_group = ""
+
+
+func _on_multi_select_finished(_nodes: Array):
+ #add_to_selection_group(nodes)
+ reset_selected_group()
+
+
+func _on_placed_tower(tower: Tower):
+ if tower.owner_id == multiplayer.get_unique_id():
+ tower.selected.connect(func():
+ _on_selected_tower(tower)
+ )
+ tower.deselected.connect(func():
+ _on_deselected_tower(tower)
+ )
+ tower.selection_group_id_changed.connect(func(previous_id: String):
+ _on_tower_selection_group_id_changed(tower, previous_id)
+ )
+
+func _on_selected_tower(tower: Tower):
+ if not has_node_in_group(tower, tower.selection_group_id):
+ add_to_selection_group([tower], tower.selection_group_id)
+
+func _on_deselected_tower(tower: Tower):
+ remove_from_selection_group([tower], tower.selection_group_id)
+
+func _on_tower_selection_group_id_changed(tower: Tower, previous_id: String):
+ move_to_selection_group([tower], previous_id, tower.selection_group_id)
diff --git a/Game/States/Build/StateBuild.gd b/Game/States/Build/StateBuild.gd
index 0bd5efb..303a2b1 100644
--- a/Game/States/Build/StateBuild.gd
+++ b/Game/States/Build/StateBuild.gd
@@ -8,9 +8,8 @@ static var current_builder_element: BuilderElement
func _state_enter():
%BuildGrid.visible = true
- if Tower.selected_towers:
- for tower in Tower.selected_towers.duplicate():
- tower.is_selected = false
+ for tower: Tower in Client.selection.get_nodes().duplicate():
+ tower.is_selected = false
func _state_exit():
diff --git a/Game/States/Default/StateDefault.gd b/Game/States/Default/StateDefault.gd
index b7b630c..014eb40 100644
--- a/Game/States/Default/StateDefault.gd
+++ b/Game/States/Default/StateDefault.gd
@@ -16,6 +16,5 @@ func _state_unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("select"):
# if not multi selecting
if not event.is_double_click() and not Input.is_action_pressed("select_multiple"):
- if Tower.selected_towers:
- for tower in Tower.selected_towers.duplicate():
- tower.is_selected = false
+ for tower: Tower in Client.selection.get_nodes().duplicate():
+ tower.is_selected = false
diff --git a/Stages/Wintermaul/HUD.gd b/Stages/Wintermaul/HUD.gd
index 34fc0ea..62a5abd 100644
--- a/Stages/Wintermaul/HUD.gd
+++ b/Stages/Wintermaul/HUD.gd
@@ -2,13 +2,6 @@ class_name HUD
extends CanvasLayer
-var selection_groups := {}
-var selected_group := "":
- set(value):
- redraw_multiselect(selected_group, value)
- selected_group = value
- redraw_select(selection_groups[selected_group][0])
-
@onready var time: Label = %Time
@onready var money: Label = %Money
@onready var income: Label = %Income
@@ -39,94 +32,74 @@ func _ready():
%TowerConfigurationsContainer.visible = false
)
- # multi select
+ # multi select setup
%SelectionContainer.visible = false
%MultiSelectionContainer.visible = false
- Client.placed_tower.connect(func(tower: Tower):
- if tower.owner_id == multiplayer.get_unique_id():
- tower.selected.connect(func():
- var multi_select_hud_data = TextureRect.new()
- multi_select_hud_data.name = tower.name
- multi_select_hud_data.modulate = Color(0.5, 0.5, 0.5)
- multi_select_hud_data.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
- multi_select_hud_data.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
- multi_select_hud_data.custom_minimum_size = Vector2(32, 64)
- var texture = AtlasTexture.new()
- texture.atlas = preload("res://Towers/Assets/spritesheet.png")
- texture.region = Rect2(5, 1, 62, 95)
- multi_select_hud_data.texture = texture
-
- if not tower.selection_group_id in selection_groups:
- selection_groups[tower.selection_group_id] = []
- selection_groups[tower.selection_group_id].append(tower)
- multi_select_hud_data.add_to_group(tower.selection_group_id)
-
- if Tower.selected_towers.size() == 1:
- %SelectionContainer.visible = true
- %MultiSelectionContainer.visible = false
-
- %MultiSelectionList.add_child(multi_select_hud_data)
- selected_group = tower.selection_group_id
- elif Tower.selected_towers.size() > 1:
- %MultiSelectionContainer.visible = true
-
- %MultiSelectionList.add_child(multi_select_hud_data)
-
- redraw_multiselect("", selected_group)
-
- redraw_select(tower)
- )
+
+ # add tower to selection
+ Client.selection.added_to_group.connect(func(nodes: Array[Node], id: String):
+ for tower: Tower in nodes:
+ var multi_select_hud_data = TextureRect.new()
+ multi_select_hud_data.modulate = Color(0.5, 0.5, 0.5)
+ multi_select_hud_data.expand_mode = TextureRect.EXPAND_IGNORE_SIZE
+ multi_select_hud_data.stretch_mode = TextureRect.STRETCH_KEEP_ASPECT_CENTERED
+ multi_select_hud_data.custom_minimum_size = Vector2(32, 64)
+ var texture = AtlasTexture.new()
+ texture.atlas = preload("res://Towers/Assets/spritesheet.png")
+ texture.region = Rect2(5, 1, 62, 95)
+ multi_select_hud_data.texture = texture
+
+ multi_select_hud_data.set_meta("tower", tower)
+ tower.set_meta("multi_select_hud", multi_select_hud_data)
+
+ multi_select_hud_data.add_to_group(id)
+ %MultiSelectionList.add_child(multi_select_hud_data)
+
+ if Client.selection.node_count == 1:
+ %SelectionContainer.visible = true
+ %MultiSelectionContainer.visible = false
+
+ elif Client.selection.node_count > 1:
+ %MultiSelectionContainer.visible = true
+
+ redraw_multiselect()
+ redraw_select(tower)
+ )
+
+ # remove tower from selection
+ Client.selection.removed_from_group.connect(func(nodes: Array[Node], _id: String):
+ for tower: Tower in nodes:
+ if Client.selection.node_count == 0:
+ %SelectionContainer.visible = false
+ %MultiSelectionContainer.visible = false
+
+ elif Client.selection.node_count == 1:
+ %MultiSelectionContainer.visible = false
+ %SelectionContainer.visible = true
+
+ # catch free error for selecting in quick succcession by double click
+ if is_instance_valid(tower.get_meta("multi_select_hud")):
+ tower.get_meta("multi_select_hud").queue_free()
- tower.deselected.connect(func():
- if Tower.selected_towers.size() == 0:
- %SelectionContainer.visible = false
- %MultiSelectionContainer.visible = false
-
- for child in %MultiSelectionList.get_children():
- child.queue_free()
- elif Tower.selected_towers.size() == 1:
- %MultiSelectionContainer.visible = false
- %SelectionContainer.visible = true
-
- var node = %MultiSelectionList.get_node_or_null(NodePath(tower.name))
- if node:
- node.queue_free()
- elif Tower.selected_towers.size() > 1:
- # only remove deselected tower from list
- var node = %MultiSelectionList.get_node_or_null(NodePath(tower.name))
- if node: # when double click selecting in quick succession not found error
- node.queue_free()
-
- if tower.selection_group_id in selection_groups:
- selection_groups[tower.selection_group_id].erase(tower)
- if selection_groups[tower.selection_group_id].is_empty():
- selection_groups.erase(tower.selection_group_id)
- )
+ tower.remove_meta("multi_select_hud")
+ )
+
+ # move tower to new selection group
+ Client.selection.moved_to_group.connect(func(nodes: Array[Node], previous_id: String, new_id: String):
+ for tower: Tower in nodes:
+ tower.get_meta("multi_select_hud").remove_from_group(previous_id)
+ tower.get_meta("multi_select_hud").add_to_group(new_id)
- tower.selection_group_id_changed.connect(func(previous_id: String):
- #Client.selection.change_selection_group_id([tower], previous_id, tower.selection_group_id)
-
- if not tower.selection_group_id in selection_groups:
- selection_groups[tower.selection_group_id] = []
- selection_groups[tower.selection_group_id].append(tower)
- %MultiSelectionList.get_node(NodePath(tower.name)).add_to_group(tower.selection_group_id)
-
- selection_groups[previous_id].erase(tower)
- if selection_groups[previous_id].is_empty():
- selection_groups.erase(previous_id)
- if previous_id == selected_group:
- selected_group = tower.selection_group_id
- %MultiSelectionList.get_node(NodePath(tower.name)).remove_from_group(previous_id)
-
- if tower.name == selection_groups[tower.selection_group_id][0].name:
- redraw_select(tower)
- )
+ if Client.selection.has_node_in_group(tower, new_id):
+ redraw_select(tower)
+ redraw_multiselect(previous_id, new_id)
)
- Client.multi_select_finished.connect(func(_nodes):
- var keys = get_ordered_group_keys()
- if keys.size() > 0:
- selected_group = keys[0]
+ # redraw on selected group change
+ Client.selection.selected_group_changed.connect(func(previous_id: String, new_id: String):
+ if Client.selection.get_selected_nodes():
+ redraw_select(Client.selection.get_selected_nodes()[0])
+ redraw_multiselect(previous_id, new_id)
)
@@ -138,70 +111,44 @@ func _input(event: InputEvent):
team_bottom.visible = not team_bottom.visible
if event.is_action_pressed("selection_cycle") and %MultiSelectionContainer.visible:
- var keys = get_ordered_group_keys()
- var current_idx = keys.find(selected_group)
- selected_group = keys[(current_idx + 1) % keys.size()]
+ if Input.is_action_pressed("reverse_cycle_direction"):
+ Client.selection.go_to_previous()
+ else:
+ Client.selection.go_to_next()
func redraw_select(tower: Tower):
%TowerData.current_tower = tower
-func redraw_multiselect(previous_group: String, new_group: String):
+func redraw_multiselect(previous_group: String = "", new_group: String = Client.selection.selected_group):
var idx = 0
- for group_key in get_ordered_group_keys():
- var group = selection_groups[group_key]
- for node in group:
- var selection_node = %MultiSelectionList.get_node_or_null(NodePath(node.name))
- if selection_node: # when double click selecting in quick succession not found error
- %MultiSelectionList.move_child(selection_node, idx)
+ for id in Client.selection.get_ordered_group_ids():
+ var group = Client.selection.selection_groups[id]
+ for node: Tower in group:
+ # when double click selecting in quick succession not found error
+ if (node.has_meta("multi_select_hud") and
+ is_instance_valid(node.get_meta("multi_select_hud"))
+ ):
+ %MultiSelectionList.move_child(node.get_meta("multi_select_hud"), idx)
idx += 1
+ # wait for nodes to be in the correct groups
+ await get_tree().process_frame
+
for node in get_tree().get_nodes_in_group(previous_group):
node.modulate = Color(0.5, 0.5, 0.5)
- var tower = Client.current_stage.get_node_or_null("%Towers/" + node.name)
+ var tower = node.get_meta("tower")
if tower:
tower.is_highlighted = false
+
for node in get_tree().get_nodes_in_group(new_group):
node.modulate = Color(1.0, 1.0, 1.0)
- var tower = Client.current_stage.get_node_or_null("%Towers/" + node.name)
+ var tower = node.get_meta("tower")
if tower:
tower.is_highlighted = true
-func get_ordered_group_keys() -> Array:
- var keys = selection_groups.keys()
- keys.sort_custom(func(a, b):
- var group_a = selection_groups[a]
- var group_b = selection_groups[b]
-
- return group_a.size() > group_b.size()
- )
- keys.sort_custom(func(a, b):
- var group_a = selection_groups[a]
- var group_b = selection_groups[b]
- var node_a = group_a[0]
- var node_b = group_b[0]
- var level_a = 0
- var level_b = 0
-
- for component in node_a.components.values():
- level_a += component.level
- for component in node_b.components.values():
- level_b += component.level
-
- return level_a > level_b
- )
- keys.sort_custom(func(a, b):
- var group_a = selection_groups[a]
- var group_b = selection_groups[b]
-
- return group_a[0].components.size() > group_b[0].components.size()
- )
-
- return keys
-
-
func _on_build_mode_button_gui_input(event: InputEvent) -> void:
if event.is_action_pressed("select"):
if Client.state is StateDefault:
diff --git a/Stages/Wintermaul/hud_tower.gd b/Stages/Wintermaul/hud_tower.gd
index d24443b..7a7ef69 100644
--- a/Stages/Wintermaul/hud_tower.gd
+++ b/Stages/Wintermaul/hud_tower.gd
@@ -36,10 +36,7 @@ func redraw_components():
func get_selected_towers() -> Array:
- var hud: HUD = Client.current_stage.get_node("%HUD")
-
- # TODO: key not found error sometimes?
- return hud.selection_groups[hud.selected_group].duplicate()
+ return Client.selection.get_selected_nodes().duplicate()
func _on_range_gui_input(event: InputEvent) -> void:
@@ -180,7 +177,7 @@ func _on_range_level_up_pressed() -> void:
Client.current_stage.add_status_message("Not enough money to level up")
return
- for tower: Tower in towers:
+ for tower in towers:
var tower_component: TowerComponent = tower.components.get(TowerComponent.ComponentType.Range)
tower_component.level += 1
diff --git a/Towers/Tower.gd b/Towers/Tower.gd
index 73b1614..c3da1fd 100644
--- a/Towers/Tower.gd
+++ b/Towers/Tower.gd
@@ -7,17 +7,11 @@ signal deselected
signal selected_secondary
-static var selected_towers: Array[Tower]
-static var hovered_tower: Tower
-
var is_selected := false:
set(value):
if value:
- if not Tower.selected_towers.has(self):
- Tower.selected_towers.append(self)
- selected.emit()
+ selected.emit()
else:
- Tower.selected_towers.erase(self)
deselected.emit()
is_highlighted = false
is_selected = value
@@ -26,12 +20,9 @@ var is_selected := false:
var is_hovered := false:
set(value):
if value:
- hovered_tower = self
Input.set_default_cursor_shape(Input.CURSOR_POINTING_HAND)
else:
- if hovered_tower == self:
- hovered_tower = null
- Input.set_default_cursor_shape(Input.CURSOR_ARROW)
+ Input.set_default_cursor_shape(Input.CURSOR_ARROW)
is_hovered = value
queue_redraw()
@@ -61,7 +52,10 @@ func _init():
func _ready():
$AnimatedSprite2D.play()
- for component in [preload("res://Towers/Components/RangeComponent.tscn").instantiate(), preload("res://Towers/Components/AttackComponent.tscn").instantiate()]:
+ for component in [
+ preload("res://Towers/Components/RangeComponent.tscn").instantiate(),
+ preload("res://Towers/Components/AttackComponent.tscn").instantiate()
+ ]:
add_component(component)
redraw_components()
diff --git a/UI/Camera.gd b/UI/Camera.gd
index 1fd9361..34e194c 100644
--- a/UI/Camera.gd
+++ b/UI/Camera.gd
@@ -63,7 +63,8 @@ func _input(event):
Input.set_default_cursor_shape(Input.CURSOR_MOVE)
elif event.is_action_released("camera_drag"):
is_in_drag_mode = false
- Input.set_default_cursor_shape(Input.CURSOR_ARROW)
+ if Input.get_current_cursor_shape() == Input.CURSOR_MOVE:
+ Input.set_default_cursor_shape(Input.CURSOR_ARROW)
if event is InputEventMouseMotion:
diff --git a/UI/GameLobby/game_lobby.gd b/UI/GameLobby/game_lobby.gd
index 85a8a91..f80015b 100644
--- a/UI/GameLobby/game_lobby.gd
+++ b/UI/GameLobby/game_lobby.gd
@@ -11,6 +11,8 @@ var refresh_interval := 15.0
func _ready() -> void:
%GamesList.get_child(0).queue_free()
+ %ServerUrl.text = GameLobby.server_base_url
+
if await check_game_lobby_available():
get_server_list()
$RefreshTimer.wait_time = refresh_interval
@@ -36,11 +38,16 @@ func get_server_list():
for node in %GamesList.get_children():
node.queue_free()
- for game in result["data"]:
- var lobby_game = lobby_game_scene.instantiate()
- lobby_game.game_id = game["id"]
- lobby_game.game_name = game["name"]
- %GamesList.add_child(lobby_game)
+ if result["data"].size() > 0:
+ %NoGamesFound.visible = false
+
+ for game in result["data"]:
+ var lobby_game = lobby_game_scene.instantiate()
+ lobby_game.game_id = game["id"]
+ lobby_game.game_name = game["name"]
+ %GamesList.add_child(lobby_game)
+ else:
+ %NoGamesFound.visible = true
func _on_back_button_pressed() -> void:
@@ -55,3 +62,15 @@ func _on_refresh_pressed() -> void:
func _on_refresh_timer_timeout() -> void:
get_server_list()
+
+
+func _on_set_server_pressed() -> void:
+ var config = Client.get_config()
+ config.set_value(
+ "general",
+ "game_lobby_server_base_url",
+ %ServerUrl.text
+ )
+ config.save("user://config")
+
+ GameLobby.server_base_url = %ServerUrl.text
diff --git a/UI/GameLobby/game_lobby.tscn b/UI/GameLobby/game_lobby.tscn
index 241dbe5..8c632d6 100644
--- a/UI/GameLobby/game_lobby.tscn
+++ b/UI/GameLobby/game_lobby.tscn
@@ -61,6 +61,7 @@ unique_name_in_owner = true
layout_mode = 2
[node name="LobbyGame" parent="MarginContainer/CenterContainer/GamesList" instance=ExtResource("3_83gpr")]
+visible = false
layout_mode = 2
[node name="ServerNotReachable" type="Label" parent="MarginContainer/CenterContainer"]
@@ -69,6 +70,12 @@ visible = false
layout_mode = 2
text = "Game Lobby Server at %SERVER% not reachable"
+[node name="NoGamesFound" type="Label" parent="MarginContainer/CenterContainer"]
+unique_name_in_owner = true
+visible = false
+layout_mode = 2
+text = "No Games Found"
+
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
layout_mode = 2
size_flags_horizontal = 8
@@ -87,8 +94,24 @@ layout_mode = 2
mouse_default_cursor_shape = 2
text = "Back"
+[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer"]
+layout_mode = 2
+size_flags_horizontal = 8
+size_flags_vertical = 0
+
+[node name="ServerUrl" type="LineEdit" parent="MarginContainer/HBoxContainer"]
+unique_name_in_owner = true
+layout_mode = 2
+expand_to_text_length = true
+
+[node name="SetServer" type="Button" parent="MarginContainer/HBoxContainer"]
+unique_name_in_owner = true
+layout_mode = 2
+text = "Set Server"
+
[node name="RefreshTimer" type="Timer" parent="."]
[connection signal="pressed" from="MarginContainer/VBoxContainer/Refresh" to="." method="_on_refresh_pressed"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/BackButton" to="." method="_on_back_button_pressed"]
+[connection signal="pressed" from="MarginContainer/HBoxContainer/SetServer" to="." method="_on_set_server_pressed"]
[connection signal="timeout" from="RefreshTimer" to="." method="_on_refresh_timer_timeout"]
diff --git a/UI/GameLobby/lobby_game.gd b/UI/GameLobby/lobby_game.gd
index 2433dfd..39f9076 100644
--- a/UI/GameLobby/lobby_game.gd
+++ b/UI/GameLobby/lobby_game.gd
@@ -16,6 +16,7 @@ func _on_join_pressed() -> void:
var result = response.parse_json()
var game_data = result["data"]
+ print(game_data)
Network.join_game(game_data["ip"], game_data["port"])
get_tree().change_scene_to_file("res://UI/PlayerLobby/Lobby.tscn")
else:
diff --git a/UI/PlayerLobby/lobby.gd b/UI/PlayerLobby/lobby.gd
index 4169478..8c1c4a9 100644
--- a/UI/PlayerLobby/lobby.gd
+++ b/UI/PlayerLobby/lobby.gd
@@ -45,7 +45,7 @@ func _ready() -> void:
if multiplayer.is_server():
$KeepAliveTimer.start()
$KeepAliveTimer.timeout.connect(func():
- GameLobby.request_post("/keep-alive")
+ await GameLobby.request_post("/keep-alive")
)
@@ -77,6 +77,7 @@ func update_list(current_list: Control, player_ids: Array):
control.get_child(0).text = str(player.username)
control.get_child(0).tooltip_text = str(id)
current_list.move_child(control, player_ids.find(id) + 1)
+ # TODO: test with 3 players
func _on_peer_connected(id):
diff --git a/project.godot b/project.godot
index 26eeb2e..7016ac2 100644
--- a/project.godot
+++ b/project.godot
@@ -116,6 +116,11 @@ select_secondary={
"deadzone": 0.5,
"events": []
}
+reverse_cycle_direction={
+"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":4194325,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
+]
+}
[layer_names]