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 ➜ Miniwindows ➜ Displaying doors on Mapper, and drawing images for room (for shops, forges, etc)

Displaying doors on Mapper, and drawing images for room (for shops, forges, etc)

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


Pages: 1 2  3  4  

Posted by Death   (55 posts)  Bio
Date Wed 13 Mar 2019 10:46 AM (UTC)
Message
Hey all,

I've scoured the internet for weeks looking for this, but I've not seen it anywhere.

I'm trying to add a RED line (or any color) on the room BORDER, but only on the side the door is on.

I get [Exits: down ] [Doors: north south west ] from my mud, so I can use this information to let the mapper know where the doors are.

The code involving mapper.lua for drawing the walls is kind of hard to understand.

Might I get a tip on how to do something like this?

All help would be appreciated.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #1 on Wed 13 Mar 2019 09:46 PM (UTC)
Message
The code in mapper.lua around line 695 shows how to draw a line to indicate an exit up, down, in or out:


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

  if room.exits.u then  -- line at top
    WindowLine (win, left, top, left + ROOM_SIZE, top, config.EXIT_COLOUR_UP_DOWN.colour, miniwin.pen_solid, 1)
  end -- if
  if room.exits.d then  -- line at bottom
    WindowLine (win, left, bottom, left + ROOM_SIZE, bottom, config.EXIT_COLOUR_UP_DOWN.colour, miniwin.pen_solid, 1)
  end -- if
  if room.exits ['in'] then  -- line at right
    WindowLine (win, left + ROOM_SIZE, top, left + ROOM_SIZE, bottom, config.EXIT_COLOUR_IN_OUT.colour, miniwin.pen_solid, 1)
  end -- if
  if room.exits.out then  -- line at left
    WindowLine (win, left, top, left, bottom, config.EXIT_COLOUR_IN_OUT.colour, miniwin.pen_solid , 1)
  end -- if



That basically shows the idea for drawing a line on top of the square that represents the room. You could copy and paste that, changing the "if" tests from whether there is an exit to whether there is a door, and perhaps change the colour and line thickness as desired.

- Nick Gammon

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

Posted by Death   (55 posts)  Bio
Date Reply #2 on Thu 14 Mar 2019 03:41 AM (UTC)
Message
Thanks Nick, I'll be playing with it.

I'm under the impression that its possible to replace tiles (fillcolours) with actual images, as explained in

[link]http://gammon.com.au/mushclient/mw_images.htm[/link]

Something like placing something like this

[link]https://rlv.zcache.co.uk/pentacle_tile-r942424ed13c14d71a0988b61a926d94e_agtk1_8byvr_307.jpg[/link]

over a tile, to show that the room is a waypoint.

I've searched the internet for a long time, and can't find any examples. Is this shown somewhere, or can you help me figure out how it might happen?
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #3 on Thu 14 Mar 2019 04:06 AM (UTC)
Message
If you want to show a single image, the simpler thing would be to just draw the image with WindowDrawImage. Tiles are more for if you want repetition (eg. bricks).

You already know the coordinates so, to borrow from that page, it would be something like:



-- do this once near the start once the mapper window has been created
WindowLoadImage (win, "waypoint", "/some_folder/waypoint.bmp")


-- in the draw_room function:
if (some_condition)
  WindowDrawImage (win, "waypoint", left, top, right, bottom, miniwin.image_stretch)  -- stretch to fill

- Nick Gammon

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

Posted by Death   (55 posts)  Bio
Date Reply #4 on Thu 14 Mar 2019 04:23 AM (UTC)
Message
Hey Nick,

Just to be clear:

this is to draw that image as one of the squares that usually shows on the mapper, instead of a square filled with terrain color, right?


so something like


      if string.match (room.info, "waypoint") then
 WindowDrawImage (win, "waypoint", left, top, right, bottom, miniwin.image_stretch)  -- stretch to fill


would be right?
Top

Posted by Death   (55 posts)  Bio
Date Reply #5 on Thu 14 Mar 2019 07:35 AM (UTC)

Amended on Thu 14 Mar 2019 07:50 AM (UTC) by Death

Message
Hey Nick,
[FIXED] ---- by putting this line here instead of at the beginning of the draw_room function (at the end)
    if string.match (room.info, "waypoint") then
     WindowDrawImage (win, "waypoint", left, top, right, bottom, miniwin.image_stretch)  -- stretch to fill
	 end 
end -- draw_room


I've added the bold code in my mapper.lua as follows:

local function get_room (uid)
   local room = supplied_get_room (uid)
   room = room or { unknown = true }

   -- defaults in case they didn't supply them ...
   room.name = room.name or string.format ("Room %s", uid)
   room.name = mw.strip_colours (room.name)  -- no colour codes for now
   room.exits = room.exits or {}
   room.area = room.area or "<No area>"
   room.hovermessage = room.hovermessage or "<Unexplored room>"
   room.bordercolour = room.bordercolour or ROOM_COLOUR.colour
   room.borderpen = room.borderpen or 0 -- solid
   room.borderpenwidth = room.borderpenwidth or 1
   room.fillcolour = room.fillcolour or 0x000000
   room.fillbrush = room.fillbrush or 1 -- no fill
   room.texture = room.texture or nil -- no texture
   WindowLoadImage (win, "waypoint", "worlds\plugins\images\waypoint.bmp")
   room.textimage = nil

   if room.texture == nil or room.texture == "" then room.texture = "test5.png" end
   if textures[room.texture] then
      room.textimage = textures[room.texture] -- assign image
   else
      if textures[room.texture] ~= false then
         local dir = GetInfo(66)
         imgpath = dir .. "worlds\plugins\images\" ..room.texture
         if WindowLoadImage(win, room.texture, imgpath) ~= 0 then
            textures[room.texture] = false  -- just indicates not found
         else
            textures[room.texture] = room.texture -- imagename
            room.textimage = room.texture
         end
      end
   end

   return room

end -- get_room



and in my draw_room
local function draw_room (uid, path, x, y)


 if string.match (room.info, "waypoint") then
     WindowDrawImage (win, "waypoint", left, top, right, bottom, miniwin.image_stretch)  -- stretch to fill
	 end

   local coords = string.format ("%i,%i", math.floor (x), math.floor (y))

   -- need this for the *current* room !!!
   drawn_coords [coords] = uid

   -- print ("drawing", uid, "at", coords)

   if drawn [uid] then
      return
   end -- done this one

   -- don't draw the same room more than once
   drawn [uid] = { coords = coords, path = path }

   local room = rooms [uid]

   -- not cached - get from caller
   if not room then
      room = get_room (uid)
      rooms [uid] = room
   end -- not in cache



I tried, and removed this code from my actual mapper plugin

      if string.match (room.info, "waypoint") then
 WindowDrawImage (win, "waypoint", left, top, right, bottom, miniwin.image_stretch)  -- stretch to fill

^^^ should I have done load?
All special rooms normally load via fillcolour as follows
      elseif string.match (room.info, "guild") then
         special_room = true
         room.fillcolour = mapper.GUILD_FILL_COLOUR.colour
         room.fillbrush = 0 -- solid


I've set the room.info to waypoint, and I'm getting this.


Run-time error
Plugin: DemonMUSH_Mapper (called from world: Demonclient)
Immediate execution
...\Master Vivi\Desktop\MUSHclient\lua\altermapper.lua:545: attempt to index global 'room' (a nil value)
stack traceback:
        ...\Master Vivi\Desktop\MUSHclient\lua\altermapper.lua:545: in function 'draw_room'
        ...\Master Vivi\Desktop\MUSHclient\lua\altermapper.lua:980: in function 'draw'
        [string "Plugin: DemonMUSH_Mapper"]:240: in function 'process_exits'
        [string "Trigger: Exits_Line"]:1: in main chunk


I tried again, but this time I modified it by adding this part again
   if room.info and room.info ~= "" then
      if string.match (room.info, "shop") then
         room.fillcolour = mapper.SHOP_FILL_COLOUR.colour
   room.fillbrush = 8  -- medium pattern
 elseif string.match (room.info, "waypoint") then
     WindowDrawImage (win, "waypoint", left, top, right, bottom, miniwin.image_stretch)  -- stretch to fill
      elseif string.match (room.info, "guild") then
         room.fillcolour = mapper.GUILD_FILL_COLOUR.colour
         room.fillbrush = 0 -- solid


and now I get
Run-time error
Plugin: DemonMUSH_Mapper (called from world: Demonclient)
Immediate execution
[string "Plugin: DemonMUSH_Mapper"]:323: bad argument #6 to 'WindowDrawImage' (number expected, got nil)
stack traceback:
        [C]: in function 'WindowDrawImage'
        [string "Plugin: DemonMUSH_Mapper"]:323: in function 'supplied_get_room'
        ...\Master Vivi\Desktop\MUSHclient\lua\altermapper.lua:250: in function 'get_room'
        ...\Master Vivi\Desktop\MUSHclient\lua\altermapper.lua:914: in function 'draw'
        [string "Plugin: DemonMUSH_Mapper"]:240: in function 'process_exits'
        [string "Trigger: Exits_Line"]:1: in main chunk

Not sure where I went wrong on it.
Top

Posted by Death   (55 posts)  Bio
Date Reply #6 on Thu 14 Mar 2019 07:55 AM (UTC)

Amended on Fri 15 Mar 2019 06:52 AM (UTC) by Death

Message
I've got the image drawing properly, but the borders for the room I'm in are RED, and they can still be seen only on some sides. I need them to show up on all 4 sides evenly, if possible, or not at all.

It can be seen here.

https://www.dropbox.com/s/2ixvprtvfnjcxmw/Screenshot%20%28201%29.png?dl=0


(I know that image looks horrible, it's just a test image)

Any idea why this alignment issue with the border might be happening and how to fix it??

ALSO, when I zoom out, it nukes the mapper window.
FIXED the errors below by adding
   
         if room.info and room.info ~= "" then
	 if string.match (room.info, "waypoint") then
     WindowDrawImage (win, "waypoint", left, top, right, bottom, miniwin.image_stretch)  -- stretch to fill
	 end
	 end


Run-time error
Plugin: DemonMUSH_Mapper (called from world: Demonclient)
Function/Sub: mapper.zoom_map called by Plugin DemonMUSH_Mapper
Reason: Executing plugin DemonMUSH_Mapper sub mapper.zoom_map
...\Jeffrey Johnston\Desktop\MUSHclient\lua\altermapper.lua:713: bad argument #1 to 'match' (string expected, got nil)
stack traceback:
        [C]: in function 'match'
        ...\Master Vivi\Desktop\MUSHclient\lua\altermapper.lua:713: in function 'draw_room'
        ...\Master Vivi\Desktop\MUSHclient\lua\altermapper.lua:982: in function 'draw'
        ...\Master Vivi\Desktop\MUSHclient\lua\altermapper.lua:1250: in function 'zoom_out'
        ...\Master Vivi\Desktop\MUSHclient\lua\altermapper.lua:1710: in function <...\Master Vivi\Desktop\MUSHclient\lua\altermapper.lua:1708>


I got it transparent now, but it won't center, and if I zoom out, it doesn't stay in the square.
On top of that, is there a way to make the image transparent and still show terrain colour under it?
Top

Posted by Death   (55 posts)  Bio
Date Reply #7 on Fri 15 Mar 2019 07:07 AM (UTC)

Amended on Fri 15 Mar 2019 09:25 AM (UTC) by Death

Message
To clear up this insane mess of a post...

Is there a way to use miniwin.image_stretch AND miniwin.image_transparent_copy at the same time when drawing an image? I want my image to be transparent, and stretch to my box, so I can still see what terrain is under the image (and so I don't get an ugly white background fill)

Also, the borders don't show any more when you draw an image. I would still like to see the borders.
Top

Posted by Fiendish   USA  (2,534 posts)  Bio   Global Moderator
Date Reply #8 on Fri 15 Mar 2019 03:08 PM (UTC)

Amended on Fri 15 Mar 2019 03:31 PM (UTC) by Fiendish

Message
Quote:
Is there a way to use miniwin.image_stretch AND miniwin.image_transparent_copy at the same time when drawing an image?


You can always stretch first to a temporary space and then copy that in with transparency.

Quote:
Also, the borders don't show any more when you draw an image. I would still like to see the borders.

I'm 99% sure without looking at your code that you are just drawing your image and your borders at the wrong coordinates. You have to be very careful about whether your coordinates are inclusive or exclusive when using the window drawing operations. Notice, for instance, that your diagonal lines do not exactly line up with the corners of your room boxes. Programatic pixel art requires exact precision.

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Death   (55 posts)  Bio
Date Reply #9 on Fri 15 Mar 2019 10:33 PM (UTC)
Message
Fiendish said:

Quote:
Is there a way to use miniwin.image_stretch AND miniwin.image_transparent_copy at the same time when drawing an image?


You can always stretch first to a temporary space and then copy that in with transparency.
How might I go about doing that?


Quote:
Also, the borders don't show any more when you draw an image. I would still like to see the borders.

I'm 99% sure without looking at your code that you are just drawing your image and your borders at the wrong coordinates. You have to be very careful about whether your coordinates are inclusive or exclusive when using the window drawing operations. Notice, for instance, that your diagonal lines do not exactly line up with the corners of your room boxes. Programatic pixel art requires exact precision.

I've not changed where it draws, but that only happens when you're in the CURRENT_ROOM, because the border gets thicker. I'll try to make current room have a border on the outside to fix it
Top

Posted by Fiendish   USA  (2,534 posts)  Bio   Global Moderator
Date Reply #10 on Sat 16 Mar 2019 02:23 AM (UTC)

Amended on Sat 16 Mar 2019 03:00 AM (UTC) by Fiendish

Message
Quote:
Quote:
You can always stretch first to a temporary space and then copy that in with transparency.

How might I go about doing that?

In the past I've done something like...

Use WindowCreate to make an invisible miniwindow that just acts as a temporary manipulation and storage buffer. Load your image into it with WindowLoadImage. Then use WindowResize to resize that miniwindow to be exactly the size you want the image to be. Then draw the image stretched into the miniwindow with WindowDrawImage. Then use WindowImageFromWindow to clone the contents of your invisible miniwindow into your main miniwindow. Then you can draw it semi-transparently using WindowDrawImageAlpha in the main miniwindow.

Quote:
I've not changed where it draws

But it appears that you have now drawn an image overhanging part of it.

Quote:
I'll try to make current room have a border on the outside to fix it

Or you could reduce the size of your waypoint image so that it doesn't overhang your border. Or you could draw the border after your waypoint image instead of before it. Though probably you should do both so that the symbol stays centered.

Also don't load your image every time you look up a room. That's wildly inefficient. You only need to load the image file once ever.

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Death   (55 posts)  Bio
Date Reply #11 on Sat 16 Mar 2019 03:08 AM (UTC)

Amended on Sat 16 Mar 2019 03:15 AM (UTC) by Death

Message
That whole create a separate miniwindow thing sounds complicated, I have no idea how to do this

Quote:


Also don't load your image every time you look up a room. That's wildly inefficient. You only need to load the image file once ever.


I had this in my get_room function

local function get_room (uid)
   local room = supplied_get_room (uid)
   room = room or { unknown = true }
   -- defaults in case they didn't supply them ...
   room.name = room.name or string.format ("Room %s", uid)
   room.name = mw.strip_colours (room.name)  -- no colour codes for now
   room.exits = room.exits or {}
   room.area = room.area or "<No area>"
   room.hovermessage = room.hovermessage or "<Unexplored room>"
   room.bordercolour = room.bordercolour or ROOM_COLOUR.colour
   room.borderpen = room.borderpen or 0 -- solid
   room.borderpenwidth = room.borderpenwidth or 1
   room.fillcolour = room.fillcolour or 0x000000
   room.fillbrush = room.fillbrush or 1 -- no fill
   room.texture = room.texture or nil -- no texture
     WindowLoadImage (win, "waypoint", "worlds\plugins\images\waypoint.bmp")
	      WindowLoadImage (win, "ocean", "worlds\plugins\images\ocean.bmp")
		  	      WindowLoadImage (win, "city", "worlds\plugins\images\city.bmp")
				   	      WindowLoadImage (win, "beach", "worlds\plugins\images\beach.bmp")
						  				   	      WindowLoadImage (win, "lightforest", "worlds\plugins\images\lightforest.bmp")
										  WindowLoadImage (win, "rock", "worlds\plugins\images\rock.bmp")
										       WindowLoadImage (win, "bank", "worlds\plugins\images\bank.bmp")
											       WindowLoadImage (win, "field", "worlds\plugins\images\field.bmp")


   room.textimage = nil

   if room.texture == nil or room.texture == "" then room.texture = "test5.png" end
   if textures[room.texture] then
      room.textimage = textures[room.texture] -- assign image
   else
      if textures[room.texture] ~= false then
         local dir = GetInfo(66)
         imgpath = dir .. "worlds\plugins\images\" ..room.texture
         if WindowLoadImage(win, room.texture, imgpath) ~= 0 then
            textures[room.texture] = false  -- just indicates not found
         else
            textures[room.texture] = room.texture -- imagename
            room.textimage = room.texture
			
         end
      end
   end
   
   return room
   
end -- get_room
and now I've changed it to be in my function draw (uid) right under
WindowCreate (win,
      windowinfo.window_left,
      windowinfo.window_top,
      config.WINDOW.width,
      config.WINDOW.height,
      windowinfo.window_mode,   -- top right
      windowinfo.window_flags,
      Theme.PRIMARY_BODY)

This should be far more efficient, right?
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #12 on Sat 16 Mar 2019 12:07 PM (UTC)

Amended on Sat 16 Mar 2019 12:09 PM (UTC) by Nick Gammon

Message

I’m on holiday right now so it isn’t easy for me to respond, however Fiendish is giving you good advice.


- Nick Gammon

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

Posted by Fiendish   USA  (2,534 posts)  Bio   Global Moderator
Date Reply #13 on Sun 17 Mar 2019 10:56 PM (UTC)

Amended on Sun 17 Mar 2019 11:19 PM (UTC) by Fiendish

Message
Quote:
This should be far more efficient, right?

Yes, that's perfect.

Quote:

That whole create a separate miniwindow thing sounds complicated, I have no idea how to do this

It is a bit complicated, but luckily for you I gave you the exact sequence of steps to do, so actually you do now know how to do it just by following the steps I wrote out. Write the code for my steps as they apply to your specific needs (your image file name and what size you want it). You can then paste it here if it doesn't work, and we will help figure out if you applied something incorrectly.

Most of the new code (from WindowCreate to WindowImageFromWindow) would basically be replacing your current call to WindowLoadImage. And then the last call to WindowDrawImageAlpha would replace your current WindowDrawImage call.

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Death   (55 posts)  Bio
Date Reply #14 on Sun 24 Mar 2019 10:26 AM (UTC)

Amended on Sun 24 Mar 2019 10:37 AM (UTC) by Death

Message
Hey all,


I've not been able to do the resizing thing, for now, but I've done quite a lot of other things. Screenshots can be seen here,

https://www.dropbox.com/s/rfhhko1rqxqcny6/Screenshot%20%28264%29.png?dl=0


and fully zoomed out
https://www.dropbox.com/s/pyn33uuzyrlrues/Screenshot%20%28265%29.png?dl=0


a few more to see my work
https://www.dropbox.com/s/mkyq94dwkff47kc/Screenshot%20%28266%29.png?dl=0

https://www.dropbox.com/s/hgp1yoz81eks5n5/Screenshot%20%28268%29.png?dl=0

https://www.dropbox.com/s/fvgtswhaczthzpx/Screenshot%20%28269%29.png?dl=0

fully zoomed out
https://www.dropbox.com/s/o8mj91pqr6d46x5/Screenshot%20%28270%29.png?dl=0

pretty zoomed out
https://www.dropbox.com/s/yfp7ygtk5x063bq/Screenshot%20%28271%29.png?dl=0



I need help figuring out how to make the room borders really fat (like room.borderpenwidth = 3) when I walk into a special room, but staying normal otherwise.

It seems to not work properly when I use WindowCircleOp for current_room.

I'm currently using
					     if uid == current_room and special_room then
                                         room.bordercolour = mapper.OUR_ROOM_COLOUR.colour
                                         room.borderpenwidth = 3		 
			             elseif uid == current_room and not special_room then
                                         WindowCircleOp (win, miniwin.circle_rectangle, left-2-room.borderpenwidth, top-2-room.borderpenwidth,
                                         right+2+room.borderpenwidth, bottom+2+room.borderpenwidth,OUR_ROOM_COLOUR.colour,
                                         room.borderpen, room.borderpenwidth,-2,miniwin.brush_null)


but it seems to not work.
If I put

if uid == current_room then
room.bordercolour = mapper.OUR_ROOM_COLOUR.colour
room.borderpenwidth = 3	

in my actual mapper plugin, it works properly, but then my current_room border when I'm NOT in those special rooms is not how I want it (+2 away from all true borders) its just a tiny flimsy line on the exact border of the rooms.

Any idea how to fix this??
I've spent like 6 hours trying to figure out this simple thing tonight. I suck.

Also, according to the second image do you think this is too much for the client to handle? Sometimes when I zoom out my map all of the way it just instantly crashes the entire MushClient.
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.


118,112 views.

This is page 1, subject is 4 pages long: 1 2  3  4  [Next page]

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.