online multiplayer chess game (note server currently down)
draggable
bendn 2022-05-18
parent 396c549 · commit 14b097f
-rw-r--r--pieces/Piece.gd11
-rw-r--r--ui/BarTextureButton.gd7
-rw-r--r--ui/colorpicker/ColorPicker.gd6
-rw-r--r--ui/colorpicker/ColorPicker.tscn5
-rw-r--r--ui/colorpicker/ColorSelect.gd23
-rw-r--r--ui/colorpicker/HexInput.gd1
-rw-r--r--ui/colorpicker/HueSlider.gd22
-rw-r--r--ui/flipbutton.gd3
8 files changed, 62 insertions, 16 deletions
diff --git a/pieces/Piece.gd b/pieces/Piece.gd
index 788df48..e55c0ff 100644
--- a/pieces/Piece.gd
+++ b/pieces/Piece.gd
@@ -79,7 +79,16 @@ func moveto(position, real := true, take := false, override_moveto = false) -> v
Utils.add_move(algebraic_take_notation(position))
real_position = position
move(real_position)
- print("%s moving from %s to %s" % [mininame + shortname + " white" if white else " black", Utils.to_algebraic(global_position / Globals.grid.piece_size), Utils.to_algebraic(real_position)])
+ print(
+ (
+ "%s moving from %s to %s"
+ % [
+ mininame + shortname + " white" if white else " black",
+ Utils.to_algebraic(global_position / Globals.grid.piece_size),
+ Utils.to_algebraic(real_position)
+ ]
+ )
+ )
SoundFx.play("Move")
has_moved = true
diff --git a/ui/BarTextureButton.gd b/ui/BarTextureButton.gd
index cd3776a..4b21324 100644
--- a/ui/BarTextureButton.gd
+++ b/ui/BarTextureButton.gd
@@ -1,7 +1,7 @@
extends Control
class_name BarTextureButton
-signal pressed()
+signal pressed
var focused = false
@@ -14,15 +14,18 @@ export(Color) var pressed_color
onready var texture_button = $Texture
onready var background = $Background
+
func _ready():
texture_button.texture_normal = texture
texture_button.texture_focused = texture
texture_button.texture_pressed = texture
texture_button.texture_hover = texture
+
func _on_Texture_pressed():
emit_signal("pressed")
+
func _process(_delta):
if texture_button.pressed:
background.color = pressed_color
@@ -31,6 +34,7 @@ func _process(_delta):
else:
background.color = normal_color
+
func _on_Texture_mouse_entered():
focused = true
background.color = highlight_color
@@ -39,4 +43,3 @@ func _on_Texture_mouse_entered():
func _on_Texture_mouse_exited():
focused = false
background.color = normal_color
-
diff --git a/ui/colorpicker/ColorPicker.gd b/ui/colorpicker/ColorPicker.gd
index a9c352d..0eb4834 100644
--- a/ui/colorpicker/ColorPicker.gd
+++ b/ui/colorpicker/ColorPicker.gd
@@ -12,14 +12,17 @@ onready var hex = $Panel/V/hex
onready var colorselect = $Panel/V/H/ColorSelect
onready var hueslider = $Panel/V/H/HueSlider
+
func open():
oldcolorview.color = color
update_color()
show()
+
func _ready():
if has_node("/root/ColorPicker"):
- open() # for testing
+ open() # for testing
+
func update_color():
newcolorpreview.color = color
@@ -27,6 +30,7 @@ func update_color():
colorselect.color = color
hueslider.hue = color.h
+
func set_color(newcolor):
color = newcolor
update_color()
diff --git a/ui/colorpicker/ColorPicker.tscn b/ui/colorpicker/ColorPicker.tscn
index 30bcd17..de00d1c 100644
--- a/ui/colorpicker/ColorPicker.tscn
+++ b/ui/colorpicker/ColorPicker.tscn
@@ -59,6 +59,7 @@ margin_left = 25.0
margin_right = 125.0
margin_bottom = 100.0
rect_min_size = Vector2( 100, 100 )
+hint_tooltip = "click it!"
size_flags_horizontal = 0
size_flags_vertical = 0
script = ExtResource( 7 )
@@ -128,7 +129,11 @@ margin_bottom = 244.0
[connection signal="gui_input" from="Panel/V/H/HueSlider" to="Panel/V/H/HueSlider" method="_gui_input"]
[connection signal="hue_changed" from="Panel/V/H/HueSlider" to="Panel/V/H/ColorSelect" method="apply_hue"]
+[connection signal="mouse_entered" from="Panel/V/H/HueSlider" to="Panel/V/H/HueSlider" method="set_focused" binds= [ true ]]
+[connection signal="mouse_exited" from="Panel/V/H/HueSlider" to="Panel/V/H/HueSlider" method="set_focused" binds= [ false ]]
[connection signal="color_changed" from="Panel/V/H/ColorSelect" to="." method="_color_changed"]
+[connection signal="mouse_entered" from="Panel/V/H/ColorSelect" to="Panel/V/H/ColorSelect" method="set_focused" binds= [ true ]]
+[connection signal="mouse_exited" from="Panel/V/H/ColorSelect" to="Panel/V/H/ColorSelect" method="set_focused" binds= [ false ]]
[connection signal="color_changed" from="Panel/V/H2/OldColorView" to="." method="_color_changed"]
[connection signal="gui_input" from="Panel/V/H2/OldColorView" to="Panel/V/H2/OldColorView" method="_gui_input"]
[connection signal="color_changed" from="Panel/V/hex" to="." method="_color_changed"]
diff --git a/ui/colorpicker/ColorSelect.gd b/ui/colorpicker/ColorSelect.gd
index 1102709..211e9f9 100644
--- a/ui/colorpicker/ColorSelect.gd
+++ b/ui/colorpicker/ColorSelect.gd
@@ -1,30 +1,39 @@
extends Control
class_name ColorSelect
-var color : Color setget set_color
+var color: Color setget set_color
+
+var _focused := false setget set_focused
onready var shader_holder := $ShaderHolder
signal color_changed(color)
+
func set_color(newcolor):
- color = newcolor
- shader_holder.material.set_shader_param("hue", color.h)
- update()
+ if newcolor != color:
+ color = newcolor
+ shader_holder.material.set_shader_param("hue", color.h)
+ update()
+
func apply_hue(newhue):
self.color.h = newhue
func _gui_input(event):
- if event is InputEventMouseButton:
+ if _focused and Input.is_action_pressed("click") and event is InputEventMouse:
var position = event.position
var saturation = position.x / rect_size.x
var value = 1 - (position.y / rect_size.y)
+ if saturation > 1 or saturation < 0 or value > 1 or value < 0:
+ _focused = false
+ return
set_color(Color.from_hsv(color.h, saturation, value))
update()
emit_signal("color_changed", color)
+
func _draw():
var vlinex = color.s * rect_size.x
var vliney = rect_size.y
@@ -39,3 +48,7 @@ func _draw():
draw_line(Vector2(0, hliney - 1), Vector2(hlinex, hliney - 1), Color.black)
draw_line(Vector2(0, hliney), Vector2(hlinex, hliney), Color.white)
draw_line(Vector2(0, hliney + 1), Vector2(hlinex, hliney + 1), Color.black)
+
+
+func set_focused(focused):
+ _focused = focused
diff --git a/ui/colorpicker/HexInput.gd b/ui/colorpicker/HexInput.gd
index 6447923..975d342 100644
--- a/ui/colorpicker/HexInput.gd
+++ b/ui/colorpicker/HexInput.gd
@@ -5,6 +5,7 @@ var color: Color setget set_color
signal color_changed(color)
+
func set_color(newcolor):
color = newcolor
var pos = caret_position
diff --git a/ui/colorpicker/HueSlider.gd b/ui/colorpicker/HueSlider.gd
index 1bf4607..c67584b 100644
--- a/ui/colorpicker/HueSlider.gd
+++ b/ui/colorpicker/HueSlider.gd
@@ -5,21 +5,33 @@ onready var line_drawer = $"../../LineDrawer"
signal hue_changed(hue)
-var hue :float setget set_hue
+var hue: float setget set_hue
+var _focused setget set_focused
+
func _gui_input(event):
- if event is InputEventMouseButton:
+ if Input.is_action_pressed("click") and event is InputEventMouse:
var position = event.position
- set_hue(position.y / rect_size.y)
+ var tmphue = position.y / rect_size.y
+ if tmphue < 0 or tmphue > 1:
+ _focused = false
+ return
+ set_hue(tmphue)
emit_signal("hue_changed", hue)
+
func set_hue(newhue):
hue = newhue
update()
+
func _draw():
- var x = rect_size.x
+ var x = rect_size.x
var y = hue * rect_size.y
- draw_line(Vector2(0, y - 1), Vector2(x, y -1), Color.black, 1, true)
+ draw_line(Vector2(0, y - 1), Vector2(x, y - 1), Color.black, 1, true)
draw_line(Vector2(0, y), Vector2(x, y), Color.white, 1, true)
draw_line(Vector2(0, y + 1), Vector2(x, y + 1), Color.black, 1, true)
+
+
+func set_focused(focused):
+ _focused = focused
diff --git a/ui/flipbutton.gd b/ui/flipbutton.gd
index d995e81..ebfec40 100644
--- a/ui/flipbutton.gd
+++ b/ui/flipbutton.gd
@@ -1,6 +1,5 @@
extends BarTextureButton
-
func _pressed():
- Globals.grid.flip_board() \ No newline at end of file
+ Globals.grid.flip_board()