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

Toggle Switches for Plugins

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


Pages: 1  2 

Posted by LupusFatalis   (154 posts)  Bio
Date Reply #15 on Tue 16 Jun 2009 05:10 AM (UTC)
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!
Top

Posted by LupusFatalis   (154 posts)  Bio
Date Reply #16 on Tue 16 Jun 2009 05:22 AM (UTC)
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...
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #17 on Tue 16 Jun 2009 07:05 AM (UTC)
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
Top

Posted by LupusFatalis   (154 posts)  Bio
Date Reply #18 on Tue 16 Jun 2009 07:13 AM (UTC)
Message
This isn't the latest and greatest: http://www.gammon.com.au/forum/?id=9359 ?
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #19 on Tue 16 Jun 2009 07:43 AM (UTC)
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
Top

Posted by LupusFatalis   (154 posts)  Bio
Date Reply #20 on Tue 16 Jun 2009 12:54 PM (UTC)

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


65,204 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.