diff --git a/vmf/scripts/mods/vmf/modules/ui/mutators/mutator_manager.lua b/vmf/scripts/mods/vmf/modules/ui/mutators/mutator_manager.lua index 50deee3..d14a15b 100644 --- a/vmf/scripts/mods/vmf/modules/ui/mutators/mutator_manager.lua +++ b/vmf/scripts/mods/vmf/modules/ui/mutators/mutator_manager.lua @@ -1,3 +1,14 @@ +--[[ + + +INCOMPATIBLE WITH: + +COMPATIBLE ONLY WITH: (incompatible with everything except) + + +]] + + --[[ Add ability to turn mods into mutators --]] local vmf = get_mod("VMF") @@ -24,12 +35,10 @@ local _MUTATORS_SORTED = false local _ALL_MUTATORS_DISABLED = false -- External modules -local _MUTATORS_VIEW +--local _MUTATORS_VIEW local _DICE_MANAGER local _SET_LOBBY_DATA -local _MUTATORS_GUI - local _DEFAULT_CONFIG -- List of enabled mutators in case VMF is reloaded in the middle of the game @@ -139,17 +148,20 @@ end function vmf.temp_show_mutator_compatibility() print("MUTATORS COMPATIBILITY:") + print("") for _, mutator in ipairs(_MUTATORS) do local compatibility = mutator:get_config().compatibility - print("\n" .. mutator:get_readable_name() .. (compatibility.mostly_compatible and "[+]" or "[-]") .. ":") + print(mutator:get_readable_name() .. (compatibility.mostly_compatible and "[+]" or "[-]") .. ":") local ident = compatibility.mostly_compatible and " - " or " + " for other_mutator in pairs(compatibility.except) do print(ident .. other_mutator:get_readable_name()) end + + print("") end end @@ -338,12 +350,10 @@ function vmf.mutator_supports_current_difficulty(mutator) local actual_difficulty = Managers.state and Managers.state.difficulty:get_difficulty() local right_difficulty = not actual_difficulty or table.contains(mutator_difficulty_levels, actual_difficulty) - local map_view = _MUTATORS_VIEW.map_view - local map_view_active = map_view and map_view.active local right_unapplied_difficulty = false - + local map_view_exists, map_view = pcall(function () return Managers.matchmaking.ingame_ui.views.map_view end) + local map_view_active = map_view_exists and map_view.active if map_view_active then - local difficulty_data = map_view.selected_level_index and map_view:get_difficulty_data(map_view.selected_level_index) local difficulty_layout = difficulty_data and difficulty_data[map_view.selected_difficulty_stepper_index] local difficulty_key = difficulty_layout and difficulty_layout.key @@ -392,7 +402,7 @@ function vmf.register_mod_as_mutator(mod, config) _MUTATORS_SORTED = false - _MUTATORS_VIEW:update_mutator_list() + --_MUTATORS_VIEW:update_mutator_list() end -- Enables/disables mutator while preserving the sequence in which they were enabled @@ -468,16 +478,14 @@ end) _DEFAULT_CONFIG = vmf:dofile("scripts/mods/vmf/modules/ui/mutators/mutator_default_config") -_MUTATORS_VIEW = vmf:dofile("scripts/mods/vmf/modules/ui/mutators/mutator_gui") +--_MUTATORS_VIEW = vmf:dofile("scripts/mods/vmf/modules/ui/mutators/mutator_gui") _DICE_MANAGER = vmf:dofile("scripts/mods/vmf/modules/ui/mutators/mutator_dice") _SET_LOBBY_DATA = vmf:dofile("scripts/mods/vmf/modules/ui/mutators/mutator_info") -_MUTATORS_GUI = vmf:dofile("scripts/mods/vmf/modules/ui/mutators/mutators_gui") - -- Initialize mutators view when map_view has been initialized already -_MUTATORS_VIEW:init(_MUTATORS_VIEW:get_map_view()) +--_MUTATORS_VIEW:init(_MUTATORS_VIEW:get_map_view()) -- Testing ---vmf:dofile("scripts/mods/vmf/modules/ui/mutators/test/mutator_test") +vmf:dofile("scripts/mods/vmf/modules/ui/mutators/test/mutator_test") --vmf:dofile("scripts/mods/vmf/modules/ui/mutators/test/mutation") --vmf:dofile("scripts/mods/vmf/modules/ui/mutators/test/deathwish") \ No newline at end of file diff --git a/vmf/scripts/mods/vmf/modules/ui/mutators/mutators_gui.lua b/vmf/scripts/mods/vmf/modules/ui/mutators/mutators_gui.lua index 6d67fe3..524b011 100644 --- a/vmf/scripts/mods/vmf/modules/ui/mutators/mutators_gui.lua +++ b/vmf/scripts/mods/vmf/modules/ui/mutators/mutators_gui.lua @@ -1,84 +1,124 @@ -local scenegraph_definition = { - sg_root = { - is_root = true, - size = {1920, 1080}, - position = {0, 0, UILayer.default} - }, - sg_mutators_background = { - vertical_alignment = "bottom", - parent = "sg_root", - horizontal_alignment = "left", - size = {547, 313}, - position = {-2, -2, 10} -- @TODO: fix the actual image - }, -} - -local widgets_definition = { - static_elements = { - scenegraph_id = "sg_root", - element = { - passes = { - { - pass_type = "texture", - - style_id = "mutators_background", - texture_id = "mutators_background_texture_id" - } - } - }, - content = { - mutators_background_texture_id = "map_view_mutators_area", - }, - style = { - mutators_background = { - scenegraph_id = "sg_mutators_background" - } - } - } - - - -} - - - - ------------------------------ - local vmf = get_mod("VMF") +local _DEFINITIONS = dofile("scripts/mods/vmf/modules/ui/mutators/mutators_gui_definitions") + local _MUTATORS = vmf.mutators local _UI_SCENEGRAPH -local _WIDGETS +local _MUTATOR_LIST_WIDGETS = {} +local _PARTY_BUTTON_WIDGET +local _OTHER_WIDGETS = {} -local _DEFINITIONS --- temp (will replace with dofile) -_DEFINITIONS = {} -_DEFINITIONS.scenegraph_definition = scenegraph_definition -_DEFINITIONS.widgets_definition = widgets_definition +local _ORIGINAL_VALUES = {} +local _MUTATOR_LIST_IS_VISIBLE +local _CURRENT_PAGE_NUMBER +local _TOTAL_PAGES_NUMBER + + +local _IS_MUTATORS_GUI_INITIALIZED = false -- #################################################################################################################### -- ##### Local functions ############################################################################################## -- #################################################################################################################### +local function get_map_view() + local map_view_exists, map_view = pcall(function () return Managers.matchmaking.ingame_ui.views.map_view end) + if map_view_exists then + return map_view + end +end + + +local function show_mutator_list(map_view, is_visible) + + _MUTATOR_LIST_IS_VISIBLE = is_visible + + if is_visible then + + -- Banner + local banner_widget = map_view.background_widgets[3] + banner_widget.style.text.localize = false + banner_widget.style.tooltip_text.localize = false + banner_widget.content.text = vmf:localize("mutators_title") + banner_widget.content.tooltip_text = vmf:localize("mutators_banner_tooltip") + + -- Players list + for _, widget in ipairs(map_view.player_list_widgets) do + widget.content.visible = false + end + + -- Players counter + map_view.player_list_conuter_text_widget.content.visible = false + else + + -- Banner + local banner_widget = map_view.background_widgets[3] + banner_widget.style.text.localize = true + banner_widget.style.tooltip_text.localize = true + banner_widget.content.text = "map_party_title" + banner_widget.content.tooltip_text = "map_party_setting_tooltip" + + -- Players list + for _, widget in ipairs(map_view.player_list_widgets) do + widget.content.visible = true + end + + -- Players counter + map_view.player_list_conuter_text_widget.content.visible = true + end +end + +local function change_map_view_look(map_view, is_vmf_look) + + if is_vmf_look then + _ORIGINAL_VALUES.settings_button_position_x = map_view.ui_scenegraph.settings_button.position[1] + _ORIGINAL_VALUES.friends_button_position_x = map_view.ui_scenegraph.friends_button.position[1] + _ORIGINAL_VALUES.lobby_button_position_x = map_view.ui_scenegraph.lobby_button.position[1] + + map_view.ui_scenegraph.settings_button.position[1] = -50 + map_view.ui_scenegraph.friends_button.position[1] = 50 + map_view.ui_scenegraph.lobby_button.position[1] = 150 + else + map_view.ui_scenegraph.settings_button.position[1] = _ORIGINAL_VALUES.settings_button_position_x + map_view.ui_scenegraph.friends_button.position[1] = _ORIGINAL_VALUES.friends_button_position_x + map_view.ui_scenegraph.lobby_button.position[1] = _ORIGINAL_VALUES.lobby_button_position_x + end +end + local function initialize_mutators_ui(map_view) + -- Scenegraph _UI_SCENEGRAPH = UISceneGraph.init_scenegraph(_DEFINITIONS.scenegraph_definition) - _WIDGETS = {} + -- Creating mutator list widgets and calculating total pages number + for i, mutator in ipairs(_MUTATORS) do + local offset = ((i - 1) % 8) + 1 + _MUTATOR_LIST_WIDGETS[i] = UIWidget.init(_DEFINITIONS.create_mutator_widget(mutator)) + _MUTATOR_LIST_WIDGETS[i].offset = {0, -32 * offset, 0} + end + _CURRENT_PAGE_NUMBER = 1 + _TOTAL_PAGES_NUMBER = math.floor(#_MUTATORS / 8) + ((#_MUTATORS % 8 > 0) and 1 or 0) - vmf:pcall(function() - _WIDGETS.static_elements = UIWidget.init(_DEFINITIONS.widgets_definition.static_elements) - end) + -- Party button + _PARTY_BUTTON_WIDGET = UIWidget.init(_DEFINITIONS.party_button_widget_defenition) - vmf:echo("AAAA: initialize_mutators_ui") + -- Other widgets + for widget_name, widget in pairs(_DEFINITIONS.widgets_definition) do + _OTHER_WIDGETS[widget_name] = UIWidget.init(widget) + end + + -- Modify original map_view look + change_map_view_look(map_view, true) + show_mutator_list(map_view, true) + + _IS_MUTATORS_GUI_INITIALIZED = true end + local function draw(map_view, dt) local input_service = map_view.input_manager:get_service("map_menu") local ui_renderer = map_view.ui_renderer @@ -86,13 +126,55 @@ local function draw(map_view, dt) UIRenderer.begin_pass(ui_renderer, _UI_SCENEGRAPH, input_service, dt, nil, render_settings) - UIRenderer.draw_widget(ui_renderer, _WIDGETS.static_elements) + -- Party button + UIRenderer.draw_widget(ui_renderer, _PARTY_BUTTON_WIDGET) + + if _MUTATOR_LIST_IS_VISIBLE then + + -- Mutator list (render only 8 (or less) currently visible mutator widgets) + for i = ((_CURRENT_PAGE_NUMBER - 1) * 8 + 1), (_CURRENT_PAGE_NUMBER * 8) do + if not _MUTATOR_LIST_WIDGETS[i] then + break + end + UIRenderer.draw_widget(ui_renderer, _MUTATOR_LIST_WIDGETS[i]) + end + + -- Other widgets + for _, widget in pairs(_OTHER_WIDGETS) do + UIRenderer.draw_widget(ui_renderer, widget) + end + end UIRenderer.end_pass(ui_renderer) end + +local function update_mousewheel_scroll_area_input() + local widget_content = _OTHER_WIDGETS.mousewheel_scroll_area.content + local mouse_scroll_value = widget_content.scroll_value + if mouse_scroll_value ~= 0 then + _CURRENT_PAGE_NUMBER = math.clamp(_CURRENT_PAGE_NUMBER + mouse_scroll_value, 1, _TOTAL_PAGES_NUMBER) + widget_content.scroll_value = 0 + end +end + + local function update_mutators_ui(map_view, dt) + + -- Show/hide mutator list if party button was pressed + local transitioning = map_view:transitioning() + local friends_menu_active = map_view.friends:is_active() + if not transitioning and not friends_menu_active then + local mutators_button_content = _PARTY_BUTTON_WIDGET.content + if mutators_button_content.button_hotspot.on_release then + map_view:play_sound("Play_hud_select") + show_mutator_list(map_view, mutators_button_content.toggled) + mutators_button_content.toggled = not mutators_button_content.toggled + end + end + draw(map_view, dt) + update_mousewheel_scroll_area_input() end -- #################################################################################################################### @@ -108,17 +190,30 @@ end) vmf:hook("MapView.update", function (func, self, dt, t) func(self, dt, t) - if self.menu_active then + if self.menu_active and _IS_MUTATORS_GUI_INITIALIZED then update_mutators_ui(self, dt) end end) -- #################################################################################################################### --- ##### Script ####################################################################################################### +-- ##### VMF internal functions and variables ######################################################################### -- #################################################################################################################### -local map_view_exists, map_view = pcall(function () return Managers.matchmaking.ingame_ui.views.map_view end) -if map_view_exists then - vmf:echo("map_view_exists!!!!!!!!!!!") - initialize_mutators_ui(map_view) -end \ No newline at end of file +function vmf.reset_map_view() + local map_view = get_map_view() + if map_view then + change_map_view_look(map_view, false) + show_mutator_list(map_view, false) + end +end + +function vmf.modify_map_view() + local map_view = get_map_view() + if map_view then + initialize_mutators_ui(map_view) + end +end + +-- #################################################################################################################### +-- ##### Script ####################################################################################################### +-- #################################################################################################################### diff --git a/vmf/scripts/mods/vmf/modules/ui/mutators/mutators_gui_definitions.lua b/vmf/scripts/mods/vmf/modules/ui/mutators/mutators_gui_definitions.lua new file mode 100644 index 0000000..033298c --- /dev/null +++ b/vmf/scripts/mods/vmf/modules/ui/mutators/mutators_gui_definitions.lua @@ -0,0 +1,175 @@ +local scenegraph_definition = { + + sg_root = { + is_root = true, + size = {1920, 1080}, + position = {0, 0, UILayer.default} + }, + + sg_mutators_list_background = { + vertical_alignment = "bottom", + parent = "sg_root", + horizontal_alignment = "left", + size = {547, 313}, + position = {-2, -2, 10} -- @TODO: fix the actual image + }, + + sg_mutators_button = { + vertical_alignment = "bottom", + parent = "sg_root", + horizontal_alignment = "left", + size = {64, 64}, + position = {87, 430.5, 10} + }, + + sg_mutators_list = { + vertical_alignment = "bottom", + horizontal_alignment = "left", + + size = {370, 265}, + position = {80, 61, 11}, --122 + + parent = "sg_root" + }, + + sg_mutators_list_start = { + vertical_alignment = "top", + horizontal_alignment = "left", + + size = {1, 1}, + offset = {0, 0, 1}, + + parent = "sg_mutators_list" + }, +} + + +local widgets_definition = { + + mutator_list_background = { + scenegraph_id = "sg_root", + element = { + passes = { + { + pass_type = "texture", + style_id = "mutators_list_background", + texture_id = "mutators_list_background_texture_id" + } + } + }, + content = { + mutators_list_background_texture_id = "map_view_mutators_area", + }, + style = { + mutators_list_background = { + scenegraph_id = "sg_mutators_list_background" + } + } + }, +--[[ + + mutators_list_debug = { + scenegraph_id = "sg_mutators_list", + element = { + passes = { + { + pass_type = "rect", + style_id = "mutators_list_background", + } + } + }, + content = {}, + style = { + mutators_list_background = { + scenegraph_id = "sg_mutators_list", + color = {255, 0, 0, 0} + }, + } + }, + + ]] + mousewheel_scroll_area = { + scenegraph_id = "sg_mutators_list", + element = { + passes = { + { + pass_type = "scroll", + scroll_function = function (ui_scenegraph_, style_, content, input_service_, scroll_axis) + content.scroll_value = content.scroll_value - scroll_axis.y + end + } + } + }, + content = { + scroll_value = 0 + }, + style = {} + }, +} + + +local party_button_widget_defenition = UIWidgets.create_octagon_button( + { + "map_view_party_button", + "map_view_party_button_lit" + }, + { + "map_party_title", + "map_party_title" + }, + "sg_mutators_button" +) + + +local function create_mutator_widget(mutator) + return { + scenegraph_id = "sg_mutators_list_start", + element = { + passes = { + -- { + -- pass_type = "rect", + + -- style_id = "mutators_list_background", + -- --texture_id = "mutators_list_background_texture_id" + -- }, + { + pass_type = "text", + + style_id = "text", + text_id = "text" + }, + + } + }, + content = { + mutators_list_background_texture_id = "map_view_mutators_area", + mutator = mutator, + text = mutator:get_readable_name(), + --text = "bIbIbI(rus)", + }, + style = { + + mutators_list_background = { + --scenegraph_id = "sg_mutators_list_start", + color = {math.random(255), math.random(255), math.random(255), 255}, + size = {370, 32} + }, + + text = { + offset = {0, -2, 2}, + font_size = 24, + font_type = "hell_shark", + dynamic_font = true, + text_color = Colors.get_color_table_with_alpha("white", 255) + }, + } + } +end + + +return { + scenegraph_definition = scenegraph_definition, + widgets_definition = widgets_definition, + party_button_widget_defenition = party_button_widget_defenition, + create_mutator_widget = create_mutator_widget +} \ No newline at end of file diff --git a/vmf/scripts/mods/vmf/modules/ui/mutators/test/mutator_test.lua b/vmf/scripts/mods/vmf/modules/ui/mutators/test/mutator_test.lua index 8fe76fd..3bc67fa 100644 --- a/vmf/scripts/mods/vmf/modules/ui/mutators/test/mutator_test.lua +++ b/vmf/scripts/mods/vmf/modules/ui/mutators/test/mutator_test.lua @@ -120,6 +120,31 @@ one_hit_one_kill:initialize_data(mod_data) one_hit_one_kill.on_enabled = function(init_call) mutator3:echo("One Hit One Kill on_enabled(" .. (init_call and "init)" or ")")) end one_hit_one_kill.on_disabled = function(init_call) mutator3:echo("One Hit One Kill on_disabled(" .. (init_call and "init)" or ")")) end vmf.initialize_mod_state(one_hit_one_kill) +---------------------------------------------------------------------------------- + +local ayyyy = new_mod("ayyyy") +mod_data = {} +mod_data.name = "ayyyy" +mod_data.is_mutator = true +ayyyy:initialize_data(mod_data) +ayyyy.on_enabled = function(init_call) mutator3:echo("ayyyy on_enabled(" .. (init_call and "init)" or ")")) end +ayyyy.on_disabled = function(init_call) mutator3:echo("ayyyy on_disabled(" .. (init_call and "init)" or ")")) end +vmf.initialize_mod_state(ayyyy) +---------------------------------------------------------------------------------- + +local lmao = new_mod("lmao") +mod_data = {} +mod_data.name = "lmao" +mod_data.is_mutator = true +mod_data.mutator_settings = { + --title = "One Hit One Kill", + difficulty_levels = {"hardest"}, + enable_after_these = {"ayyyy"} +} +lmao:initialize_data(mod_data) +lmao.on_enabled = function(init_call) mutator3:echo("lmao on_enabled(" .. (init_call and "init)" or ")")) end +lmao.on_disabled = function(init_call) mutator3:echo("lmao on_disabled(" .. (init_call and "init)" or ")")) end +vmf.initialize_mod_state(lmao) ---------------------------------------------------------------------------------- diff --git a/vmf/scripts/mods/vmf/vmf_loader.lua b/vmf/scripts/mods/vmf/vmf_loader.lua index fba5907..140c265 100644 --- a/vmf/scripts/mods/vmf/vmf_loader.lua +++ b/vmf/scripts/mods/vmf/vmf_loader.lua @@ -28,7 +28,12 @@ return { dofile("scripts/mods/vmf/modules/ui/options/vmf_options_view") dofile("scripts/mods/vmf/modules/vmf_options") - if VT1 then dofile("scripts/mods/vmf/modules/ui/mutators/mutator_manager") end + if VT1 then + dofile("scripts/mods/vmf/modules/ui/mutators/mutator_manager") + dofile("scripts/mods/vmf/modules/ui/mutators/mutators_gui") + end + + object.vmf = get_mod("VMF") @@ -60,6 +65,7 @@ return { object.vmf.create_network_dictionary() object.vmf.ping_vmf_users() + object.vmf.modify_map_view() object.vmf.temp_show_mutator_compatibility() object.vmf.all_mods_loaded_event() @@ -79,6 +85,7 @@ return { print("VMF:ON_RELOAD()") object.vmf.disable_mods_options_button() object.vmf.close_opened_custom_menus() + object.vmf.reset_map_view() object.vmf.delete_keybinds() object.vmf.mods_unload_event() object.vmf.hooks_unload()