online multiplayer chess game (note server currently down)
moves list
| -rw-r--r-- | Grid.gd | 6 | ||||
| -rw-r--r-- | Utils.gd | 15 | ||||
| -rw-r--r-- | ui/GameUI.tscn | 28 | ||||
| -rw-r--r-- | ui/MovesList.gd | 19 | ||||
| -rw-r--r-- | ui/StartMenu.gd | 19 | ||||
| -rw-r--r-- | ui/StartMenu.tscn | 1 | ||||
| -rw-r--r-- | ui/Status.gd | 6 | ||||
| -rw-r--r-- | ui/main.tres | 11 |
8 files changed, 82 insertions, 23 deletions
@@ -111,13 +111,13 @@ func _on_turn_over(): if !can_move(): if Globals.in_check: var winner := "black" if Globals.turn else "white" - status_label.text = "%s won the game by checkmate" % winner + status_label.text("%s won the game by checkmate" % winner) win(winner) else: - status_label.text = "stalemate" + status_label.text("stalemate") drawed() elif threefoldrepetition(): - status_label.text = "draw by threefold repetition" + status_label.text("draw by threefold repetition") drawed() @@ -1,10 +1,12 @@ extends Node -var turn_moves := "1. " +var turn_moves: PoolStringArray = [] var turns_moves := [] var counter := 0 +signal newmove + func _ready(): Events.connect("turn_over", self, "_on_turn_over") @@ -14,9 +16,8 @@ func _on_turn_over(): counter += 1 if counter >= 2: counter = 0 - print(turn_moves) - turns_moves.append(turn_moves) - turn_moves = str(Globals.white_turns + 1) + ". " + turns_moves.append(turn_moves.join(" ")) + turn_moves.resize(0) func is_pawn(inode): @@ -24,7 +25,11 @@ func is_pawn(inode): func add_move(move): - turn_moves = turn_moves + " " + move + if turn_moves.size() == 0: + turn_moves.append(str(Globals.white_turns + 1) + ". " + move) + else: + turn_moves.append(move) + emit_signal("newmove", turn_moves[-1]) func calculate_algebraic_position(real_position): diff --git a/ui/GameUI.tscn b/ui/GameUI.tscn index 3f72619..51cf767 100644 --- a/ui/GameUI.tscn +++ b/ui/GameUI.tscn @@ -1,10 +1,12 @@ -[gd_scene load_steps=7 format=2] +[gd_scene load_steps=9 format=2] [ext_resource path="res://ui/main.tres" type="Theme" id=1] [ext_resource path="res://ui/roboto.tres" type="DynamicFont" id=2] [ext_resource path="res://assets/ui/Roboto-Medium.ttf" type="DynamicFontData" id=3] [ext_resource path="res://ui/TimerLabels.gd" type="Script" id=4] [ext_resource path="res://ui/Timer.gd" type="Script" id=5] +[ext_resource path="res://ui/MovesList.gd" type="Script" id=6] +[ext_resource path="res://ui/Status.gd" type="Script" id=7] [sub_resource type="DynamicFont" id=1] size = 25 @@ -40,9 +42,9 @@ __meta__ = { } [node name="BlackTime" type="Label" parent="Holder/Back/VBox"] -margin_top = 251.0 +margin_top = 167.0 margin_right = 400.0 -margin_bottom = 334.0 +margin_bottom = 250.0 custom_fonts/font = ExtResource( 2 ) text = "00:00.0" align = 1 @@ -62,17 +64,29 @@ margin_right = -72.0 color = Color( 0, 0, 0, 1 ) [node name="Status" type="Label" parent="Holder/Back/VBox"] -margin_top = 384.0 +visible = false +margin_top = 355.0 margin_right = 400.0 -margin_bottom = 415.0 +margin_bottom = 386.0 custom_fonts/font = SubResource( 1 ) align = 1 autowrap = true +script = ExtResource( 7 ) + +[node name="MovesList" type="ItemList" parent="Holder/Back/VBox"] +margin_top = 300.0 +margin_right = 400.0 +margin_bottom = 500.0 +rect_min_size = Vector2( 0, 200 ) +focus_mode = 0 +custom_constants/hseparation = 25 +max_columns = 2 +script = ExtResource( 6 ) [node name="WhiteTime" type="Label" parent="Holder/Back/VBox"] -margin_top = 465.0 +margin_top = 550.0 margin_right = 400.0 -margin_bottom = 548.0 +margin_bottom = 633.0 custom_fonts/font = ExtResource( 2 ) text = "00:00.0" align = 1 diff --git a/ui/MovesList.gd b/ui/MovesList.gd new file mode 100644 index 0000000..1e47843 --- /dev/null +++ b/ui/MovesList.gd @@ -0,0 +1,19 @@ +extends ItemList + +onready var scrollbar = get_v_scroll() +var tween: Tween + + +func _ready(): + tween = Tween.new() + add_child(tween) + Utils.connect("newmove", self, "on_new_move") + + +func on_new_move(move): + add_item(move) + tween.interpolate_property( # scrolldown + scrollbar, "value", scrollbar.value, scrollbar.max_value, 0.5, Tween.TRANS_BOUNCE, Tween.EASE_IN_OUT + ) + tween.start() + scrollbar.value = scrollbar.max_value diff --git a/ui/StartMenu.gd b/ui/StartMenu.gd index 9081788..299ae72 100644 --- a/ui/StartMenu.gd +++ b/ui/StartMenu.gd @@ -4,6 +4,8 @@ const world = preload("res://World.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 @@ -16,6 +18,7 @@ func _on_local_pressed(): func _ready(): randomize() + colorrect.color = nice_colors[randi() % nice_colors.size()] timer.start(timer_length) _on_Timer_timeout() @@ -29,14 +32,16 @@ func _on_settings_pressed(): func _on_Timer_timeout(): + 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, - Color(rand_range(0, 1), rand_range(0, 1), rand_range(0, 1)), - timer_length, - Tween.TRANS_ELASTIC, - Tween.EASE_IN_OUT + colorrect, "color", colorrect.color, clr, timer_length, Tween.TRANS_ELASTIC, Tween.EASE_IN_OUT ) tween.start() timer.start(timer_length) + + +func rand(clr): + return rand_range(0, 1 - clr) diff --git a/ui/StartMenu.tscn b/ui/StartMenu.tscn index 61fca7f..5a970d2 100644 --- a/ui/StartMenu.tscn +++ b/ui/StartMenu.tscn @@ -10,6 +10,7 @@ anchor_bottom = 1.0 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.972549, 0.85098, 0.294118, 1 ), Color( 0.164706, 0.0862745, 0.247059, 1 ) ] [node name="ColorRect" type="ColorRect" parent="."] anchor_right = 1.0 diff --git a/ui/Status.gd b/ui/Status.gd new file mode 100644 index 0000000..aa49be3 --- /dev/null +++ b/ui/Status.gd @@ -0,0 +1,6 @@ +extends Label + + +func text(newtext): + show() + text = newtext diff --git a/ui/main.tres b/ui/main.tres index 77741de..e798c9d 100644 --- a/ui/main.tres +++ b/ui/main.tres @@ -1,4 +1,4 @@ -[gd_resource type="Theme" load_steps=10 format=2] +[gd_resource type="Theme" load_steps=12 format=2] [ext_resource path="res://ui/verdana.tres" type="DynamicFont" id=1] [ext_resource path="res://ui/button.tres" type="StyleBox" id=2] @@ -10,9 +10,13 @@ [sub_resource type="StyleBoxEmpty" id=2] +[sub_resource type="StyleBoxEmpty" id=4] + [sub_resource type="StyleBoxFlat" id=3] bg_color = Color( 0.0784314, 0.0784314, 0.0784314, 1 ) +[sub_resource type="StyleBoxEmpty" id=5] + [resource] default_font = ExtResource( 1 ) Button/colors/font_color = Color( 1, 1, 1, 1 ) @@ -33,6 +37,10 @@ CheckBox/icons/radio_unchecked_disabled = null CheckBox/icons/unchecked = ExtResource( 4 ) CheckBox/icons/unchecked_disabled = null HBoxContainer/constants/separation = 15 +ItemList/colors/font_color = Color( 1, 1, 1, 1 ) +ItemList/colors/font_color_selected = Color( 0.905882, 0.905882, 0.905882, 1 ) +ItemList/styles/bg = SubResource( 4 ) +ItemList/styles/bg_focus = ExtResource( 7 ) OptionButton/colors/font_color = Color( 1, 1, 1, 1 ) OptionButton/colors/font_color_focus = Color( 1, 1, 1, 1 ) OptionButton/colors/font_color_hover = Color( 0, 0, 0, 1 ) @@ -47,3 +55,4 @@ PopupMenu/icons/radio_unchecked = ExtResource( 3 ) PopupMenu/styles/hover = SubResource( 3 ) PopupMenu/styles/panel = ExtResource( 7 ) VBoxContainer/constants/separation = 15 +VScrollBar/styles/scroll = SubResource( 5 ) |