Skip to content

Commit 26aa02d

Browse files
committed
Tidied up with symbolic constants and neater formatting
1 parent 98b79bc commit 26aa02d

File tree

1 file changed

+122
-64
lines changed

1 file changed

+122
-64
lines changed

lua/mapper.lua

Lines changed: 122 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Date: 11th March 2010
77
Amended: 15th August 2010
88
Amended: 2nd October 2010
99
Amended: 18th October 2010 to added find callback
10+
Amended: 16th November 2010 to add symbolic constants (miniwin.xxxx)
1011
1112
Generic MUD mapper.
1213
@@ -63,7 +64,7 @@ Room info should include:
6364

6465
module (..., package.seeall)
6566

66-
VERSION = 2.2 -- for querying by plugins
67+
VERSION = 2.3 -- for querying by plugins
6768

6869
require "movewindow"
6970
require "copytable"
@@ -312,7 +313,7 @@ local function draw_configuration ()
312313
local frame_width = GAP + width + GAP + rh_size + GAP -- gap / text / gap / box / gap
313314

314315
-- fill entire box with grey
315-
WindowRectOp (win, 2, x, y, x + frame_width, y + font_height * lines + 10, 0xDCDCDC)
316+
WindowRectOp (win, miniwin.rect_fill, x, y, x + frame_width, y + font_height * lines + 10, 0xDCDCDC)
316317
-- frame it
317318
draw_3d_box (win, x, y, frame_width, font_height * lines + 10)
318319

@@ -323,19 +324,37 @@ local function draw_configuration ()
323324
WindowText (win, FONT_ID, "Configuration", x, y, 0, 0, 0x808080, true)
324325

325326
-- close box
326-
WindowRectOp (win, 1, x + frame_width - box_size - GAP * 2, y + 1,
327-
x + frame_width - GAP * 2, y + 1 + box_size, 0x808080)
328-
WindowLine (win, x + frame_width - box_size - GAP * 2 + 3, y + 4,
329-
x + frame_width - GAP * 2 - 3, y - 2 + box_size, 0x808080, 0, 1)
330-
WindowLine (win, x - 4 + frame_width - GAP * 2, y + 4,
331-
x - 1 + frame_width - box_size - GAP * 2 + 3, y - 2 + box_size, 0x808080, 0, 1)
327+
WindowRectOp (win,
328+
miniwin.rect_frame,
329+
x + frame_width - box_size - GAP * 2,
330+
y + 1,
331+
x + frame_width - GAP * 2,
332+
y + 1 + box_size,
333+
0x808080)
334+
WindowLine (win,
335+
x + frame_width - box_size - GAP * 2 + 3,
336+
y + 4,
337+
x + frame_width - GAP * 2 - 3,
338+
y - 2 + box_size,
339+
0x808080,
340+
miniwin.pen_solid, 1)
341+
WindowLine (win,
342+
x - 4 + frame_width - GAP * 2,
343+
y + 4,
344+
x - 1 + frame_width - box_size - GAP * 2 + 3,
345+
y - 2 + box_size,
346+
0x808080,
347+
miniwin.pen_solid, 1)
332348

333349
-- close configuration hotspot
334350
WindowAddHotspot(win, "$<close_configure>",
335-
x + frame_width - box_size - GAP * 2, y + 1, x + frame_width - GAP * 2, y + 1 + box_size, -- rectangle
351+
x + frame_width - box_size - GAP * 2,
352+
y + 1,
353+
x + frame_width - GAP * 2,
354+
y + 1 + box_size, -- rectangle
336355
"", "", "", "", "mapper.mouseup_close_configure", -- mouseup
337356
"Click to close",
338-
1, 0) -- hand cursor
357+
miniwin.cursor_hand, 0) -- hand cursor
339358

340359
y = y + font_height
341360

@@ -344,15 +363,31 @@ local function draw_configuration ()
344363
for k, v in pairsByKeys (config) do
345364
if v.colour then
346365
WindowText (win, FONT_ID, v.name, x, y, 0, 0, 0x000000, true)
347-
WindowRectOp (win, 2, x + width + rh_size / 2, y + 1, x + width + rh_size / 2 + box_size, y + 1 + box_size, v.colour)
348-
WindowRectOp (win, 1, x + width + rh_size / 2, y + 1, x + width + rh_size / 2 + box_size, y + 1 + box_size, 0x000000)
366+
WindowRectOp (win,
367+
miniwin.rect_fill,
368+
x + width + rh_size / 2,
369+
y + 1,
370+
x + width + rh_size / 2 + box_size,
371+
y + 1 + box_size,
372+
v.colour)
373+
WindowRectOp (win,
374+
miniwin.rect_frame,
375+
x + width + rh_size / 2,
376+
y + 1,
377+
x + width + rh_size / 2 + box_size,
378+
y + 1 + box_size,
379+
0x000000)
349380

350381
-- colour change hotspot
351-
WindowAddHotspot(win, "$colour:" .. k,
352-
x + GAP, y + 1, x + width + rh_size / 2 + box_size, y + 1 + box_size, -- rectangle
382+
WindowAddHotspot(win,
383+
"$colour:" .. k,
384+
x + GAP,
385+
y + 1,
386+
x + width + rh_size / 2 + box_size,
387+
y + 1 + box_size, -- rectangle
353388
"", "", "", "", "mapper.mouseup_change_colour", -- mouseup
354389
"Click to change colour",
355-
1, 0) -- hand cursor
390+
miniwin.cursor_hand, 0) -- hand cursor
356391

357392
y = y + font_height
358393
end -- a colour item
@@ -361,63 +396,83 @@ local function draw_configuration ()
361396

362397
-- depth
363398
WindowText (win, FONT_ID, "Depth", x, y, 0, 0, 0x000000, true)
364-
WindowText (win, FONT_ID_UL, tostring (config.SCAN.depth), x + width + GAP, y, 0, 0, 0x808080, true)
399+
WindowText (win, FONT_ID_UL, tostring (config.SCAN.depth), x + width + GAP, y, 0, 0, 0x808080, true)
365400

366401
-- depth hotspot
367-
WindowAddHotspot(win, "$<depth>",
368-
x + GAP, y, x + frame_width, y + font_height, -- rectangle
402+
WindowAddHotspot(win,
403+
"$<depth>",
404+
x + GAP,
405+
y,
406+
x + frame_width,
407+
y + font_height, -- rectangle
369408
"", "", "", "", "mapper.mouseup_change_depth", -- mouseup
370409
"Click to change scan depth",
371-
1, 0) -- hand cursor
410+
miniwin.cursor_hand, 0) -- hand cursor
372411
y = y + font_height
373412

374413
-- font
375414
WindowText (win, FONT_ID, "Font", x, y, 0, 0, 0x000000, true)
376-
WindowText (win, FONT_ID_UL, config.FONT.name .. " " .. config.FONT.size, x + width + GAP, y, 0, 0, 0x808080, true)
415+
WindowText (win, FONT_ID_UL, config.FONT.name .. " " .. config.FONT.size, x + width + GAP, y, 0, 0, 0x808080, true)
377416

378417
-- colour font hotspot
379-
WindowAddHotspot(win, "$<font>",
380-
x + GAP, y, x + frame_width, y + font_height, -- rectangle
418+
WindowAddHotspot(win,
419+
"$<font>",
420+
x + GAP,
421+
y,
422+
x + frame_width,
423+
y + font_height, -- rectangle
381424
"", "", "", "", "mapper.mouseup_change_font", -- mouseup
382425
"Click to change font",
383-
1, 0) -- hand cursor
426+
miniwin.cursor_hand, 0) -- hand cursor
384427
y = y + font_height
385428

386429

387430
-- width
388431
WindowText (win, FONT_ID, "Width", x, y, 0, 0, 0x000000, true)
389-
WindowText (win, FONT_ID_UL, tostring (config.WINDOW.width), x + width + GAP, y, 0, 0, 0x808080, true)
432+
WindowText (win, FONT_ID_UL, tostring (config.WINDOW.width), x + width + GAP, y, 0, 0, 0x808080, true)
390433

391434
-- width hotspot
392-
WindowAddHotspot(win, "$<width>",
393-
x + GAP, y, x + frame_width, y + font_height, -- rectangle
435+
WindowAddHotspot(win,
436+
"$<width>",
437+
x + GAP,
438+
y,
439+
x + frame_width,
440+
y + font_height, -- rectangle
394441
"", "", "", "", "mapper.mouseup_change_width", -- mouseup
395442
"Click to change window width",
396-
1, 0) -- hand cursor
443+
miniwin.cursor_hand, 0) -- hand cursor
397444
y = y + font_height
398445

399446
-- height
400447
WindowText (win, FONT_ID, "Height", x, y, 0, 0, 0x000000, true)
401-
WindowText (win, FONT_ID_UL, tostring (config.WINDOW.height), x + width + GAP, y, 0, 0, 0x808080, true)
448+
WindowText (win, FONT_ID_UL, tostring (config.WINDOW.height), x + width + GAP, y, 0, 0, 0x808080, true)
402449

403450
-- height hotspot
404-
WindowAddHotspot(win, "$<height>",
405-
x + GAP, y, x + frame_width, y + font_height, -- rectangle
451+
WindowAddHotspot(win,
452+
"$<height>",
453+
x + GAP,
454+
y,
455+
x + frame_width,
456+
y + font_height, -- rectangle
406457
"", "", "", "", "mapper.mouseup_change_height", -- mouseup
407458
"Click to change window height",
408-
1, 0) -- hand cursor
459+
miniwin.cursor_hand, 0) -- hand cursor
409460
y = y + font_height
410461

411462
-- delay
412463
WindowText (win, FONT_ID, "Walk delay", x, y, 0, 0, 0x000000, true)
413-
WindowText (win, FONT_ID_UL, tostring (config.DELAY.time), x + width + GAP, y, 0, 0, 0x808080, true)
464+
WindowText (win, FONT_ID_UL, tostring (config.DELAY.time), x + width + GAP, y, 0, 0, 0x808080, true)
414465

415466
-- height hotspot
416-
WindowAddHotspot(win, "$<delay>",
417-
x + GAP, y, x + frame_width, y + font_height, -- rectangle
467+
WindowAddHotspot(win,
468+
"$<delay>",
469+
x + GAP,
470+
y,
471+
x + frame_width,
472+
y + font_height, -- rectangle
418473
"", "", "", "", "mapper.mouseup_change_delay", -- mouseup
419474
"Click to change speedwalk delay",
420-
1, 0) -- hand cursor
475+
miniwin.cursor_hand, 0) -- hand cursor
421476
y = y + font_height
422477

423478
end -- draw_configuration
@@ -519,7 +574,7 @@ local function draw_room (uid, path, x, y)
519574
end -- if down
520575

521576
if exit_info then
522-
local linetype = 0 -- unbroken
577+
local linetype = miniwin.pen_solid -- unbroken
523578
local linewidth = 1 -- not recent
524579

525580
-- try to cache room
@@ -528,7 +583,7 @@ local function draw_room (uid, path, x, y)
528583
end -- if
529584

530585
if rooms [exit_uid].unknown then
531-
linetype = 2 -- dots
586+
linetype = miniwin.pen_dot -- dots
532587
end -- if
533588

534589
local next_x = x + exit_info.at [1] * (ROOM_SIZE + DISTANCE_TO_NEXT_ROOM)
@@ -548,7 +603,7 @@ local function draw_room (uid, path, x, y)
548603

549604
-- here if room leads back to itself
550605
exit_info = stub_exit_info
551-
linetype = 1 -- dash
606+
linetype = miniwin.pen_dash -- dash
552607

553608
else
554609
if (not show_other_areas and rooms [exit_uid].area ~= current_area) or
@@ -559,7 +614,7 @@ local function draw_room (uid, path, x, y)
559614
if plan_to_draw [exit_uid] and plan_to_draw [exit_uid] ~= next_coords then
560615
-- here if room already going to be drawn
561616
exit_info = stub_exit_info
562-
linetype = 1 -- dash
617+
linetype = miniwin.pen_dash -- dash
563618
else
564619
-- remember to draw room next iteration
565620
local new_path = copytable.deep (path)
@@ -579,7 +634,7 @@ local function draw_room (uid, path, x, y)
579634
end -- if
580635
end -- if
581636
end -- if
582-
end -- f
637+
end -- if
583638
end -- if drawn on this spot
584639

585640
WindowLine (win, x + exit_info.x1, y + exit_info.y1, x + exit_info.x2, y + exit_info.y2, exit_line_colour, linetype, linewidth)
@@ -601,7 +656,10 @@ local function draw_room (uid, path, x, y)
601656
y + arrow [6])
602657

603658
-- draw arrow
604-
WindowPolygon(win, points, exit_line_colour, 0, 1, exit_line_colour, 0, true, true)
659+
WindowPolygon(win, points,
660+
exit_line_colour, miniwin.pen_solid, 1,
661+
exit_line_colour, miniwin.brush_solid,
662+
true, true)
605663

606664
end -- one way
607665

@@ -612,33 +670,33 @@ local function draw_room (uid, path, x, y)
612670

613671

614672
if room.unknown then
615-
WindowCircleOp (win, 2, left, top, right, bottom,
616-
config.UNKNOWN_ROOM_COLOUR.colour, 2, 1, -- dotted single pixel pen
617-
-1, 1) -- no brush
673+
WindowCircleOp (win, miniwin.circle_rectangle, left, top, right, bottom,
674+
config.UNKNOWN_ROOM_COLOUR.colour, miniwin.pen_dot, 1, -- dotted single pixel pen
675+
-1, miniwin.brush_null) -- opaque, no brush
618676
else
619-
WindowCircleOp (win, 2, left, top, right, bottom,
620-
0, 5, 0, -- no pen
677+
WindowCircleOp (win, miniwin.circle_rectangle, left, top, right, bottom,
678+
0, miniwin.pen_null, 0, -- no pen
621679
room.fillcolour, room.fillbrush) -- brush
622680

623-
WindowCircleOp (win, 2, left, top, right, bottom,
681+
WindowCircleOp (win, miniwin.circle_rectangle, left, top, right, bottom,
624682
room.bordercolour, room.borderpen, room.borderpenwidth, -- pen
625-
-1, 1) -- no brush
683+
-1, miniwin.brush_null) -- opaque, no brush
626684
end -- if
627685

628686

629687
-- show up and down in case we can't get a line in
630688

631689
if room.exits.u then -- line at top
632-
WindowLine (win, left, top, left + ROOM_SIZE, top, config.EXIT_COLOUR_UP_DOWN.colour, 0, 1)
690+
WindowLine (win, left, top, left + ROOM_SIZE, top, config.EXIT_COLOUR_UP_DOWN.colour, miniwin.pen_solid, 1)
633691
end -- if
634692
if room.exits.d then -- line at bottom
635-
WindowLine (win, left, bottom, left + ROOM_SIZE, bottom, config.EXIT_COLOUR_UP_DOWN.colour, 0, 1)
693+
WindowLine (win, left, bottom, left + ROOM_SIZE, bottom, config.EXIT_COLOUR_UP_DOWN.colour, miniwin.pen_solid, 1)
636694
end -- if
637695
if room.exits ['in'] then -- line at right
638-
WindowLine (win, left + ROOM_SIZE, top, left + ROOM_SIZE, bottom, config.EXIT_COLOUR_IN_OUT.colour, 0, 1)
696+
WindowLine (win, left + ROOM_SIZE, top, left + ROOM_SIZE, bottom, config.EXIT_COLOUR_IN_OUT.colour, miniwin.pen_solid, 1)
639697
end -- if
640698
if room.exits.out then -- line at left
641-
WindowLine (win, left, top, left, bottom, config.EXIT_COLOUR_IN_OUT.colour, 0, 1)
699+
WindowLine (win, left, top, left, bottom, config.EXIT_COLOUR_IN_OUT.colour, miniwin.pen_solid , 1)
642700
end -- if
643701

644702
speedwalks [uid] = path -- so we know how to get here
@@ -651,7 +709,7 @@ local function draw_room (uid, path, x, y)
651709
"", -- cancelmousedown
652710
"mapper.mouseup_room", -- mouseup
653711
room.hovermessage,
654-
1, 0) -- hand cursor
712+
miniwin.cursor_hand, 0) -- hand cursor
655713

656714
end -- draw_room
657715

@@ -706,23 +764,23 @@ local function draw_zone_exit (exit)
706764
local offset = ROOM_SIZE
707765

708766
-- draw circle around us
709-
WindowCircleOp (win, 1,
767+
WindowCircleOp (win, miniwin.circle_ellipse,
710768
x - offset, y - offset,
711769
x + offset, y + offset,
712770
ColourNameToRGB "cornflowerblue", -- pen colour
713-
0, -- solid pen
771+
miniwin.pen_solid, -- solid pen
714772
3, -- pen width
715773
0, -- brush colour
716-
1 ) -- null brush
774+
miniwin.brush_null) -- null brush
717775

718-
WindowCircleOp (win, 1,
776+
WindowCircleOp (win, miniwin.circle_ellipse,
719777
x - offset, y - offset,
720778
x + offset, y + offset,
721779
ColourNameToRGB "cyan", -- pen colour
722-
0, -- solid pen
780+
miniwin.pen_solid, -- solid pen
723781
1, -- pen width
724782
0, -- brush colour
725-
1 ) -- null brush
783+
miniwin.brush_null) -- null brush
726784

727785
end -- draw_zone_exit
728786

@@ -970,7 +1028,7 @@ function draw (uid)
9701028
"", -- cancelmousedown
9711029
"mapper.mouseup_configure", -- mouseup
9721030
"Click to configure map",
973-
1, 0) -- hand cursor
1031+
miniwin.cursor_hand, 0) -- hand cursor
9741032
end -- if
9751033

9761034
if type (show_help) == "function" then
@@ -992,7 +1050,7 @@ function draw (uid)
9921050
"", -- cancelmousedown
9931051
"mapper.show_help", -- mouseup
9941052
"Click for help",
995-
1, 0) -- hand cursor
1053+
miniwin.cursor_hand, 0) -- hand cursor
9961054
end -- if
9971055

9981056
-- 3D box around whole thing
@@ -1061,7 +1119,7 @@ function init (t)
10611119
font_height = WindowFontInfo (win, FONT_ID, 1) -- height
10621120

10631121
-- find where window was last time
1064-
windowinfo = movewindow.install (win, 7)
1122+
windowinfo = movewindow.install (win, miniwin.pos_center_right)
10651123

10661124
-- calculate box sizes, arrows, connecting lines etc.
10671125
build_room_info ()
@@ -1376,7 +1434,7 @@ end -- cancel_speedwalk
13761434
function mouseup_room (flags, hotspot_id)
13771435
local uid = hotspot_id
13781436

1379-
if bit.band (flags, 0x20) ~= 0 then
1437+
if bit.band (flags, miniwin.hotspot_got_rh_mouse) ~= 0 then
13801438

13811439
-- RH click
13821440

@@ -1390,7 +1448,7 @@ function mouseup_room (flags, hotspot_id)
13901448
-- here for LH click
13911449

13921450
-- Control key down?
1393-
if bit.band (flags, 0x02) ~= 0 then
1451+
if bit.band (flags, miniwin.hotspot_got_control) ~= 0 then
13941452
cancel_speedwalk ()
13951453
return
13961454
end -- if ctrl-LH click

0 commit comments

Comments
 (0)