I'm writing a plugin right now that has hotspots located on top of different words. I'm trying to make it so when you mouseover one of the hotspots it will add brackets to the word under the hotspot (just to indicate mouseover.) Currently it does do this, however it also duplicates the words lower on the miniwindow.
When iterating over the table that creates the hotspots I use: "m=1" before the ipairs loop and "m=m+1" to keep track of the cycles. If I just use "i" from "for i, v in ipairs(some_table)" then it will work as expected. But I can't do this because in my plugin (this one is just an example) I am using a custom iterator so the order it iterates and the cycle number are different.
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Thursday, January 28, 2016, 7:40 PM -->
<!-- MuClient version 5.00 -->
<!-- Plugin "test" generated by Plugin Wizard -->
<muclient
<plugin
name="test"
author="Zim"
id="6741be368ebea9880ba5faac">
language="Lua"
purpose="testing stuff"
save_state="y"
date_written="2016-01-28 19:38:51"
requires="5.00"
version="1.0"
>
</plugin>
<!-- Get our standard constants -->
<include name="constants.lua"/>
<timers>
<timer name="tic" enabled="y" minute="0" second="1.00" offset_second="0.00" send_to="12"
>
<send>
update_window()
</send>
</timer>
</timers>
<!-- Script -->
<script>
<![CDATA[
--------------------------------------------------------------------------------
-- ENABLE/DISABLE
--------------------------------------------------------------------------------
function OnPluginEnable ()
WindowShow (win, true)
end
function OnPluginDisable()
WindowShow (win, false)
end
function OnPluginClose ()
WindowShow (win, false)
end
--------------------------------------------------------------------------------
-- MINIWINDOW
--------------------------------------------------------------------------------
function update_window()
WindowCircleOp (win, 3, 1, 1, window_width - 1, window_height - 1,
ColourNameToRGB("gray"), 0, 2, ColourNameToRGB("white"), 0, 1, 1) -- frame
m = 1
for i, v in ipairs(some_table) do
WindowText (win, "f", display_with_brackets(i),
5, 5+m*(5+font_height)-font_height, window_width, 5+m*(5+font_height), ColourNameToRGB("black"),
false) -- not Unicode
WindowAddHotspot(win, "h"..tostring(i),
5, 5+m*(5+font_height)-font_height, window_width, 5+m*(5+font_height), -- rectangle
"mouseover", -- MouseOver
"canclemouseover", -- CancelMouseOver
"",
"",
"",
"", -- tooltip text
1, 0) -- hand cursor
m = m +1
end
WindowShow(win, true)
end
--------------------------------------------------------------------------------
-- ADD BRACKETS TO MOUSEOVER TEXT
--------------------------------------------------------------------------------
function display_with_brackets(index)
if index == mouseover_spot then
return "["..some_table[index].."]"
else
return some_table[index]
end
end
--------------------------------------------------------------------------------
-- HOTSPOT HANDLERS
--------------------------------------------------------------------------------
function mouseover(flags, hotspot_id)
for p = 1, #some_table, 1 do
if hotspot_id == "h"..tostring(p) then
mouseover_spot = p
update_window()
break
end
end
end
function canclemouseover(flags, hotspot_id)
for p = 1, #some_table, 1 do
if hotspot_id == "h"..tostring(p) then
mouseover_spot = false
update_window()
break
end
end
end
--------------------------------------------------------------------------------
-- START EXECUTION HERE
--------------------------------------------------------------------------------
some_table = {"I", "really", "don't", "know", "why", "this", "does", "this!"}
win = "test" .. GetPluginID ()
WindowCreate (win, 0, 0, 0, 0, miniwin.pos_center_all, 0, ColourNameToRGB("black")) -- load dummy window so we can load fonts
WindowFont (win, "f", "FixedSys", 10, false, false, false, false)
font_height = WindowFontInfo (win, "f", 1)
window_height = 300
window_width = 100
WindowCreate (win, 0, 0, window_width, window_height, miniwin.pos_center_all, 0, ColourNameToRGB("black"))
update_window()
]]>
</script>
</muclient>
|