Skip to content

Commit

Permalink
Add scrollable logger as mod loader option
Browse files Browse the repository at this point in the history
  • Loading branch information
kartoFlane committed May 17, 2020
1 parent aa32fdc commit 3da949d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 15 deletions.
7 changes: 7 additions & 0 deletions scripts/mod_loader/localization/dictionary_English.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ return {
["ModContent_ButtonTooltip_ModLoaderConfig"] = "Configure some features of the mod loader.",
["ModLoaderConfig_FrameTitle"] = "Mod Loader Configuration",

["ModLoaderConfig_Text_ScrollableLogger"] = "Enable Scrolling Messages in Console",
["ModLoaderConfig_Tooltip_ScrollableLogger"] = "Allow scrolling through LOG messages in console. Can scroll back up to 200 messages. Also has the "..
"benefit of making multi-line messages more readable.\n\n"..
"This method only stores messages printed through the LOG function, so error messages printed in "..
"red by the game will be lost when scrolling.\n\n"..
"Navigate using mouse scroll, or page up/down keys. Hold down shift to jump by more.",

["ModLoaderConfig_Text_LogLevel"] = "Logging level",
["ModLoaderConfig_Tooltip_LogLevel"] = "Controls where the game's logging messages are printed.",
["ModLoaderConfig_DD_LogLevel_0"] = "None",
Expand Down
4 changes: 2 additions & 2 deletions scripts/mod_loader/mod_loader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ local ScrollableLogger = require("scripts/mod_loader/logger_scrollable")
local BasicLoggerImpl = require("scripts/mod_loader/logger_basic")
local BufferedLoggerImpl = require("scripts/mod_loader/logger_buffered")

local useScrollableLogger = false
if useScrollableLogger then
mod_loader.scrollableLogger = false
if mod_loader.scrollableLogger then
mod_loader.logger = ScrollableLogger(BufferedLoggerImpl())
else
mod_loader.logger = Logger(BasicLoggerImpl())
Expand Down
21 changes: 21 additions & 0 deletions scripts/mod_loader/modapi/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
function CurrentModLoaderConfig()
local data = {}

data.scrollableLogger = mod_loader.scrollableLogger
data.logLevel = mod_loader.logger:getLoggingLevel()
data.printCallerInfo = mod_loader.logger:getPrintCallerInfo()
data.developmentMode = modApi.developmentMode
Expand Down Expand Up @@ -48,6 +49,7 @@ end

function DefaultModLoaderConfig()
return {
scrollableLogger = false,
logLevel = 1, -- log to console by default
printCallerInfo = true,
developmentMode = false,
Expand Down Expand Up @@ -93,7 +95,26 @@ function LoadModLoaderConfig(overrideLoadProfileConfig)
return data
end

local function updateLogger(config)
if mod_loader.scrollableLogger ~= config.scrollableLogger then
Logger = Logger or require("scripts/mod_loader/logger")
local ScrollableLogger = require("scripts/mod_loader/logger_scrollable")

local BasicLoggerImpl = require("scripts/mod_loader/logger_basic")
local BufferedLoggerImpl = require("scripts/mod_loader/logger_buffered")

mod_loader.scrollableLogger = config.scrollableLogger
if mod_loader.scrollableLogger then
mod_loader.logger = ScrollableLogger(BufferedLoggerImpl())
else
mod_loader.logger = Logger(BasicLoggerImpl())
end
end
end

function ApplyModLoaderConfig(config)
updateLogger(config)

mod_loader.logger:setLoggingLevel(config.logLevel)
mod_loader.logger:setPrintCallerInfo(config.printCallerInfo)
modApi.developmentMode = config.developmentMode
Expand Down
36 changes: 23 additions & 13 deletions scripts/mod_loader/modui/modloader_configuration.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ local function cleanup()
end

local function createUi()
local cboxScrollableLogger = nil
local ddLogLevel = nil
local cboxCaller = nil
local cboxDevelopmentMode = nil
Expand All @@ -27,6 +28,7 @@ local function createUi()

local onExit = function(self)
local data = {
scrollableLogger = cboxScrollableLogger.checked,
logLevel = ddLogLevel.value,
printCallerInfo = cboxCaller.checked,
developmentMode = cboxDevelopmentMode.checked,
Expand All @@ -49,20 +51,21 @@ local function createUi()
end

local uiSetSettings = function(config)
ddLogLevel.value = config.logLevel
ddLogLevel.choice = ddLogLevel.value + 1
cboxDevelopmentMode.checked = config.developmentMode
cboxCaller.checked = config.printCallerInfo
cboxFloatyTooltips.checked = config.floatyTooltips
cboxProfileConfig.checked = config.profileConfig

cboxErrorFrame.checked = config.showErrorFrame
cboxVersionFrame.checked = config.showVersionFrame
cboxResourceError.checked = config.showResourceWarning
cboxGamepadWarning.checked = config.showGamepadWarning
cboxRestartReminder.checked = config.showRestartReminder
cboxScrollableLogger.checked = config.scrollableLogger
ddLogLevel.value = config.logLevel
ddLogLevel.choice = ddLogLevel.value + 1
cboxCaller.checked = config.printCallerInfo
cboxDevelopmentMode.checked = config.developmentMode
cboxFloatyTooltips.checked = config.floatyTooltips
cboxProfileConfig.checked = config.profileConfig

cboxErrorFrame.checked = config.showErrorFrame
cboxVersionFrame.checked = config.showVersionFrame
cboxResourceError.checked = config.showResourceWarning
cboxGamepadWarning.checked = config.showGamepadWarning
cboxRestartReminder.checked = config.showRestartReminder
cboxPilotRestartReminder.checked = config.showPilotRestartReminder
cboxProfileFrame.checked = config.showProfileSettingsFrame
cboxProfileFrame.checked = config.showProfileSettingsFrame

local t = cboxFloatyTooltips.root.tooltip
modApi.floatyTooltips = config.floatyTooltips
Expand Down Expand Up @@ -173,6 +176,13 @@ local function createUi()
:width(1)
:addTo(scrollarea)

-- ////////////////////////////////////////////////////////////////////////
-- Scrollable logger
cboxScrollableLogger = createCheckboxOption(
GetText("ModLoaderConfig_Text_ScrollableLogger"),
GetText("ModLoaderConfig_Tooltip_ScrollableLogger")
):addTo(layout)

-- ////////////////////////////////////////////////////////////////////////
-- Logging level
ddLogLevel = UiDropDown(
Expand Down

0 comments on commit 3da949d

Please sign in to comment.