Merge pull request #23 from Darktide-Mod-Framework/marchfixes
Fix command window output, add require_restart support, gamepad fixes
This commit is contained in:
commit
fcfd5477dd
7 changed files with 61 additions and 33 deletions
|
@ -329,6 +329,9 @@ return {
|
||||||
ru = "Консоль разработчика закрыта.",
|
ru = "Консоль разработчика закрыта.",
|
||||||
["zh-cn"] = "已关闭开发者控制台。",
|
["zh-cn"] = "已关闭开发者控制台。",
|
||||||
},
|
},
|
||||||
|
dev_console_close_warning = {
|
||||||
|
en = "The developer console is disabled, but must be closed manually.",
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
-- MUTATORS
|
-- MUTATORS
|
||||||
|
|
|
@ -117,11 +117,12 @@ local function initialize_generic_widget_data(mod, data, localize)
|
||||||
new_data.mod_name = mod:get_name()
|
new_data.mod_name = mod:get_name()
|
||||||
|
|
||||||
-- Defined in widget
|
-- Defined in widget
|
||||||
new_data.type = data.type
|
new_data.type = data.type
|
||||||
new_data.setting_id = data.setting_id
|
new_data.setting_id = data.setting_id
|
||||||
new_data.title = data.title -- optional, if (localize == true)
|
new_data.title = data.title -- optional, if (localize == true)
|
||||||
new_data.tooltip = data.tooltip -- optional
|
new_data.tooltip = data.tooltip -- optional
|
||||||
new_data.default_value = data.default_value
|
new_data.default_value = data.default_value
|
||||||
|
new_data.require_restart = data.require_restart -- optional
|
||||||
|
|
||||||
-- Overwrite global optons localization setting if widget defined it
|
-- Overwrite global optons localization setting if widget defined it
|
||||||
if data.localize == nil then
|
if data.localize == nil then
|
||||||
|
|
|
@ -49,16 +49,24 @@ local function close_dev_console()
|
||||||
|
|
||||||
CommandWindow.close()
|
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
|
||||||
dmf:pcall(function()
|
if _ffi then
|
||||||
_ffi.cdef([[
|
dmf:pcall(function()
|
||||||
void* FindWindowA(const char* lpClassName, const char* lpWindowName);
|
if _ffi then
|
||||||
int64_t SendMessageA(void* hWnd, unsigned int Msg, uint64_t wParam, int64_t lParam);
|
_ffi.cdef([[
|
||||||
]])
|
void* FindWindowA(const char* lpClassName, const char* lpWindowName);
|
||||||
local WM_CLOSE = 0x10;
|
int64_t SendMessageA(void* hWnd, unsigned int Msg, uint64_t wParam, int64_t lParam);
|
||||||
local hwnd = _ffi.C.FindWindowA("ConsoleWindowClass", "Developer console")
|
]])
|
||||||
_ffi.C.SendMessageA(hwnd, WM_CLOSE, 0, 0)
|
local WM_CLOSE = 0x10;
|
||||||
end)
|
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
|
_console_data.enabled = false
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,7 +7,7 @@ if not _io.initialized then
|
||||||
_io = dmf.deepcopy(Mods.lua.io)
|
_io = dmf.deepcopy(Mods.lua.io)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Local backup of the io library
|
-- Local backup of the os library
|
||||||
local _os = dmf:persistent_table("_os")
|
local _os = dmf:persistent_table("_os")
|
||||||
_os.initialized = _os.initialized or false
|
_os.initialized = _os.initialized or false
|
||||||
if not _os.initialized then
|
if not _os.initialized then
|
||||||
|
@ -17,6 +17,11 @@ end
|
||||||
-- Global backup of original print() method
|
-- Global backup of original print() method
|
||||||
local print = __print
|
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)
|
local function table_dump(key, value, depth, max_depth)
|
||||||
if max_depth < depth then
|
if max_depth < depth then
|
||||||
return
|
return
|
||||||
|
@ -28,7 +33,7 @@ local function table_dump(key, value, depth, max_depth)
|
||||||
if value_type == "table" then
|
if value_type == "table" then
|
||||||
prefix = prefix .. ((key == nil and "") or " = ")
|
prefix = prefix .. ((key == nil and "") or " = ")
|
||||||
|
|
||||||
print(prefix .. "table")
|
log_and_console_print(prefix .. "table")
|
||||||
|
|
||||||
for key_, value_ in pairs(value) do
|
for key_, value_ in pairs(value) do
|
||||||
table_dump(key_, value_, depth + 1, max_depth)
|
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 meta then
|
||||||
if type(meta) == "boolean" then
|
if type(meta) == "boolean" then
|
||||||
print(prefix .. "protected metatable")
|
log_and_console_print(prefix .. "protected metatable")
|
||||||
else
|
else
|
||||||
print(prefix .. "metatable")
|
log_and_console_print(prefix .. "metatable")
|
||||||
for key_, value_ in pairs(meta) do
|
for key_, value_ in pairs(meta) do
|
||||||
if key_ ~= "__index" and key_ ~= "super" then
|
if key_ ~= "__index" and key_ ~= "super" then
|
||||||
table_dump(key_, value_, depth + 1, max_depth)
|
table_dump(key_, value_, depth + 1, max_depth)
|
||||||
|
@ -49,9 +54,9 @@ local function table_dump(key, value, depth, max_depth)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif value_type == "function" or value_type == "thread" or value_type == "userdata" or value == nil then
|
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
|
else
|
||||||
print(prefix .. " = " .. tostring(value) .. " (" .. value_type .. ")")
|
log_and_console_print(prefix .. " = " .. tostring(value) .. " (" .. value_type .. ")")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -77,7 +82,7 @@ DMFMod.dump = function (self, dumped_object, dumped_object_name, max_depth)
|
||||||
end
|
end
|
||||||
|
|
||||||
if dumped_object_name then
|
if dumped_object_name then
|
||||||
print(string.format("<%s>", dumped_object_name))
|
log_and_console_print(string.format("<%s>", dumped_object_name))
|
||||||
end
|
end
|
||||||
|
|
||||||
if not max_depth then
|
if not max_depth then
|
||||||
|
@ -96,7 +101,7 @@ DMFMod.dump = function (self, dumped_object, dumped_object_name, max_depth)
|
||||||
end
|
end
|
||||||
|
|
||||||
if dumped_object_name then
|
if dumped_object_name then
|
||||||
print(string.format("</%s>", dumped_object_name))
|
log_and_console_print(string.format("</%s>", dumped_object_name))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -924,7 +924,7 @@ DMFOptionsView._update_settings_content_widgets = function (self, dt, t, input_s
|
||||||
end
|
end
|
||||||
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 scenegraph_id = "settings_grid_content_pivot"
|
||||||
local default_value = config.default_value
|
local default_value = config.default_value
|
||||||
local default_value_type = type(default_value)
|
local default_value_type = type(default_value)
|
||||||
|
@ -1112,20 +1112,23 @@ DMFOptionsView.cb_on_settings_pressed = function (self, widget, entry)
|
||||||
end
|
end
|
||||||
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 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
|
for i = 1, #entry.options do
|
||||||
local option = entry.options[i]
|
local option = entry.options[i]
|
||||||
|
|
||||||
if option.id == option_id then
|
if option.value == option_value then
|
||||||
self._require_restart = option.require_restart
|
self._require_restart = option.require_restart
|
||||||
|
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
|
||||||
self._require_restart = entry.require_restart
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -171,6 +171,7 @@ local blueprints = {
|
||||||
|
|
||||||
if new_value ~= nil and new_value ~= value then
|
if new_value ~= nil and new_value ~= value then
|
||||||
on_activated(new_value, entry)
|
on_activated(new_value, entry)
|
||||||
|
entry.changed_callback(new_value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
@ -291,6 +292,7 @@ blueprints.percent_slider = {
|
||||||
|
|
||||||
if new_value then
|
if new_value then
|
||||||
on_activated(new_value * 100, entry)
|
on_activated(new_value * 100, entry)
|
||||||
|
entry.changed_callback(new_value)
|
||||||
|
|
||||||
content.slider_value = new_value
|
content.slider_value = new_value
|
||||||
content.previous_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)
|
local new_value = explode_function(new_normalized_value, entry)
|
||||||
|
|
||||||
on_activated(new_value, entry)
|
on_activated(new_value, entry)
|
||||||
|
entry.changed_callback(new_value)
|
||||||
|
|
||||||
content.slider_value = new_normalized_value
|
content.slider_value = new_normalized_value
|
||||||
content.previous_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)
|
local new_value = math.lerp(entry.min_value, entry.max_value, new_value_fraction)
|
||||||
|
|
||||||
on_activated(new_value, entry)
|
on_activated(new_value, entry)
|
||||||
|
entry.changed_callback(new_value)
|
||||||
|
|
||||||
content.slider_value = new_value_fraction
|
content.slider_value = new_value_fraction
|
||||||
content.previous_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 selected_index and focused then
|
||||||
if using_gamepad and hotspot.on_pressed then
|
if using_gamepad and hotspot.on_pressed then
|
||||||
new_value = options[selected_index].id
|
new_value = options[selected_index].value
|
||||||
end
|
end
|
||||||
|
|
||||||
hotspot_style.on_pressed_sound = hotspot_style.on_pressed_fold_in_sound
|
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>"
|
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 = 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")
|
local preview_value = preview_option and preview_option.display_name or Managers.localization:localize("loc_settings_option_unavailable")
|
||||||
|
|
||||||
content.value_text = preview_value
|
content.value_text = preview_value
|
||||||
|
@ -636,7 +640,7 @@ blueprints.dropdown = {
|
||||||
for i = 1, #options do
|
for i = 1, #options do
|
||||||
local option = options[i]
|
local option = options[i]
|
||||||
|
|
||||||
if option.id == preview_option_id then
|
if option.value == preview_option_value then
|
||||||
selected_index = i
|
selected_index = i
|
||||||
|
|
||||||
break
|
break
|
||||||
|
@ -729,6 +733,7 @@ blueprints.dropdown = {
|
||||||
if new_value ~= value then
|
if new_value ~= value then
|
||||||
local on_activated = entry.on_activated
|
local on_activated = entry.on_activated
|
||||||
on_activated(new_value, entry)
|
on_activated(new_value, entry)
|
||||||
|
entry.changed_callback(new_value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -159,6 +159,7 @@ local create_checkbox_template = function (self, params)
|
||||||
display_name = params.title,
|
display_name = params.title,
|
||||||
indentation_level = params.depth,
|
indentation_level = params.depth,
|
||||||
tooltip_text = params.tooltip,
|
tooltip_text = params.tooltip,
|
||||||
|
require_restart = params.require_restart,
|
||||||
value_type = "boolean",
|
value_type = "boolean",
|
||||||
}
|
}
|
||||||
template.on_activated = function(new_value)
|
template.on_activated = function(new_value)
|
||||||
|
@ -189,6 +190,7 @@ local create_mod_toggle_template = function (self, params)
|
||||||
disabled = params.disabled,
|
disabled = params.disabled,
|
||||||
indentation_level = 0,
|
indentation_level = 0,
|
||||||
tooltip_text = params.description,
|
tooltip_text = params.description,
|
||||||
|
require_restart = params.require_restart,
|
||||||
value_type = "boolean",
|
value_type = "boolean",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,6 +228,7 @@ local create_dropdown_template = function (self, params)
|
||||||
indentation_level = params.depth,
|
indentation_level = params.depth,
|
||||||
options = params.options,
|
options = params.options,
|
||||||
tooltip_text = params.tooltip,
|
tooltip_text = params.tooltip,
|
||||||
|
require_restart = params.require_restart,
|
||||||
widget_type = "dropdown",
|
widget_type = "dropdown",
|
||||||
}
|
}
|
||||||
template.on_activated = function(new_value)
|
template.on_activated = function(new_value)
|
||||||
|
|
Loading…
Add table
Reference in a new issue