De-hardcode font material for command list gui to fix localization
This commit is contained in:
parent
99799a4a10
commit
3182e06c25
1 changed files with 18 additions and 18 deletions
|
@ -5,7 +5,6 @@ local MULTISTRING_INDICATOR_TEXT = "[...]"
|
|||
local DEFAULT_HUD_SCALE = 100
|
||||
|
||||
local FONT_TYPE = "arial"
|
||||
local FONT_MATERIAL = "content/ui/fonts/arial"
|
||||
local FONT_SIZE = 22
|
||||
|
||||
local MAX_COMMANDS_VISIBLE = 5
|
||||
|
@ -57,8 +56,7 @@ local function get_hud_scale()
|
|||
end
|
||||
|
||||
|
||||
local function get_text_size(text, font_type, font_size)
|
||||
local font_data = Managers.font:data_by_type(font_type)
|
||||
local function get_text_size(text, font_data, font_size)
|
||||
local font = font_data.path
|
||||
local additional_settings = {
|
||||
flags = font_data.render_flags or 0
|
||||
|
@ -81,11 +79,11 @@ local function get_text_width(text, font, font_size)
|
|||
end
|
||||
|
||||
|
||||
local function get_scaled_font_size_by_width(text, font_type, font_size, max_width)
|
||||
local function get_scaled_font_size_by_width(text, font_data, font_size, max_width)
|
||||
local scale = RESOLUTION_LOOKUP.scale
|
||||
local min_font_size = 1
|
||||
local scaled_font_size = math.max(font_size * scale, 1)
|
||||
local text_width = get_text_size(text, font_type, scaled_font_size)
|
||||
local text_width = get_text_size(text, font_data, scaled_font_size)
|
||||
|
||||
if max_width < text_width then
|
||||
repeat
|
||||
|
@ -95,7 +93,7 @@ local function get_scaled_font_size_by_width(text, font_type, font_size, max_wid
|
|||
|
||||
font_size = math.max(font_size - 1, min_font_size)
|
||||
scaled_font_size = math.max(font_size * scale, 1)
|
||||
text_width = math.floor(get_text_size(text, font_type, scaled_font_size))
|
||||
text_width = math.floor(get_text_size(text, font_data, scaled_font_size))
|
||||
until text_width <= max_width
|
||||
end
|
||||
|
||||
|
@ -115,6 +113,8 @@ end
|
|||
|
||||
|
||||
local function draw(commands_list, selected_command_index)
|
||||
local font_data = Managers.font:data_by_type(FONT_TYPE)
|
||||
local font = font_data.path
|
||||
|
||||
create_gui()
|
||||
if not _gui then
|
||||
|
@ -152,30 +152,30 @@ local function draw(commands_list, selected_command_index)
|
|||
local font_size = FONT_SIZE
|
||||
|
||||
for i, command in ipairs(displayed_commands) do
|
||||
font_size = get_scaled_font_size_by_width(command.name, FONT_TYPE, FONT_SIZE, BASE_COMMAND_TEXT_WIDTH)
|
||||
font_size = get_scaled_font_size_by_width(command.name, font_data, FONT_SIZE, BASE_COMMAND_TEXT_WIDTH)
|
||||
|
||||
-- draw "/command_name" text
|
||||
local scaled_offet_x = (OFFSET_X + STRING_X_MARGIN) * scale
|
||||
local scaled_offset_y = (OFFSET_Y - STRING_HEIGHT * (i + selected_strings_number - 1) + STRING_Y_OFFSET) * scale
|
||||
|
||||
local string_position = Vector3(scaled_offet_x, scaled_offset_y, OFFSET_Z + 2)
|
||||
Gui.slug_text(_gui, command.name, FONT_MATERIAL, font_size, string_position, nil, Color(255, 100, 255, 100))
|
||||
Gui.slug_text(_gui, command.name, font, font_size, string_position, nil, Color(255, 100, 255, 100))
|
||||
|
||||
local command_text_strings = word_wrap(command.full_text, FONT_MATERIAL, font_size, BASE_COMMAND_TEXT_WIDTH)
|
||||
local command_text_strings = word_wrap(command.full_text, font, font_size, BASE_COMMAND_TEXT_WIDTH)
|
||||
local multistring = #command_text_strings > 1
|
||||
local first_description_string
|
||||
if multistring then
|
||||
if command.selected then
|
||||
selected_strings_number = #command_text_strings
|
||||
else
|
||||
local multistring_indicator_width = get_text_width(MULTISTRING_INDICATOR_TEXT, FONT_MATERIAL, font_size)
|
||||
local multistring_indicator_width = get_text_width(MULTISTRING_INDICATOR_TEXT, font, font_size)
|
||||
local command_text_width = BASE_COMMAND_TEXT_WIDTH - (multistring_indicator_width / scale)
|
||||
command_text_strings = word_wrap(command.full_text, FONT_MATERIAL, font_size, command_text_width)
|
||||
command_text_strings = word_wrap(command.full_text, font, font_size, command_text_width)
|
||||
|
||||
-- draw that [...] thing
|
||||
local multistring_offset_x = (OFFSET_X + WIDTH) * scale - multistring_indicator_width
|
||||
local multistring_indicator_position = Vector3(multistring_offset_x, string_position.y, string_position.z)
|
||||
Gui.slug_text(_gui, MULTISTRING_INDICATOR_TEXT, FONT_MATERIAL, font_size,
|
||||
Gui.slug_text(_gui, MULTISTRING_INDICATOR_TEXT, font, font_size,
|
||||
multistring_indicator_position, nil, Color(255, 100, 100, 100))
|
||||
end
|
||||
first_description_string = string.sub(command_text_strings[1], #command.name + 2)
|
||||
|
@ -184,18 +184,18 @@ local function draw(commands_list, selected_command_index)
|
|||
end
|
||||
|
||||
-- draw command description text (1st string)
|
||||
local first_description_string_width = get_text_width(command.name, FONT_MATERIAL, font_size)
|
||||
local first_description_string_width = get_text_width(command.name, font, font_size)
|
||||
|
||||
local first_description_pos_x = string_position.x + first_description_string_width
|
||||
local first_description_string_position = Vector3(first_description_pos_x, string_position.y, string_position.z)
|
||||
Gui.slug_text(_gui, first_description_string, FONT_MATERIAL, font_size,
|
||||
Gui.slug_text(_gui, first_description_string, font, font_size,
|
||||
first_description_string_position, nil, Color(255, 255, 255, 255))
|
||||
|
||||
-- draw command description text (2+ strings)
|
||||
if command.selected and multistring then
|
||||
for j = 2, selected_strings_number do
|
||||
string_position.y = string_position.y - STRING_HEIGHT * scale
|
||||
Gui.slug_text(_gui, command_text_strings[j], FONT_MATERIAL, font_size,
|
||||
Gui.slug_text(_gui, command_text_strings[j], font, font_size,
|
||||
string_position, nil, Color(255, 255, 255, 255))
|
||||
end
|
||||
end
|
||||
|
@ -227,11 +227,11 @@ local function draw(commands_list, selected_command_index)
|
|||
if selected_command_index > 0 then
|
||||
total_number_indicator = selected_command_index .. "/" .. total_number_indicator
|
||||
end
|
||||
local total_number_indicator_width = get_text_width(total_number_indicator, FONT_MATERIAL, font_size)
|
||||
local total_number_indicator_width = get_text_width(total_number_indicator, font, font_size)
|
||||
local total_number_indicator_x = (WIDTH) * scale - total_number_indicator_width
|
||||
local total_number_indicator_y = (OFFSET_Y + STRING_Y_OFFSET) * scale
|
||||
local total_number_indicator_position = Vector3(total_number_indicator_x, total_number_indicator_y, OFFSET_Z + 2)
|
||||
Gui.slug_text(_gui, total_number_indicator, FONT_MATERIAL, font_size,
|
||||
Gui.slug_text(_gui, total_number_indicator, font, font_size,
|
||||
total_number_indicator_position, nil, Color(255, 100, 100, 100))
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue