-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nemrav
committed
Jan 15, 2025
1 parent
da6c155
commit 7e496f9
Showing
21 changed files
with
906 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
class_name MultiplayerEventsObject | ||
extends RefCounted | ||
|
||
signal save_ips(save_file: ConfigFile) | ||
signal load_ips(load_file: ConfigFile) | ||
|
||
const ips_file_path_setting : String = "openvic/settings/ips_file_path" | ||
const ips_file_path_default : String = "user://ips.cfg" | ||
|
||
var _saved_ips_file_path : String = ProjectSettings.get_setting(ips_file_path_setting, ips_file_path_default) | ||
var _saved_ips_file := ConfigFile.new() | ||
|
||
var config_file_loaded : bool = false | ||
|
||
const USER : StringName = &"USER" | ||
const SERVER_NAMES : StringName = &"SERVER_NAMES" | ||
const SERVER_IPS : StringName = &"SERVER_IPS" | ||
const PLAYER_NAME : StringName = &"player_name" | ||
const HOST_GAME_NAME : StringName = &"host_game_name" | ||
const HOST_GAME_PASSWORD : StringName = &"host_game_password" | ||
|
||
const DEFAULT_PLAYER_NAME : StringName = &"Player1" | ||
const DEFAULT_GAME_NAME : StringName = &"Player1's Game" | ||
const DEFAULT_GAME_PASSWORD : StringName = &"" | ||
|
||
func get_override_path() -> String: | ||
var override_path : String = ProjectSettings.get_setting("application/config/project_settings_override", "") | ||
if override_path.is_empty(): | ||
override_path = _saved_ips_file_path | ||
return override_path | ||
|
||
func get_ips_config_file() -> ConfigFile: | ||
if config_file_loaded: | ||
return _saved_ips_file | ||
else: | ||
return load_ips_config_file() | ||
|
||
func load_ips_config_file() -> ConfigFile: | ||
var override_path := get_override_path() | ||
if FileAccess.file_exists(override_path): | ||
if _saved_ips_file.load(override_path) != OK: | ||
push_error("Failed to load overrides from %s" % override_path) | ||
else: | ||
if !_saved_ips_file.has_section_key(USER,PLAYER_NAME): | ||
_saved_ips_file.set_value(USER,PLAYER_NAME,DEFAULT_PLAYER_NAME) | ||
if !_saved_ips_file.has_section_key(USER,HOST_GAME_NAME): | ||
_saved_ips_file.set_value(USER,HOST_GAME_NAME,DEFAULT_GAME_NAME) | ||
if !_saved_ips_file.has_section_key(USER,HOST_GAME_PASSWORD): | ||
_saved_ips_file.set_value(USER,HOST_GAME_PASSWORD,DEFAULT_GAME_PASSWORD) | ||
save_ips_config_file() | ||
load_ips.emit(_saved_ips_file) | ||
config_file_loaded = true | ||
return _saved_ips_file | ||
|
||
func save_ips_config_file() -> void: | ||
var override_path := get_override_path() | ||
_saved_ips_file.save(_saved_ips_file_path) | ||
if _saved_ips_file.save(override_path) != OK: | ||
push_error("Failed to save ip overrides to %s" % override_path) | ||
else: | ||
save_ips.emit(_saved_ips_file) | ||
|
||
func _init() -> void: | ||
load_ips_config_file() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
game/src/Game/Menu/MultiplayerMenu/ConnectionFailDialog.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
extends AcceptDialog | ||
class_name ConnectionFailDialog | ||
|
||
enum FAIL_REASONS {NO_SERVER, PASSWORD, BAD_IP} | ||
|
||
@export var reason_text : String | ||
@export var no_server_fail_text : String | ||
@export var bad_password_fail_text : String | ||
@export var bad_ip_text : String | ||
|
||
@onready var reason_text_map : Dictionary = { | ||
FAIL_REASONS.NO_SERVER : no_server_fail_text, | ||
FAIL_REASONS.PASSWORD : bad_password_fail_text, | ||
FAIL_REASONS.BAD_IP : bad_ip_text | ||
} | ||
|
||
@export var label : Label | ||
|
||
func display(reason : FAIL_REASONS) -> void: | ||
label.text = "%s %s" % [tr(reason_text), tr(reason_text_map[reason])] | ||
popup_centered() |
23 changes: 23 additions & 0 deletions
23
game/src/Game/Menu/MultiplayerMenu/DirectConnectionEntry.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
extends HBoxContainer | ||
class_name DirectConnectionEntry | ||
|
||
@export var ip_edit : SecretEdit | ||
@export var name_edit : LineEdit | ||
@export var connect_button : Button | ||
@export var delete_button : Button | ||
|
||
# Collects connect and delete presses from its children, and emits | ||
# the corresponding signals for the connection controller to handle | ||
|
||
signal connect_to_ip(ip : String) | ||
signal delete() | ||
|
||
func setup(name_in : StringName, ip : StringName) -> void: | ||
name_edit.text = name_in | ||
ip_edit.set_text(ip) | ||
|
||
func _on_connect_pressed() -> void: | ||
connect_to_ip.emit(ip_edit.get_text()) | ||
|
||
func _on_delete_pressed() -> void: | ||
delete.emit() |
50 changes: 50 additions & 0 deletions
50
game/src/Game/Menu/MultiplayerMenu/DirectConnectionEntry.tscn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
[gd_scene load_steps=3 format=3 uid="uid://br26w6mwqilyr"] | ||
|
||
[ext_resource type="Script" path="res://src/Game/Menu/MultiplayerMenu/DirectConnectionEntry.gd" id="1_8v0qa"] | ||
[ext_resource type="PackedScene" uid="uid://dcsy6w6ow2xxg" path="res://src/Game/Menu/MultiplayerMenu/SecretEdit.tscn" id="2_3yivm"] | ||
|
||
[node name="DirectConnectionEntry" type="HBoxContainer" node_paths=PackedStringArray("ip_edit", "name_edit", "connect_button", "delete_button")] | ||
anchors_preset = 10 | ||
anchor_right = 1.0 | ||
offset_bottom = 31.0 | ||
grow_horizontal = 2 | ||
script = ExtResource("1_8v0qa") | ||
ip_edit = NodePath("SecretEdit") | ||
name_edit = NodePath("EditName") | ||
connect_button = NodePath("Connect") | ||
delete_button = NodePath("Delete") | ||
|
||
[node name="EditName" type="LineEdit" parent="."] | ||
layout_mode = 2 | ||
size_flags_horizontal = 3 | ||
placeholder_text = "Game1" | ||
max_length = 32 | ||
editable = false | ||
|
||
[node name="VSeparator" type="VSeparator" parent="."] | ||
layout_mode = 2 | ||
|
||
[node name="SecretEdit" parent="." instance=ExtResource("2_3yivm")] | ||
layout_mode = 2 | ||
size_flags_horizontal = 3 | ||
editable = false | ||
|
||
[node name="VSeparator2" type="VSeparator" parent="."] | ||
layout_mode = 2 | ||
|
||
[node name="Connect" type="Button" parent="."] | ||
layout_mode = 2 | ||
text = "MP_DIRECT_CONNECT" | ||
|
||
[node name="Edit" type="CheckButton" parent="."] | ||
layout_mode = 2 | ||
text = "MP_DIRECT_EDIT" | ||
|
||
[node name="Delete" type="Button" parent="."] | ||
layout_mode = 2 | ||
text = "MP_DIRECT_DELETE" | ||
|
||
[connection signal="pressed" from="Connect" to="." method="_on_connect_pressed"] | ||
[connection signal="toggled" from="Edit" to="EditName" method="set_editable"] | ||
[connection signal="toggled" from="Edit" to="SecretEdit" method="set_editable"] | ||
[connection signal="pressed" from="Delete" to="." method="_on_delete_pressed"] |
Oops, something went wrong.