Browse Source

Make text work better on smaller map zoom

master
Hamcha 8 months ago
parent
commit
9383bc9803
Signed by: Hamcha GPG Key ID: 41467804B19A3315
2 changed files with 34 additions and 8 deletions
  1. +14
    -5
      Classes/Coordinates.gd
  2. +20
    -3
      Scenes/UI/SpaceMapInside.gd

+ 14
- 5
Classes/Coordinates.gd View File

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


+ 20
- 3
Scenes/UI/SpaceMapInside.gd View File

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