online multiplayer chess game (note server currently down)
| -rw-r--r-- | Utils.gd | 12 | ||||
| -rw-r--r-- | networking/Network.gd | 9 | ||||
| -rw-r--r-- | networking/PacketHandler.gd | 155 | ||||
| -rw-r--r-- | project.godot | 8 | ||||
| -rw-r--r-- | ui/Lobby.gd | 177 | ||||
| -rw-r--r-- | ui/Lobby.tscn | 51 | ||||
| -rw-r--r-- | ui/Settings.tscn | 39 | ||||
| -rw-r--r-- | ui/StartMenu.gd | 30 | ||||
| -rw-r--r-- | ui/StartMenu.tscn | 41 | ||||
| -rw-r--r-- | ui/background/ColorfullBackground.gd | 39 | ||||
| -rw-r--r-- | ui/background/ColorfullBackground.tscn | 11 |
11 files changed, 331 insertions, 241 deletions
@@ -5,7 +5,7 @@ signal newfen(fen) var turn_moves: PoolStringArray = [] var turns_moves: PoolStringArray = [] - +var internet = false var counter := 0 @@ -70,6 +70,7 @@ func internet_available() -> bool: var httpurl = "https://1.1.1.1" var returnable = http.request(httpurl) == OK http.queue_free() + internet = returnable return returnable @@ -148,3 +149,12 @@ func fen() -> String: ] ) # pos # turn # castling # enpassant # halfmove # fullmove return fen + + +func _notification(what: int) -> void: + if what == MainLoop.NOTIFICATION_WM_QUIT_REQUEST or what == MainLoop.NOTIFICATION_WM_GO_BACK_REQUEST: + if get_tree().get_root().has_node("Board"): + Globals.network.send_packet(Globals.network.game_code, Globals.network.HEADERS.stopgame) + yield(get_tree(), "idle_frame") # wait for the packet to send + Log.info("Bye!") + get_tree().quit() diff --git a/networking/Network.gd b/networking/Network.gd index 2b42f98..9d3c165 100644 --- a/networking/Network.gd +++ b/networking/Network.gd @@ -53,6 +53,10 @@ func ping() -> void: send_packet("ping", HEADERS.ping) +func close(): + ws.disconnect_from_host(0, "Close") + + func _connection_established(_protocol) -> void: connected = true emit_signal("connection_established") @@ -92,7 +96,10 @@ func _data_recieved() -> void: HEADERS.joinrequest: emit_signal("join_result", text) HEADERS.stopgame: - emit_signal("game_over", "your opponent requested stop", true) + if PacketHandler.leaving: + PacketHandler.leaving = false + else: # dont emit the signal if its a stophost thing (HACK) + emit_signal("game_over", "your opponent requested stop", true) HEADERS.startgame: emit_signal("start_game") HEADERS.ping: diff --git a/networking/PacketHandler.gd b/networking/PacketHandler.gd new file mode 100644 index 0000000..9ce4a09 --- /dev/null +++ b/networking/PacketHandler.gd @@ -0,0 +1,155 @@ +extends Node +class_name NetManager + +### for the ui +signal set_buttons(enabled) +signal set_status(status, err, isok) +signal set_visible(visibility) +signal set_back_button(disabled) + +signal game_over +signal game_started + +var hosting = false +var leaving = false + +var status = ["", true, false] + +func set_buttons(enabled): + status[2] = enabled + emit_signal("set_buttons", enabled) + +func return(): + if hosting: + leaving = true + Globals.network.send_packet(Globals.network.game_code, Network.HEADERS.stopgame) # stop hosting + hosting = false + set_buttons(true) + set_status("", true) + + +func _ready(): + get_tree().set_auto_accept_quit(false) + if Utils.internet_available(): + var net = Network.new() + set_status("Connecting", true) + Events.connect("go_back", self, "_handle_game_over") + net.connect("move_data", self, "_on_data") + net.connect("join_result", self, "_on_join_result") + net.connect("host_result", self, "_on_host_result") + net.connect("game_over", self, "_handle_game_over") + net.connect("start_game", self, "_start_game") + net.connect("connection_established", self, "network_ready") + add_child(net) + Globals.network = net + + +func requestjoin(): + set_buttons( false) + emit_signal("set_back_button", true) + Globals.network.send_packet(Globals.network.game_code, Globals.network.HEADERS.joinrequest) + + +func requesthost(): + set_buttons(false) + emit_signal("set_back_button", true) + Globals.network.send_packet(Globals.network.game_code, Globals.network.HEADERS.hostrequest) + + +func network_ready(): + set_status("", true) + set_buttons(true) + + +func set_status(text, isok): + status[0] = text + status[1] = isok + emit_signal("set_status", text, isok) + + +func _on_join_result(accepted: String) -> void: + if handle_result(accepted, "Joined!", false): + Globals.network.send_packet(Globals.network.game_code, Globals.network.HEADERS.startgame) + + +func _on_host_result(accepted: String) -> void: + hosting = handle_result(accepted, "Hosted!") + + +func handle_result(accepted: String, resultstring: String, team: bool = true) -> bool: + emit_signal("set_back_button", false) + Globals.team = team + if accepted == "Y": + set_status(resultstring, true) + return true + set_status(accepted, false) + set_buttons( true) + return false + + +func _handle_game_over(error = "game over", isok = true) -> void: + Globals.reset_vars() + if get_tree().get_root().has_node("Board"): + get_tree().get_root().get_node("Board").queue_free() + set_status(error, isok) + emit_signal("set_visible", true) + emit_signal("game_over") + + +func _start_game() -> void: + hosting = false + var board = load("res://Board.tscn").instance() + get_tree().get_root().add_child(board) + emit_signal("set_visible", false) + emit_signal("game_started") + set_buttons(false) + + +static func add_turn() -> void: + Events.emit_signal("just_before_turn_over") + Globals.add_turn() + Globals.turn = not Globals.turn + Events.emit_signal("turn_over") + + +func _on_data(data: Dictionary) -> void: + Log.debug([data, " recieved"]) + Globals.fullmove = data["fullmove"] + Globals.turn = data["turn"] + Globals.halfmove = data["halfmove"] + Events.emit_signal("data_recieved") + match data["movetype"]: + Network.MOVEHEADERS.passant: + # en passant + var end_pos = dict2vec(data["positions"][1]) + var start_piece = Piece.at_pos(dict2vec(data["positions"][0])) + Piece.at_pos(dict2vec(data["positions"][2])).took() # kill the unfortunate + start_piece.passant(end_pos) + Network.MOVEHEADERS.move: + var start_piece = Piece.at_pos(dict2vec(data["positions"][0])) + var end_pos = dict2vec(data["positions"][1]) + var end_piece = Piece.at_pos(end_pos) + if end_piece != null: + start_piece.take(end_piece) + else: + start_piece.moveto(end_pos) + Network.MOVEHEADERS.castle: + var king = Piece.at_pos(dict2vec(data["positions"]["king"])) + var rook = Piece.at_pos(dict2vec(data["positions"]["rook"])) + rook.moveto(dict2vec(data["positions"]["rookdestination"]), true, false, true) + Utils.add_move(king.castle(dict2vec(data["positions"]["kingdestination"]))) + Network.MOVEHEADERS.promote: + var dict_data = data["positions"] # positions is a dict for readability sometimes + var pawn = Piece.at_pos(dict2vec(dict_data["start_position"])) + var dest = dict2vec(dict_data["destination"]) + if Piece.at_pos(dest) != null: + Piece.at_pos(dest).took() # move the pawn to the new place, killing if necessary + pawn.clear_clicked() + Globals.grid.make_piece(dest, Pawn.piece(dict_data["become"]), dict_data["white"]) # create the promotion + pawn.took() # kill the pawn + Utils.add_move(dict_data["notation"]) # add a move + Globals.grid.print_matrix_pretty(Globals.grid.matrix) + + +static func dict2vec(dict: Dictionary) -> Vector2: + return Vector2(dict["x"], dict["y"]) diff --git a/project.godot b/project.godot index 3b8a2c8..029ce81 100644 --- a/project.godot +++ b/project.godot @@ -65,6 +65,11 @@ _global_script_classes=[ { "path": "res://ui/Log.gd" }, { "base": "Node", +"class": "NetManager", +"language": "GDScript", +"path": "res://networking/PacketHandler.gd" +}, { +"base": "Node", "class": "Network", "language": "GDScript", "path": "res://networking/Network.gd" @@ -116,6 +121,7 @@ _global_script_class_icons={ "King": "res://assets/pieces/california/wK.png", "Knight": "res://assets/pieces/california/wN.png", "Log": "", +"NetManager": "", "Network": "", "OldColorView": "", "Pawn": "res://assets/pieces/california/wP.png", @@ -145,6 +151,8 @@ Events="*res://Events.gd" Utils="*res://Utils.gd" SoundFx="*res://sounds/SoundFX.tscn" SaveLoad="*res://saveload.gd" +ColorBack="*res://ui/background/ColorfullBackground.tscn" +PacketHandler="*res://networking/PacketHandler.gd" [debug] diff --git a/ui/Lobby.gd b/ui/Lobby.gd index e4da73d..3217b41 100644 --- a/ui/Lobby.gd +++ b/ui/Lobby.gd @@ -1,26 +1,26 @@ extends Control -onready var address: LineEdit = $Back/Center/HBox/VBox/Address -onready var buttons = $Back/Center/HBox/VBox/buttons -onready var status_ok = $Back/Center/HBox/VBox/StatusOK -onready var status_fail = $Back/Center/HBox/VBox/StatusFail +onready var address: LineEdit = $Darken/Center/HBox/VBox/Address +onready var buttons = $Darken/Center/HBox/VBox/buttons +onready var status_ok = $Darken/Center/HBox/VBox/StatusOK +onready var status_fail = $Darken/Center/HBox/VBox/StatusFail func toggle(onoff) -> void: visible = onoff - if onoff: - for i in get_tree().get_nodes_in_group("control"): - i.mouse_filter = MOUSE_FILTER_STOP - else: - for i in get_tree().get_nodes_in_group("control"): - i.mouse_filter = MOUSE_FILTER_IGNORE -func _handle_game_over(error = "game over", isok = true) -> void: - set_buttons() - Globals.reset_vars() - end_game() - _set_status(error, isok) +func _ready(): + PacketHandler.connect("set_back_button", $Darken/Center/HBox/VBox/backbutton, "set_disabled") + PacketHandler.connect("set_status", self, "_set_status") + PacketHandler.connect("set_buttons", self, "_set_buttons") + PacketHandler.connect("set_visible", self, "toggle") + _set_status(PacketHandler.status[0], PacketHandler.status[1]) + if !Utils.internet_available(): + _set_status("no internet", false) + _set_buttons(false) + else: + _set_buttons(PacketHandler.status[2]) func _set_status(text, isok) -> void: # Simple way to show status. @@ -34,16 +34,20 @@ func _set_status(text, isok) -> void: # Simple way to show status. status_fail.visible = len(status_fail.text) > 0 +func _set_buttons(enabled = true) -> void: + for c in buttons.get_children(): + c.disabled = !enabled + address.editable = enabled + + func _on_join_pressed() -> void: - Globals.network.game_code = validate_text() - Globals.network.send_packet(Globals.network.game_code, Globals.network.HEADERS.joinrequest) - set_buttons(false) + validate_text() + PacketHandler.requestjoin() func _on_HostButton_pressed() -> void: - Globals.network.game_code = validate_text() - Globals.network.send_packet(Globals.network.game_code, Globals.network.HEADERS.hostrequest) - set_buttons(false) + validate_text() + PacketHandler.requesthost() func validate_text(text = address.get_text()) -> String: @@ -52,133 +56,14 @@ func validate_text(text = address.get_text()) -> String: text = text.replace(" ", "_") address.text = text address.caret_position = pos + Globals.network.game_code = text return text -func _ready() -> void: - get_tree().set_auto_accept_quit(false) - Events.connect("go_back", self, "_handle_game_over") - if !is_instance_valid(Globals.network): - if Utils.internet_available(): - _set_status("Connecting...", true) - var net = Network.new() - net.connect("move_data", self, "_on_data") - net.connect("join_result", self, "_on_join_result") - net.connect("host_result", self, "_on_host_result") - net.connect("game_over", self, "_handle_game_over") - net.connect("start_game", self, "_start_game") - net.connect("connection_established", self, "network_ready") - add_child(net) - Globals.network = net - else: - set_buttons(false) - _set_status("No internet connection", false) - - -func network_ready(): - set_buttons(true) - _set_status("", true) - - -func end_game() -> void: - if get_tree().get_root().has_node("Board"): - get_tree().get_root().get_node("Board").queue_free() - toggle(true) - - -func create_world() -> void: - var board = load("res://Board.tscn").instance() - get_tree().get_root().add_child(board) - toggle(false) - - -func _start_game() -> void: - create_world() - - -func _on_join_result(accepted: String) -> void: - Globals.team = false - if accepted == "Y": - _set_status("Joined!", true) - Globals.network.send_packet("", Globals.network.HEADERS.startgame) - else: - _set_status(accepted, false) - set_buttons() - - -func set_buttons(enabled = true) -> void: - for c in buttons.get_children(): - c.disabled = !enabled - address.editable = enabled - - -func _on_host_result(accepted: String) -> void: - Globals.team = true - if accepted == "Y": - _set_status("Hosted!", true) - else: - _set_status(accepted, false) - set_buttons() - - -func add_turn() -> void: - Events.emit_signal("just_before_turn_over") - Globals.add_turn() - Globals.turn = not Globals.turn - Events.emit_signal("turn_over") - - -func _on_data(data: Dictionary) -> void: - Log.debug([data, " recieved"]) - Globals.fullmove = data["fullmove"] - Globals.turn = data["turn"] - Globals.halfmove = data["halfmove"] - Events.emit_signal("data_recieved") - match data["movetype"]: - Network.MOVEHEADERS.passant: - # en passant - var end_pos = dict2vec(data["positions"][1]) - var start_piece = Piece.at_pos(dict2vec(data["positions"][0])) - Piece.at_pos(dict2vec(data["positions"][2])).took() # kill the unfortunate - start_piece.passant(end_pos) - Network.MOVEHEADERS.move: - var start_piece = Piece.at_pos(dict2vec(data["positions"][0])) - var end_pos = dict2vec(data["positions"][1]) - var end_piece = Piece.at_pos(end_pos) - if end_piece != null: - start_piece.take(end_piece) - else: - start_piece.moveto(end_pos) - Network.MOVEHEADERS.castle: - var king = Piece.at_pos(dict2vec(data["positions"]["king"])) - var rook = Piece.at_pos(dict2vec(data["positions"]["rook"])) - rook.moveto(dict2vec(data["positions"]["rookdestination"]), true, false, true) - Utils.add_move(king.castle(dict2vec(data["positions"]["kingdestination"]))) - Network.MOVEHEADERS.promote: - var dict_data = data["positions"] # positions is a dict for readability sometimes - var pawn = Piece.at_pos(dict2vec(dict_data["start_position"])) - var dest = dict2vec(dict_data["destination"]) - if Piece.at_pos(dest) != null: - Piece.at_pos(dest).took() # move the pawn to the new place, killing if necessary - pawn.clear_clicked() - Globals.grid.make_piece(dest, Pawn.piece(dict_data["become"]), dict_data["white"]) # create the promotion - pawn.took() # kill the pawn - Utils.add_move(dict_data["notation"]) # add a move - Globals.grid.print_matrix_pretty(Globals.grid.matrix) - - -func dict2vec(dict: Dictionary) -> Vector2: - return Vector2(dict["x"], dict["y"]) - - -func _notification(what: int) -> void: - if what == MainLoop.NOTIFICATION_WM_QUIT_REQUEST or what == MainLoop.NOTIFICATION_WM_GO_BACK_REQUEST: - if get_tree().get_root().has_node("Board"): - Globals.network.send_packet(Globals.network.game_code, Globals.network.HEADERS.stopgame) - yield(get_tree(), "idle_frame") # wait for the packet to send - get_tree().quit() - - func _on_Address_text_entered(new_text: String): validate_text(new_text) - Globals.network.game_code = new_text + + +func _on_backbutton_pressed(): + PacketHandler.return() + get_tree().change_scene("res://ui/StartMenu.tscn") diff --git a/ui/Lobby.tscn b/ui/Lobby.tscn index 9be128e..66ec1e5 100644 --- a/ui/Lobby.tscn +++ b/ui/Lobby.tscn @@ -9,28 +9,36 @@ anchor_bottom = 1.0 theme = ExtResource( 1 ) script = ExtResource( 2 ) -[node name="Back" type="ColorRect" parent="." groups=["control"]] +[node name="Darken" type="ColorRect" parent="."] anchor_right = 1.0 anchor_bottom = 1.0 -color = Color( 0, 0, 0, 0.784314 ) +color = Color( 0, 0, 0, 0.396078 ) -[node name="Center" type="CenterContainer" parent="Back" groups=["control"]] +[node name="Center" type="CenterContainer" parent="Darken"] anchor_right = 1.0 anchor_bottom = 1.0 -[node name="HBox" type="HBoxContainer" parent="Back/Center" groups=["control"]] -margin_left = 425.0 -margin_top = 286.0 -margin_right = 775.0 -margin_bottom = 513.0 +[node name="HBox" type="HBoxContainer" parent="Darken/Center"] +margin_left = 536.0 +margin_top = 226.0 +margin_right = 886.0 +margin_bottom = 574.0 -[node name="VBox" type="VBoxContainer" parent="Back/Center/HBox" groups=["control"]] +[node name="VBox" type="VBoxContainer" parent="Darken/Center/HBox"] margin_right = 350.0 -margin_bottom = 227.0 +margin_bottom = 348.0 -[node name="Address" type="LineEdit" parent="Back/Center/HBox/VBox" groups=["control"]] +[node name="backbutton" type="Button" parent="Darken/Center/HBox/VBox"] margin_right = 350.0 margin_bottom = 106.0 +focus_mode = 0 +enabled_focus_mode = 0 +text = "go back" + +[node name="Address" type="LineEdit" parent="Darken/Center/HBox/VBox"] +margin_top = 121.0 +margin_right = 350.0 +margin_bottom = 227.0 rect_min_size = Vector2( 350, 0 ) focus_mode = 1 text = "game_code" @@ -40,12 +48,12 @@ placeholder_text = "game_code" caret_blink = true caret_blink_speed = 0.35 -[node name="buttons" type="HBoxContainer" parent="Back/Center/HBox/VBox" groups=["control"]] -margin_top = 121.0 +[node name="buttons" type="HBoxContainer" parent="Darken/Center/HBox/VBox"] +margin_top = 242.0 margin_right = 350.0 -margin_bottom = 227.0 +margin_bottom = 348.0 -[node name="JoinButton" type="Button" parent="Back/Center/HBox/VBox/buttons" groups=["control"]] +[node name="JoinButton" type="Button" parent="Darken/Center/HBox/VBox/buttons"] margin_right = 150.0 margin_bottom = 106.0 rect_min_size = Vector2( 150, 0 ) @@ -55,7 +63,7 @@ disabled = true enabled_focus_mode = 0 text = "join" -[node name="HostButton" type="Button" parent="Back/Center/HBox/VBox/buttons" groups=["control"]] +[node name="HostButton" type="Button" parent="Darken/Center/HBox/VBox/buttons"] margin_left = 165.0 margin_right = 350.0 margin_bottom = 106.0 @@ -65,7 +73,7 @@ disabled = true enabled_focus_mode = 0 text = "host" -[node name="StatusOK" type="Label" parent="Back/Center/HBox/VBox" groups=["control"]] +[node name="StatusOK" type="Label" parent="Darken/Center/HBox/VBox"] visible = false margin_top = 242.0 margin_right = 500.0 @@ -73,7 +81,7 @@ margin_bottom = 292.0 custom_colors/font_color = Color( 1, 1, 1, 1 ) autowrap = true -[node name="StatusFail" type="Label" parent="Back/Center/HBox/VBox" groups=["control"]] +[node name="StatusFail" type="Label" parent="Darken/Center/HBox/VBox"] visible = false margin_top = 307.0 margin_right = 500.0 @@ -81,6 +89,7 @@ margin_bottom = 357.0 custom_colors/font_color = Color( 0.698039, 0.415686, 0.415686, 1 ) autowrap = true -[connection signal="text_entered" from="Back/Center/HBox/VBox/Address" to="." method="_on_Address_text_entered"] -[connection signal="pressed" from="Back/Center/HBox/VBox/buttons/JoinButton" to="." method="_on_join_pressed"] -[connection signal="pressed" from="Back/Center/HBox/VBox/buttons/HostButton" to="." method="_on_HostButton_pressed"] +[connection signal="pressed" from="Darken/Center/HBox/VBox/backbutton" to="." method="_on_backbutton_pressed"] +[connection signal="text_entered" from="Darken/Center/HBox/VBox/Address" to="." method="_on_Address_text_entered"] +[connection signal="pressed" from="Darken/Center/HBox/VBox/buttons/JoinButton" to="." method="_on_join_pressed"] +[connection signal="pressed" from="Darken/Center/HBox/VBox/buttons/HostButton" to="." method="_on_HostButton_pressed"] diff --git a/ui/Settings.tscn b/ui/Settings.tscn index 6a5dcf3..317f99b 100644 --- a/ui/Settings.tscn +++ b/ui/Settings.tscn @@ -6,34 +6,36 @@ [ext_resource path="res://ui/Preview.gd" type="Script" id=4] [ext_resource path="res://ui/colorpicker/ColorPickerButton.tscn" type="PackedScene" id=5] -[node name="Settings" type="Control" groups=["control"]] +[node name="Settings" type="Control"] anchor_right = 1.0 anchor_bottom = 1.0 theme = ExtResource( 1 ) script = ExtResource( 2 ) -[node name="ColorRect" type="ColorRect" parent="." groups=["control"]] +[node name="ColorRect" type="ColorRect" parent="."] anchor_right = 1.0 anchor_bottom = 1.0 -color = Color( 0, 0, 0, 1 ) +color = Color( 0, 0, 0, 0.384314 ) -[node name="HBoxContainer" type="HBoxContainer" parent="ColorRect" groups=["control"]] +[node name="HBoxContainer" type="HBoxContainer" parent="ColorRect"] anchor_right = 1.0 anchor_bottom = 1.0 margin_top = 80.0 +mouse_filter = 2 alignment = 1 -[node name="VBoxContainer" type="VBoxContainer" parent="ColorRect/HBoxContainer" groups=["control"]] -margin_left = 54.0 -margin_right = 420.0 +[node name="VBoxContainer" type="VBoxContainer" parent="ColorRect/HBoxContainer"] +margin_left = 165.0 +margin_right = 531.0 margin_bottom = 720.0 +mouse_filter = 2 -[node name="BackButton" type="Button" parent="ColorRect/HBoxContainer/VBoxContainer" groups=["control"]] +[node name="BackButton" type="Button" parent="ColorRect/HBoxContainer/VBoxContainer"] margin_right = 366.0 margin_bottom = 106.0 text = "back" -[node name="PieceSet" type="OptionButton" parent="ColorRect/HBoxContainer/VBoxContainer" groups=["control"]] +[node name="PieceSet" type="OptionButton" parent="ColorRect/HBoxContainer/VBoxContainer"] margin_top = 121.0 margin_right = 366.0 margin_bottom = 277.0 @@ -97,12 +99,13 @@ margin_right = 200.0 margin_bottom = 200.0 rect_min_size = Vector2( 100, 100 ) -[node name="VBoxContainer2" type="VBoxContainer" parent="ColorRect/HBoxContainer" groups=["control"]] -margin_left = 435.0 -margin_right = 804.0 +[node name="VBoxContainer2" type="VBoxContainer" parent="ColorRect/HBoxContainer"] +margin_left = 546.0 +margin_right = 915.0 margin_bottom = 720.0 +mouse_filter = 2 -[node name="VsyncButton" type="CheckBox" parent="ColorRect/HBoxContainer/VBoxContainer2" groups=["control"]] +[node name="VsyncButton" type="CheckBox" parent="ColorRect/HBoxContainer/VBoxContainer2"] margin_right = 369.0 margin_bottom = 140.0 focus_mode = 0 @@ -110,7 +113,7 @@ pressed = true enabled_focus_mode = 0 text = "vsync" -[node name="FullscreenButton" type="CheckBox" parent="ColorRect/HBoxContainer/VBoxContainer2" groups=["control"]] +[node name="FullscreenButton" type="CheckBox" parent="ColorRect/HBoxContainer/VBoxContainer2"] margin_top = 155.0 margin_right = 369.0 margin_bottom = 295.0 @@ -118,17 +121,17 @@ focus_mode = 0 enabled_focus_mode = 0 text = "fullscreen" -[node name="Borderless" type="CheckBox" parent="ColorRect/HBoxContainer/VBoxContainer2" groups=["control"]] +[node name="Borderless" type="CheckBox" parent="ColorRect/HBoxContainer/VBoxContainer2"] margin_top = 310.0 margin_right = 369.0 margin_bottom = 450.0 -focus_mode = 0 +focus_mode = 1 enabled_focus_mode = 0 text = "borders" [node name="VBoxContainer3" type="VBoxContainer" parent="ColorRect/HBoxContainer"] -margin_left = 819.0 -margin_right = 1145.0 +margin_left = 930.0 +margin_right = 1256.0 margin_bottom = 720.0 [node name="resetbutton" type="Button" parent="ColorRect/HBoxContainer/VBoxContainer3"] diff --git a/ui/StartMenu.gd b/ui/StartMenu.gd index dd4e5fc..de541e2 100644 --- a/ui/StartMenu.gd +++ b/ui/StartMenu.gd @@ -2,30 +2,14 @@ extends Control const world = preload("res://Board.tscn") -export(float) var timer_length := 0.0 - -export(Array, Color) var nice_colors - -onready var settings := $ColorRect/Settings -onready var colorrect := $ColorRect -onready var tween := $Tween -onready var timer := $Timer -onready var lobby := $ColorRect/Lobby +onready var settings := $Darken/Settings func _ready() -> void: - randomize() - colorrect.color = nice_colors[randi() % nice_colors.size()] - timer.start(timer_length) - _on_Timer_timeout() if OS.has_feature("HTML5"): find_node("quit").queue_free() -func rand(clr) -> float: - return clamp(clr + rand_range(0, .1) if randi() % 2 else clr - rand_range(0, .1), 0, 1) - - func _on_local_pressed() -> void: get_tree().change_scene_to(world) @@ -38,15 +22,5 @@ func _on_settings_pressed() -> void: settings.toggle(true) -func _on_Timer_timeout() -> void: - var clr = nice_colors[randi() % nice_colors.size()] - clr.r = rand(clr.r) - clr.b = rand(clr.b) - clr.g = rand(clr.g) - tween.interpolate_property(colorrect, "color", colorrect.color, clr, timer_length, Tween.TRANS_ELASTIC) - tween.start() - timer.start(timer_length) - - func _on_multiplayer_pressed() -> void: - lobby.toggle(true) + get_tree().change_scene("res://ui/Lobby.tscn") diff --git a/ui/StartMenu.tscn b/ui/StartMenu.tscn index e42a053..63b7595 100644 --- a/ui/StartMenu.tscn +++ b/ui/StartMenu.tscn @@ -1,34 +1,32 @@ -[gd_scene load_steps=5 format=2] +[gd_scene load_steps=4 format=2] [ext_resource path="res://ui/theme/main.tres" type="Theme" id=1] [ext_resource path="res://ui/StartMenu.gd" type="Script" id=2] [ext_resource path="res://ui/Settings.tscn" type="PackedScene" id=3] -[ext_resource path="res://ui/Lobby.tscn" type="PackedScene" id=4] -[node name="StartMenu" type="Control" groups=["control"]] +[node name="StartMenu" type="Control"] anchor_right = 1.0 anchor_bottom = 1.0 mouse_filter = 2 theme = ExtResource( 1 ) script = ExtResource( 2 ) -timer_length = 2.8 -nice_colors = [ Color( 0.784314, 0.427451, 0.427451, 1 ), Color( 0.913725, 0.847059, 0.403922, 1 ), Color( 0.380392, 0.741176, 0.647059, 1 ), Color( 0.321569, 0.368627, 0.858824, 1 ), Color( 0.843137, 0.133333, 0.133333, 1 ), Color( 0.109804, 0.160784, 0.564706, 1 ), Color( 0.376471, 0.796078, 0.317647, 1 ), Color( 0.8, 0.364706, 0.588235, 1 ), Color( 0.984314, 0.858824, 0.282353, 1 ), Color( 0.164706, 0.0862745, 0.247059, 1 ) ] -[node name="ColorRect" type="ColorRect" parent="." groups=["control"]] +[node name="Darken" type="ColorRect" parent="."] anchor_right = 1.0 anchor_bottom = 1.0 mouse_filter = 2 -color = Color( 0, 0, 0, 1 ) +color = Color( 0, 0, 0, 0.392157 ) -[node name="MainButtons" type="VBoxContainer" parent="ColorRect" groups=["control"]] +[node name="MainButtons" type="VBoxContainer" parent="Darken"] anchor_left = 0.5 anchor_right = 0.5 anchor_bottom = 1.0 margin_left = -157.5 margin_right = 157.5 +mouse_filter = 2 alignment = 1 -[node name="multiplayer" type="Button" parent="ColorRect/MainButtons" groups=["control"]] +[node name="multiplayer" type="Button" parent="Darken/MainButtons"] margin_top = 226.0 margin_right = 315.0 margin_bottom = 332.0 @@ -37,7 +35,7 @@ size_flags_horizontal = 4 enabled_focus_mode = 0 text = "multiplayer" -[node name="settings" type="Button" parent="ColorRect/MainButtons" groups=["control"]] +[node name="settings" type="Button" parent="Darken/MainButtons"] margin_left = 38.0 margin_top = 347.0 margin_right = 276.0 @@ -47,7 +45,7 @@ size_flags_horizontal = 4 enabled_focus_mode = 0 text = "settings" -[node name="local" type="Button" parent="ColorRect/MainButtons" groups=["control"]] +[node name="local" type="Button" parent="Darken/MainButtons"] visible = false margin_left = 113.0 margin_top = 242.0 @@ -59,7 +57,7 @@ size_flags_horizontal = 4 enabled_focus_mode = 0 text = "local" -[node name="quit" type="Button" parent="ColorRect/MainButtons" groups=["control"]] +[node name="quit" type="Button" parent="Darken/MainButtons"] margin_left = 86.0 margin_top = 468.0 margin_right = 228.0 @@ -69,19 +67,10 @@ size_flags_horizontal = 4 enabled_focus_mode = 0 text = "exit" -[node name="Settings" parent="ColorRect" instance=ExtResource( 3 )] -visible = false - -[node name="Lobby" parent="ColorRect" groups=["control"] instance=ExtResource( 4 )] +[node name="Settings" parent="Darken" instance=ExtResource( 3 )] visible = false -[node name="Tween" type="Tween" parent="."] - -[node name="Timer" type="Timer" parent="."] -one_shot = true - -[connection signal="pressed" from="ColorRect/MainButtons/multiplayer" to="." method="_on_multiplayer_pressed"] -[connection signal="pressed" from="ColorRect/MainButtons/settings" to="." method="_on_settings_pressed"] -[connection signal="pressed" from="ColorRect/MainButtons/local" to="." method="_on_local_pressed"] -[connection signal="pressed" from="ColorRect/MainButtons/quit" to="." method="_on_quit_pressed"] -[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"] +[connection signal="pressed" from="Darken/MainButtons/multiplayer" to="." method="_on_multiplayer_pressed"] +[connection signal="pressed" from="Darken/MainButtons/settings" to="." method="_on_settings_pressed"] +[connection signal="pressed" from="Darken/MainButtons/local" to="." method="_on_local_pressed"] +[connection signal="pressed" from="Darken/MainButtons/quit" to="." method="_on_quit_pressed"] diff --git a/ui/background/ColorfullBackground.gd b/ui/background/ColorfullBackground.gd new file mode 100644 index 0000000..e4cfcfe --- /dev/null +++ b/ui/background/ColorfullBackground.gd @@ -0,0 +1,39 @@ +extends ColorRect + +export(Array, Color) var colors = [ + Color(0.784314, 0.427451, 0.427451, 1), + Color(0.913725, 0.847059, 0.403922, 1), + Color(0.380392, 0.741176, 0.647059, 1), + Color(0.321569, 0.368627, 0.858824, 1), + Color(0.843137, 0.133333, 0.133333, 1), + Color(0.109804, 0.160784, 0.564706, 1), + Color(0.376471, 0.796078, 0.317647, 1), + Color(0.8, 0.364706, 0.588235, 1), + Color(0.984314, 0.858824, 0.282353, 1), + Color(0.164706, 0.0862745, 0.247059, 1) +] +export(float) var length = 2.8 + +var tween = Tween.new() +var timer = Timer.new() + + +static func rand(clr) -> float: + return clamp(clr + rand_range(0, .1) if randi() % 2 else clr - rand_range(0, .1), 0, 1) + + +func _ready(): + randomize() + add_child(timer) + add_child(tween) + timer.connect("timeout", self, "change_color") + color = colors[randi() % colors.size()] + change_color() + + +func change_color(): + var clr = colors[randi() % colors.size()] + clr = Color(rand(clr.r), rand(clr.g), rand(clr.b), 1) + tween.interpolate_property(self, "color", color, clr, length, Tween.TRANS_ELASTIC) + tween.start() + timer.start(length) diff --git a/ui/background/ColorfullBackground.tscn b/ui/background/ColorfullBackground.tscn new file mode 100644 index 0000000..d941557 --- /dev/null +++ b/ui/background/ColorfullBackground.tscn @@ -0,0 +1,11 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://ui/background/ColorfullBackground.gd" type="Script" id=1] + +[node name="ColorfullBackground" type="ColorRect"] +anchor_right = 1.0 +anchor_bottom = 1.0 +mouse_filter = 2 +color = Color( 0, 0, 0, 1 ) +script = ExtResource( 1 ) +colors = [ Color( 0.784314, 0.427451, 0.427451, 1 ), Color( 0.913725, 0.847059, 0.403922, 1 ), Color( 0.380392, 0.741176, 0.647059, 1 ), Color( 0.321569, 0.368627, 0.858824, 1 ), Color( 0.345098, 0.345098, 0.345098, 1 ), Color( 0.109804, 0.160784, 0.564706, 1 ), Color( 0.376471, 0.796078, 0.317647, 1 ), Color( 0.8, 0.364706, 0.588235, 1 ), Color( 0.984314, 0.858824, 0.282353, 1 ), Color( 0.164706, 0.0862745, 0.247059, 1 ) ] |