[Commands GUI] Clean up + little style changes
This commit is contained in:
parent
09245cda24
commit
68855130db
1 changed files with 114 additions and 124 deletions
|
@ -1,40 +1,27 @@
|
|||
local vmf = get_mod("VMF") --@TODO: remove it?
|
||||
local vmf = get_mod("VMF")
|
||||
|
||||
local _gui
|
||||
local MULTISTRING_INDICATOR_TEXT = "[...]"
|
||||
|
||||
if VT1 then
|
||||
-- @TODO: I don't think I need the 2nd texture
|
||||
_gui = World.create_screen_gui(Managers.world:world("top_ingame_view"), "immediate",
|
||||
"material", "materials/fonts/gw_fonts",
|
||||
"material", "materials/ui/ui_1080p_ingame_common")
|
||||
else
|
||||
_gui = World.create_screen_gui(Managers.world:world("top_ingame_view"),
|
||||
"material", "materials/fonts/gw_fonts", "immediate")
|
||||
end
|
||||
local FONT_TYPE = "hell_shark_arial"
|
||||
local FONT_SIZE = 22
|
||||
|
||||
-- DebugScreen.gui = World.create_screen_gui(world, "material", "materials/fonts/gw_fonts",
|
||||
-- "material", "materials/menu/debug_screen", "immediate")
|
||||
local MAX_COMMANDS_VISIBLE = 5
|
||||
|
||||
local STRING_HEIGHT = 25
|
||||
local STRING_Y_OFFSET = 7
|
||||
local STRING_X_MARGIN = 10
|
||||
|
||||
local _FONT_TYPE = "hell_shark_arial"
|
||||
local _FONT_SIZE = 22
|
||||
local OFFSET_X = 0
|
||||
local OFFSET_Y = 200
|
||||
local OFFSET_Z = 880
|
||||
local WIDTH = 550
|
||||
|
||||
local _MULTISTRING_INDICATOR_TEXT = "[...]"
|
||||
local _gui = World.create_screen_gui(Managers.world:world("top_ingame_view"), "immediate",
|
||||
"material", "materials/fonts/gw_fonts")
|
||||
|
||||
local _MAX_COMMANDS_VISIBLE = 5
|
||||
|
||||
local _STRING_HEIGHT = 25
|
||||
local _STRING_Y_OFFSET = 7
|
||||
local _STRING_X_MARGIN = 10
|
||||
|
||||
local _OFFSET_X = 0
|
||||
local _OFFSET_Y = 200
|
||||
local _OFFSET_Z = 880
|
||||
local _WIDTH = 550
|
||||
|
||||
-- ####################################################################################################################
|
||||
-- ##### Local functions ##############################################################################################
|
||||
-- ####################################################################################################################
|
||||
-- #####################################################################################################################
|
||||
-- ##### Local functions ###############################################################################################
|
||||
-- #####################################################################################################################
|
||||
|
||||
local function get_text_width(text, font_material, font_size)
|
||||
local text_extent_min, text_extent_max = Gui.text_extents(_gui, text, font_material, font_size)
|
||||
|
@ -42,6 +29,7 @@ local function get_text_width(text, font_material, font_size)
|
|||
return text_height
|
||||
end
|
||||
|
||||
|
||||
local function word_wrap(text, font_material, font_size, max_width)
|
||||
local whitespace = " "
|
||||
local soft_dividers = "-+&/*"
|
||||
|
@ -53,18 +41,18 @@ local function word_wrap(text, font_material, font_size, max_width)
|
|||
soft_dividers, return_dividers, reuse_global_table)
|
||||
end
|
||||
|
||||
|
||||
local function draw(commands_list, selected_command_index)
|
||||
-- VT2 requires applying additional HUD scaling
|
||||
if not VT1 then
|
||||
UPDATE_RESOLUTION_LOOKUP(true, UISettings.hud_scale * 0.01)
|
||||
end
|
||||
|
||||
--vmf:pcall(function()
|
||||
local selected_command_new_index = 0
|
||||
|
||||
-- pick displayed commands
|
||||
local last_displayed_command = math.max(math.min(_MAX_COMMANDS_VISIBLE, #commands_list), selected_command_index)
|
||||
local first_displayed_command = math.max(1, last_displayed_command - (_MAX_COMMANDS_VISIBLE - 1))
|
||||
local last_displayed_command = math.max(math.min(MAX_COMMANDS_VISIBLE, #commands_list), selected_command_index)
|
||||
local first_displayed_command = math.max(1, last_displayed_command - (MAX_COMMANDS_VISIBLE - 1))
|
||||
local displayed_commands = {}
|
||||
for i = first_displayed_command, last_displayed_command do
|
||||
local new_entry = {}
|
||||
|
@ -82,35 +70,34 @@ local function draw(commands_list, selected_command_index)
|
|||
|
||||
local selected_strings_number = 1
|
||||
|
||||
local font, font_size = UIFontByResolution({font_type = _FONT_TYPE, font_size = _FONT_SIZE})
|
||||
local font, font_size = UIFontByResolution({font_type = FONT_TYPE, font_size = FONT_SIZE})
|
||||
local font_material = font[1]
|
||||
local font_name = font[3]
|
||||
|
||||
for i, command in ipairs(displayed_commands) do
|
||||
|
||||
-- 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 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)
|
||||
local string_position = Vector3(scaled_offet_x, scaled_offset_y, OFFSET_Z + 2)
|
||||
Gui.text(_gui, command.name, font_material, font_size, font_name, string_position, Color(255, 100, 255, 100))
|
||||
|
||||
local command_text_strings = word_wrap(command.full_text, font_material, font_size, _WIDTH - _STRING_X_MARGIN * 2)
|
||||
local command_text_strings = word_wrap(command.full_text, font_material, font_size, WIDTH - STRING_X_MARGIN * 2)
|
||||
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 command_text_width = _WIDTH - _STRING_X_MARGIN * 2 - (multistring_indicator_width / scale)
|
||||
local multistring_indicator_width = get_text_width(MULTISTRING_INDICATOR_TEXT, font_material, font_size)
|
||||
local command_text_width = WIDTH - STRING_X_MARGIN * 2 - (multistring_indicator_width / scale)
|
||||
command_text_strings = word_wrap(command.full_text, font_material, font_size, command_text_width)
|
||||
|
||||
-- draw that [...] thing
|
||||
local multistring_offset_x = (_OFFSET_X + _WIDTH) * scale - multistring_indicator_width
|
||||
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.text(_gui, _MULTISTRING_INDICATOR_TEXT, font_material, font_size, font_name,
|
||||
Gui.text(_gui, MULTISTRING_INDICATOR_TEXT, font_material, font_size, font_name,
|
||||
multistring_indicator_position, Color(255, 100, 100, 100))
|
||||
end
|
||||
first_description_string = string.sub(command_text_strings[1], #command.name + 2)
|
||||
|
@ -129,7 +116,7 @@ local function draw(commands_list, selected_command_index)
|
|||
-- 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
|
||||
string_position.y = string_position.y - STRING_HEIGHT * scale
|
||||
Gui.text(_gui, command_text_strings[j], font_material, font_size, font_name,
|
||||
string_position, Color(255, 255, 255, 255))
|
||||
end
|
||||
|
@ -137,21 +124,21 @@ local function draw(commands_list, selected_command_index)
|
|||
end
|
||||
|
||||
-- background rectangle
|
||||
local bg_height = _STRING_HEIGHT * (#displayed_commands + selected_strings_number - 1)
|
||||
local bg_pos_y = _OFFSET_Y - bg_height
|
||||
local bg_height = STRING_HEIGHT * (#displayed_commands + selected_strings_number - 1)
|
||||
local bg_pos_y = OFFSET_Y - bg_height
|
||||
|
||||
local bg_position = Vector3(_OFFSET_X * scale, bg_pos_y * scale, _OFFSET_Z)
|
||||
local bg_size = Vector2(_WIDTH * scale, bg_height * scale)
|
||||
local bg_position = Vector3(OFFSET_X * scale, bg_pos_y * scale, OFFSET_Z)
|
||||
local bg_size = Vector2(WIDTH * scale, bg_height * scale)
|
||||
local bg_color = Color(200, 10, 10, 10)
|
||||
Gui.rect(_gui, bg_position, bg_size, bg_color)
|
||||
|
||||
-- selection rectangle
|
||||
if selected_command_new_index > 0 then
|
||||
local selection_height = _STRING_HEIGHT * selected_strings_number
|
||||
local selection_pos_y = _OFFSET_Y - selection_height - _STRING_HEIGHT * (selected_command_new_index - 1)
|
||||
local selection_height = STRING_HEIGHT * selected_strings_number
|
||||
local selection_pos_y = OFFSET_Y - selection_height - STRING_HEIGHT * (selected_command_new_index - 1)
|
||||
|
||||
local selection_position = Vector3(_OFFSET_X * scale, selection_pos_y * scale, _OFFSET_Z + 1)
|
||||
local selection_size = Vector2(_WIDTH * scale, selection_height * scale)
|
||||
local selection_position = Vector3(OFFSET_X * scale, selection_pos_y * scale, OFFSET_Z + 1)
|
||||
local selection_size = Vector2(WIDTH * scale, selection_height * scale)
|
||||
local selection_color = Color(100, 120, 120, 120)
|
||||
Gui.rect(_gui, selection_position, selection_size, selection_color)
|
||||
end
|
||||
|
@ -163,17 +150,20 @@ local function draw(commands_list, selected_command_index)
|
|||
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_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)
|
||||
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.text(_gui, total_number_indicator, font_material, font_size, font_name,
|
||||
total_number_indicator_position, Color(255, 100, 100, 100))
|
||||
end
|
||||
--end)
|
||||
|
||||
if not VT1 then
|
||||
UPDATE_RESOLUTION_LOOKUP(true)
|
||||
end
|
||||
end
|
||||
|
||||
-- #####################################################################################################################
|
||||
-- ##### Return ########################################################################################################
|
||||
-- #####################################################################################################################
|
||||
|
||||
return draw
|
||||
|
|
Loading…
Add table
Reference in a new issue