[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]  Toggle Switches for Plugins

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: Toggle Switches for Plugins
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please).
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Pages: 1 2  

Posted by LupusFatalis   (154 posts)  [Biography] bio
Date Tue 16 Jun 2009 12:54 PM (UTC)  quote  ]

Amended on Tue 16 Jun 2009 12:55 PM (UTC) by LupusFatalis

Message
Ok, got it working. And I duplicated some of your code and now have a working heartbeat, check it out!

In the timers section:
  <timer second="1.00" 
         enabled="y" 
         script="heartbeat"
         >
  </timer>

And later in the script:
function heartbeat (timername)
  for n, v in ipairs (buttons) do

    if v.icon then
      if WindowLoadImage (win, n, GetInfo (66) .. v.icon) ~= error_code.eOK then
          DoAfterSpecial (1, string.format ([[
              ColourNote ("white", "red", "Could not load image '%s'")]], 
                          string.gsub (GetInfo (66) .. v.icon, '\', '\\')),
                          sendto.script)
      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
					
	if v.target_plugin then                    
      -- grey out if disabled now
      if not GetPluginInfo (v.target_plugin, 17) then 
         WindowFilter (win, x1, y1, x2, y2, 8, .4)
      end  -- if
    end -- if
  end --  for each world
end -- heartbeat
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Tue 16 Jun 2009 07:43 AM (UTC)  quote  ]
Message
When I asked which plugin you were working on and you replied:

Quote:

Oh, I'm working on the IconBar plugin.


I released 3 or 4 versions of that, which is why I asked.

In page 1 of this thread I mentioned http://www.gammon.com.au/forum/?id=9280 which has versions 1 and 2 of the plugin, but you are using http://www.gammon.com.au/forum/?id=9359 which is indeed later, but has version 4 of the plugin in it.

Since you are using the latest, greatest version, you also need to add a bit of code to the cooldowns section, which also draws the icon.

In the function SetCooldown, after the lines:


  if max > 0 then
    percent = (amount or 0) / max 
  else
    percent = 0  -- don't divide by zero!
  end -- if
  
  -- reload the image
  if WindowDrawImage(win, n, 
                  x1, y1,   -- left, top
                  x2, y2,  -- right, bottom
                  2)  -- mode - stretch or shrink
    ~= error_code.eOK then
    WindowRectOp (win, 2, x1, y1,   -- left, top
                  x2, y2,  -- right, bottom
                  BACKGROUND_COLOUR)
  end


Add:

           
  if buttons [n].target_plugin then                    
    -- grey out if disabled now
    if not GetPluginInfo (buttons [n].target_plugin, 17) then 
       WindowFilter (win, x1, y1, x2, y2, 8, .4)
    end  -- if
  end -- if



- Nick Gammon

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

Posted by LupusFatalis   (154 posts)  [Biography] bio
Date Tue 16 Jun 2009 07:13 AM (UTC)  quote  ]
Message
This isn't the latest and greatest: http://www.gammon.com.au/forum/?id=9359 ?
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Tue 16 Jun 2009 07:05 AM (UTC)  quote  ]
Message
Did you use the plugin further down that page? The version 2.0 one?

As for the heartbeat, you probably need a timer that fires every second, and in that, loop through every button (like when the buttons are loaded) and draws the image appropriately.


- Nick Gammon

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

Posted by LupusFatalis   (154 posts)  [Biography] bio
Date Tue 16 Jun 2009 05:22 AM (UTC)  quote  ]
Message
Oh, I found another spot it won't work, I think. When the plugins are enabled/disabled in other means. Not necessarily by the user, but by the plugin itself. I was thinking maybe putting a heartbeat function in, like you did in the script. But is there a way to reference the id from the buttons rather than manually checking them? etc...
[Go to top] top

Posted by LupusFatalis   (154 posts)  [Biography] bio
Date Tue 16 Jun 2009 05:10 AM (UTC)  quote  ]
Message
Hmm... I copied that, the part that checks to see if its disabled when it loads the bar works fine. And the button toggles it on and off, but it only toggles the contrast to normal. Copied exactly what you have.
buttons = {

 -- button 1
 {
  icon = "search_32.png",
  tooltip = "Underdark Mapper",
  target_plugin = "aba6daf3fb30699071cb5d05",
  script = function (n) 
            
            local id = buttons [n].target_plugin
            
            local f = frames [n]  -- where is image?
            local x1, y1, x2, y2 = f.x1, f.y1, f.x2, f.y2
            
            -- redraw the image
            WindowDrawImage(win, n, 
                    x1 + 1, y1 + 1,   -- left, top
                    x2 - 1, y2 - 1,  -- right, bottom
                    2)  -- mode - stretch or shrink
                    
            -- toggle enable flag for target plugin
            EnablePlugin(id, not GetPluginInfo (id, 17))
            
            -- grey out if disabled now
            if not GetPluginInfo (id, 17) then 
               WindowFilter (win, x1, y1, x2, y2, 8, .4)
            end  -- if
  
            end,  -- function

  },   -- end of button 1

   -- button 2
 {
  icon = "bubble_32.png",
  tooltip = "Spell Practice",
  target_plugin = "656eeab9f4fe9bd89d066e25",
  script = function (n) 
            
            local id = buttons [n].target_plugin
            
            local f = frames [n]  -- where is image?
            local x1, y1, x2, y2 = f.x1, f.y1, f.x2, f.y2
            
            -- redraw the image
            WindowDrawImage(win, n, 
                    x1 + 1, y1 + 1,   -- left, top
                    x2 - 1, y2 - 1,  -- right, bottom
                    2)  -- mode - stretch or shrink
                    
            -- toggle enable flag for target plugin
            EnablePlugin(id, not GetPluginInfo (id, 17))
            
            -- grey out if disabled now
            if not GetPluginInfo (id, 17) then 
               WindowFilter (win, x1, y1, x2, y2, 8, .4)
            end  -- if
  
            end,  -- function

  },   -- end of button 2

   -- button 3
 {
  icon = "block_32.png",
  tooltip = "Crafting Omit",
  target_plugin = "157dce098adaa8ceebcbfc88",
  script = function (n) 
            
            local id = buttons [n].target_plugin
            
            local f = frames [n]  -- where is image?
            local x1, y1, x2, y2 = f.x1, f.y1, f.x2, f.y2
            
            -- redraw the image
            WindowDrawImage(win, n, 
                    x1 + 1, y1 + 1,   -- left, top
                    x2 - 1, y2 - 1,  -- right, bottom
                    2)  -- mode - stretch or shrink
                    
            -- toggle enable flag for target plugin
            EnablePlugin(id, not GetPluginInfo (id, 17))
            
            -- grey out if disabled now
            if not GetPluginInfo (id, 17) then 
               WindowFilter (win, x1, y1, x2, y2, 8, .4)
            end  -- if
			
            end,  -- function

  },   -- end of button 3

  
 --> add more buttons here
 
  
} -- end of buttons table


Thanks again Nick!
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Mon 15 Jun 2009 11:42 PM (UTC)  quote  ]

Amended on Mon 15 Jun 2009 11:45 PM (UTC) by Nick Gammon

Message
Well you have got me going on this one now ...

I am still not sure which plugin you used, the page I mentioned had two on it, but I'll assume you used the lower one, which lets you have horizontal and vertical icons, and be dragged around.

The code below lets you grey out the whole icon, by reloading the image, and decreasing its contrast if the target plugin is not enabled:


 -- button 1
 {
  icon = "search_32.png",
  tooltip = "Underdark Mapper",
  target_plugin = "aba6daf3fb30699071cb5d05",
  script = function (n) 
            
            local id = buttons [n].target_plugin
            
            local f = frames [n]  -- where is image?
            local x1, y1, x2, y2 = f.x1, f.y1, f.x2, f.y2
            
            -- redraw the image
            WindowDrawImage(win, n, 
                    x1 + 1, y1 + 1,   -- left, top
                    x2 - 1, y2 - 1,  -- right, bottom
                    2)  -- mode - stretch or shrink
                    
            -- toggle enable flag for target plugin
            EnablePlugin(id, not GetPluginInfo (id, 17))
            
            -- grey out if disabled now
            if not GetPluginInfo (id, 17) then 
               WindowFilter (win, x1, y1, x2, y2, 8, .4)
            end  -- if
  
            end,  -- function

  },   -- end of button 3


I've fiddled around a bit to make it more readable. For one thing, you don't need to test if something elseif not something. For example:


if GetPluginInfo (id, 17) then
  -- do something
elseif not GetPluginInfo (id, 17) then
  -- do something else
end -- if


A simple else will do that, you don't need to test again, ie.


if GetPluginInfo (id, 17) then
  -- do something
else
  -- do something else
end -- if


Also it seems more logical to me to test if the plugin is enabled *after* you have toggled its enable flag.

My code above simply reloads the image (I wasn't sure if changing its contrast would be symmetrical, the image might have eventually degraded). Fortunately all the images are still in memory. Also the current plugin's window is stored in the variable "win" already.

The only problem I then found was if you reloaded the plugin (after testing) and the target plugin (the mapper) was already disabled, the icon would be drawn the wrong way around. So I added a couple more lines further down where the image is originally loaded. That is, after:


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


Add:



    if v.target_plugin then                    
      -- grey out if disabled now
      if not GetPluginInfo (v.target_plugin, 17) then 
         WindowFilter (win, x1, y1, x2, y2, 8, .4)
      end  -- if
    end -- if


This is why the variable which contained the target plugin's ID had to be moved from a local variable to be inside the table.

- Nick Gammon

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

Posted by LupusFatalis   (154 posts)  [Biography] bio
Date Mon 15 Jun 2009 08:49 PM (UTC)  quote  ]
Message
Oh, I'm working on the IconBar plugin.

And this seems to work, not exactly what I was intended (grays the area around the icon instead of the icon itself), but it does convey whether its enabled/disabled. At least after the first click--not ideal, but good enough I suppose.
  -- button 1
 {
  icon = "search_32.png",
  tooltip = "Underdark Mapper",
  script = function ()   -- script to execute when clicked
	local id = "aba6daf3fb30699071cb5d05"
	local id2 = GetPluginID()
	if GetPluginInfo (id, 17) then WindowFilter (id2, 2, 2, 41, 42, 8, 2)
	elseif not GetPluginInfo (id, 17) then WindowFilter (id2, 2, 2, 41, 42, 8, .5) end
	EnablePlugin(id, not GetPluginInfo (id, 17))
	end,  -- script function
  }, -- end of button 1
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Mon 15 Jun 2009 05:20 AM (UTC)  quote  ]
Message
I'm not sure exactly which plugin you borrowed from now, but to make it visually show it is disabled, you could probably lower the contrast of the icon (of course, then you have to put it back again later). See:

http://www.gammon.com.au/mushclient/mw_images.htm

- Nick Gammon

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

Posted by LupusFatalis   (154 posts)  [Biography] bio
Date Mon 15 Jun 2009 04:40 AM (UTC)  quote  ]
Message
heh, that's a lot better

Is there any way to have it change icons to distinguish whether it is enabled or disabled? Or gray out the entire bit, like you do with the cooldown? I was thinking maybe altering the cooldown code to accept 0 and act as if it were infinite. But looking at it, its beyond the scope by my bumbling abilities in lua.
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Mon 15 Jun 2009 04:05 AM (UTC)  quote  ]

Amended on Mon 15 Jun 2009 04:06 AM (UTC) by Nick Gammon

Message
Now to make it shorter:


-- button 1
 {
  icon = "Compass_32x32.png",
  tooltip = "Underdark Mapper",
  script = function ()   -- script to execute when clicked
      local id = "aba6daf3fb30699071cb5d05"
      EnablePlugin(id, not GetPluginInfo (id, 17))
      end,  -- script function
  }, -- end of button 1


Doing a "not" on a boolean reverses the sense of it (ie. not true is false, not false is true).

- Nick Gammon

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

Posted by LupusFatalis   (154 posts)  [Biography] bio
Date Mon 15 Jun 2009 03:40 AM (UTC)  quote  ]
Message
Thanks guys, here is what worked...
  -- button 1
 {
  icon = "Compass_32x32.png",
  tooltip = "Underdark Mapper",
  script = function ()   -- script to execute when clicked
				if world.GetPluginInfo("aba6daf3fb30699071cb5d05", 17) == true then
					world.EnablePlugin("aba6daf3fb30699071cb5d05", false)
				elseif world.GetPluginInfo("aba6daf3fb30699071cb5d05", 17) == false then
					world.EnablePlugin("aba6daf3fb30699071cb5d05", true)
				end
			end,  -- script function
  }, -- end of button 1
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Sun 14 Jun 2009 09:23 PM (UTC)  quote  ]

Amended on Sun 14 Jun 2009 09:24 PM (UTC) by Nick Gammon

Message
I tried your test on an existing plugin:


/print (GetPluginInfo("391192793248409895090099", 17))  --> true


In Lua, true is not the same as 1, one is a boolean value, one is a number. Thus the tests "== 1" and "== 0" will always fail, as the function returns true and false.

The documentation for GetPluginInfo correctly states it returns a boolean:


17: Enabled? (boolean)


- Nick Gammon

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

Posted by LupusFatalis   (154 posts)  [Biography] bio
Date Sat 13 Jun 2009 05:21 PM (UTC)  quote  ]
Message
Oh, this is a completely separate plugin. I'm just trying to edit nick's Icon_Bar plugin to work for me. I'm having trouble with it because its Lua. The plugin I'm enabling/disabling is a different one entirely, and written in python. Its likely that I'll put in these toggle buttons for quite a few plugins if I can get them working. Just trying to get the one working for now.
[Go to top] top

Posted by Worstje   Netherlands  (867 posts)  [Biography] bio
Date Sat 13 Jun 2009 07:17 AM (UTC)  quote  ]
Message
Scripts inside a plugin won't run while the plugin is disabled. So clicking a miniwindow used by the same plugin to enable it again won't work.

I usually get this kind of functionality working with an extra plugin that is used solely for enabling/disabling.
[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.


5,748 views.

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

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[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]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]