Fixes for logging, chat messages, first-run notification, improved error alerts

This commit is contained in:
Aussiemon 2023-01-08 00:19:18 -07:00
parent f39b7ae72f
commit c77af55020
10 changed files with 84 additions and 40 deletions

View file

@ -19,6 +19,11 @@ return {
es = "Velocidad de desplazamiento en el menu",
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 = {
en = "%%",
},

View file

@ -1,14 +1,14 @@
local dmf
-- Global variable indicating which version of the game is currently running
VT1 = false
-- Native mod object used by Fatshark mod manager
local dmf_mod_object = {}
-- Global method to load a file through iowith a return
local mod_dofile = Mods.file.dofile
-- Global backup of original print() method
local print = __print
-- #####################################################################################################################
-- ##### Initialization ################################################################################################
-- #####################################################################################################################

View file

@ -1,6 +1,15 @@
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 _logging_settings
local _logging_settings_lookup = {
[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
[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 function add_chat_notification(message)
local event_manager = Managers.event
local function add_chat_notification(message, notification_type, sound_event, replay_to_chat_on_error)
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
event_manager:trigger("event_add_notification_message", "default", message, nil, _notification_sound)
elseif replay_to_chat_on_error then
table.insert(_unsent_chat_messages, {message, "NOTIFICATION"})
end
end
local function add_chat_message(message, sender)
local chat_manager = Managers.chat
local event_manager = Managers.event
local channel_sender = sender or "SYSTEM"
if chat_manager and event_manager then
local message_obj = {
message_body = message,
is_current_user = false,
}
-- Send to our stored chat element if it exists
if _chat_element then
_chat_element:_add_message(message, channel_sender, ChatManagerConstants.ChannelTag.PRIVATE)
local participant = {
displayname = sender or "SYSTEM",
}
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
else
-- 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})
end
end
@ -67,8 +78,8 @@ local function safe_format(mod, str, ...)
end
local function send_to_notifications(self, message)
add_chat_notification(message)
local function send_to_notifications(self, message, notification_type, sound_event)
add_chat_notification(message, notification_type, sound_event, true)
end
@ -82,6 +93,12 @@ local function send_to_chat(self, msg_type, message)
end
local string_format = string.format
local function printf(f, ...)
print(string_format(f, ...))
end
local function send_to_log(self, msg_type, message)
printf("[MOD][%s][%s] %s", self:get_name(), string.upper(msg_type), message)
end
@ -92,8 +109,12 @@ local function log_message(self, msg_type, message, ...)
message = safe_format(self, tostring(message), ...)
if message 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)
end
end
if _logging_settings[msg_type].send_to_chat then
send_to_chat(self, msg_type, message)
end
@ -160,10 +181,14 @@ end
-- Can't be hooked right away, since hooking module is not initialized yet
-- Sends unsent messages to chat when chat channel is finally created
function dmf.delayed_chat_messages_hook()
dmf:hook_safe("VivoxManager", "join_chat_channel", function (self)
if #_unsent_chat_messages > 0 and #self:connected_chat_channels() > 0 then
dmf:hook_safe("ConstantElementChat", "_handle_input", function (self)
-- 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
add_chat_message(message)
add_chat_message(message[1], message[2])
end
for i, _ in ipairs(_unsent_chat_messages) do

View file

@ -3,6 +3,9 @@
--]]
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
local _mutators = {}

View file

@ -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
-- defined the same setting_id.
_defined_mod_settings = {}
-- Initialize widgets' data.
for _, widget_data in ipairs(_unfolded_raw_widgets_data) do
local initialized_widget_data = initialize_widget_data(mod, widget_data, localize, collapsed_widgets)

View file

@ -1,6 +1,6 @@
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 {
delete = function()
return

View file

@ -3,6 +3,9 @@ local dmf = get_mod("DMF")
-- Global method to load a file through io with a return
local mod_dofile = Mods.file.dofile
-- Global backup of original print() method
local print = __print
-- #####################################################################################################################
-- ##### Local functions ###############################################################################################
-- #####################################################################################################################

View file

@ -7,6 +7,9 @@ local _io = Mods.lua.io
-- Global backup of the os library
local _os = Mods.lua.os
-- Global backup of original print() method
local print = __print
local function table_dump(key, value, depth, max_depth)
if max_depth < depth then
return

View file

@ -1,3 +1,6 @@
-- Global backup of original print() method
local print = __print
-- #####################################################################################################################
-- ##### Local functions ###############################################################################################
-- #####################################################################################################################

View file

@ -275,5 +275,6 @@ if not dmf:get("dmf_initialized") then
dmf.load_dmf_options_view_settings()
end
dmf:notify(dmf:localize("dmf_first_run_notification"))
dmf:set("dmf_initialized", true)
end