mutators: title placement

This commit is contained in:
UnShame 2018-02-22 19:50:24 +03:00
parent afb4b3fa57
commit 99093eddcf
4 changed files with 65 additions and 29 deletions

View file

@ -24,6 +24,7 @@ The config object is optional but obviously you'd want to provide at least a rea
title = "", title = "",
short_title = "", short_title = "",
description = "No description provided", description = "No description provided",
title_placement = "after",
dice = { dice = {
grims = 0, grims = 0,
tomes = 0, tomes = 0,
@ -58,6 +59,10 @@ The short title will be used in the lobby browser.
``description = "No description provided"`` ``description = "No description provided"``
The description will show up in the tooltip of your mutator on the map screen. The description will show up in the tooltip of your mutator on the map screen.
``title_placement = "after"``
The determines where the title of your mod will be placed in the tab menu, the lobby name and chat messages: before all other, after all other or in the middle instead of the regular difficulty name (if it is present).
Possible values: `"before", "after", "replace"`
``dice = { grims = 0, tomes = 0, bonus = 0 }`` ``dice = { grims = 0, tomes = 0, bonus = 0 }``
This determines how many additional dice the players will get for completing maps with your mutator enabled. This determines how many additional dice the players will get for completing maps with your mutator enabled.

View file

@ -6,6 +6,7 @@ return {
}, },
title = "", title = "",
short_title = "", short_title = "",
title_placement = "after",
description = "No description provided", description = "No description provided",
difficulty_levels = { difficulty_levels = {
"easy", "easy",

View file

@ -6,20 +6,14 @@ local mutators = manager.mutators
local were_enabled_before = false local were_enabled_before = false
-- Assembles a list of enabled mutators -- Assembles a list of enabled mutators
local function get_enabled_mutators_names(separator, short) local function add_enabled_mutators_titles_to_string(str, separator, short)
local name = nil local _mutators = {}
for _, mutator in ipairs(mutators) do for _, mutator in ipairs(mutators) do
local config = mutator:get_config()
if mutator:is_enabled() then if mutator:is_enabled() then
local added_name = (short and config.short_title or config.title or mutator:get_name()) table.insert(_mutators, mutator)
if name then
name = name .. separator .. added_name
else
name = added_name
end end
end end
end return manager.add_mutator_titles_to_string(_mutators, str, separator, short)
return name
end end
-- Sets the lobby name -- Sets the lobby name
@ -32,10 +26,10 @@ local function set_lobby_data()
not Managers.matchmaking.lobby.get_stored_lobby_data not Managers.matchmaking.lobby.get_stored_lobby_data
) then return end ) then return end
local name = get_enabled_mutators_names(" ", true) local name = add_enabled_mutators_titles_to_string("", " ", true)
local default_name = LobbyAux.get_unique_server_name() local default_name = LobbyAux.get_unique_server_name()
if name then if string.len(name) > 0 then
name = "||" .. name .. "|| " .. default_name name = "||" .. name .. "|| " .. default_name
else else
name = default_name name = default_name
@ -66,14 +60,9 @@ manager:hook("IngamePlayerListUI.update_difficulty", function(func, self)
local difficulty_settings = Managers.state.difficulty:get_difficulty_settings() local difficulty_settings = Managers.state.difficulty:get_difficulty_settings()
local difficulty_name = difficulty_settings.display_name local difficulty_name = difficulty_settings.display_name
local name = not self.is_in_inn and Localize(difficulty_name) or nil local name = not self.is_in_inn and Localize(difficulty_name) or ""
local mutators_name = get_enabled_mutators_names(" ", true) name = add_enabled_mutators_titles_to_string(name, " ", true)
if mutators_name then
if name then name = name .. " " else name = "" end
name = name .. mutators_name
else
name = ""
end
self.set_difficulty_name(self, name) self.set_difficulty_name(self, name)
self.current_difficulty_name = difficulty_name self.current_difficulty_name = difficulty_name
@ -83,8 +72,8 @@ end)
manager:hook("MatchmakingStateHostGame.host_game", function(func, self, ...) manager:hook("MatchmakingStateHostGame.host_game", function(func, self, ...)
func(self, ...) func(self, ...)
set_lobby_data() set_lobby_data()
local names = get_enabled_mutators_names(", ") local names = add_enabled_mutators_titles_to_string("", ", ")
if names then if string.len(names) > 0 then
manager:chat_broadcast("ENABLED MUTATORS: " .. names) manager:chat_broadcast("ENABLED MUTATORS: " .. names)
were_enabled_before = true were_enabled_before = true
elseif were_enabled_before then elseif were_enabled_before then
@ -95,8 +84,8 @@ end)
-- Send special messages with enabled mutators list to players just joining the lobby -- Send special messages with enabled mutators list to players just joining the lobby
manager:hook("MatchmakingManager.rpc_matchmaking_request_join_lobby", function(func, self, sender, client_cookie, host_cookie, lobby_id, friend_join) 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 = add_enabled_mutators_titles_to_string("", ", ")
if name then if string.len(name) > 0 then
local message = "[Automated message] This lobby has the following difficulty mod active : " .. name local message = "[Automated message] This lobby has the following difficulty mod active : " .. name
manager:chat_whisper(get_peer_id_from_cookie(client_cookie), message) manager:chat_whisper(get_peer_id_from_cookie(client_cookie), message)
end end

View file

@ -253,9 +253,7 @@ manager.disable_impossible_mutators = function(notify, everybody, reason)
if #disabled_mutators > 0 and notify then if #disabled_mutators > 0 and notify then
if not reason then reason = "" end if not reason then reason = "" end
local message = everybody and "MUTATORS DISABLED " .. reason .. ":" or "Mutators disabled " .. reason .. ":" local message = everybody and "MUTATORS DISABLED " .. reason .. ":" or "Mutators disabled " .. reason .. ":"
for i, mutator in ipairs(disabled_mutators) do message = message .. " " .. manager.add_mutator_titles_to_string(disabled_mutators, "", ", ", false)
message = message .. (i == 1 and " " or ", ") .. (mutator:get_config().title or mutator:get_name())
end
if everybody then if everybody then
manager:chat_broadcast(message) manager:chat_broadcast(message)
else else
@ -272,6 +270,48 @@ manager.update = function()
end end
end end
-- Appends, prepends and replaces the string with mutator titles
manager.add_mutator_titles_to_string = function(_mutators, str, separator, short)
if #_mutators == 0 then return str end
local before = nil
local after = nil
local replace = nil
for _, mutator in ipairs(_mutators) do
local config = mutator:get_config()
local added_name = (short and config.short_title or config.title or mutator:get_name())
if config.title_placement == "before" then
if before then
before = added_name .. separator .. before
else
before = added_name
end
elseif config.title_placement == "replace" then
if replace then
replace = replace .. separator .. added_name
else
replace = added_name
end
else
if after then
after = after .. separator .. added_name
else
after = added_name
end
end
end
local new_str = replace or str
if before then
new_str = before .. (string.len(new_str) > 0 and separator or "") .. new_str
end
if after then
new_str = new_str .. (string.len(new_str) > 0 and separator or "") .. after
end
return new_str
end
--[[ --[[
MUTATOR'S OWN METHODS MUTATOR'S OWN METHODS
@ -406,5 +446,6 @@ mutators_view:init(mutators_view:get_map_view())
--[[ --[[
Testing Testing
--]] --]]
--manager:dofile("scripts/mods/vmf/modules/mutators/mutator_test") -- manager:dofile("scripts/mods/vmf/modules/mutators/mutator_test")
--manager:dofile("scripts/mods/vmf/modules/mutators/mutators/mutation") -- manager:dofile("scripts/mods/vmf/modules/mutators/mutators/mutation")
-- manager:dofile("scripts/mods/vmf/modules/mutators/mutators/deathwish")