Merge pull request #23 from Darktide-Mod-Framework/marchfixes

Fix command window output, add require_restart support, gamepad fixes
This commit is contained in:
Aussiemon 2023-03-29 15:03:17 -06:00 committed by GitHub
commit fcfd5477dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 61 additions and 33 deletions

View file

@ -329,6 +329,9 @@ return {
ru = "Консоль разработчика закрыта.",
["zh-cn"] = "已关闭开发者控制台。",
},
dev_console_close_warning = {
en = "The developer console is disabled, but must be closed manually.",
},
-- MUTATORS

View file

@ -122,6 +122,7 @@ local function initialize_generic_widget_data(mod, data, localize)
new_data.title = data.title -- optional, if (localize == true)
new_data.tooltip = data.tooltip -- optional
new_data.default_value = data.default_value
new_data.require_restart = data.require_restart -- optional
-- Overwrite global optons localization setting if widget defined it
if data.localize == nil then

View file

@ -49,8 +49,10 @@ local function close_dev_console()
CommandWindow.close()
-- CommandWindow won't close by itself, so it have to be closed manually
-- CommandWindow won't close by itself, so it has to be closed through FFI
if _ffi then
dmf:pcall(function()
if _ffi then
_ffi.cdef([[
void* FindWindowA(const char* lpClassName, const char* lpWindowName);
int64_t SendMessageA(void* hWnd, unsigned int Msg, uint64_t wParam, int64_t lParam);
@ -58,8 +60,14 @@ local function close_dev_console()
local WM_CLOSE = 0x10;
local hwnd = _ffi.C.FindWindowA("ConsoleWindowClass", "Developer console")
_ffi.C.SendMessageA(hwnd, WM_CLOSE, 0, 0)
end
end)
-- Or manually closed by the user
else
dmf:warning(dmf:localize("dev_console_close_warning"))
end
_console_data.enabled = false
end
end

View file

@ -7,7 +7,7 @@ if not _io.initialized then
_io = dmf.deepcopy(Mods.lua.io)
end
-- Local backup of the io library
-- Local backup of the os library
local _os = dmf:persistent_table("_os")
_os.initialized = _os.initialized or false
if not _os.initialized then
@ -17,6 +17,11 @@ end
-- Global backup of original print() method
local print = __print
local function log_and_console_print(message, ...)
print(message, ...)
CommandWindow.print(message, ...)
end
local function table_dump(key, value, depth, max_depth)
if max_depth < depth then
return
@ -28,7 +33,7 @@ local function table_dump(key, value, depth, max_depth)
if value_type == "table" then
prefix = prefix .. ((key == nil and "") or " = ")
print(prefix .. "table")
log_and_console_print(prefix .. "table")
for key_, value_ in pairs(value) do
table_dump(key_, value_, depth + 1, max_depth)
@ -38,9 +43,9 @@ local function table_dump(key, value, depth, max_depth)
if meta then
if type(meta) == "boolean" then
print(prefix .. "protected metatable")
log_and_console_print(prefix .. "protected metatable")
else
print(prefix .. "metatable")
log_and_console_print(prefix .. "metatable")
for key_, value_ in pairs(meta) do
if key_ ~= "__index" and key_ ~= "super" then
table_dump(key_, value_, depth + 1, max_depth)
@ -49,9 +54,9 @@ local function table_dump(key, value, depth, max_depth)
end
end
elseif value_type == "function" or value_type == "thread" or value_type == "userdata" or value == nil then
print(prefix .. " = " .. tostring(value))
log_and_console_print(prefix .. " = " .. tostring(value))
else
print(prefix .. " = " .. tostring(value) .. " (" .. value_type .. ")")
log_and_console_print(prefix .. " = " .. tostring(value) .. " (" .. value_type .. ")")
end
end
@ -77,7 +82,7 @@ DMFMod.dump = function (self, dumped_object, dumped_object_name, max_depth)
end
if dumped_object_name then
print(string.format("<%s>", dumped_object_name))
log_and_console_print(string.format("<%s>", dumped_object_name))
end
if not max_depth then
@ -96,7 +101,7 @@ DMFMod.dump = function (self, dumped_object, dumped_object_name, max_depth)
end
if dumped_object_name then
print(string.format("</%s>", dumped_object_name))
log_and_console_print(string.format("</%s>", dumped_object_name))
end
end

View file

@ -924,7 +924,7 @@ DMFOptionsView._update_settings_content_widgets = function (self, dt, t, input_s
end
end
DMFOptionsView._create_settings_widget_from_config = function (self, config, category, suffix, callback_name)
DMFOptionsView._create_settings_widget_from_config = function (self, config, category, suffix, callback_name, changed_callback_name)
local scenegraph_id = "settings_grid_content_pivot"
local default_value = config.default_value
local default_value_type = type(default_value)
@ -1112,20 +1112,23 @@ DMFOptionsView.cb_on_settings_pressed = function (self, widget, entry)
end
end
DMFOptionsView.cb_on_settings_changed = function (self, widget, entry, option_id)
DMFOptionsView.cb_on_settings_changed = function (self, widget, entry, option_value)
if not self._require_restart then
if option_id then
-- Entry supersedes option
if entry.require_restart then
self._require_restart = true
-- Search by option value
elseif option_value then
for i = 1, #entry.options do
local option = entry.options[i]
if option.id == option_id then
if option.value == option_value then
self._require_restart = option.require_restart
break
end
end
else
self._require_restart = entry.require_restart
end
end
end

View file

@ -171,6 +171,7 @@ local blueprints = {
if new_value ~= nil and new_value ~= value then
on_activated(new_value, entry)
entry.changed_callback(new_value)
end
end
}
@ -291,6 +292,7 @@ blueprints.percent_slider = {
if new_value then
on_activated(new_value * 100, entry)
entry.changed_callback(new_value)
content.slider_value = new_value
content.previous_slider_value = new_value
@ -389,6 +391,7 @@ blueprints.value_slider = {
local new_value = explode_function(new_normalized_value, entry)
on_activated(new_value, entry)
entry.changed_callback(new_value)
content.slider_value = new_normalized_value
content.previous_slider_value = new_normalized_value
@ -499,6 +502,7 @@ blueprints.slider = {
local new_value = math.lerp(entry.min_value, entry.max_value, new_value_fraction)
on_activated(new_value, entry)
entry.changed_callback(new_value)
content.slider_value = new_value_fraction
content.previous_slider_value = new_value_fraction
@ -601,7 +605,7 @@ blueprints.dropdown = {
if selected_index and focused then
if using_gamepad and hotspot.on_pressed then
new_value = options[selected_index].id
new_value = options[selected_index].value
end
hotspot_style.on_pressed_sound = hotspot_style.on_pressed_fold_in_sound
@ -612,7 +616,7 @@ blueprints.dropdown = {
value = entry.get_function and entry:get_function() or content.internal_value or "<not selected>"
local preview_option = options_by_value[value]
local preview_option_id = preview_option and preview_option.id
local preview_option_value = preview_option and preview_option.value
local preview_value = preview_option and preview_option.display_name or Managers.localization:localize("loc_settings_option_unavailable")
content.value_text = preview_value
@ -636,7 +640,7 @@ blueprints.dropdown = {
for i = 1, #options do
local option = options[i]
if option.id == preview_option_id then
if option.value == preview_option_value then
selected_index = i
break
@ -729,6 +733,7 @@ blueprints.dropdown = {
if new_value ~= value then
local on_activated = entry.on_activated
on_activated(new_value, entry)
entry.changed_callback(new_value)
end
end

View file

@ -159,6 +159,7 @@ local create_checkbox_template = function (self, params)
display_name = params.title,
indentation_level = params.depth,
tooltip_text = params.tooltip,
require_restart = params.require_restart,
value_type = "boolean",
}
template.on_activated = function(new_value)
@ -189,6 +190,7 @@ local create_mod_toggle_template = function (self, params)
disabled = params.disabled,
indentation_level = 0,
tooltip_text = params.description,
require_restart = params.require_restart,
value_type = "boolean",
}
@ -226,6 +228,7 @@ local create_dropdown_template = function (self, params)
indentation_level = params.depth,
options = params.options,
tooltip_text = params.tooltip,
require_restart = params.require_restart,
widget_type = "dropdown",
}
template.on_activated = function(new_value)