First_Person_Slapper/Scenes/InfoScreen.gd
2022-10-12 13:59:09 -04:00

31 lines
1.0 KiB
GDScript

tool
extends Spatial
export(String, MULTILINE) var text = " " setget set_text_to_screen
export(Vector2) var offset = Vector2(1.0, 0.5) setget set_screen_offset
func set_screen_offset(new_offest):
offset = new_offest
set_text_to_screen(text)
func set_text_to_screen(new_text):
text = new_text
$ScreenText.text = text
var lines = text.split('\n',false)
var string_size: Vector2 = Vector2(0,0)
for line in lines:
if $ScreenText.font.get_string_size(line).x > string_size.x:
string_size = $ScreenText.font.get_string_size(line)
var pixel_size = $ScreenText.pixel_size
var number_of_line = text.split('\n',false).size()
$ScreenBackGround.scale = Vector3(string_size.x * pixel_size + offset.x,
string_size.y * pixel_size * number_of_line + offset.y,1);
$Glass.scale = Vector3(string_size.x * pixel_size + offset.x,
string_size.y * pixel_size * number_of_line + offset.y,0.025);
$ScreenContour.scale = Vector3(string_size.x * pixel_size + offset.x + 0.25,
string_size.y * pixel_size * number_of_line + offset.y + 0.25,0.025);