| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Message
|
Quote:
I'm from China.
I just want to point out that the mapper will handle Unicode text for room names and area names. For example:

The tricky part is the mouseover (tooltip) parts because the tooltips are hard (or impossible) to get Unicode text into.
To work around this I have amended the mapper to detect mouse-overs. See:
https://github.com/nickgammon/mushclient/commit/90c3ce9
Source for mapper.lua:
https://github.com/nickgammon/mushclient/blob/master/lua/mapper.lua
The amended code detects mouse-overs for the rooms, and builds its own tooltip using WindowPolygon and a transparent window which sits on top of the mapper window. This seems to work OK, have fun playing with it.
Plugin changed to display these tooltips:
 |
To save and install the Example_Mapper plugin do this:
- Copy between the lines below (to the Clipboard)
- Open a text editor (such as Notepad) and paste the plugin into it
- Save to disk on your PC, preferably in your plugins directory, as Example_Mapper.xml
- Go to the MUSHclient File menu -> Plugins
- Click "Add"
- Choose the file Example_Mapper.xml (which you just saved in step 3) as a plugin
- Click "Close"
|
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE muclient>
<muclient>
<plugin
name="Example_Mapper"
author="Nick Gammon"
id="63e6909083318cf63707c044"
language="Lua"
purpose="Example mapper"
save_state="y"
date_written="2014-10-22"
requires="4.61"
version="1.0"
>
<description trim="y">
<![CDATA[
AUTOMATIC MAPPER ... by Nick Gammon
ACTIONS
mapper help --> this help (or click the "?" button on the bottom right)
]]>
</description>
</plugin>
<aliases>
<alias
match="mapper help"
script="OnHelp"
enabled="y"
>
</alias>
<alias
match="mapper test"
script="test"
enabled="y"
>
</alias>
</aliases>
<!-- Script -->
<script>
<![CDATA[
-- mapper module
require "mapper"
-- configuration table
config = { }
rooms = {
[1] = {
name = "沼泽",
exits = { n = 2, s = 3, e = 4}
},
[2] = {
name = "酒馆",
exits = { s = 1 }
},
[3] = {
name = "屠夫",
exits = { n = 1 }
},
[4] = {
name = "屠夫",
exits = { w = 1, e = 5 }
},
[5] = {
name = "西大街",
exits = { w = 4 }
},
} -- example rooms table
-- -----------------------------------------------------------------
-- mapper 'mouseover' callback - draw a tooltip
-- -----------------------------------------------------------------
function mouseover_room (uid, flags)
local room = rooms [tonumber (uid)]
if not room then
return
end -- room not found
local hotspot_left = WindowHotspotInfo (mapper.win, uid, 1)
local hotspot_top = WindowHotspotInfo (mapper.win, uid, 2)
local main_left = WindowInfo (mapper.win, 10)
local main_top = WindowInfo (mapper.win, 11)
if not hotspot_left or not hotspot_top then
return
end -- hotspot not found
local message = "*信息*\n" .. room.name
mw.tooltip (win_tooltip, -- window name to use
font_tooltip, -- font to use for each line
bold_font_tooltip, -- font to use for bold lines
message, -- tooltip text
hotspot_left + main_left + 2, hotspot_top + main_top + 3, -- where to put it
0, -- colour for text (black)
0, -- colour for border (black)
tooltip_background_colour) -- colour for background
end -- mouseover_room
function cancelmouseover_room (uid, flags)
WindowShow (win_tooltip, false)
end -- cancelmouseover_room
-- -----------------------------------------------------------------
-- mapper 'get_room' callback - it wants to know about room uid
-- -----------------------------------------------------------------
function get_room (uid)
room = rooms [uid]
if not room then
return nil
end -- if not found
room.area = "悲伤之地" -- OK, let's assume every room is in this area
room.hovermessage = ""
return room
end -- get_room
-- -----------------------------------------------------------------
-- Plugin Install
-- -----------------------------------------------------------------
function OnPluginInstall ()
-- initialize mapper
mapper.init {
config = config, -- ie. colours, sizes
get_room = get_room, -- info about room (uid)
show_help = OnHelp, -- to show help
room_mouseover = mouseover_room,
room_cancelmouseover = cancelmouseover_room,
}
mapper.mapprint (string.format ("MUSHclient mapper installed, version %0.1f", mapper.VERSION))
-- get ready for tooltips
win_tooltip = GetPluginID () .. "_tooltip"
font_tooltip = "tf"
bold_font_tooltip = "tfb"
WindowCreate (win_tooltip, 0, 0, 0, 0, 0, 0, 0)
WindowFont (win_tooltip, font_tooltip, "SimSun", 12)
WindowFont (win_tooltip, bold_font_tooltip, "SimSun", 12, true)
tooltip_background_colour = ColourNameToRGB ("#FFFFE1")
end -- OnPluginInstall
-- -----------------------------------------------------------------
-- Plugin Help
-- -----------------------------------------------------------------
function OnHelp ()
mapper.mapprint (string.format ("[MUSHclient mapper, version %0.1f]", mapper.VERSION))
mapper.mapprint (world.GetPluginInfo (world.GetPluginID (), 3))
end
-- -----------------------------------------------------------------
-- test
-- -----------------------------------------------------------------
function test (name, line, wildcards)
mapper.draw (1) -- draw room 1
end -- test
]]>
</script>
</muclient>
[EDIT] Moved tooltip stuff into mw.lua. Latest version:
https://github.com/nickgammon/mushclient/blob/master/lua/mw.lua
Improved drawing of text boxes (eg. area name, room name) so that text isn't jammed up against the edge. See gauge.lua:
https://github.com/nickgammon/mushclient/blob/master/lua/gauge.lua
Improved screenshot:
 |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|