Files
Diabolo/DoOtboy/do-otboy/scripts/phone_device.gd
T

103 lines
5.0 KiB
GDScript
Raw Normal View History

extends Control
## Vector phone shells. Screens are ordinary controls, so notifications stay clickable.
var smartphone := true
var dialing := false
var pulse := 0.0
var display: Control
func build(smart: bool) -> void:
smartphone = smart
mouse_filter = Control.MOUSE_FILTER_IGNORE
custom_minimum_size = Vector2(274, 558) if smart else Vector2(232, 448)
size = custom_minimum_size
display = Control.new()
display.position = Vector2(12, 15) if smart else Vector2(24, 68)
display.size = Vector2(250, 528) if smart else Vector2(184, 155)
display.clip_contents = true
display.mouse_filter = Control.MOUSE_FILTER_IGNORE
add_child(display)
func rounded(rect: Rect2, color: Color, border: Color, radius: int, width: int = 1) -> void:
var box := StyleBoxFlat.new()
box.bg_color = color
box.border_color = border
box.set_border_width_all(width)
box.set_corner_radius_all(radius)
draw_style_box(box, rect)
func text_at(at: Vector2, text: String, font_size: int, color: Color) -> void:
var font := ThemeDB.fallback_font
var width := font.get_string_size(text, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size).x
draw_string(font, at - Vector2(width / 2, 0), text, HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, color)
func handset(center: Vector2, color: Color) -> void:
draw_polyline(PackedVector2Array([center+Vector2(-12,3), center+Vector2(-11,-2), center+Vector2(-5,-5), center+Vector2(5,-5), center+Vector2(11,-2), center+Vector2(12,3)]), color, 3, true)
draw_line(center+Vector2(-12,3), center+Vector2(-7,3), color, 3, true)
draw_line(center+Vector2(7,3), center+Vector2(12,3), color, 3, true)
func _draw() -> void:
if smartphone:
rounded(Rect2(5, 13, 274, 558), Color(0,0,0,0.28), Color.TRANSPARENT, 42)
rounded(Rect2(0, 0, 274, 558), Color("25232e"), Color("5b5666"), 40, 2)
rounded(Rect2(5, 5, 264, 548), Color("07080d"), Color("101117"), 36)
rounded(Rect2(12, 15, 250, 528), Color("171420"), Color.TRANSPARENT, 30)
rounded(Rect2(99, 17, 76, 18), Color("07080d"), Color.TRANSPARENT, 10)
draw_circle(Vector2(156,26), 3, Color("202733"))
rounded(Rect2(-3, 100, 3, 42), Color("4a4554"), Color.TRANSPARENT, 1)
rounded(Rect2(274, 140, 3, 54), Color("4a4554"), Color.TRANSPARENT, 1)
var center := Vector2(137, 196)
if dialing:
for i in range(3):
var progress := fmod(pulse * 0.55 + i / 3.0, 1.0)
draw_arc(center, 42 + progress * 38, 0, TAU, 70, Color(0.86,0.45,0.65,(1-progress)*0.18), 1.5, true)
draw_circle(center, 42, Color("393044"))
text_at(center + Vector2(0,12), "М", 34, Color("e5c8df"))
for i in range(3):
var point := Vector2(67 + i * 70, 413)
draw_circle(point, 21, Color("2a2633"))
if i == 0:
rounded(Rect2(point-Vector2(3,9), Vector2(6,14)), Color("a39aa9"), Color.TRANSPARENT, 3)
draw_arc(point-Vector2(0,2), 7, 0, PI, 20, Color("a39aa9"), 1.5, true)
draw_line(point+Vector2(0,5),point+Vector2(0,10),Color("a39aa9"),1.5,true)
elif i == 1:
for row in range(3):
for col in range(3): draw_circle(point + Vector2(col*5-5,row*5-5),1.1,Color("a39aa9"))
else:
draw_colored_polygon(PackedVector2Array([point+Vector2(-8,-3),point+Vector2(-3,-3),point+Vector2(2,-7),point+Vector2(2,7),point+Vector2(-3,3),point+Vector2(-8,3)]),Color("a39aa9"))
draw_arc(point+Vector2(1,0),9,-0.8,0.8,12,Color("a39aa9"),1.4,true)
draw_circle(Vector2(137,493),25,Color("a94760"))
handset(Vector2(137,493),Color("f9e7ef"))
rounded(Rect2(106, 530, 62, 4),Color("948894"),Color.TRANSPARENT,2)
else:
rounded(Rect2(5, 12, 232, 448),Color(0,0,0,0.3),Color.TRANSPARENT,34)
rounded(Rect2(0, 0, 232, 448),Color("3a3b3e"),Color("67686b"),32,2)
rounded(Rect2(7, 7, 218, 434),Color("27292c"),Color("1b1d21"),26)
for row in range(3):
for col in range(9): draw_circle(Vector2(91+col*6,27+row*4),1.2,Color("111317"))
text_at(Vector2(116,55),"mobile",10,Color("777a7c"))
rounded(Rect2(18,62,196,167),Color("101513"),Color("555b57"),6,2)
rounded(Rect2(24,68,184,155),Color("a3b58c"),Color("80916e"),2)
rounded(Rect2(76,241,80,56),Color("66696c"),Color("85888a"),14)
rounded(Rect2(85,249,62,40),Color("3e4246"),Color("272b2e"),10)
text_at(Vector2(116,274),"OK",13,Color("cbced0"))
for i in range(2):
var x := 22.0 if i == 0 else 166.0
rounded(Rect2(x,243,44,24),Color("44474b"),Color("1f2226"),7)
draw_line(Vector2(x+14,254),Vector2(x+30,254),Color("969c9e"),2,true)
rounded(Rect2(x,272,44,24),Color("363a3d"),Color("1e2025"),7)
handset(Vector2(x+22,284),Color("8ca887") if i==0 else Color("b47878"))
var legends := ["", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz", "", "+", ""]
for row in range(4):
for col in range(3):
var index := row*3+col
var rect := Rect2(22+col*64,307+row*30,58,26)
rounded(rect,Color("373a3e"),Color("191d20"),7)
var digit: String = str(index+1) if index<9 else ["*","0","#"][index-9]
text_at(rect.position+Vector2(17,18),digit,16,Color("d5d7d5"))
text_at(rect.position+Vector2(40,16),legends[index],7,Color("939997"))
func animate(delta: float, connecting: bool) -> void:
dialing = connecting
pulse += delta
if smartphone: queue_redraw()