2022-07-27 23:48:49 +00:00
|
|
|
-- Copyright (c) 2019-2022 David Vogel
|
|
|
|
--
|
|
|
|
-- This software is released under the MIT License.
|
|
|
|
-- https://opensource.org/licenses/MIT
|
|
|
|
|
|
|
|
-----------------------
|
|
|
|
-- Load global stuff --
|
|
|
|
-----------------------
|
|
|
|
|
|
|
|
--------------------------
|
|
|
|
-- Load library modules --
|
|
|
|
--------------------------
|
|
|
|
|
|
|
|
local Coords = require("coordinates")
|
|
|
|
|
|
|
|
----------
|
|
|
|
-- Code --
|
|
|
|
----------
|
|
|
|
|
2022-08-27 12:32:01 +00:00
|
|
|
---Removes all messages with the AutoClose flag.
|
2022-07-29 18:44:36 +00:00
|
|
|
---Use this before you recreate all auto closing messages.
|
2022-08-27 12:32:01 +00:00
|
|
|
function Message:CloseAutoClose()
|
2022-07-29 18:44:36 +00:00
|
|
|
self.List = self.List or {}
|
|
|
|
|
|
|
|
for k, message in pairs(self.List) do
|
2022-08-27 12:32:01 +00:00
|
|
|
if message.AutoClose then
|
2022-07-29 18:44:36 +00:00
|
|
|
self.List[k] = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-27 23:48:49 +00:00
|
|
|
---Add a general runtime error message to the message list.
|
|
|
|
---This will always overwrite the last runtime error with the same id.
|
|
|
|
---@param id string
|
|
|
|
---@param ... string
|
|
|
|
function Message:ShowRuntimeError(id, ...)
|
|
|
|
self.List = self.List or {}
|
|
|
|
|
|
|
|
self.List["RuntimeError" .. id] = {
|
|
|
|
Type = "error",
|
|
|
|
Lines = { ... },
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
---Calls func and catches any exception.
|
|
|
|
---If there is one, a runtime error message will be shown to the user.
|
|
|
|
---@param id string
|
|
|
|
---@param func function
|
|
|
|
function Message:CatchException(id, func)
|
2022-07-28 09:56:14 +00:00
|
|
|
local ok, err = xpcall(func, debug.traceback)
|
2022-07-27 23:48:49 +00:00
|
|
|
if not ok then
|
2022-07-28 09:56:14 +00:00
|
|
|
|
|
|
|
print(string.format("An exception happened in %s: %s", id, err))
|
2022-07-27 23:48:49 +00:00
|
|
|
self:ShowRuntimeError(id, string.format("An exception happened in %s", id), err)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
---Request the user to let the addon automatically reset some Noita settings.
|
|
|
|
function Message:ShowResetNoitaSettings()
|
|
|
|
self.List = self.List or {}
|
|
|
|
|
|
|
|
self.List["ResetNoitaSettings"] = {
|
|
|
|
Type = "info",
|
|
|
|
Lines = {
|
|
|
|
"You requested to reset some game settings like:",
|
|
|
|
"- Custom resolutions",
|
2022-08-27 12:32:01 +00:00
|
|
|
"- Screen-shake intensity",
|
2022-07-27 23:48:49 +00:00
|
|
|
" ",
|
|
|
|
"Press the following button to reset the settings and close Noita automatically:",
|
|
|
|
},
|
|
|
|
Actions = {
|
2022-07-28 11:29:10 +00:00
|
|
|
{ Name = "Reset and close (May corrupt current save!)", Hint = nil, HintDesc = nil, Callback = function() Modification:Reset() end },
|
2022-07-27 23:48:49 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
---Request the user to let the addon automatically set Noita settings based on the given callback.
|
|
|
|
---@param callback function
|
|
|
|
---@param desc string -- What's wrong.
|
|
|
|
function Message:ShowSetNoitaSettings(callback, desc)
|
|
|
|
self.List = self.List or {}
|
|
|
|
|
|
|
|
self.List["SetNoitaSettings"] = {
|
|
|
|
Type = "warning",
|
|
|
|
Lines = {
|
|
|
|
"It seems that not all requested settings are applied to Noita:",
|
|
|
|
desc or "",
|
|
|
|
" ",
|
|
|
|
"Press the button at the bottom to set up and close Noita automatically.",
|
|
|
|
" ",
|
2022-07-28 11:29:10 +00:00
|
|
|
"You can always reset any custom settings by right clicking the `start capture`",
|
2022-07-27 23:48:49 +00:00
|
|
|
"button at the top left.",
|
|
|
|
},
|
|
|
|
Actions = {
|
2022-07-28 11:29:10 +00:00
|
|
|
{ Name = "Setup and close (May corrupt current save!)", Hint = nil, HintDesc = nil, Callback = callback },
|
2022-07-27 23:48:49 +00:00
|
|
|
},
|
2022-08-27 12:32:01 +00:00
|
|
|
AutoClose = true, -- This message will automatically close.
|
2022-07-27 23:48:49 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2022-07-28 20:34:56 +00:00
|
|
|
---Request the user to restart Noita.
|
|
|
|
---@param desc string -- What's wrong.
|
|
|
|
function Message:ShowRequestRestart(desc)
|
|
|
|
self.List = self.List or {}
|
|
|
|
|
|
|
|
self.List["RequestRestart"] = {
|
|
|
|
Type = "warning",
|
|
|
|
Lines = {
|
|
|
|
"It seems that not all requested settings are applied to Noita:",
|
|
|
|
desc or "",
|
|
|
|
" ",
|
|
|
|
"To resolve this issue, restart the game.",
|
|
|
|
},
|
2022-08-27 12:32:01 +00:00
|
|
|
AutoClose = true, -- This message will automatically close.
|
2022-07-28 20:34:56 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2022-07-27 23:48:49 +00:00
|
|
|
---Request the user to let the addon automatically set Noita settings based on the given callback.
|
|
|
|
---@param callback function
|
|
|
|
---@param desc string -- What's wrong.
|
|
|
|
function Message:ShowWrongResolution(callback, desc)
|
|
|
|
self.List = self.List or {}
|
|
|
|
|
|
|
|
self.List["WrongResolution"] = {
|
|
|
|
Type = "warning",
|
|
|
|
Lines = {
|
|
|
|
"The resolution changed:",
|
|
|
|
desc or "",
|
|
|
|
" ",
|
2023-03-15 22:58:50 +00:00
|
|
|
"To fix:",
|
|
|
|
"- Deselect and select the Noita window, or",
|
|
|
|
"- restart Noita or revert the resolution change."
|
2022-07-27 23:48:49 +00:00
|
|
|
},
|
|
|
|
Actions = {
|
|
|
|
{ Name = "Query settings again", Hint = nil, HintDesc = nil, Callback = function() Coords:ReadResolutions() end },
|
|
|
|
},
|
2022-08-27 12:32:01 +00:00
|
|
|
AutoClose = true, -- This message will automatically close.
|
2022-07-27 23:48:49 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
---Tell the user that there are files in the output directory.
|
|
|
|
function Message:ShowOutputNonEmpty()
|
|
|
|
self.List = self.List or {}
|
|
|
|
|
|
|
|
self.List["OutputNonEmpty"] = {
|
|
|
|
Type = "hint",
|
|
|
|
Lines = {
|
|
|
|
"There are already files in the output directory.",
|
|
|
|
"If you are continuing a capture session, ignore this message.",
|
|
|
|
" ",
|
|
|
|
"If you are about to capture a new map, make sure to delete all files in the output directory first."
|
|
|
|
},
|
|
|
|
Actions = {
|
|
|
|
{ Name = "Open output directory", Hint = nil, HintDesc = nil, Callback = function() os.execute("start .\\mods\\noita-mapcap\\output\\") end },
|
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2022-07-29 18:44:36 +00:00
|
|
|
---Tell the user that some settings are not optimal.
|
|
|
|
---@param ... string
|
|
|
|
function Message:ShowGeneralSettingsProblem(...)
|
|
|
|
self.List = self.List or {}
|
|
|
|
|
|
|
|
self.List["GeneralSettingsProblem"] = {
|
|
|
|
Type = "hint",
|
|
|
|
Lines = { ... },
|
2022-08-27 12:32:01 +00:00
|
|
|
AutoClose = true, -- This message will automatically close.
|
2022-07-29 18:44:36 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2022-07-27 23:48:49 +00:00
|
|
|
---Tell the user that there is something wrong with the mod installation.
|
|
|
|
---@param ... string
|
|
|
|
function Message:ShowGeneralInstallationProblem(...)
|
|
|
|
self.List = self.List or {}
|
|
|
|
|
|
|
|
self.List["GeneralInstallationProblem"] = {
|
|
|
|
Type = "error",
|
|
|
|
Lines = { ... },
|
|
|
|
}
|
|
|
|
end
|
2022-08-27 12:07:37 +00:00
|
|
|
|
2022-08-27 12:32:01 +00:00
|
|
|
---Tell the user that some modification couldn't be applied because it is unsupported.
|
2022-08-27 12:07:37 +00:00
|
|
|
---@param realm "config"|"magicNumbers"|"processMemory"|"filePatches"
|
|
|
|
---@param name string
|
|
|
|
---@param value any
|
|
|
|
function Message:ShowModificationUnsupported(realm, name, value)
|
|
|
|
self.List = self.List or {}
|
|
|
|
|
|
|
|
self.List["ModificationFailed"] = {
|
|
|
|
Type = "warning",
|
|
|
|
Lines = {
|
|
|
|
string.format("Couldn't modify %q in %q realm.", name, realm),
|
|
|
|
" ",
|
|
|
|
"This simply means that this modification is not supported for the Noita version you are using.",
|
|
|
|
"Feel free to open an issue at https://github.com/Dadido3/noita-mapcap.",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|