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 ➜ Making a miniwindow moveable.

Making a miniwindow moveable.

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


Posted by Joseisme   (11 posts)  Bio
Date Fri 14 Dec 2012 06:15 AM (UTC)

Amended on Fri 14 Dec 2012 07:09 PM (UTC) by Nick Gammon

Message
First off I would like to thank Nick and the community for helping me in the past. Each time I have learned a little more and in turn my small MUD community has profited from the improved plugins.

I am currently working on improving my existing plugins to make them look and work a little better, as well as some minor bug fixes. The majority of the code works off of the item window tutorial Nick gave on youtube and the help he gave in improving it later.

Now I would like to figure out a way to make these nice miniwindows movable. This would make them a ton better and would silence some complaints in my MUD community.


I will try to make this brief. The plugin works by reading this information every one second, which is updated and sent by the server to the client.

%PLUGINATOR_START%
Riln: 7905
Fully Rested - Well-Fed
P-avoid, T-none, A-random
Standing
You are suffering no significant wounds.
[[Stealthed]]
 ~~ GUILD ~~
Rank 99 member of Rook Parlour
Promotion: 0 / 25250
%PLUGINATOR_END%



Then it displays it in a miniwindow with this:

<triggers>
  <trigger
   enabled="y"
   group="godlyplugin"
   match="^\%PLUGINATOR\_START\%$"
   name="status3"
   omit_from_output="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>require "wait"

wait.make (function ()  -- coroutine starts here


local win = GetPluginID () .. ":status3"
local font = "k"

if not WindowInfo (win, 1) then
  WindowCreate (win, 0, 0, 0, 0, 6, 0, 0)
  WindowFont (win, font, "Lucida Console", 8)  
end -- if

-- request inventory



-- wait for status screen to start

local line, wildcard, styles = wait.match ("*", 10, trigger_flag.OmitFromOutput)

if not line then
  ColourNote ("white", "blue", "No status received within 10 seconds")
  return
end -- if

local inv = {}
local max_width = WindowTextWidth (win, font, "Status")

-- loop until end of status

while true do
  -- save status line
  table.insert (inv, styles)
  -- work out max width
  max_width = math.max (max_width, WindowTextWidth (win, font, line))

  line, wildcards, styles = wait.match ("*", 10, trigger_flag.OmitFromOutput)

  -- see if end of status

  if string.match (line, "%%PLUGINATOR_END*") then
    break
  end -- if

end -- while loop

local font_height = WindowFontInfo (win, font, 1)

local window_width = max_width + 10
local window_height = font_height * (#inv + 2) + 10

-- make window correct size

WindowCreate (win, 0, 0, window_width, window_height, 6, 0, ColourNameToRGB "black")
WindowGradient (win, 0, 0, 0, 0, ColourNameToRGB ("#2F2F4F"), ColourNameToRGB ("black"), 2)

-- heading line

WindowText (win, font, "Status", 5, 5, 0, 0, ColourNameToRGB  "dodgerblue")

-- draw each status line

local y = font_height * 2 + 5

for i, styles in ipairs (inv) do

  local x = 5
  for _, style in ipairs (styles) do
    x = x + WindowText (win, font, style.text, x, y, 0, 0, style.textcolour)
  end -- for
  y = y + font_height

end -- for each status item

WindowShow (win, true)


end)   -- end of coroutine</send>
  </trigger>
</triggers>



Before I have asked here, I have tried it on my own by calling the movewindow.lua module, installing it then putting it into the windowcreate. Unfortunately, I do not yet have a deep enough understanding to get it to work. Would anyone in the here be willing to modify it to be moveable and add the ability for the window position to be save on exit? By the way, I have read the around the forums for info but at this point I just feel overwhelmed.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #1 on Fri 14 Dec 2012 07:35 PM (UTC)
Message
You need to turn it into a plugin, which isn't that hard. As an example for you and other coders I have done that below.

Template:saveplugin=Pluginator_Status To save and install the Pluginator_Status 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 Pluginator_Status.xml
  4. Go to the MUSHclient File menu -> Plugins
  5. Click "Add"
  6. Choose the file Pluginator_Status.xml (which you just saved in step 3) as a plugin
  7. Click "Close"



You can change its name to something more appropriate if you want.

The added parts (and things I moved around) are in bold.


<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>

<muclient>
<plugin
   name="Pluginator_Status"
   author="Joseisme "
   id="44e90f17e7cbb012a2fe7161"
   language="Lua"
   purpose="Shows stats in a miniwindow"
   save_state="y"
   date_written="2012-12-15 07:11:40"
   requires="4.80"
   version="1.0"
   >
<description trim="y">
<![CDATA[
Stats are shown when appropriate message arrives from the MUD.
]]>
</description>

</plugin>


<!--  Triggers  -->

<triggers>
  <trigger
   enabled="y"
   group="godlyplugin"
   match="^\%PLUGINATOR\_START\%$"
   name="status3"
   omit_from_output="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>
  
require "wait"

wait.make (function ()  -- coroutine starts here

-- wait for status screen to start

local line, wildcard, styles = wait.match ("*", 10, trigger_flag.OmitFromOutput)

if not line then
  ColourNote ("white", "blue", "No status received within 10 seconds")
  return
end -- if

local inv = {}
local max_width = WindowTextWidth (win, font, "Status")

-- loop until end of status

while true do
  -- save status line
  table.insert (inv, styles)
  -- work out max width
  max_width = math.max (max_width, WindowTextWidth (win, font, line))

  line, wildcards, styles = wait.match ("*", 10, trigger_flag.OmitFromOutput)

  -- see if end of status

  if string.match (line, "%%PLUGINATOR_END*") then
    break
  end -- if

end -- while loop

local window_width = max_width + 10
local window_height = font_height * (#inv + 2) + 10

-- make window correct size

-- recreate the window the correct size and position
WindowCreate (win, 
               windowinfo.window_left, 
               windowinfo.window_top, 
               window_width,    -- width
               window_height,   -- height
               windowinfo.window_mode,   -- whatever
               windowinfo.window_flags,
               ColourNameToRGB "black") 


WindowGradient (win, 0, 0, 0, 0, ColourNameToRGB ("#2F2F4F"), ColourNameToRGB ("black"), 
                miniwin.gradient_vertical)

-- heading line

WindowText (win, font, "Status", 5, 5, 0, 0, ColourNameToRGB  "dodgerblue")


-- add the drag handler so they can move the window around
movewindow.add_drag_handler (win, 0, 0, 0, font_height + 5)


-- draw each status line

local y = font_height * 2 + 5

for i, styles in ipairs (inv) do

  local x = 5
  for _, style in ipairs (styles) do
    x = x + WindowText (win, font, style.text, x, y, 0, 0, style.textcolour)
  end -- for
  y = y + font_height

end -- for each status item

WindowShow (win, true)


end)   -- end of coroutine

</send>
  </trigger>
</triggers>

<!--  Script  -->


<script>
<![CDATA[


function OnPluginInstall ()
 
  win = GetPluginID () .. "_status3"
  font = "k"

  require "movewindow"  -- load the movewindow.lua module

  -- install the window movement handler, get back the window position
  windowinfo = movewindow.install (win, miniwin.pos_top_right) 
   
  -- make window so I can grab the font info
  WindowCreate (win, 
                 windowinfo.window_left, 
                 windowinfo.window_top, 
                 1, 1,              -- width, height
                 windowinfo.window_mode,   
                 windowinfo.window_flags,
                 ColourNameToRGB ("black")) 

  WindowFont (win, font, "Lucida Console", 8)  
  font_height = WindowFontInfo (win, font, 1)  -- height
  
end -- OnPluginInstall

function OnPluginSaveState ()
  -- save window current location for next time  
  movewindow.save_state (win)
end -- function OnPluginSaveState


]]>
</script> 


</muclient>


I moved the initial create of the window to get the font size to OnPluginInstall (you only need to do that once). Then it grabs the saved window position from the state file.

On a plugin save, it saves the window position.

- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #2 on Fri 14 Dec 2012 07:37 PM (UTC)
Message
General description of the process here:

http://www.gammon.com.au/forum/?id=9594

- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #3 on Fri 14 Dec 2012 07:50 PM (UTC)
Message
If your players install this plugin make sure they also remove the earlier trigger you did. Otherwise they'll have two windows, one they can move and one they can't.

- Nick Gammon

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

Posted by Joseisme   (11 posts)  Bio
Date Reply #4 on Sat 15 Dec 2012 01:42 AM (UTC)
Message
Thanks again Nick! This is a lot simpler than what I was trying to do earlier. Now all i have to do is apply this technique to the other plugins and make sure nothing clashes, which won't be a problem.

Oh and if you were curious the MUD is called CLOK. wiki.contrarium.net
Top

Posted by Joseisme   (11 posts)  Bio
Date Reply #5 on Sat 15 Dec 2012 03:50 AM (UTC)
Message
I went ahead and made two other plugins that work off of the same code. I changed all the names and gave them each unique IDs. They are all working great but I had a question. What gives one window a priority over the others? What I mean is I have 3 windows displaying different things and one window will always be on top of the others, one will always be under the other windows and one will always stay in the middle if all windows are stacked on top of each other.

Is it going by name? Load order? I tried changing that and still the same windows had the same priority.

Again thank you for the help. Even without this they will still work just fine.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #6 on Sat 15 Dec 2012 05:26 AM (UTC)
Message
I think it is ascending alphabetic order of the miniwindow name. So if you stick "A", "B", "C" in front of the names you control the order.

- Nick Gammon

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

Posted by Fiendish   USA  (2,534 posts)  Bio   Global Moderator
Date Reply #7 on Sat 15 Dec 2012 05:35 AM (UTC)

Amended on Sat 15 Dec 2012 05:38 AM (UTC) by Fiendish

Message
Quote:
I think it is ascending alphabetic order of the miniwindow name. So if you stick "A", "B", "C" in front of the names you control the order.

Also WindowSetZOrder(BSTR WindowName, long Order)


I recommend using something like this:

plugin:
https://aardwolfclientpackage.googlecode.com/svn/trunk/MUSHclient/worlds/plugins/aard_miniwindow_z_order_monitor.xml

documentation:
https://code.google.com/p/aardwolfclientpackage/wiki/ZOrderMonitor

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

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #8 on Sat 15 Dec 2012 09:48 PM (UTC)
Message
I'd forgotten about WindowSetZOrder, lol. I think that was Fiendish's idea. :)

Template:function=WindowSetZOrder WindowSetZOrder

The documentation for the WindowSetZOrder script function is available online. It is also in the MUSHclient help file.


- 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.


22,979 views.

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.