[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Plugins
. . -> [Subject]  Plugin to provide a bar of "action icons"
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Plugin to provide a bar of "action icons"

It is now over 60 days since the last post. This thread is closed.   [New subject]  Start a new subject   [Refresh] Refresh page


Pages: 1 2  

Posted by Nick Gammon   Australia  (19,609 posts)  [Biography] bio   Forum Administrator
Date Wed 25 Feb 2009 10:44 PM (UTC)  quote  ]

Amended on Mon 30 Mar 2009 08:33 PM (UTC) by Nick Gammon

Message
The plugin below uses miniwindows to implement "action icons" (see screenshot in the next post).

[EDIT] For a newer version that also shows cooldown times, see http://www.gammon.com.au/forum/?id=9359

What this lets you do is have a configurable (by editing the plugin) bar of icons, which can be dragged around to anywhere in your output window.

Each button has an image on it which is loaded from a BMP or PNG file. If you click on a button, then the associated action is performed. You can do either or both of:


  • Execute a command (this is sent to the command processor in MUSHclient). The default is, that the command would be sent to the MUD, unless it matches an alias. Variables in the form @name are expanded, so you can do things like: kick @target

  • Execute a script function. This lets you do fancier things like doing something if your health is low, and something else if it is high.


The icon size is configurable (see ICON_SIZE below). I chose 32 x 32 as that gives a reasonable icon. The image files you specify are shrunk or expanded to that 32 x 32 box, so the best results would occur if your images are the same size as ICON_SIZE.

The bar automatically resizes to fit as many buttons as you specify.

You configure the plugin by editing (and adding to) the buttons table below (the part in bold). Hopefully it is reasonably self-explanatory. The icon files default to being in the same directory as the MUSHclient executable.

If you want to change that, change the line below:


if WindowLoadImage (win, n, GetInfo (66) .. v.icon) ~= error_code.eOK then


to something that suits you. For example, make it just:


if WindowLoadImage (win, n, v.icon) ~= error_code.eOK then


If you do that, then you have to specify the full pathname for each image file.

Or, you could put the icons in a sub-directory, like this:


if WindowLoadImage (win, n, GetInfo (66) .. "icons\\" .. v.icon) ~= error_code.eOK then


You drag the button bar around by mousing down in the gaps between the icons (or at the edge of the window) in such a way that you aren't clicking on an icon itself. Then the window can be moved around.

Below is the plugin.

Save between the lines as Icon_Bar.xml and use File menu -> Plugins to load that file as a plugin.

[EDIT] Newer version released below (further down this thread) on 29th March 2009.


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE muclient>

<muclient>
<plugin
   name="Icon_Bar"
   author="Nick Gammon"
   id="ede0920fc1173d5a03140f0e"
   language="Lua"
   purpose="Shows a bar of buttons you can click on to do things"
   date_written="2009-02-26 09:00"
   requires="4.40"
   save_state="y"
   version="1.0"
   >
   
<description trim="y">
<![CDATA[
Install this plugin to show an button bar.

Click on an icon to execute a script or send a command to the MUD.

]]>
</description>

</plugin>

<!--  Script  -->

<script>
<![CDATA[

-- table of buttons

--[[
  Each button can have up to four entries:
  
  icon - filename of the image to draw
  tooltip - what to show if you hover the mouse over the button
  send - what to send to the MUD
  script - a script function to call

--]]
  

buttons = {

  -- button 1
  {
  icon = "HealIcon.png",
  tooltip = "Heal self",
  send = "cast 'lesser heal' self",
  },
  
  -- button 2
  {
  icon = "SwordIcon.png",
  tooltip = "Attack",
  send = "kill @target",
  },
  
  -- button 3
 {
  icon = "SparkIcon2.png",
  tooltip = "Cast Fireball",
  send = "cast fireball",
  script = function () 
            ColourNote ('white', 'green', 'script test') 
            end,
  },
  
  
 --> add more buttons here
 
  
} -- end of buttons table


-- configuration

ICON_SIZE = 32

BACKGROUND_COLOUR = ColourNameToRGB "bisque"
BOX_COLOUR = ColourNameToRGB "royalblue"
BUTTON_EDGE = ColourNameToRGB "silver"

MOUSE_DOWN_COLOUR = ColourNameToRGB "darkorange"

FONT_NAME = "Fixedsys"
FONT_SIZE = 9

-- where to put the window
WINDOW_POSITION = 6  -- top right
OFFSET = 6  -- gap inside box
EDGE_WIDTH = 2 -- size of border stroke

--[[
Useful positions:

4 = top left
5 = center left-right at top
6 = top right
7 = on right, center top-bottom
8 = on right, at bottom
9 = center left-right at bottom
--]]

function mousedown (flags, hotspot_id)

  if hotspot_id == "box" then
  
    -- find where mouse is so we can adjust window relative to mouse
    startx, starty = WindowInfo (win, 14), WindowInfo (win, 15)
    
    -- find where window is in case we drag it offscreen
    origx, origy = WindowInfo (win, 10), WindowInfo (win, 11)
  
    return
  end -- if the box, not a button
    
   -- convert id to a number, for table lookup
  local n = tonumber (hotspot_id)
  
  -- draw the button border in another colour for visual feedback
  WindowRectOp (win, 1, 
                frames [n].x1, frames [n].y1, frames [n].x2, frames [n].y2, 
                MOUSE_DOWN_COLOUR) 
  
  Redraw ()                
end -- mousedown

function cancelmousedown (flags, hotspot_id)
  local n = tonumber (hotspot_id)
  
  -- draw the button border in original colour for visual feedback
  WindowRectOp (win, 1, 
                frames [n].x1, frames [n].y1, frames [n].x2, frames [n].y2, 
                BUTTON_EDGE) 
  Redraw ()                

end -- cancelmousedown

function mouseup (flags, hotspot_id)
    
  -- fix border colour
  cancelmousedown (flags, hotspot_id)
  
  local n = tonumber (hotspot_id)
  
  local button = buttons [n]
  
  -- send to world if something specified
  if type (button.send) == "string" and 
    button.send ~= "" then
     
    local errors =  {} -- no errors yet
  
    -- function to do the replacements for string.gsub
    
    local function replace_variables (s)
      s = string.sub (s, 2)  -- remove the @
      replacement = GetPluginVariable ("", s)    -- look up variable in global variables
      if not replacement then  -- not there, add to errors list
        table.insert (errors, s)
        return
      end -- not there
      return replacement  -- return variable
    end -- replace_variables 
    
    -- replace all variables starting with @
    
    local command = string.gsub (button.send, "@%a[%w_]*", replace_variables)
    
    -- report any errors
    
    if #errors > 0 then
      for k, v in ipairs (errors) do
        ColourNote ("white", "red", "Variable '" .. v .. "' does not exist")
      end -- for
      return
    end -- error in replacing
     
    Execute (command)
  end -- if
  
  -- execute script if wanted
  if type (button.script) == "function" then
    button.script (n) 
  end -- if
     
end -- mouseup

function dragmove(flags, hotspot_id)

  -- find where it is now
  local posx, posy = WindowInfo (win, 17),
                     WindowInfo (win, 18)

  -- move the window to the new location
  WindowPosition(win, posx - startx, posy - starty, 0, 2);
  
  -- change the mouse cursor shape appropriately
  if posx < 0 or posx > GetInfo (281) or
     posy < 0 or posy > GetInfo (280) then
    check (SetCursor ( 11))   -- X cursor
  else
    check (SetCursor ( 1))   -- hand cursor
  end -- if
  
end -- dragmove

function dragrelease(flags, hotspot_id)
  local newx, newy = WindowInfo (win, 17), WindowInfo (win, 18)
  
  -- don't let them drag it out of view
  if newx < 0 or newx > GetInfo (281) or
     newy < 0 or newy > GetInfo (280) then
     -- put it back
    WindowPosition(win, origx, origy, 0, 2);
  end -- if out of bounds
  
end -- dragrelease

frames = {}

function OnPluginInstall ()

  local x, y, mode, flags = 
      tonumber (GetVariable ("windowx")) or 0,
      tonumber (GetVariable ("windowy")) or 0,
      tonumber (GetVariable ("windowmode")) or WINDOW_POSITION, -- top right
      tonumber (GetVariable ("windowflags")) or 0
  
  win = GetPluginID ()  -- get a unique name
  
  -- make the miniwindow
  WindowCreate (win, 
             x, y,   -- left, top (auto-positions)
             (#buttons * (ICON_SIZE + OFFSET)) + OFFSET,     -- width
             ICON_SIZE + (OFFSET * 2),  -- height
             mode,   -- position mode
             flags,  -- flags
             BACKGROUND_COLOUR) 
                
  -- draw the buttons
  
  for n, v in ipairs (buttons) do

    if v.icon then
      if WindowLoadImage (win, n, GetInfo (66) .. v.icon) ~= error_code.eOK then
          ColourNote ("white", "red", "Could not load image '" .. GetInfo (66) .. v.icon .. "'")
      end -- if
    end -- if icon specified
         
    -- where to draw the icon
    local x1, y1 = (n - 1) * (ICON_SIZE + OFFSET) + OFFSET, OFFSET
    local x2, y2 = n * (ICON_SIZE + OFFSET) + OFFSET, ICON_SIZE + OFFSET
    
    -- draw the image
    WindowDrawImage(win, n, 
                    x1, y1,   -- left, top
                    x2 - OFFSET, y2,  -- right, bottom
                    2)  -- mode - stretch or shrink

    -- remember where to draw the frame, for mouse clicks
    frames [n] = { 
            x1 = x1 - 1,
            y1 = y1 - 1,
            x2 = x2 - OFFSET + 1,
            y2 = y2 + 1
            }
    
    -- draw the button border
    WindowRectOp (win, 1, 
                  frames [n].x1, frames [n].y1, frames [n].x2, frames [n].y2, 
                  BUTTON_EDGE) 
    
    -- make a hotspot we can click on
    WindowAddHotspot(win, n,  
                 x1 - 1, y1 - 1, x2 - OFFSET + 1, y2 + 1,   -- rectangle
                 "",   -- mouseover
                 "",   -- cancelmouseover
                 "mousedown",
                 "cancelmousedown", 
                 "mouseup", 
                 v.tooltip,  -- tooltip text
                 1, 0)  -- hand cursor
                      
  end --  for each button
  

  -- draw the border of the whole box
  WindowCircleOp (win, 2, 0, 0, 0, 0, BOX_COLOUR, 6, EDGE_WIDTH, 0x000000, 1) 
    
  -- make a hotspot
  WindowAddHotspot(win, "box",  
                   0, 0, 0, 0,   -- whole window
                   "",   -- MouseOver
                   "",   -- CancelMouseOver
                   "mousedown",
                   "",   -- CancelMouseDown
                   "",   -- MouseUp
                   "Drag to move",  -- tooltip text
                   1, 0)  -- hand cursor
                   
  WindowDragHandler(win, "box", "dragmove", "dragrelease", 0) 
  
  if GetVariable ("enabled") == "false" then
    ColourNote ("yellow", "", "Warning: Plugin " .. GetPluginName ().. " is currently disabled.")
    check (EnablePlugin(GetPluginID (), false))
    return
  end -- they didn't enable us last time
 
  -- ensure window visible
  WindowShow (win, true)
    
end -- OnPluginInstall

-- hide window on removal
function OnPluginClose ()
  WindowShow (win,  false)  -- hide it
end -- OnPluginClose

-- show window on enable
function OnPluginEnable ()
  WindowShow (win,  true)  -- show it
end -- OnPluginEnable

-- hide window on disable
function OnPluginDisable ()
  WindowShow (win,  false)  -- hide it
end -- OnPluginDisable

function OnPluginSaveState ()
  SetVariable ("enabled", tostring (GetPluginInfo (GetPluginID (), 17)))
  SetVariable ("windowx", tostring (WindowInfo (win, 10)))
  SetVariable ("windowy", tostring (WindowInfo (win, 11)))
  SetVariable ("windowmode", tostring (WindowInfo (win, 7)))
  SetVariable ("windowflags", tostring (WindowInfo (win, 8)))
end -- OnPluginSaveState

]]>
</script>

</muclient>

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (19,609 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Wed 25 Feb 2009 10:45 PM (UTC)  quote  ]
Message

Example of it in operation:


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Onoitsu2   USA  (246 posts)  [Biography] bio
Date Reply #2 on Thu 26 Feb 2009 12:28 AM (UTC)  quote  ]
Message
HOLY COW! I never thought I'd see the day when this would be implemented in the client itself, this is probably the one thing that will bring me back to playing again. I, when I started mudding used zMud, and absolutely LOVED the buttons for doing things, including the tri-state buttons, and toggle buttons, but using that plugin I see those being easily done in just a few lines. I ultimately chose MUSHclient due to its customization abilities and scripting for several "standardized" languages, unlike zMud that has a language all its own.

Now to make toggleable buttons need to implement a dual-icon option, or even a triple one, and have it redraw whenever an icon is pushed to show its new status. As well as add an externally callable function to toggle the state of a button.

I cant wait to add things to it when I do get time to get back into mudding.

-Onoitsu2
[Go to top] top

Posted by Drake1132   (5 posts)  [Biography] bio
Date Reply #3 on Sun 22 Mar 2009 07:51 PM (UTC)  quote  ]
Message
I noticed in the code the following line...

requires="4.40"


I also noticed that if I try to load this plugin into version 4.37 that it doesn't work and throws a warning/error stating that I need version 4.40 or higher of the client.

Does this plugin actually work under 4.37? If not, does that mean it only works in the current SVN version of the program?

Thanks,
Drake
[Go to top] top

Posted by Nick Gammon   Australia  (19,609 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Sun 22 Mar 2009 08:03 PM (UTC)  quote  ]
Message
It requires 4.40 onwards because 4.40 introduced support for dragging windows around.

However version 4.40 can be downloaded (as an installer) from here:

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

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Drake1132   (5 posts)  [Biography] bio
Date Reply #5 on Mon 23 Mar 2009 03:30 AM (UTC)  quote  ]
Message
Awesome! Thanks a lot Nick :)
[Go to top] top

Posted by Hanaisse   Canada  (114 posts)  [Biography] bio
Date Reply #6 on Tue 24 Mar 2009 12:43 AM (UTC)  quote  ]
Message
Is there a limit on # of buttons you can have? And, if you have enough to go from the left side of the screen all the way to the right then add a new one, will it create a second row of buttons?

aka: Hana
Owner in Training of: Fury of the Gods
alm-dev.org:4000
[Go to top] top

Posted by Nick Gammon   Australia  (19,609 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Wed 25 Mar 2009 04:42 AM (UTC)  quote  ]
Message
No particular limit, but they'll eventually disappear off the edge of the screen.

There is no provision for two rows, I'll leave that as an exercise. :)

These two lines in particular would need to be fiddled with to allow for automatically making multiple lines:


-- where to draw the icon
local x1, y1 = (n - 1) * (ICON_SIZE + OFFSET) + OFFSET, OFFSET
local x2, y2 = n * (ICON_SIZE + OFFSET) + OFFSET, ICON_SIZE + OFFSET


Also the initial window creation size would need to be adjusted to make the window deeper if the number of icons warranted it.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (19,609 posts)  [Biography] bio   Forum Administrator
Date Reply #8 on Sat 28 Mar 2009 08:28 PM (UTC)  quote  ]

Amended on Sat 02 May 2009 10:34 PM (UTC) by Nick Gammon

Message
Below is an improved version that has the following extra features:


  • You can now have a horizontal or vertical bar. Just change the ENTITY in line 3 of the code below from "y" for horizontal to "n" for vertical.

  • When you mouse-over the button bar, when the mouse is over the places where it can be dragged, the mouse cursor turns into a NS-EW arrow, to distinguish it from the hand cursor that shows you can click on a button.


If you need more than one bar of icons you could easily install the plugin twice - just make a copy and change the plugin ID line below to something different (or you will get an error loading the second one). Then just load both plugins.

eg. Change the line:


  id="ede0920fc1173d5a03140f0e"


to:


  id="4a07bf87849d7b8df1345b3f"


Below is the plugin.

Save between the lines as Icon_Bar.xml and use File menu -> Plugins to load that file as a plugin.


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE muclient [
  <!ENTITY horizontal "y" > 
]>

<muclient>
<plugin
   name="Icon_Bar"
   author="Nick Gammon"
   id="ede0920fc1173d5a03140f0e"
   language="Lua"
   purpose="Shows a bar of buttons you can click on to do things"
   date_written="2009-02-26 09:00"
   date_modified="2009-03-29 07:00"
   requires="4.40"
   save_state="y"
   version="2.0"
   >
   
<description trim="y">
<![CDATA[
Install this plugin to show an button bar.

Click on an icon to execute a script or send a command to the MUD.

]]>
</description>

</plugin>

<!--  Script  -->

<script>

horizontal = ("&horizontal;"):lower ():sub (1, 1) == "y";

<![CDATA[

-- table of buttons

--[[
  Each button can have up to four entries:
  
  icon - filename of the image to draw
  tooltip - what to show if you hover the mouse over the button
  send - what to send to the MUD
  script - a script function to call

--]]
  

buttons = {

  -- button 1
  {
  icon = "HealIcon.png",    -- icon image
  tooltip = "Heal self",    -- tooltip help text
  send = "cast 'lesser heal' self",   -- what to send
  },   -- end of button 1
  
  -- button 2
  {
  icon = "SwordIcon.png",
  tooltip = "Attack",
  send = "kill @target",
  },   -- end of button 2
  
  -- button 3
 {
  icon = "SparkIcon2.png",
  tooltip = "Cast Fireball",
  send = "cast fireball",
  script = function () 
            ColourNote ('white', 'green', 'script test') 
            end,  -- function

  },   -- end of button 3
  
  
 --> add more buttons here
 
  
} -- end of buttons table


-- configuration

ICON_SIZE = 32

BACKGROUND_COLOUR = ColourNameToRGB "bisque"
BOX_COLOUR = ColourNameToRGB "royalblue"
BUTTON_EDGE = ColourNameToRGB "silver"

MOUSE_DOWN_COLOUR = ColourNameToRGB "darkorange"

FONT_NAME = "Fixedsys"
FONT_SIZE = 9

-- where to put the window
WINDOW_POSITION = 6  -- top right
OFFSET = 6  -- gap inside box
EDGE_WIDTH = 2 -- size of border stroke

--[[
Useful positions:

4 = top left
5 = center left-right at top
6 = top right
7 = on right, center top-bottom
8 = on right, at bottom
9 = center left-right at bottom
--]]


function mousedown (flags, hotspot_id)

  if hotspot_id == "_" then
  
    -- find where mouse is so we can adjust window relative to mouse
    startx, starty = WindowInfo (win, 14), WindowInfo (win, 15)
    
    -- find where window is in case we drag it offscreen
    origx, origy = WindowInfo (win, 10), WindowInfo (win, 11)
  
    return
    end -- if
    
    
  local n = tonumber (hotspot_id)
  
  -- draw the button border in another colour for visual feedback
  WindowRectOp (win, 1, 
                frames [n].x1, frames [n].y1, frames [n].x2, frames [n].y2, 
                MOUSE_DOWN_COLOUR) 
  
  Redraw ()                
end -- mousedown

function cancelmousedown (flags, hotspot_id)
  local n = tonumber (hotspot_id)
  
  -- draw the button border in original colour for visual feedback
  WindowRectOp (win, 1, 
                frames [n].x1, frames [n].y1, frames [n].x2, frames [n].y2, 
                BUTTON_EDGE) 
  Redraw ()                

end -- cancelmousedown

function mouseup (flags, hotspot_id)
   
  -- fix border colour
  cancelmousedown (flags, hotspot_id)
  
  local n = tonumber (hotspot_id)
  
  local button = buttons [n]
  
  -- send to world if something specified
  if type (button.send) == "string" and 
    button.send ~= "" then
     
    local errors =  {} -- no errors yet
  
    -- function to do the replacements for string.gsub
    
    local function replace_variables (s)
      s = string.sub (s, 2)  -- remove the @
      replacement = GetPluginVariable ("", s)    -- look up variable in global variables
      if not replacement then  -- not there, add to errors list
        table.insert (errors, s)
        return
      end -- not there
      return replacement  -- return variable
    end -- replace_variables 
    
    -- replace all variables starting with @
    
    local command = string.gsub (button.send, "@%a[%w_]*", replace_variables)
    
    -- report any errors
    
    if #errors > 0 then
      for k, v in ipairs (errors) do
        ColourNote ("white", "red", "Variable '" .. v .. "' does not exist")
      end -- for
      return
    end -- error in replacing
     
    Execute (command)
  end -- if
  
  -- execute script if wanted
  if type (button.script) == "function" then
    button.script (n) 
  end -- if
     
end -- mouseup

function dragmove(flags, hotspot_id)

  -- find where it is now
  local posx, posy = WindowInfo (win, 17),
                     WindowInfo (win, 18)

  -- move the window to the new location
  WindowPosition(win, posx - startx, posy - starty, 0, 2);
  
  -- change the mouse cursor shape appropriately
  if posx < 0 or posx > GetInfo (281) or
     posy < 0 or posy > GetInfo (280) then
    SetCursor (11)   -- X cursor
  else
    SetCursor (10)   -- arrow (NS/EW) cursor
  end -- if
  
end -- dragmove

function dragrelease(flags, hotspot_id)
  local newx, newy = WindowInfo (win, 17), WindowInfo (win, 18)
  
  -- don't let them drag it out of view
  if newx < 0 or newx > GetInfo (281) or
     newy < 0 or newy > GetInfo (280) then
     -- put it back
    WindowPosition(win, origx, origy, 0, 2);
  end -- if out of bounds
  
end -- dragrelease

frames = {}

function OnPluginInstall ()

  local x, y, mode, flags = 
      tonumber (GetVariable ("windowx")) or 0,
      tonumber (GetVariable ("windowy")) or 0,
      tonumber (GetVariable ("windowmode")) or WINDOW_POSITION, -- top right
      tonumber (GetVariable ("windowflags")) or 0
  
  win = GetPluginID ()  -- get a unique name
  
  local gauge_height, gauge_width
  
  if horizontal then
    window_width = (#buttons * (ICON_SIZE + OFFSET)) + OFFSET
    window_height = ICON_SIZE + (OFFSET * 2)
  else
    window_width = ICON_SIZE + (OFFSET * 2)
    window_height = (#buttons * (ICON_SIZE + OFFSET)) + OFFSET
  end -- if
  
  -- make the miniwindow
  WindowCreate (win, 
             x, y,   -- left, top (auto-positions)
             window_width,     -- width
             window_height,  -- height
             mode,   -- position mode
             flags,  -- flags
             BACKGROUND_COLOUR) 
                
  -- draw the buttons
  
  for n, v in ipairs (buttons) do

    if v.icon then
      if WindowLoadImage (win, n, GetInfo (66) .. v.icon) ~= error_code.eOK then
          ColourNote ("white", "red", "Could not load image '" .. GetInfo (66) .. v.icon .. "'")
      end -- if
    end -- if icon specified
       
    local x1, y1, x2, y2

    -- where to draw the icon
    if horizontal then
      x1, y1 = (n - 1) * (ICON_SIZE + OFFSET) + OFFSET, OFFSET
      x2, y2 = n * (ICON_SIZE + OFFSET), ICON_SIZE + OFFSET
    else
      x1, y1 = OFFSET, (n - 1) * (ICON_SIZE + OFFSET) + OFFSET
      x2, y2 = ICON_SIZE + OFFSET, n * (ICON_SIZE + OFFSET)
    end -- if
        
    -- draw the image
    WindowDrawImage(win, n, 
                    x1, y1,   -- left, top
                    x2, y2,  -- right, bottom
                    2)  -- mode - stretch or shrink

    -- remember where to draw the frame, for mouse clicks
    frames [n] = { 
            x1 = x1 - 1,
            y1 = y1 - 1,
            x2 = x2 + 1,
            y2 = y2 + 1
            }
    
    -- draw the button border
    WindowRectOp (win, 1, 
                  frames [n].x1, frames [n].y1, frames [n].x2, frames [n].y2, 
                  BUTTON_EDGE) 
    
    -- make a hotspot we can click on
    WindowAddHotspot(win, n,  
                 frames [n].x1, frames [n].y1, frames [n].x2, frames [n].y2,   -- rectangle
                 "",   -- mouseover
                 "",   -- cancelmouseover
                 "mousedown",
                 "cancelmousedown", 
                 "mouseup", 
                 v.tooltip,  -- tooltip text
                 1, 0)  -- hand cursor
                      
  end --  for each world
  

  -- draw the border of the whole box
  WindowCircleOp (win, 2, 0, 0, 0, 0, BOX_COLOUR, 6, EDGE_WIDTH, 0x000000, 1) 
    
  -- make a hotspot
  WindowAddHotspot(win, "_",  
                   0, 0, 0, 0,   -- whole window
                   "",   -- MouseOver
                   "",   -- CancelMouseOver
                   "mousedown",
                   "",   -- CancelMouseDown
                   "",   -- MouseUp
                   "Drag to move",  -- tooltip text
                   10, 0)  -- arrow (NS/EW) cursor
                   
  WindowDragHandler(win, "_", "dragmove", "dragrelease", 0) 
  
  if GetVariable ("enabled") == "false" then
    ColourNote ("yellow", "", "Warning: Plugin " .. GetPluginName ().. " is currently disabled.")
    EnablePlugin (GetPluginID (), false)
    return
  end -- they didn't enable us last time
 
  -- ensure window visible
  WindowShow (win, true)
    
end -- OnPluginInstall

-- hide window on removal
function OnPluginClose ()
  WindowShow (win,  false)  -- hide it
end -- OnPluginClose

-- show window on enable
function OnPluginEnable ()
  WindowShow (win,  true)  -- show it
end -- OnPluginEnable

-- hide window on disable
function OnPluginDisable ()
  WindowShow (win,  false)  -- hide it
end -- OnPluginDisable

function OnPluginSaveState ()
  SetVariable ("enabled",     tostring (GetPluginInfo (GetPluginID (), 17)))
  SetVariable ("windowx",     WindowInfo (win, 10))
  SetVariable ("windowy",     WindowInfo (win, 11))
  SetVariable ("windowmode",  WindowInfo (win, 7))
  SetVariable ("windowflags", WindowInfo (win, 8))
end -- OnPluginSaveState

]]>
</script>

</muclient>

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Atomicoctobot   (19 posts)  [Biography] bio
Date Reply #9 on Sun 29 Mar 2009 12:42 AM (UTC)  quote  ]
Message
Would it be possible to create a popup menu for individual buttons to reduce the number of necessary buttons? For instance, instead of having five buttons for five special attacks, have one button with a popup menu listing those five specials.
[Go to top] top

Posted by Nick Gammon   Australia  (19,609 posts)  [Biography] bio   Forum Administrator
Date Reply #10 on Sun 29 Mar 2009 01:48 AM (UTC)  quote  ]

Amended on Sun 29 Mar 2009 01:51 AM (UTC) by Nick Gammon

Message
It is easy if you mean an "ordinary" menu, not a menu of icons.

For example, instead of the code for button 3 above, replace with this:


 -- button 3
 {
  icon = "SparkIcon2.png",
  tooltip = "Special Attacks",
  script = function () 
                  
        local result = WindowMenu (win, 
          WindowInfo (win, 14),  -- x
          WindowInfo (win, 15),  -- y

          "Backstab|Stun|Kick|Taunt")  -- menu items
        
        if result ~= "" then
          Send (result:lower () .. " " .. GetPluginVariable ("", "target"))
        end -- if

  
            end,  -- function

  },  -- end of button 3


This uses WindowMenu to display a pop-up menu with four items in it. If you select one of the four (and thus get a non-empty string as a result) you send the resulting command to the MUD, followed by the name of the current target.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (19,609 posts)  [Biography] bio   Forum Administrator
Date Reply #11 on Sun 29 Mar 2009 01:49 AM (UTC)  quote  ]
Message

Example of how it looks:


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Atomicoctobot   (19 posts)  [Biography] bio
Date Reply #12 on Sun 29 Mar 2009 05:57 PM (UTC)  quote  ]
Message
That looks terrific, but I'm having difficulty trying to wrap my head around configuring the code. In essence, what I want to achieve is this:

-- button 8
{
icon = "spear2.png",
tooltip = "Special Attacks",
script = function ()

local result = WindowMenu (win,
WindowInfo (win, 14), -- x
WindowInfo (win, 15), -- y

"Backstab|Stun|Kick|Taunt") -- menu items

if result ~= "Backstab" then
Send "say backstab"
if result ~= "Stun" then
Send "say backstab"
if result ~= "Kick" then
Send "say backstab"
if result ~= "Taunt" then
Send "say backstab"
end -- if

end, -- function

}, -- end of button 8
[Go to top] top

Posted by Nick Gammon   Australia  (19,609 posts)  [Biography] bio   Forum Administrator
Date Reply #13 on Sun 29 Mar 2009 09:26 PM (UTC)  quote  ]
Message
I just don't get what your code is trying to do. For example this:


if result ~= "Backstab" then


means if they did not select Backstab.

Then you say if they did NOT select backstab:


Send "say backstab"


Why do that?

And then further down, you also "say backstab" no matter what the test is for.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Onoitsu2   USA  (246 posts)  [Biography] bio
Date Reply #14 on Sun 29 Mar 2009 10:37 PM (UTC)  quote  ]
Message
I think the issue was copying and pasting over exuberance, and not examining things that were pasted.

-Onoitsu2
[Go to top] 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.


19,725 views.

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

It is now over 60 days since the last post. This thread is closed.   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Web site powered by FutureQuest.Net]