Dev Blog

Hi, this is the Stranded III development blog (see also Forum Thread, Comment Thread).

Overview (115 Entries)

Entry 9 - Lua Scripted Menu - February 19, 2013

Lua Scripted Menu
Only a scripted menu is a good menu.
The following Lua code generates the result you're seeing on the screenshot.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
--  Load Interface Images
button0=loadImage("interface/menu_button.png")
button1=loadImage("interface/menu_button_hover.png")
cursor=loadImage("interface/cursor.png")

function menu()
     -- Button Font
     fontSize(20)
     fontStyle(1)
     fontColor(1,0,0,0.5)
     
     -- Buttons
     if button("Play",5,5)>0 then
     end
     
     if button("Editor",5,screenHeight()/2)>0 then
          menuEditor();
     end
     
     if button("Quit",5,screenHeight()-35-5)>0 then
          menuQuit();
     end
     
     -- Mouse Cursor
     color(1,1,1,1)
     x=menuMouseX()
     y=menuMouseY()
     drawImage(cursor,x,y)
end

-- Draw a clickable button (200x35)
-- Returns >0 (mouse key ID) when clicked, 0 otherwise
function button(label,x,y)
     mx=menuMouseX()
     my=menuMouseY()
     color(1,1,1,1)
     -- Is mouse over button?
     if mx>=x and my>=y and mx<=x+200 and my<=y+35 then
          -- Hover
          drawImage(button1,x,y)
          drawText(label,x+100-textWidth(label)/2,y+3)
          -- Click
          if mouseButton()>0 then
               return mouseButton()
          end
     else
          -- No Hover
          drawImage(button0,x,y)
          drawText(label,x+100-textWidth(label)/2,y+3)
     end
     return 0
end


IMG:https://stuff.unrealsoftware.de/s3_menu01.jpg

No big deal but it shows how things will work. You will be able to script the in-game interface in the very same way.
Note (for people who are used to CS2D/Carnage Contest Lua scripting): The color commands have 4 parameters. The last one is the alpha value. The parameters range from 0 to 1 (not from 0 to 255).
The used images in this shot are obviously NOT final but only placeholders!

Scaling
Moreover I decided to allow scaling objects in the editor. It's already fully implemented. You can either scale proportionally (change scale in all directions in the same magnitude) or you can change the scale on single angles for example to get a palm tree which is just very high.
IMG:https://stuff.unrealsoftware.de/s3_editor24.jpg

Disqus

blog comments powered by Disqus