|
5 | 5 | Author: Nick Gammon
|
6 | 6 | Date: 11th March 2010
|
7 | 7 | Amended: 15th August 2010
|
| 8 | +Amended: 2nd October 2010 |
8 | 9 |
|
9 | 10 | Generic MUD mapper.
|
10 | 11 |
|
@@ -61,7 +62,7 @@ Room info should include:
|
61 | 62 |
|
62 | 63 | module (..., package.seeall)
|
63 | 64 |
|
64 |
| -VERSION = 2.0 -- for querying by plugins |
| 65 | +VERSION = 2.1 -- for querying by plugins |
65 | 66 |
|
66 | 67 | require "movewindow"
|
67 | 68 | require "copytable"
|
@@ -230,25 +231,54 @@ local function check_connected ()
|
230 | 231 | return true
|
231 | 232 | end -- check_connected
|
232 | 233 |
|
233 |
| -local function get_number_from_user (msg, title, current, min, max) |
234 |
| - local n = utils.inputbox (msg, title, current) |
| 234 | +local function make_number_checker (title, min, max, decimals) |
| 235 | + return function (s) |
| 236 | + local n = tonumber (s) |
| 237 | + if not n then |
| 238 | + utils.msgbox (title .. " must be a number", "Incorrect input", "ok", "!", 1) |
| 239 | + return false -- bad input |
| 240 | + end -- if |
| 241 | + |
| 242 | + if n < min or n > max then |
| 243 | + utils.msgbox (title .. " must be in range " .. min .. " to " .. max, "Incorrect input", "ok", "!", 1) |
| 244 | + return false -- bad input |
| 245 | + end -- if |
235 | 246 |
|
236 |
| - if not n then |
237 |
| - return nil |
238 |
| - end -- if dismissed |
| 247 | + if not decimals then |
| 248 | + if string.match (s, "%.") then |
| 249 | + utils.msgbox (title .. " cannot have decimal places", "Incorrect input", "ok", "!", 1) |
| 250 | + return false -- bad input |
| 251 | + end -- if |
| 252 | + end -- no decimals |
| 253 | + |
| 254 | + return true -- good input |
| 255 | + end -- generated function |
239 | 256 |
|
240 |
| - n = tonumber (n) |
241 |
| - if not n then |
242 |
| - utils.msgbox ("You must enter a number", "Incorrect input", "ok", "!", 1) |
243 |
| - return nil |
244 |
| - end -- if |
| 257 | +end -- make_number_checker |
| 258 | + |
| 259 | + |
| 260 | +local function get_number_from_user (msg, title, current, min, max, decimals) |
| 261 | + local max_length = math.ceil (math.log10 (max) + 1) |
245 | 262 |
|
246 |
| - if n < min or n > max then |
247 |
| - utils.msgbox (title .. " must be in range " .. min .. " to " .. max, "Incorrect input", "ok", "!", 1) |
248 |
| - return nil |
| 263 | + -- if decimals allowed, allow room for them |
| 264 | + if decimals then |
| 265 | + max_length = max_length + 2 -- allow for 0.x |
249 | 266 | end -- if
|
250 |
| - |
251 |
| - return n |
| 267 | + |
| 268 | + -- if can be negative, allow for minus sign |
| 269 | + if min < 0 then |
| 270 | + max_length = max_length + 1 |
| 271 | + end -- if can be negative |
| 272 | + |
| 273 | + return tonumber (utils.inputbox (msg, title, current, nil, nil, |
| 274 | + { validate = make_number_checker (title, min, max, decimals), |
| 275 | + prompt_height = 14, |
| 276 | + box_height = 130, |
| 277 | + box_width = 300, |
| 278 | + reply_width = 150, |
| 279 | + max_length = max_length, |
| 280 | + } -- end extra stuff |
| 281 | + )) |
252 | 282 | end -- get_number_from_user
|
253 | 283 |
|
254 | 284 | local function draw_configuration ()
|
@@ -1452,7 +1482,7 @@ end -- mouseup_change_depth
|
1452 | 1482 |
|
1453 | 1483 | function mouseup_change_delay (flags, hotspot_id)
|
1454 | 1484 |
|
1455 |
| - local delay = get_number_from_user ("Choose speedwalk delay time (0 to 10 seconds)", "Delay in seconds", config.DELAY.time, 0, 10) |
| 1485 | + local delay = get_number_from_user ("Choose speedwalk delay time (0 to 10 seconds)", "Delay in seconds", config.DELAY.time, 0, 10, true) |
1456 | 1486 |
|
1457 | 1487 | if not delay then
|
1458 | 1488 | return
|
|
0 commit comments