Make text work better on smaller map zoom

This commit is contained in:
Hamcha 2020-07-27 11:27:19 +02:00
parent 745438e419
commit 9383bc9803
Signed by: hamcha
GPG Key ID: 41467804B19A3315
2 changed files with 34 additions and 8 deletions

View File

@ -3,15 +3,24 @@ class_name Coordinates
static func as_string(coord: Vector2, include_subcoord: bool = false) -> String: static func as_string(coord: Vector2, include_subcoord: bool = false) -> String:
var x = floor(coord.x) var x = floor(coord.x)
var y = floor(coord.y) var y = floor(coord.y)
var sector_name = to_letter(int(x)) var main = as_string_parts(coord)
if y < 0: var sector_name = main[0] + main[1]
sector_name += to_letter(int(y))
else:
sector_name += str(int(y))
if include_subcoord: if include_subcoord:
sector_name += ".%02d/%02d" % [(coord.x - x) * 100, (coord.y - y) * 100] sector_name += ".%02d/%02d" % [(coord.x - x) * 100, (coord.y - y) * 100]
return sector_name return sector_name
static func as_string_parts(coord: Vector2) -> Array:
var x = floor(coord.x)
var y = floor(coord.y)
var x_str = to_letter(int(x))
var y_str = ""
if y < 0:
y_str = to_letter(int(y))
else:
y_str = str(int(y))
return [x_str, y_str]
static func to_letter(num: int) -> String: static func to_letter(num: int) -> String:
#var letters = "ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ" #var letters = "ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ"
var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

View File

@ -22,6 +22,7 @@ var last_mouse_pos = Vector2.ZERO
var set_position = true var set_position = true
var radar_next_remaining = RADAR_EFFECT_DELAY var radar_next_remaining = RADAR_EFFECT_DELAY
var offset = Vector2.ZERO var offset = Vector2.ZERO
var text_two_lines = false
onready var scene = $"/root/scene" onready var scene = $"/root/scene"
onready var speed_text = $"../HBoxContainer/HBoxContainer/CurrentSpeed" onready var speed_text = $"../HBoxContainer/HBoxContainer/CurrentSpeed"
@ -29,6 +30,9 @@ onready var dir_text = $"../HBoxContainer/HBoxContainer/CurrentAngle"
var last_pos = [] var last_pos = []
func _ready():
font = font.duplicate()
func _physics_process(delta): func _physics_process(delta):
radar_next_remaining -= delta radar_next_remaining -= delta
if radar_next_remaining < 0: if radar_next_remaining < 0:
@ -64,8 +68,12 @@ func _draw():
for y in range(-1, rows+1): for y in range(-1, rows+1):
var real_x = x + int(origin.x/cell_size) var real_x = x + int(origin.x/cell_size)
var real_y = y + int(origin.y/cell_size) var real_y = y + int(origin.y/cell_size)
var sector_name = Coordinates.as_string(Vector2(real_x, real_y)) var sector = Coordinates.as_string_parts(Vector2(real_x, real_y))
draw_string(font, Vector2(x * cell_size + 6 - xoffset, y * cell_size + 20 - yoffset), sector_name, Color(1,1,1,0.5)) if text_two_lines:
draw_string(font, Vector2(x * cell_size + 6 - xoffset, y * cell_size + 20 - yoffset), sector[0], Color(1,1,1,0.5))
draw_string(font, Vector2(x * cell_size + 6 - xoffset, y * cell_size + 20 - yoffset + font.size + 2), sector[1], Color(1,1,1,0.5))
else:
draw_string(font, Vector2(x * cell_size + 6 - xoffset, y * cell_size + 20 - yoffset), sector[0] + sector[1], Color(1,1,1,0.5))
var viewport = Rect2(origin, win_size) var viewport = Rect2(origin, win_size)
@ -105,16 +113,17 @@ func _input(event):
if not visible: if not visible:
return return
if event.is_action_pressed("ui_zoomin"): if event.is_action_pressed("ui_zoomin"):
print(cell_size)
if cell_size < MAX_ZOOM: if cell_size < MAX_ZOOM:
_recalc_offset(ZOOM_STEP) _recalc_offset(ZOOM_STEP)
cell_size += ZOOM_STEP cell_size += ZOOM_STEP
update_font()
update() update()
return return
if event.is_action_pressed("ui_zoomout"): if event.is_action_pressed("ui_zoomout"):
if cell_size > MIN_ZOOM: if cell_size > MIN_ZOOM:
_recalc_offset(-ZOOM_STEP) _recalc_offset(-ZOOM_STEP)
cell_size -= ZOOM_STEP cell_size -= ZOOM_STEP
update_font()
update() update()
return return
if event is InputEventMouseButton: if event is InputEventMouseButton:
@ -129,6 +138,14 @@ func _input(event):
update() update()
return return
func update_font():
print(cell_size)
text_two_lines = cell_size < 70
if cell_size < 100:
font.size = 11
else:
font.size = 14
func _recalc_offset(mult: float): func _recalc_offset(mult: float):
var mouse = get_local_mouse_position() var mouse = get_local_mouse_position()
origin = ((origin + mouse) / cell_size * (cell_size + mult)) - mouse origin = ((origin + mouse) / cell_size * (cell_size + mult)) - mouse