Fixes for logging, chat messages, first-run notification, improved error alerts
This commit is contained in:
parent
f39b7ae72f
commit
c77af55020
10 changed files with 84 additions and 40 deletions
|
@ -19,6 +19,11 @@ return {
|
||||||
es = "Velocidad de desplazamiento en el menu",
|
es = "Velocidad de desplazamiento en el menu",
|
||||||
ru = "Скорость прокрутки меню",
|
ru = "Скорость прокрутки меню",
|
||||||
},
|
},
|
||||||
|
dmf_first_run_notification = {
|
||||||
|
en = "Welcome to the Darktide Mod Framework. Mod options have been added to the Options Menu.",
|
||||||
|
es = "Bienvenidos a el Mod Framework de Darktide. Hemos agregado las opciones de Mod a el menu de opciones.",
|
||||||
|
de = "Willkommen beim Darktide Mod Framework. Ein Button für Mod-Optionen wurde dem Hauptmenu hinzugefügt.",
|
||||||
|
},
|
||||||
percent = {
|
percent = {
|
||||||
en = "%%",
|
en = "%%",
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
local dmf
|
local dmf
|
||||||
|
|
||||||
-- Global variable indicating which version of the game is currently running
|
|
||||||
VT1 = false
|
|
||||||
|
|
||||||
-- Native mod object used by Fatshark mod manager
|
-- Native mod object used by Fatshark mod manager
|
||||||
local dmf_mod_object = {}
|
local dmf_mod_object = {}
|
||||||
|
|
||||||
-- Global method to load a file through iowith a return
|
-- Global method to load a file through iowith a return
|
||||||
local mod_dofile = Mods.file.dofile
|
local mod_dofile = Mods.file.dofile
|
||||||
|
|
||||||
|
-- Global backup of original print() method
|
||||||
|
local print = __print
|
||||||
|
|
||||||
-- #####################################################################################################################
|
-- #####################################################################################################################
|
||||||
-- ##### Initialization ################################################################################################
|
-- ##### Initialization ################################################################################################
|
||||||
-- #####################################################################################################################
|
-- #####################################################################################################################
|
||||||
|
|
|
@ -1,6 +1,15 @@
|
||||||
local dmf = get_mod("DMF")
|
local dmf = get_mod("DMF")
|
||||||
|
|
||||||
|
local ChatManagerConstants = require("scripts/foundation/managers/chat/chat_manager_constants")
|
||||||
|
local UISoundEvents = require("scripts/settings/ui/ui_sound_events")
|
||||||
|
|
||||||
|
-- Global backup of original print() method
|
||||||
|
local print = __print
|
||||||
|
|
||||||
|
local _chat_element
|
||||||
|
|
||||||
local _unsent_chat_messages = {}
|
local _unsent_chat_messages = {}
|
||||||
|
|
||||||
local _logging_settings
|
local _logging_settings
|
||||||
local _logging_settings_lookup = {
|
local _logging_settings_lookup = {
|
||||||
[0] = {[1] = false, [2] = false, [3] = false}, -- Disabled
|
[0] = {[1] = false, [2] = false, [3] = false}, -- Disabled
|
||||||
|
@ -12,46 +21,48 @@ local _logging_settings_lookup = {
|
||||||
[6] = {[1] = false, [2] = true, [3] = true}, -- Chat and Notification
|
[6] = {[1] = false, [2] = true, [3] = true}, -- Chat and Notification
|
||||||
[7] = {[1] = true, [2] = true, [3] = true}, -- All
|
[7] = {[1] = true, [2] = true, [3] = true}, -- All
|
||||||
}
|
}
|
||||||
local _notification_sound = "wwise/events/ui/play_ui_click"
|
|
||||||
|
local _notification_types = {
|
||||||
|
achievement = true,
|
||||||
|
alert = true,
|
||||||
|
contract = true,
|
||||||
|
currency = true,
|
||||||
|
default = true,
|
||||||
|
dev = true,
|
||||||
|
item_granted = true,
|
||||||
|
matchmaking = true,
|
||||||
|
}
|
||||||
|
|
||||||
-- #####################################################################################################################
|
-- #####################################################################################################################
|
||||||
-- ##### Local functions ###############################################################################################
|
-- ##### Local functions ###############################################################################################
|
||||||
-- #####################################################################################################################
|
-- #####################################################################################################################
|
||||||
|
|
||||||
local function add_chat_notification(message)
|
local function add_chat_notification(message, notification_type, sound_event, replay_to_chat_on_error)
|
||||||
local event_manager = Managers.event
|
if Managers.event then
|
||||||
|
Managers.event:trigger("event_add_notification_message",
|
||||||
|
_notification_types[notification_type] and notification_type or "default",
|
||||||
|
message or "",
|
||||||
|
nil,
|
||||||
|
sound_event or UISoundEvents.default_click
|
||||||
|
)
|
||||||
|
|
||||||
if event_manager then
|
elseif replay_to_chat_on_error then
|
||||||
event_manager:trigger("event_add_notification_message", "default", message, nil, _notification_sound)
|
table.insert(_unsent_chat_messages, {message, "NOTIFICATION"})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function add_chat_message(message, sender)
|
local function add_chat_message(message, sender)
|
||||||
local chat_manager = Managers.chat
|
local channel_sender = sender or "SYSTEM"
|
||||||
local event_manager = Managers.event
|
|
||||||
|
|
||||||
if chat_manager and event_manager then
|
-- Send to our stored chat element if it exists
|
||||||
local message_obj = {
|
if _chat_element then
|
||||||
message_body = message,
|
_chat_element:_add_message(message, channel_sender, ChatManagerConstants.ChannelTag.PRIVATE)
|
||||||
is_current_user = false,
|
|
||||||
}
|
|
||||||
|
|
||||||
local participant = {
|
else
|
||||||
displayname = sender or "SYSTEM",
|
-- Otherwise play the message as a notification for now, and replay it later
|
||||||
}
|
add_chat_notification(message, nil, nil, false)
|
||||||
|
table.insert(_unsent_chat_messages, {message, sender})
|
||||||
local message_sent = false
|
|
||||||
|
|
||||||
local channel_handle, channel = next(chat_manager:connected_chat_channels())
|
|
||||||
if channel then
|
|
||||||
event_manager:trigger("chat_manager_message_recieved", channel_handle, participant, message_obj)
|
|
||||||
message_sent = true
|
|
||||||
end
|
|
||||||
|
|
||||||
if not message_sent then
|
|
||||||
table.insert(_unsent_chat_messages, message)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -67,8 +78,8 @@ local function safe_format(mod, str, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function send_to_notifications(self, message)
|
local function send_to_notifications(self, message, notification_type, sound_event)
|
||||||
add_chat_notification(message)
|
add_chat_notification(message, notification_type, sound_event, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -82,6 +93,12 @@ local function send_to_chat(self, msg_type, message)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local string_format = string.format
|
||||||
|
local function printf(f, ...)
|
||||||
|
print(string_format(f, ...))
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
local function send_to_log(self, msg_type, message)
|
local function send_to_log(self, msg_type, message)
|
||||||
printf("[MOD][%s][%s] %s", self:get_name(), string.upper(msg_type), message)
|
printf("[MOD][%s][%s] %s", self:get_name(), string.upper(msg_type), message)
|
||||||
end
|
end
|
||||||
|
@ -92,8 +109,12 @@ local function log_message(self, msg_type, message, ...)
|
||||||
message = safe_format(self, tostring(message), ...)
|
message = safe_format(self, tostring(message), ...)
|
||||||
if message then
|
if message then
|
||||||
if _logging_settings[msg_type].send_to_notifications then
|
if _logging_settings[msg_type].send_to_notifications then
|
||||||
|
if msg_type == "error" then
|
||||||
|
send_to_notifications(self, {text = message}, "alert", UISoundEvents.notification_matchmaking_failed)
|
||||||
|
else
|
||||||
send_to_notifications(self, message)
|
send_to_notifications(self, message)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
if _logging_settings[msg_type].send_to_chat then
|
if _logging_settings[msg_type].send_to_chat then
|
||||||
send_to_chat(self, msg_type, message)
|
send_to_chat(self, msg_type, message)
|
||||||
end
|
end
|
||||||
|
@ -160,10 +181,14 @@ end
|
||||||
-- Can't be hooked right away, since hooking module is not initialized yet
|
-- Can't be hooked right away, since hooking module is not initialized yet
|
||||||
-- Sends unsent messages to chat when chat channel is finally created
|
-- Sends unsent messages to chat when chat channel is finally created
|
||||||
function dmf.delayed_chat_messages_hook()
|
function dmf.delayed_chat_messages_hook()
|
||||||
dmf:hook_safe("VivoxManager", "join_chat_channel", function (self)
|
dmf:hook_safe("ConstantElementChat", "_handle_input", function (self)
|
||||||
if #_unsent_chat_messages > 0 and #self:connected_chat_channels() > 0 then
|
|
||||||
|
-- Store the chat element for adding messages directly
|
||||||
|
_chat_element = self
|
||||||
|
|
||||||
|
if #_unsent_chat_messages > 0 then
|
||||||
for _, message in ipairs(_unsent_chat_messages) do
|
for _, message in ipairs(_unsent_chat_messages) do
|
||||||
add_chat_message(message)
|
add_chat_message(message[1], message[2])
|
||||||
end
|
end
|
||||||
|
|
||||||
for i, _ in ipairs(_unsent_chat_messages) do
|
for i, _ in ipairs(_unsent_chat_messages) do
|
||||||
|
|
|
@ -3,6 +3,9 @@
|
||||||
--]]
|
--]]
|
||||||
local dmf = get_mod("DMF")
|
local dmf = get_mod("DMF")
|
||||||
|
|
||||||
|
-- Global backup of original print() method
|
||||||
|
local print = __print
|
||||||
|
|
||||||
-- List of mods that are also mutators in order in which they should be enabled
|
-- List of mods that are also mutators in order in which they should be enabled
|
||||||
local _mutators = {}
|
local _mutators = {}
|
||||||
|
|
||||||
|
|
|
@ -518,6 +518,7 @@ local function initialize_mod_options_widgets_data(mod, widgets_data, localize)
|
||||||
-- Before starting widgets data initialization, clear this table. It's used to detect if 2 widgets
|
-- Before starting widgets data initialization, clear this table. It's used to detect if 2 widgets
|
||||||
-- defined the same setting_id.
|
-- defined the same setting_id.
|
||||||
_defined_mod_settings = {}
|
_defined_mod_settings = {}
|
||||||
|
|
||||||
-- Initialize widgets' data.
|
-- Initialize widgets' data.
|
||||||
for _, widget_data in ipairs(_unfolded_raw_widgets_data) do
|
for _, widget_data in ipairs(_unfolded_raw_widgets_data) do
|
||||||
local initialized_widget_data = initialize_widget_data(mod, widget_data, localize, collapsed_widgets)
|
local initialized_widget_data = initialize_widget_data(mod, widget_data, localize, collapsed_widgets)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
local dmf = get_mod("DMF")
|
local dmf = get_mod("DMF")
|
||||||
|
|
||||||
-- @TODO: move it to on_reload when it will be implemented in vt1
|
-- @TODO: move it to on_reload
|
||||||
Managers.dmf = Managers.dmf or {
|
Managers.dmf = Managers.dmf or {
|
||||||
delete = function()
|
delete = function()
|
||||||
return
|
return
|
||||||
|
|
|
@ -3,6 +3,9 @@ local dmf = get_mod("DMF")
|
||||||
-- Global method to load a file through io with a return
|
-- Global method to load a file through io with a return
|
||||||
local mod_dofile = Mods.file.dofile
|
local mod_dofile = Mods.file.dofile
|
||||||
|
|
||||||
|
-- Global backup of original print() method
|
||||||
|
local print = __print
|
||||||
|
|
||||||
-- #####################################################################################################################
|
-- #####################################################################################################################
|
||||||
-- ##### Local functions ###############################################################################################
|
-- ##### Local functions ###############################################################################################
|
||||||
-- #####################################################################################################################
|
-- #####################################################################################################################
|
||||||
|
|
|
@ -7,6 +7,9 @@ local _io = Mods.lua.io
|
||||||
-- Global backup of the os library
|
-- Global backup of the os library
|
||||||
local _os = Mods.lua.os
|
local _os = Mods.lua.os
|
||||||
|
|
||||||
|
-- Global backup of original print() method
|
||||||
|
local print = __print
|
||||||
|
|
||||||
local function table_dump(key, value, depth, max_depth)
|
local function table_dump(key, value, depth, max_depth)
|
||||||
if max_depth < depth then
|
if max_depth < depth then
|
||||||
return
|
return
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
-- Global backup of original print() method
|
||||||
|
local print = __print
|
||||||
|
|
||||||
-- #####################################################################################################################
|
-- #####################################################################################################################
|
||||||
-- ##### Local functions ###############################################################################################
|
-- ##### Local functions ###############################################################################################
|
||||||
-- #####################################################################################################################
|
-- #####################################################################################################################
|
||||||
|
|
|
@ -275,5 +275,6 @@ if not dmf:get("dmf_initialized") then
|
||||||
dmf.load_dmf_options_view_settings()
|
dmf.load_dmf_options_view_settings()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
dmf:notify(dmf:localize("dmf_first_run_notification"))
|
||||||
dmf:set("dmf_initialized", true)
|
dmf:set("dmf_initialized", true)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue