Jump to content

LuaGui


AggrorJorn
 Share

Recommended Posts

File Name: LuaGui

File Submitter: Aggror

File Submitted: 12 Jul 2010

File Updated: 29 Jul 2010

File Category: Lua Scripts

 

LuaGui is an easy to use GUI command set. It is not really finished but can allready be used for your game project. The zip file contains several example files. Feel free to use or change LuaGui to your needs. Happy GUI writing! ;) If you have any questions: don't hesitate to ask!

 

Possibilities with LuaGui

 

- Create a button (normal mode, hover mode and mousedown mode.)

- Position the button on screen.

- Draw text inside your button.

- Specify the position of your text inside the button.

- Let LuaGui automaticly addept your buttons to different resolutions.

- Create a checkbox.

- Create a slider button.

- Easy handling of mouse events or when a checkbox is checked/unchecked.

 

 

NOTE.

This is still a work in progress.


  •  
    - The event handling will eventually be combined with callbacks.
    - Working on a slider and editbox.
     

 

Commands:

 

Create a button.

buttonName = LuaGui.CreateButton()

Specify a base resolution. lets say you make a button for a resolution of 1800 x 1200. The person playing your game has a resolution of 1440 x 900. If you set the base resolution command, LuaGui will automaticly scale and position your button according to the right resolution.

buttonName:SetBaseResolution(1400,900)

 

Specify the images that the button uses. (normal mode, hover mode and mousedown mode.)

buttonName:SetImages("abstract::play_N.dds","abstract::play_H.dds","abstract::play_C.dds")

 

Specify a position for the button.

buttonName:SetPosition(200,200)

 

Add some text to your button.

buttonName:SetText("Leadwerks")

 

Set the position of the text. See the image for the positions. The second and third parameter can be used for margins

buttonName:SetTextPosition("BottomRight",0,0)

http://leadwerks.com/werkspace/index.php?app=core&module=attach§ion=attach&attach_rel_module=post&attach_id=901

 

Set a different font for your button.

buttonName:SetButtonFont("Arial12Shadow")

 

Create a mouse event for when the mouse is clicked: MouseClicked(). The parameter can be used to specify which mouse button.

1 = left mouse button. 2 = right mouse button. 3 = mousewheel

 

if button1:MouseClicked(1)==1 then
	test = test + 1
end

 

Create a mouse event for when the mouse is clicked: MouseClicked(). The parameter can be used to specify which mouse button.

1 = left mouse button. 2 = right mouse button. 3 = mousewheel

if button1:MouseDown(2)==1 then
	test = test - 1
end

 

 

Create a checkbox.

checkboxName = LuaGui.CreateCheckBox()

 

Specify an 'unchecked' button and a 'checked' button.

checkboxName:SetImages("abstract::unchecked.dds","abstract::checked.dds")

 

Create an event for the CheckBox

if checkbox1:Checked()==1 then
	test = 1
else
	test = 0
end

 

 

 

Create a Slider.

sliderName = LuaGui.CreateSlider()

 

Specify the images that the slider uses. (normal mode, hover mode, mousedown mode and a background.)

sliderName:SetImages("abstract::slider2_N.dds","abstract::slider2_H.dds","abstract::slider2_C.dds","abstract::slider2_B.dds")

 

Specify whether the slider is horizontal or vertical. Horizontal by default.

sliderName:SetDirection("vertical")

 

Set the slider values. First 2 parameters: starting X and Y position of the slider.

The last 2 parameters: minimum and maximum X or Y values.

sliderName:SetValues(100,150,100,200)

 

Returns the value of the slider button in percentages from 0 - 100.

variable = sliderName:GetValue()

 

LuaGui.zip

Link to comment
Share on other sites

@Pancakes: hope it can help you.

 

@Ziored: I was thinking about that, but then I face a problem. This is the current function:

--Place the button on an X and Y position. Also adjusts the position according to the resolution.
function LuaGui:Position(x,y)

self.buttonX  = x * self.scaleX
self.buttonY  = y * self.scaleY
end

 

The x and y position are adjusted according to the resolution. If I remove these 2 lines, the correct position is no longer calculated. Perhaps I can fit it in the UpdateButton(). Thanks!

Link to comment
Share on other sites

@Ziored: I was thinking about that, but then I face a problem. This is the current function:

--Place the button on an X and Y position. Also adjusts the position according to the resolution.
function LuaGui:Position(x,y)

self.buttonX  = x * self.scaleX
self.buttonY  = y * self.scaleY
end

 

The x and y position are adjusted according to the resolution. If I remove these 2 lines, the correct position is no longer calculated. Perhaps I can fit it in the UpdateButton(). Thanks!

I was only speaking about the name of the method, not its code content... I don't know very well how Lua works, perhaps there is already a global "SetPosition" method for any new object?

?? FRANCESCO CROCETTI ??

http://skaredcreations.com

Link to comment
Share on other sites

  • 3 weeks later...
  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...