@@ -5,27 +5,81 @@ gui/prerelease-warning
5
5
======================
6
6
Shows a warning on world load for pre-release builds.
7
7
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
+
8
12
=end]]
9
13
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
13
28
-- 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
15
30
return
16
31
end
17
32
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 ]
21
78
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 )
27
81
28
- pack_message = pack_message or [[
82
+ pack_message = [[
29
83
30
84
This should not be enabled by default in a pack.
31
85
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(
37
91
table.insert (message , NEWLINE )
38
92
table.insert (message , {text = v , pen = COLOR_LIGHTMAGENTA })
39
93
end
40
- pack_message = ' '
41
94
end
42
95
43
96
dfhack .print (' \n ' )
@@ -47,13 +100,42 @@ for k,v in ipairs(message) do
47
100
dfhack .color (v .pen )
48
101
dfhack .print (v .text )
49
102
else
50
- dfhack .color (COLOR_YELLOW )
103
+ dfhack .color (color )
51
104
dfhack .print (v )
52
105
end
53
106
end
54
107
55
108
dfhack .color (COLOR_RESET )
56
109
dfhack .print (' \n\n ' )
57
110
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