I decided to enhance the script a bit. Its not "pure elegance" as the targed is to make it as easy to understand as possible. Have Fun
Scriptname: dm_mouse.lua
What it does: Brings up a Dialog picture with some buttons including handling [...] if you click the right mousebutton. Click on OK will close the dialog.
You can use it for whatever you like (free as in freedome)
what it looks like:
How to set up: extract the archive (attached) to your scriptbank folder. Attach dm_mouse.lua to a always active entity.
Script: (you don't have to copy it, it is in the archive, too)
MouseActive=0
pressed=0
MouseDown=0
-- Buttons Array
Buttons={}
-- How many Buttons do we have in the Dialog
MaxButtons=4
function dm_mouse_init(e)
-- Dialog Backdrop
FrameImg = LoadImage( "scriptbank\\png\\frame.png" )
-- Option Buttons as Button 1 - 3
bOption1= LoadImage( "scriptbank\\png\\b_option1.png" )
bOption2= LoadImage( "scriptbank\\png\\b_option2.png" )
bOption3= LoadImage( "scriptbank\\png\\b_option3.png" )
-- OK Button as Button nr 4
bOkImg= LoadImage( "scriptbank\\png\\b_ok.png" )
-- MouseCursor
CursorImg = LoadImage ( "scriptbank\\png\\cursor.png" )
end
function dm_mouse_main(e)
ActivateMouse()
if g_MouseClick == 2 and pressed == 0 then
MouseActive = 1- MouseActive
pressed = 1
if MouseActive == 0 then
MouseDeactivated()
else
MouseActivated()
end
end
if g_MouseClick == 0 then
pressed = 0
MouseDown=0
end
if MouseActive == 1 and pressed == 0 then
SetSpritePosition ( Cursor , g_MouseX ,g_MouseY )
if g_MouseClick ==1 and MouseDown==0 then
MouseDown=1
MouseClicked()
end
-- For Help placing Sprites uncomment next line
-- ShowMouseCoords()
else
DeactivateMouse()
end
end
function ShowMouseCoords()
-- For Debugging and placing Sprites..well very basic help ^^
Prompt ("X :"..g_MouseX.." Y:"..g_MouseY)
end
function MouseActivated()
-- init dialog
-- BackDrop Image
Dialog= CreateSprite (FrameImg)
SetSpritePosition ( Dialog, 29.5 , 23 )
-- Buttons
-- Setup the Buttons in an Array
Buttons[1] = {} -- create a new Button
Buttons[1][1] = 64.5 --x top left
Buttons[1][2] = 66 --y top left
Buttons[1][3] = 5 --width
Buttons[1][4] = 2.7 --height
Buttons[1][5] = CreateSprite (bOption1) -- Image to use
Buttons[2] = {} -- create a new Button
Buttons[2][1] = 64.5 --x top left
Buttons[2][2] = 69 --y top left
Buttons[2][3] = 5 --width
Buttons[2][4] = 2.7 --height
Buttons[2][5] = CreateSprite (bOption2)
Buttons[3] = {} -- create a new Button
Buttons[3][1] = 64.5 --x top left
Buttons[3][2] = 72 --y top left
Buttons[3][3] = 5 --width
Buttons[3][4] = 2.7 --height
Buttons[3][5] = CreateSprite (bOption3)
Buttons[4] = {} -- create a new Button
Buttons[4][1] = 64.5 --x top left
Buttons[4][2] = 75 --y top left
Buttons[4][3] = 5 --width
Buttons[4][4] = 2.7 --height
Buttons[4][5] = CreateSprite (bOkImg)
-- Set Up Sprite Positions
for i=1,MaxButtons do
SetSpritePosition ( Buttons[i][5], Buttons[i][1], Buttons[i][2] )
end
-- create MouseCursor
Cursor= CreateSprite ( CursorImg )
end
function MouseDeactivated()
DeactivateMouse()
MouseActive=0
-- Delete MouseCursor
DeleteSprite ( Cursor )
-- clean up dialog pictures
DeleteSprite ( Dialog )
for i=1,MaxButtons do
DeleteSprite( Buttons[i][5] )
end
end
function MouseClicked()
-- Handle Your mouse click events here
local bt_clicked=0
for i=1,MaxButtons do
if g_MouseX>Buttons[i][1] and g_MouseX<Buttons[i][1]+Buttons[i][3] and g_MouseY>Buttons[i][2] and g_MouseY<Buttons[i][2]+Buttons[i][4] then
bt_clicked=i
end
end
-- Handle your bt_clicked events here: bt_clicked is the number of the clicked button
if bt_clicked==1 then
-- Button 1 clicked
PromptDuration ("Button 1",3000)
end
if bt_clicked==2 then
-- Button 2 clicked
PromptDuration ("Button 2",3000)
end
if bt_clicked==3 then
-- Button 3 clicked
PromptDuration ("Button 3",3000)
end
if bt_clicked==4 then
-- Button 4 clicked ->OK Button -> leave Dialog
MouseDeactivated()
end
end
Modify it to your needs and have fun with it