online multiplayer chess game (note server currently down)
yay tile labels
| -rw-r--r-- | Grid.gd | 30 | ||||
| -rw-r--r-- | Square.tscn | 4 | ||||
| -rw-r--r-- | World.tscn | 4 | ||||
| -rw-r--r-- | ui/BottomLeftLabel.tscn | 18 | ||||
| -rw-r--r-- | ui/TopRightLabel.tscn | 19 | ||||
| -rw-r--r-- | ui/UI.tscn (renamed from UI.tscn) | 0 | ||||
| -rw-r--r-- | ui/verdana-bold.ttf | 3 | ||||
| -rw-r--r-- | ui/verdana.tres | 6 |
8 files changed, 81 insertions, 3 deletions
@@ -9,6 +9,8 @@ export(Color) var overlay_color = Color(0.2, 0.345098, 0.188235, 0.592157) const Piece = preload("res://Piece.tscn") const Square = preload("res://Square.tscn") +const BottomLeftLabel = preload("res://ui/BottomLeftLabel.tscn") +const TopRightLabel = preload("res://ui/TopRightLabel.tscn") const piece_size = Vector2(100, 100) const default_metadata = { @@ -30,15 +32,41 @@ var last_clicked onready var background = $Background onready var ASSETS_PATH = "res://assets/" + PIECE_SET + "/" onready var piece_sets = walk_dir() +onready var foreground = $Foreground +onready var pieces = $Pieces func _ready(): Globals.grid = self # tell the globals that this is the grid init_board() # create the tile squares init_matrix() # create the pieces + init_labels() Events.connect("turn_over", self, "_on_turn_over") # listen for turn_over events +func init_labels(): + for i in range(8): + var letterslabel = BottomLeftLabel.instance() + letterslabel.rect_position.x = i * piece_size.x + letterslabel.rect_position.y = piece_size.y * 7 + size_label(letterslabel, i) + letterslabel.get_node("Label").text = Utils.calculate_algebraic_position( + letterslabel.rect_position / piece_size + )[0] + foreground.add_child(letterslabel) + var numberslabel = TopRightLabel.instance() + numberslabel.rect_position.y = i * piece_size.x + numberslabel.rect_position.x = piece_size.x * 7 + size_label(numberslabel, i) + numberslabel.get_node("Label").text = str(8 - i) + foreground.add_child(numberslabel) + + +func size_label(label, i): + label.rect_size = piece_size + label.get_node("Label").add_color_override("font_color", board_color1 if i % 2 == 0 else board_color2) + + func threefoldrepetition(): for i in history_matrixes.values(): if i >= 3: @@ -150,7 +178,7 @@ func make_piece(position: Vector2, script: String, sprite: String, white: bool = piece.real_position = position # set the real position piece.global_position = position * piece_size # set the global position piece.white = white # set its team - add_child(piece) # add the piece to the grid + pieces.add_child(piece) # add the piece to the grid return piece # return the piece diff --git a/Square.tscn b/Square.tscn index 6018f08..a70cec1 100644 --- a/Square.tscn +++ b/Square.tscn @@ -9,8 +9,8 @@ extents = Vector2( 381, 394.5 ) [node name="Square" type="ColorRect"] anchor_right = 1.0 anchor_bottom = 1.0 -margin_right = -800.0 -margin_bottom = -800.0 +margin_right = -780.0 +margin_bottom = -780.0 mouse_filter = 2 script = ExtResource( 1 ) @@ -8,3 +8,7 @@ script = ExtResource( 1 ) [node name="Background" type="Node2D" parent="Grid"] + +[node name="Pieces" type="Node2D" parent="Grid"] + +[node name="Foreground" type="CanvasLayer" parent="Grid"] diff --git a/ui/BottomLeftLabel.tscn b/ui/BottomLeftLabel.tscn new file mode 100644 index 0000000..27bd9a7 --- /dev/null +++ b/ui/BottomLeftLabel.tscn @@ -0,0 +1,18 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://ui/verdana.tres" type="DynamicFont" id=1] + +[node name="LabelsBottomLeft" type="Control"] +margin_right = 40.0 +margin_bottom = 40.0 + +[node name="Label" type="Label" parent="."] +anchor_top = 1.0 +anchor_bottom = 1.0 +margin_left = 8.0 +margin_top = -32.0 +margin_right = 40.0 +margin_bottom = -8.0 +custom_fonts/font = ExtResource( 1 ) +text = "b3" +valign = 1 diff --git a/ui/TopRightLabel.tscn b/ui/TopRightLabel.tscn new file mode 100644 index 0000000..8f3918f --- /dev/null +++ b/ui/TopRightLabel.tscn @@ -0,0 +1,19 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://ui/verdana.tres" type="DynamicFont" id=1] + +[node name="LabelsTopRight" type="Control"] +margin_right = 40.0 +margin_bottom = 40.0 + +[node name="Label" type="Label" parent="."] +anchor_left = 1.0 +anchor_right = 1.0 +margin_left = -40.0 +margin_top = 8.0 +margin_right = -8.0 +margin_bottom = 32.0 +custom_fonts/font = ExtResource( 1 ) +text = "b3" +align = 2 +valign = 1 diff --git a/ui/verdana-bold.ttf b/ui/verdana-bold.ttf new file mode 100644 index 0000000..2c94112 --- /dev/null +++ b/ui/verdana-bold.ttf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:174568c4633a8a688d579d283f7508c16e437434fd5ac97d4ce30dfc42d0860b +size 208456 diff --git a/ui/verdana.tres b/ui/verdana.tres new file mode 100644 index 0000000..f51027c --- /dev/null +++ b/ui/verdana.tres @@ -0,0 +1,6 @@ +[gd_resource type="DynamicFont" load_steps=2 format=2] + +[ext_resource path="res://ui/verdana-bold.ttf" type="DynamicFontData" id=1] + +[resource] +font_data = ExtResource( 1 ) |