Skip to content

Commit 9e3bf18

Browse files
committed
Add a "do not show again" option to prerelease-warning
1 parent 64fc377 commit 9e3bf18

File tree

1 file changed

+99
-17
lines changed

1 file changed

+99
-17
lines changed

gui/prerelease-warning.lua

Lines changed: 99 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,81 @@ gui/prerelease-warning
55
======================
66
Shows a warning on world load for pre-release builds.
77
8+
With no arguments passed, the warning is shown unless the "do not show again"
9+
option has been selected. With the ``force`` argument, the warning is always
10+
shown.
11+
812
=end]]
913

10-
shown = shown or false
11-
if shown then return end
12-
if not dfhack.isPrerelease() then qerror('not a prerelease build') end
14+
local gui = require 'gui'
15+
local dlg = require 'gui.dialogs'
16+
local json = require 'json'
17+
local utils = require 'utils'
18+
19+
local force = ({...})[1] == 'force'
20+
local config = json.open('dfhack-config/prerelease-warning.json')
21+
22+
if config.data.hide and not force then
23+
return
24+
end
25+
if not dfhack.isPrerelease() and not force then
26+
qerror('not a prerelease build')
27+
end
1328
-- Don't fire during worldgen
14-
if dfhack.internal.getAddress('gametype') and df.global.gametype == df.game_type.NONE then
29+
if dfhack.internal.getAddress('gametype') and df.global.gametype == df.game_type.NONE and not force then
1530
return
1631
end
1732

18-
local gui = require 'gui'
19-
local dlg = require 'gui.dialogs'
20-
local utils = require 'utils'
33+
local state = dfhack.getDFHackRelease():lower():match('[a-z]+')
34+
if not utils.invert{'alpha', 'beta', 'rc', 'r'}[state] then
35+
dfhack.printerr('warning: unknown release state: ' .. state)
36+
state = 'unknown'
37+
end
38+
39+
40+
message = ({
41+
alpha = {
42+
'Warning',
43+
COLOR_YELLOW,
44+
'This is an alpha build of DFHack. Some structures are likely', NEWLINE,
45+
'to be incorrect, resulting in crashes or save corruption', NEWLINE,
46+
{pen=COLOR_LIGHTRED, text='Make backups of your saves often!'}
47+
},
48+
beta = {
49+
'Warning',
50+
COLOR_YELLOW,
51+
'This is a beta release of DFHack. It is more stable than an', NEWLINE,
52+
'alpha release, but bugs are still possible, possibly including', NEWLINE,
53+
'crashes and save corruption.', NEWLINE,
54+
'Make backups of your saves beforehand to be safe.'
55+
},
56+
rc = {
57+
'Notice',
58+
COLOR_YELLOW,
59+
'This is a DFHack release candidate. It is fairly stable but', NEWLINE,
60+
'likely contains newer features that are not fully-tested.', NEWLINE,
61+
'Crashes are unlikely, but always make backups of your saves', NEWLINE,
62+
'to be safe.'
63+
},
64+
r = {
65+
'Error',
66+
COLOR_LIGHTRED,
67+
'This release is flagged as a prerelease but named as a', NEWLINE,
68+
'stable release.', NEWLINE,
69+
{pen=COLOR_LIGHTMAGENTA, text='Please report this to the DFHack team or a pack maintainer.'}
70+
},
71+
unknown = {
72+
'Error',
73+
COLOR_LIGHTMAGENTA,
74+
'Unknown prerelease DFHack build. This should never happen!', NEWLINE,
75+
'Please report this to the DFHack team or a pack maintainer.'
76+
}
77+
})[state]
2178

22-
message = {
23-
'This is a prerelease build of DFHack. Some structures are likely', NEWLINE,
24-
'to be incorrect, resulting in crashes or save corruption', NEWLINE,
25-
{pen=COLOR_LIGHTRED, text='Make backups of your saves often!'},
26-
}
79+
title = table.remove(message, 1)
80+
color = table.remove(message, 1)
2781

28-
pack_message = pack_message or [[
82+
pack_message = [[
2983
3084
This should not be enabled by default in a pack.
3185
If you are seeing this message and did not enable/install DFHack
@@ -37,7 +91,6 @@ if #pack_message > 0 and (path:find('lnp') or path:find('starter') or path:find(
3791
table.insert(message, NEWLINE)
3892
table.insert(message, {text=v, pen=COLOR_LIGHTMAGENTA})
3993
end
40-
pack_message = ''
4194
end
4295

4396
dfhack.print('\n')
@@ -47,13 +100,42 @@ for k,v in ipairs(message) do
47100
dfhack.color(v.pen)
48101
dfhack.print(v.text)
49102
else
50-
dfhack.color(COLOR_YELLOW)
103+
dfhack.color(color)
51104
dfhack.print(v)
52105
end
53106
end
54107

55108
dfhack.color(COLOR_RESET)
56109
dfhack.print('\n\n')
57110

58-
dlg.showMessage('Warning', message, COLOR_YELLOW)
59-
shown = true
111+
WarningBox = defclass(nil, dlg.MessageBox)
112+
113+
function WarningBox:getWantedFrameSize()
114+
local w, h = WarningBox.super.getWantedFrameSize(self)
115+
return w, h + 2
116+
end
117+
118+
function WarningBox:onRenderFrame(dc,rect)
119+
WarningBox.super.onRenderFrame(self,dc,rect)
120+
dc:pen(COLOR_WHITE):key_pen(COLOR_LIGHTRED)
121+
:seek(rect.x1 + 2, rect.y2 - 2)
122+
:key('CUSTOM_D'):string(': Do not show again')
123+
:advance(10)
124+
:key('LEAVESCREEN'):string('/')
125+
:key('SELECT'):string(': Dismiss')
126+
end
127+
128+
function WarningBox:onInput(keys)
129+
if keys.CUSTOM_D then
130+
config.data.hide = true
131+
config:write()
132+
keys.LEAVESCREEN = true
133+
end
134+
WarningBox.super.onInput(self, keys)
135+
end
136+
137+
WarningBox{
138+
frame_title = title,
139+
text = message,
140+
text_pen = color
141+
}:show()

0 commit comments

Comments
 (0)