Submit Your Own Code

PSP Lua CodeBase : Generic Menu

Description:
With this code you can add custom Menus to your game. You just need to call
menu(...) and it will return the number of the item which the user has chosen. Save
the code as menu.lua and put a dofile("menu.lua") into your project.

menu(_x,_y,_width,_height,_cls,_intialSelection,_stdColor,_highliteColor,
_backColor,...)
_x: Where on the x-axis the menu should appear
_y: Where on the y-axis the menu should appear
_width: for drawing a rectangle around the menu
_height: for drawing a rectangle around the menu
_cls: true -> menu will clear screen, false -> menu will not clear screen
_intialSelection: indicates which item in the menu is marked
_stdColor: Color of unmarked items
_highliteColor: Color of marked items
_backColor: Color of Background
...: The items that should be displayed

If you set _width and _height to 0 then no box around the menu will appear.

 -- EVILMANA.COM PSP LUA CODEBASE
-- www.evilmana.com/tutorials/codebase
-- Generic Menu
-- SUBMITTED BY: MiDi

function
menu(_x,_y,_width,_height,_cls,_intialSelection,_stdColor,
_highliteColor,_backColor,...)

    currentSelection = _intialSelection

    _oldpad = Controls.read()

    while true do

        _pad = Controls.read()

        if(_cls) then screen:clear() end

        screen:fillRect(_x,_y,_width,_height,Color.new(128,128,128))
        screen:fillRect(_x+1,_y+1,_width-2,_height-2,Color.new(255,255,255))
        screen:fillRect(_x+2,_y+2,_width-4,_height-4,_backColor)

        for i = 1, arg.n, 1 do 
            if(i~=currentSelection) then 
                screen:print(_x + 15, _y + (15 * i), arg[i], _stdColor) 
            else 
                screen:print(_x + 15, _y + (15 * i), arg[i], _highliteColor) 
            end 
        end

        if((_pad:up() ~= _oldpad:up()) and _pad:up()) then
            currentSelection = currentSelection - 1
            if(currentSelection == 0) then currentSelection = arg.n end
        end

        if((_pad:down() ~= _oldpad:down()) and _pad:down()) then
            currentSelection = currentSelection + 1
            if(currentSelection == arg.n + 1) then currentSelection = 1 end
        end

        if(_pad:cross()) then return currentSelection end

        _oldpad = _pad

               screen.waitVblankStart()
            screen.flip()

    end

end

Back to CodeBase
 

Please welcome daryy, our newest member.

Who's Online: 3 Guests, 2 Users
PL3X, daryy

Total Members: 556
Total Posts: 13060
Total Topics: 1480
Total Categories: 8
Total Boards: 35

Recent Posts:

Re: Lua 5.1.4 help. by daryy
Re: PGELua Help - need term for a special rotation fix (mathematical issue) by yaustar
Re: Lua Loader? by Buddy4point0
Re: Lua Loader? by osgeld
Re: Lua Loader? by acer5050
Re: Lua Loader? by bumuckl
Re: Lua Loader? by acer5050
Re: Lua Loader? by bumuckl


Copyright © 2006-2007 www.EvilMana.com All rights reserved.
EvilMana Logo by emcp and Charlie