diff --git a/vmf_source/scripts/mods/vmf/modules/mutators/mutator_dice.lua b/vmf_source/scripts/mods/vmf/modules/mutators/mutator_dice.lua index 4f258f0..4c912ce 100644 --- a/vmf_source/scripts/mods/vmf/modules/mutators/mutator_dice.lua +++ b/vmf_source/scripts/mods/vmf/modules/mutators/mutator_dice.lua @@ -1,11 +1,15 @@ +--[[ Add additional dice to end game roll --]] + local manager = get_mod("vmf_mutator_manager") +-- List of all die types local missions = { "bonus_dice_hidden_mission", "tome_bonus_mission", "grimoire_hidden_mission" } +-- Amounts of additional dice to be added at level completion local num_dice_per_mission = { bonus_dice_hidden_mission = 0, tome_bonus_mission = 0, @@ -18,6 +22,7 @@ manager:hook("GameModeManager.complete_level", function(func, self) local mission_system = Managers.state.entity:system("mission_system") local active_mission = mission_system.active_missions + -- Add additional dice for _, mission in ipairs(missions) do for _ = 1, num_dice_per_mission[mission] do mission_system:request_mission(mission, nil, Network.peer_id()) @@ -25,12 +30,14 @@ manager:hook("GameModeManager.complete_level", function(func, self) end end + -- Get total number of dice for name, obj in pairs(active_mission) do if table.has_item(missions, name) then num_dice = num_dice + obj.current_amount end end + -- Remove excess dice for _, mission in ipairs(missions) do if active_mission[mission] then for _ = 1, active_mission[mission].current_amount do @@ -47,6 +54,7 @@ manager:hook("GameModeManager.complete_level", function(func, self) return func(self) end) +-- Adds/remove dice local function adjustDice(grims, tomes, bonus, multiplier) if grims then num_dice_per_mission.grimoire_hidden_mission = num_dice_per_mission.grimoire_hidden_mission + grims * multiplier end if tomes then num_dice_per_mission.tome_bonus_mission = num_dice_per_mission.tome_bonus_mission + tomes * multiplier end diff --git a/vmf_source/scripts/mods/vmf/modules/mutators/mutator_gui.lua b/vmf_source/scripts/mods/vmf/modules/mutators/mutator_gui.lua index 5b2a8da..6703c31 100644 --- a/vmf_source/scripts/mods/vmf/modules/mutators/mutator_gui.lua +++ b/vmf_source/scripts/mods/vmf/modules/mutators/mutator_gui.lua @@ -1,3 +1,5 @@ +--[[ Add mutators panel to the map view --]] + local manager = get_mod("vmf_mutator_manager") local mutators = manager.mutators @@ -149,28 +151,40 @@ local mutators_view = { end end, + -- Sets appropriate text and style to checkboxes, hides/shows them as needed update_checkboxes = function(self) local widgets = self.map_view.normal_settings_widget_types for i = 1, PER_PAGE do + local current_index = PER_PAGE * (self.current_page - 1) + i + local checkbox = self.mutator_checkboxes[i] local hotspot = checkbox.content.button_hotspot + + -- Hide if fewer mutators shown than there are checkboxes if #self.mutators_sorted < current_index then + checkbox.content.setting_text = "" checkbox.content.tooltip_text = "" + + -- Remove from render lists widgets.adventure["mutator_checkbox_" .. i] = nil widgets.survival["mutator_checkbox_" .. i] = nil else local mutator_info = self.mutators_sorted[current_index] local mutator = get_mod(mutator_info[1]) + -- Set text and tooltip checkbox.content.setting_text = mutator_info[2] checkbox.content.tooltip_text = self:generate_tooltip_for(mutator) + + -- Add to render lists widgets.adventure["mutator_checkbox_" .. i] = checkbox widgets.survival["mutator_checkbox_" .. i] = checkbox + -- Set colors based on whether mutator can be enabled local active = mutator:can_be_enabled() local color = active and "cheeseburger" or "slate_gray" local color_hover = active and "white" or "slate_gray" @@ -178,10 +192,12 @@ local mutators_view = { checkbox.style.setting_text_hover.text_color = Colors.get_color_table_with_alpha(color_hover, 255) checkbox.style.checkbox_style.color = Colors.get_color_table_with_alpha(color_hover, 255) + -- Sound on hover if hotspot.on_hover_enter then self.map_view:play_sound("Play_hud_hover") end + -- Click event if hotspot.on_release then self.map_view:play_sound("Play_hud_hover") if mutator:is_enabled() then @@ -190,11 +206,13 @@ local mutators_view = { mutator:enable() end end + checkbox.content.selected = mutator:is_enabled() end end end, + -- Activate on button click or map open activate = function(self) if not self.initialized or not self.map_view.active or self.active then return end @@ -225,6 +243,7 @@ local mutators_view = { --print("ACTIVE!") end, + -- Deactivate on button click or map close deactivate = function(self) if not self.initialized or not self.active then return end @@ -258,6 +277,7 @@ local mutators_view = { --print("DEACTIVE") end, + -- Changes which muttators are displayed on_mutators_page_change = function(self, index_change) if not self.initialized then return end @@ -278,11 +298,14 @@ local mutators_view = { end end, + -- Creates and return text for checkbox tooltip generate_tooltip_for = function(self, mutator) + -- Description local config = mutator:get_config() local text = config.description - local supports_difficulty = mutator:supports_current_difficulty() + -- Show supported difficulty when can't be enabled due to difficulty level + local supports_difficulty = mutator:supports_current_difficulty() if not supports_difficulty then text = text .. "\nSupported difficulty levels:" for i, difficulty in ipairs(config.difficulty_levels) do @@ -290,13 +313,19 @@ local mutators_view = { end end + -- Show enabled incompatible local incompatible_mutators = mutator:get_incompatible_mutators(true) local currently_compatible = #incompatible_mutators == 0 + + -- Or all incompatible if difficulty is compatible if supports_difficulty and #incompatible_mutators == 0 then incompatible_mutators = mutator:get_incompatible_mutators() end + if #incompatible_mutators > 0 then + if currently_compatible and config.incompatible_with_all or #incompatible_mutators == #mutators - 1 then + -- Show special message when incompatible with all text = text .. "\nIncompatible with all other mutators" else text = text .. "\nIncompatible with:" @@ -305,10 +334,13 @@ local mutators_view = { text = text .. (i == 1 and " " or ", ") .. name end end + elseif config.compatible_with_all then + -- Special message when compatible with all text = text .. "\nCompatible with all other mutators" end + -- Special message if switched to unsupported difficulty level if mutator:is_enabled() and not supports_difficulty then text = text .. "\nWill be disabled when Play is pressed" end @@ -383,4 +415,16 @@ local mutators_view = { end } +-- Initialize mutators view after map view +manager:hook("MapView.init", function(func, self, ...) + func(self, ...) + manager:pcall(function() mutators_view:init(self) end) +end) + +-- Destroy mutators view after map view +manager:hook("MapView.destroy", function(func, ...) + mutators_view:deinitialize() + func(...) +end) + return mutators_view \ No newline at end of file diff --git a/vmf_source/scripts/mods/vmf/modules/mutators/mutator_gui_definitions.lua b/vmf_source/scripts/mods/vmf/modules/mutators/mutator_gui_definitions.lua index 7d620f0..6e98cc5 100644 --- a/vmf_source/scripts/mods/vmf/modules/mutators/mutator_gui_definitions.lua +++ b/vmf_source/scripts/mods/vmf/modules/mutators/mutator_gui_definitions.lua @@ -1,8 +1,10 @@ local definitions = local_require("scripts/ui/views/map_view_definitions") local scenegraph_definition = definitions.scenegraph_definition +-- Mutators to show per page definitions.PER_PAGE = 6 +-- Button to toggle mutators view scenegraph_definition.mutators_button = { vertical_alignment = "bottom", parent = "banner_party", @@ -17,6 +19,8 @@ scenegraph_definition.mutators_button = { 1 } } + +-- This will replace the Mission text scenegraph_definition.banner_mutators_text = { vertical_alignment = "center", parent = "banner_level", @@ -34,30 +38,35 @@ scenegraph_definition.banner_mutators_text = { local new_widgets = { + + -- This will replace the banner behind the Mission text banner_mutators_widget = UIWidgets.create_texture_with_text_and_tooltip("title_bar", "Mutators", "Enable and disable mutators", "banner_level", "banner_mutators_text", { - vertical_alignment = "center", - scenegraph_id = "banner_mutators_text", - localize = false, - font_size = 28, - horizontal_alignment = "center", - font_type = "hell_shark", - text_color = Colors.get_color_table_with_alpha("cheeseburger", 255) - }, - { - font_size = 24, - max_width = 500, - localize = false, - horizontal_alignment = "left", - vertical_alignment = "top", - font_type = "hell_shark", - text_color = Colors.get_color_table_with_alpha("white", 255), - line_colors = {}, - offset = { - 0, - 0, - 50 + vertical_alignment = "center", + scenegraph_id = "banner_mutators_text", + localize = false, + font_size = 28, + horizontal_alignment = "center", + font_type = "hell_shark", + text_color = Colors.get_color_table_with_alpha("cheeseburger", 255) + }, + { + font_size = 24, + max_width = 500, + localize = false, + horizontal_alignment = "left", + vertical_alignment = "top", + font_type = "hell_shark", + text_color = Colors.get_color_table_with_alpha("white", 255), + line_colors = {}, + offset = { + 0, + 0, + 50 + } } - }), + ), + + -- Button to toggle mutators view mutators_button_widget = { element = UIElements.ToggleIconButton, content = { @@ -172,6 +181,7 @@ local new_widgets = { } } +-- Checkboxes for i = 1, definitions.PER_PAGE do new_widgets["mutator_checkbox_" .. i] = { scenegraph_id = "mutator_checkbox_" .. i, diff --git a/vmf_source/scripts/mods/vmf/modules/mutators/mutator_info.lua b/vmf_source/scripts/mods/vmf/modules/mutators/mutator_info.lua index 477a606..b54de4e 100644 --- a/vmf_source/scripts/mods/vmf/modules/mutators/mutator_info.lua +++ b/vmf_source/scripts/mods/vmf/modules/mutators/mutator_info.lua @@ -1,16 +1,19 @@ +--[[ Notify players of enabled mutators via chat and tab menu --]] + local manager = get_mod("vmf_mutator_manager") local mutators = manager.mutators local were_enabled_before = false -local function get_enabled_mutators_names(short) +-- Assembles a list of enabled mutators +local function get_enabled_mutators_names(separator, short) local name = nil for _, mutator in ipairs(mutators) do local config = mutator:get_config() if mutator:is_enabled() then local added_name = (short and config.short_title or config.title or mutator:get_name()) if name then - name = name .. " " .. added_name + name = name .. separator .. added_name else name = added_name end @@ -19,11 +22,12 @@ local function get_enabled_mutators_names(short) return name end +-- Sets the lobby name local function set_lobby_data() if not Managers.matchmaking then return end - local name = get_enabled_mutators_names(true) + local name = get_enabled_mutators_names(" ", true) local default_name = LobbyAux.get_unique_server_name() if name then @@ -38,6 +42,8 @@ local function set_lobby_data() Managers.matchmaking.lobby:set_lobby_data(lobby_data) end +-- Return a function for chat system to only send messages to specific client +-- TODO: test if this works local function get_member_func(client_cookie) local peer_id = tostring(client_cookie) for _ = 1, 3 do @@ -58,19 +64,21 @@ local function get_member_func(client_cookie) end end - +-- Set difficulty in the tab menu +-- TODO: see if this can be set every time a mutator is enabled/disable manager:hook("IngamePlayerListUI.set_difficulty_name", function(func, self, name) - local mutators_name = get_enabled_mutators_names(true) + local mutators_name = get_enabled_mutators_names(" ", true) if mutators_name then name = name .. " " .. mutators_name end self.headers.content.game_difficulty = name end) +-- Notify everybody about enabled/disabled mutators when Play button is pressed on the map screen manager:hook("MatchmakingStateHostGame.host_game", function(func, self, ...) func(self, ...) set_lobby_data() - local names = get_enabled_mutators_names() + local names = get_enabled_mutators_names(", ") if names then Managers.chat:send_system_chat_message(1, "ENABLED MUTATORS: " .. names, 0, true) were_enabled_before = true @@ -80,8 +88,10 @@ manager:hook("MatchmakingStateHostGame.host_game", function(func, self, ...) end end) +-- Send special messages with enabled mutators list to players just joining the lobby +-- TODO: test if this works manager:hook("MatchmakingManager.rpc_matchmaking_request_join_lobby", function(func, self, sender, client_cookie, host_cookie, lobby_id, friend_join) - local name = get_enabled_mutators_names() + local name = get_enabled_mutators_names(", ") if name then local message = "[Automated message] This lobby has the following difficulty mod active : " .. name manager:hook("Managers.chat.channels[1].members_func", get_member_func(client_cookie)) @@ -91,4 +101,4 @@ manager:hook("MatchmakingManager.rpc_matchmaking_request_join_lobby", function(f func(self, sender, client_cookie, host_cookie, lobby_id, friend_join) end) -return set_lobby_data \ No newline at end of file +return set_lobby_data diff --git a/vmf_source/scripts/mods/vmf/modules/mutators/mutator_manager.lua b/vmf_source/scripts/mods/vmf/modules/mutators/mutator_manager.lua index 2519fa3..2e1543f 100644 --- a/vmf_source/scripts/mods/vmf/modules/mutators/mutator_manager.lua +++ b/vmf_source/scripts/mods/vmf/modules/mutators/mutator_manager.lua @@ -1,3 +1,5 @@ +--[[ Add ability to turn mods into mutators --]] + local manager = new_mod("vmf_mutator_manager") manager:localization("localization/mutator_manager") @@ -103,8 +105,8 @@ manager.disable_impossible_mutators = function(notify, everybody) end if #disabled_mutators > 0 and notify then local message = everybody and "MUTATORS DISABLED DUE TO DIFFICULTY CHANGE:" or "Mutators disabled due to difficulty change:" - for _, mutator in ipairs(disabled_mutators) do - message = message .. " " .. (mutator:get_config().title or mutator:get_name()) + for i, mutator in ipairs(disabled_mutators) do + message = message .. (i == 1 and " " or ", ") .. (mutator:get_config().title or mutator:get_name()) end if everybody then Managers.chat:send_system_chat_message(1, message, 0, true) @@ -275,14 +277,14 @@ local function disable_mutator(self) manager:pcall(function() set_mutator_state(self, false) end) end --- Checks current difficulty and map selection screen settings to determine if a mutator can be enabled +-- Checks current difficulty, map selection screen settings (optionally) and incompatible mutators to determine if a mutator can be enabled local function can_be_enabled(self, ignore_map) if #self:get_incompatible_mutators(true) > 0 then return false end return self:supports_current_difficulty(ignore_map) - end +-- Only checks difficulty local function supports_current_difficulty(self, ignore_map) local mutator_difficulty_levels = self:get_config().difficulty_levels local actual_difficulty = Managers.state and Managers.state.difficulty:get_difficulty() @@ -308,6 +310,7 @@ local function get_config(self) return mutators_config[self:get_name()] end +-- Returns a list of incompatible with self mutators, all or only enabled ones local function get_incompatible_mutators(self, enabled_only) local incompatible_mutators = {} for _, other_mutator in ipairs(mutators) do @@ -382,71 +385,14 @@ manager:hook("DifficultyManager.set_difficulty", function(func, self, difficulty end) --- Initialize mutators view after map view -manager:hook("MapView.init", function(func, self, ...) - func(self, ...) - manager:pcall(function() mutators_view:init(self) end) -end) - --- Destroy mutators view after map view -manager:hook("MapView.destroy", function(func, ...) - mutators_view:deinitialize() - func(...) -end) - +--[[ + INITIALIZE +--]] -- Initialize mutators view when map_view has been initialized already manager:pcall(function() mutators_view:init(mutators_view:get_map_view()) end) - - - - - - - - - - - - - - --[[ Testing --]] -local mutator2 = new_mod("mutator2") -local mutator3 = new_mod("mutator3") -local mutator555 = new_mod("mutator555") - -mutator555:register_as_mutator({ - incompatible_with_all = true -}) -mutator555:create_options({}, true, "mutator555", "mutator555 description") -mutator555.on_enabled = function() end -mutator555.on_disabled = function() end - - -mutator3:register_as_mutator({ - incompatible_with = { - "mutator4" - } -}) -mutator3.on_enabled = function() end -mutator3.on_disabled = function() end - -mutator2:register_as_mutator({ - compatible_with_all = true, - difficulty_levels = { - "hardest" - } -}) -mutator2.on_enabled = function() end -mutator2.on_disabled = function() end - ---[[for i=4,17 do - local mutator = new_mod("mutator" .. i) - mutator:register_as_mutator({}) - mutator.on_enabled = function() end - mutator.on_disabled = function() end -end--]] \ No newline at end of file +manager:dofile("scripts/mods/vmf/modules/mutators/mutator_test") diff --git a/vmf_source/scripts/mods/vmf/modules/mutators/mutator_test.lua b/vmf_source/scripts/mods/vmf/modules/mutators/mutator_test.lua new file mode 100644 index 0000000..fe8f03b --- /dev/null +++ b/vmf_source/scripts/mods/vmf/modules/mutators/mutator_test.lua @@ -0,0 +1,35 @@ +local mutator2 = new_mod("mutator2") +local mutator3 = new_mod("mutator3") +local mutator555 = new_mod("mutator555") + +mutator555:register_as_mutator({ + incompatible_with_all = true +}) +mutator555:create_options({}, true, "mutator555", "mutator555 description") +mutator555.on_enabled = function() end +mutator555.on_disabled = function() end + + +mutator3:register_as_mutator({ + incompatible_with = { + "mutator4" + } +}) +mutator3.on_enabled = function() end +mutator3.on_disabled = function() end + +mutator2:register_as_mutator({ + compatible_with_all = true, + difficulty_levels = { + "hardest" + } +}) +mutator2.on_enabled = function() end +mutator2.on_disabled = function() end + +--[[for i=4,17 do + local mutator = new_mod("mutator" .. i) + mutator:register_as_mutator({}) + mutator.on_enabled = function() end + mutator.on_disabled = function() end +end--]] \ No newline at end of file