mirror of
https://github.com/Dadido3/noita-mapcap.git
synced 2024-11-22 21:17:33 +00:00
David Vogel
31fc11ef1b
- Modernise UI, and simplify its logic - Add UI graphics - Add modification.lua which contains everything to modify Noita settings - Add message.lua which handles messages for users - Add check.lua which checks things, triggers messages and suggest user actions - Remove ACTIONS category from settings - Add more live capturing parameters to settings - Restrict vector input fields in settings - Rename pixel-size setting to pixel-scale - Let GetRect return two vectors instead of RECT object - Add VirtualOffsetPixelPerfect and FullscreenMode field to Coords - Fix captureScreenshot when the outputPixelScale is 0 - Show runtime errors in UI via message.lua - Other small fixes
134 lines
3.7 KiB
Lua
134 lines
3.7 KiB
Lua
-- 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 --
|
|
----------
|
|
|
|
---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)
|
|
local ok, err = pcall(func)
|
|
if not ok then
|
|
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",
|
|
" ",
|
|
"Press the following button to reset the settings and close Noita automatically:",
|
|
},
|
|
Actions = {
|
|
{ Name = "Reset and close", Hint = nil, HintDesc = nil, Callback = function() Modification:Reset() end },
|
|
},
|
|
}
|
|
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.",
|
|
"Alternatively disable `Use custom resolution` in the mod settings.",
|
|
" ",
|
|
"You can always reset these settings by right clicking the `start capture`",
|
|
"button at the top left.",
|
|
},
|
|
Actions = {
|
|
{ Name = "Setup and close", Hint = nil, HintDesc = nil, Callback = callback },
|
|
},
|
|
}
|
|
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:ShowWrongResolution(callback, desc)
|
|
self.List = self.List or {}
|
|
|
|
self.List["WrongResolution"] = {
|
|
Type = "warning",
|
|
Lines = {
|
|
"The resolution changed:",
|
|
desc or "",
|
|
" ",
|
|
"To fix: Restart Noita or revert the change."
|
|
},
|
|
Actions = {
|
|
{ Name = "Query settings again", Hint = nil, HintDesc = nil, Callback = function() Coords:ReadResolutions() end },
|
|
},
|
|
}
|
|
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
|
|
|
|
---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
|