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 anthonyjee, our newest member.

Who's Online:

Total Members: 522
Total Posts: 13085
Total Topics: 1515
Total Categories: 7
Total Boards: 42

Recent Posts:

Re: Hello every body... by DeniseVera
Need help please by Robbynator
Re: Hello every body... by horvathann
Re: background criminal record check by backgroundchecker
background criminal record check by backgroundchecker
Intro to Perl Part 2: What are Scalars? & Examples by Chi Kitory
Intro to Perl Part 1 About Perl and Hello World by Chi Kitory
Re: Trying To Get Rid of the Spammers by Charlie


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