online multiplayer chess game (note server currently down)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
extends Control
class_name ColorPickerBetter  # when you dont like the native color picker so you make your own

var color: Color

var _manual_change := false

signal color_changed(color)
signal done(color)

onready var hex = $Panel/hex
onready var rgb = $Panel/H/rgb.get_children()
onready var preview = $Panel/H/Preview


func _ready():
	update_hex_and_preview(false)


func update_r(value: float):
	if _manual_change:
		return
	color.r = value / 255
	update_hex_and_preview()


func update_b(value: float):
	if _manual_change:
		return
	color.b = value / 255
	update_hex_and_preview()


func update_g(value: float):
	if _manual_change:
		return
	color.g = value / 255
	update_hex_and_preview()


func update_hex_and_preview(to_signal := true):  # update the hex and preview
	_manual_change = true
	rgb[0].value = color.r * 255
	rgb[1].value = color.g * 255
	rgb[2].value = color.b * 255
	_manual_change = false
	var pos = hex.caret_position
	hex.text = "#" + color.to_html(false)
	hex.caret_position = pos  # make it in the right place
	preview.color = color
	if to_signal:
		emit_signal("color_changed", color)


func _on_hex_text_entered(new_text: String):
	color = Color(new_text)
	update_hex_and_preview()


func _on_OKButton_pressed():
	emit_signal("done", color)