Add capture grid size check

- Check if capture grid size is smaller than the virtual resolution
- Automatically close resolved messages
This commit is contained in:
David Vogel 2022-07-29 20:44:36 +02:00
parent a2cb806ffa
commit 3fa95de8e6
3 changed files with 51 additions and 3 deletions

View File

@ -46,6 +46,9 @@ function Check:Regular(interval)
if self.Counter > 0 then return end
self.Counter = interval
-- Remove some messages, so they will automatically disappear when the problem is solved.
Message:CloseAutoclose()
-- Compare Noita config and actual window resolution.
local topLeft, bottomRight = ScreenCap.GetRect() -- Actual window client area.
if topLeft and bottomRight then
@ -107,4 +110,20 @@ function Check:Regular(interval)
end
end
-- Check if capture grid size is smaller than the virtual resolution.
-- This is not perfect, as it doesn't take rounding and cropping into account, so the actual captured area may be a few pixels smaller.
local mode = ModSettingGet("noita-mapcap.capture-mode")
local captureGridSize = tonumber(ModSettingGet("noita-mapcap.grid-size"))
if mode ~= "live" and (Coords.VirtualResolution.x < captureGridSize or Coords.VirtualResolution.y < captureGridSize) then
Message:ShowGeneralSettingsProblem(
"The virtual resolution is smaller than the capture grid size.",
"This means that you will get black areas in your final stitched image.",
" ",
"Apply either of the following in the mod settings:",
string.format("- Set the grid size to at most %s.", math.min(Coords.VirtualResolution.x, Coords.VirtualResolution.y)),
string.format("- Increase the custom resolutions to at least %s in any direction.", captureGridSize),
"- Change capture mode to `live`."
)
end
end

View File

@ -17,6 +17,18 @@ local Coords = require("coordinates")
-- Code --
----------
---Removes all messages with the autoclose flag.
---Use this before you recreate all auto closing messages.
function Message:CloseAutoclose()
self.List = self.List or {}
for k, message in pairs(self.List) do
if message.Autoclose then
self.List[k] = nil
end
end
end
---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
@ -82,6 +94,7 @@ function Message:ShowSetNoitaSettings(callback, desc)
Actions = {
{ Name = "Setup and close (May corrupt current save!)", Hint = nil, HintDesc = nil, Callback = callback },
},
Autoclose = true, -- This message will automatically close.
}
end
@ -98,6 +111,7 @@ function Message:ShowRequestRestart(desc)
" ",
"To resolve this issue, restart the game.",
},
Autoclose = true, -- This message will automatically close.
}
end
@ -118,6 +132,7 @@ function Message:ShowWrongResolution(callback, desc)
Actions = {
{ Name = "Query settings again", Hint = nil, HintDesc = nil, Callback = function() Coords:ReadResolutions() end },
},
Autoclose = true, -- This message will automatically close.
}
end
@ -139,6 +154,18 @@ function Message:ShowOutputNonEmpty()
}
end
---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 = { ... },
Autoclose = true, -- This message will automatically close.
}
end
---Tell the user that there is something wrong with the mod installation.
---@param ... string
function Message:ShowGeneralInstallationProblem(...)

View File

@ -114,9 +114,11 @@ function UI:_DrawMessages(messages)
end
GuiLayoutEnd(gui)
local clicked = GuiImageButton(gui, self:_GenID(), 5, 0, "", "mods/noita-mapcap/files/ui-gfx/dismiss-8x8.png")
--GuiTooltip(gui, "Dismiss message", "")
if clicked then messages[key] = nil end
if not message.Autoclose then
local clicked = GuiImageButton(gui, self:_GenID(), 5, 0, "", "mods/noita-mapcap/files/ui-gfx/dismiss-8x8.png")
--GuiTooltip(gui, "Dismiss message", "")
if clicked then messages[key] = nil end
end
GuiLayoutEnd(gui)