mutators: title placement
This commit is contained in:
parent
afb4b3fa57
commit
99093eddcf
4 changed files with 65 additions and 29 deletions
|
@ -24,6 +24,7 @@ The config object is optional but obviously you'd want to provide at least a rea
|
|||
title = "",
|
||||
short_title = "",
|
||||
description = "No description provided",
|
||||
title_placement = "after",
|
||||
dice = {
|
||||
grims = 0,
|
||||
tomes = 0,
|
||||
|
@ -58,6 +59,10 @@ The short title will be used in the lobby browser.
|
|||
``description = "No description provided"``
|
||||
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 }``
|
||||
This determines how many additional dice the players will get for completing maps with your mutator enabled.
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ return {
|
|||
},
|
||||
title = "",
|
||||
short_title = "",
|
||||
title_placement = "after",
|
||||
description = "No description provided",
|
||||
difficulty_levels = {
|
||||
"easy",
|
||||
|
|
|
@ -6,20 +6,14 @@ local mutators = manager.mutators
|
|||
local were_enabled_before = false
|
||||
|
||||
-- Assembles a list of enabled mutators
|
||||
local function get_enabled_mutators_names(separator, short)
|
||||
local name = nil
|
||||
local function add_enabled_mutators_titles_to_string(str, separator, short)
|
||||
local _mutators = {}
|
||||
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 .. separator .. added_name
|
||||
else
|
||||
name = added_name
|
||||
end
|
||||
table.insert(_mutators, mutator)
|
||||
end
|
||||
end
|
||||
return name
|
||||
return manager.add_mutator_titles_to_string(_mutators, str, separator, short)
|
||||
end
|
||||
|
||||
-- Sets the lobby name
|
||||
|
@ -32,10 +26,10 @@ local function set_lobby_data()
|
|||
not Managers.matchmaking.lobby.get_stored_lobby_data
|
||||
) 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()
|
||||
if name then
|
||||
if string.len(name) > 0 then
|
||||
name = "||" .. name .. "|| " .. default_name
|
||||
else
|
||||
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_name = difficulty_settings.display_name
|
||||
|
||||
local name = not self.is_in_inn and Localize(difficulty_name) or nil
|
||||
local mutators_name = get_enabled_mutators_names(" ", true)
|
||||
if mutators_name then
|
||||
if name then name = name .. " " else name = "" end
|
||||
name = name .. mutators_name
|
||||
else
|
||||
name = ""
|
||||
end
|
||||
local name = not self.is_in_inn and Localize(difficulty_name) or ""
|
||||
name = add_enabled_mutators_titles_to_string(name, " ", true)
|
||||
|
||||
self.set_difficulty_name(self, name)
|
||||
|
||||
self.current_difficulty_name = difficulty_name
|
||||
|
@ -83,8 +72,8 @@ end)
|
|||
manager:hook("MatchmakingStateHostGame.host_game", function(func, self, ...)
|
||||
func(self, ...)
|
||||
set_lobby_data()
|
||||
local names = get_enabled_mutators_names(", ")
|
||||
if names then
|
||||
local names = add_enabled_mutators_titles_to_string("", ", ")
|
||||
if string.len(names) > 0 then
|
||||
manager:chat_broadcast("ENABLED MUTATORS: " .. names)
|
||||
were_enabled_before = true
|
||||
elseif were_enabled_before then
|
||||
|
@ -95,8 +84,8 @@ end)
|
|||
|
||||
-- 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)
|
||||
local name = get_enabled_mutators_names(", ")
|
||||
if name then
|
||||
local name = add_enabled_mutators_titles_to_string("", ", ")
|
||||
if string.len(name) > 0 then
|
||||
local message = "[Automated message] This lobby has the following difficulty mod active : " .. name
|
||||
manager:chat_whisper(get_peer_id_from_cookie(client_cookie), message)
|
||||
end
|
||||
|
|
|
@ -253,9 +253,7 @@ manager.disable_impossible_mutators = function(notify, everybody, reason)
|
|||
if #disabled_mutators > 0 and notify then
|
||||
if not reason then reason = "" end
|
||||
local message = everybody and "MUTATORS DISABLED " .. reason .. ":" or "Mutators disabled " .. reason .. ":"
|
||||
for i, mutator in ipairs(disabled_mutators) do
|
||||
message = message .. (i == 1 and " " or ", ") .. (mutator:get_config().title or mutator:get_name())
|
||||
end
|
||||
message = message .. " " .. manager.add_mutator_titles_to_string(disabled_mutators, "", ", ", false)
|
||||
if everybody then
|
||||
manager:chat_broadcast(message)
|
||||
else
|
||||
|
@ -272,6 +270,48 @@ manager.update = function()
|
|||
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
|
||||
|
@ -406,5 +446,6 @@ mutators_view:init(mutators_view:get_map_view())
|
|||
--[[
|
||||
Testing
|
||||
--]]
|
||||
--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/mutator_test")
|
||||
-- manager:dofile("scripts/mods/vmf/modules/mutators/mutators/mutation")
|
||||
-- manager:dofile("scripts/mods/vmf/modules/mutators/mutators/deathwish")
|
||||
|
|
Loading…
Add table
Reference in a new issue