Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ A question about mapper.lua.

A question about mapper.lua.

It is now over 60 days since the last post. This thread is closed.     Refresh page


Pages: 1  2 

Posted by Lzkd   (28 posts)  Bio
Date Reply #15 on Sun 09 Nov 2014 04:06 AM (UTC)

Amended on Sun 09 Nov 2014 04:14 AM (UTC) by Lzkd

Message
But the final results.

Removed plugin Example_Mapper (63e6909083318cf63707c044)
MUSHclient mapper installed, version 2.5
Added plugin D:\MUSHclient\worlds\plugins\t_maper.xml
table: 022F4F58
b = 1
c = 1
4:
  "reason"=true
  "path":
    1:
      "uid"=4
      "dir"="e"


I just want to get the room 1 to room 5 path.But this is not what I want.
Please tell me, how can I do, to get what I want.
Thank you again to spend valuable time, read my post.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #16 on Sun 09 Nov 2014 06:52 AM (UTC)
Message
Change the function to:


---------################ Here is my own to add. ##############-----
function find_test ()
current = 1   -- where we start
wanted = 5    -- where we want to go

	a, b, c = mapper.find_paths(current, 
	           function (uid)
             return uid == wanted,  -- wanted room?
                    uid == wanted   -- stop searching?
            end)
	print(a)
	print("b = "..b)
	print("c = "..c)
	tprint(a)
end


It searches until this is true:


 function (uid)
             return uid == wanted,  -- wanted room?
                    uid == wanted   -- stop searching?
            end)


That is the current uid is equal to the wanted uid.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #17 on Sun 09 Nov 2014 06:54 AM (UTC)
Message
"stop searching" is for deciding if one match will do. For example, to find a room, a single match will stop the search.

For finding (say) shops, you might get many shops.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #18 on Sun 09 Nov 2014 06:55 AM (UTC)
Message
Results of modified code:


b = 2
c = 2
5:
  "reason"=true
  "path":
    1:
      "dir"="e"
      "uid"=4
    2:
      "uid"=5
      "dir"="e"


It is two rooms to the east, taking a depth of 2 rooms search.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Lzkd   (28 posts)  Bio
Date Reply #19 on Sun 09 Nov 2014 09:40 AM (UTC)
Message
Thank you very much, I think I get what I want.
Thanks again for your kind help.
The hope can quickly draw the map.Go!Go!!Go!!!
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #20 on Tue 11 Nov 2014 12:10 AM (UTC)

Amended on Wed 12 Nov 2014 03:27 AM (UTC) by Nick Gammon

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:

Template:saveplugin=Example_Mapper To save and install the Example_Mapper plugin do this:
  1. Copy between the lines below (to the Clipboard)
  2. Open a text editor (such as Notepad) and paste the plugin into it
  3. Save to disk on your PC, preferably in your plugins directory, as Example_Mapper.xml
  4. Go to the MUSHclient File menu -> Plugins
  5. Click "Add"
  6. Choose the file Example_Mapper.xml (which you just saved in step 3) as a plugin
  7. 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

Posted by Lzkd   (28 posts)  Bio
Date Reply #21 on Tue 11 Nov 2014 10:40 AM (UTC)
Message
Hi,Nick

It's amazing to me!!!
This looks really interesting.I must have a good research.
Thank you again for your guidance.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #22 on Wed 12 Nov 2014 03:21 AM (UTC)

Amended on Wed 12 Nov 2014 03:24 AM (UTC) by Nick Gammon

Message
I made a few more changes to mw.lua.

Now the tooltip has rounded corners, and you can put lines in bold, like this:



The plugin above has been amended slightly to allow you to supply a bold font to the tooltip function.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Lzkd   (28 posts)  Bio
Date Reply #23 on Thu 13 Nov 2014 01:19 AM (UTC)
Message
Nick Gammon said:


The plugin above has been amended slightly to allow you to supply a bold font to the tooltip function.


Wa!!!!

This is too strong.This can be turned into a very beautiful.
I love MUSHclient.I love Nick.
Top

Posted by Lzkd   (28 posts)  Bio
Date Reply #24 on Sat 15 Nov 2014 01:57 AM (UTC)

Amended on Sat 15 Nov 2014 02:29 AM (UTC) by Lzkd

Message
Hi,Nick

I did some tests.Has been unable to solve the problem.
I updated it several files.mapper.lua,mw.lua,gauge.lua
Then loading plug-ins.Finally get the same result.
------
Sorry, I don't know how the pictures.Please click this link.
http://i.imgur.com/gKypHAh.jpg
------
I have been looking for, where it is wrong.Finally, I noted.

<?xml version="1.0" encoding="utf-8"?>


I think, may be the cause of UTF-8.I will save the plugin, into utf-8.Then the success of the show.
-------
Please click this link.
http://i.imgur.com/le2Xrcd.jpg
-------
But, in my world.I can't get utf-8.Just to get GBK(GB2312).Excuse me, this method can be solved?
Thank you again for your help, and attention to this post.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #25 on Sat 15 Nov 2014 03:05 AM (UTC)
Message
Can't you use Notepad and use UTF-8?

I don't know of any easy way of converting from GB2312 to UTF-8.

You could try:

http://www.gammon.com.au/scripts/doc.php?lua=utils.utf8convert

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #26 on Sat 15 Nov 2014 03:26 AM (UTC)
Message
Also see iconv

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Lzkd   (28 posts)  Bio
Date Reply #27 on Sat 15 Nov 2014 08:47 AM (UTC)

Amended on Sat 15 Nov 2014 08:50 AM (UTC) by Lzkd

Message
Nick Gammon said:

Can't you use Notepad and use UTF-8?

I don't know of any easy way of converting from GB2312 to UTF-8.

You could try:

http://www.gammon.com.au/scripts/doc.php?lua=utils.utf8convert


Hi,Nick
Thank you for your guidance.I think I completed the expected effect.However, instead of using utils.utf8convert() to complete.I search to a DLL file, it can be completed GB2312 to utf-8.

Thank you again for your concern and help.
Top

Posted by Lzkd   (28 posts)  Bio
Date Reply #28 on Sun 16 Nov 2014 12:59 AM (UTC)
Message
Nick Gammon said:

Can't you use Notepad and use UTF-8?



Hi,Nick

Yesterday forgot to explain.I can make my notepad use utf-8.But in my world, the string can be, are gb2312.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #29 on Sun 16 Nov 2014 10:42 PM (UTC)
Message
I don't understand that, and I'm not sure of how to answer it.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


89,610 views.

This is page 2, subject is 2 pages long:  [Previous page]  1  2 

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.