Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[clientside][dev 8] Simple menu framework
#2
Now you can use in the (version >=G2O- 0.0.6)
Code:
class Menu
{
    constructor(x, y, title, lineHeight)
    {
        m_Position = { x = x, y = y };
        m_TitleId = Draw(x, y, title);
        m_TitleId.font="Font_Old_10_White_Hi.TGA";
        m_TitleId.setColor(123, 118, 94);
        m_TextureId = Texture(x-100, y-100, 3000, 1500, "MENU_INGAME.TGA")
        m_Options = [];
        m_CopyOptions = [];
        m_LineHeight = lineHeight
        m_Cur = 0;
        m_Page = 0;
        m_Showed = false;

        local m_This = this;
        addEventHandler("onKey", function(key) {m_This.menuKeyHandler(key);});
        
    }
function drawLajkDev(txt, fnt, x, y, r, g, b)
{
local draw=Draw(x, y, txt);
draw=Draw(x, y, txt);
draw.font=fnt;
draw.setColor(r, g, b);
return draw;
}
function addOption(title)
    {
        if(m_Options.len() == 0)
        {
            m_Position.y += 300;
            m_Options.append(drawLajkDev(title, "Font_Old_10_White_Hi.TGA", m_Position.x + 50, m_Position.y, 255, 255, 255));
            m_CopyOptions.append(title);
        }
        else
        {
            m_Position.y += 150;
            m_Options.append(drawLajkDev(title, "Font_Old_10_White_Hi.TGA", m_Position.x + 50, m_Position.y, 111, 106, 81));
            m_CopyOptions.append(title);
        }
    }

function show()
    {
        m_Showed = true;
        m_TitleId.visible=true;
        m_TextureId.visible=true;
            
        for(local i = 0; i < m_LineHeight; i++)
        {
            m_Options[i].visible=true;
        }
    }

function hide()
    {
        m_Showed = false;
        m_TitleId.visible=false;
        m_TextureId.visible=false;
        for(local i = 0; i < m_LineHeight; i++)
        {
            m_Options[i].visible=false;
        }
    }
    
function moveDown()
{
    if(m_Cur<m_Options.len()-1){m_Cur++;}else{m_Cur=0;}
    refresh();
}
function moveUp()
{
    if(m_Cur>0){m_Cur--;}else{m_Cur=m_Options.len()-1;}
    refresh();
}

function refresh()
{
for(local i = 0; i < m_LineHeight; i++)
        {
            try {
                m_Options[i].text=m_CopyOptions[i + m_Page];
                m_Options[i].setColor(111, 106, 81);
            } catch(error) {
                m_Options[i].text="";
                m_Options[i].setColor(111, 106, 81);
            }
        }

        if(m_Page > 0)
            m_Options[m_Cur - m_Page].setColor(255, 255, 255);
        else
            m_Options[m_Cur].setColor(255, 255, 255);

}

function menuKeyHandler(key)//Handler is in constructor
    {
        if(m_Showed)
        {    
            if(key==KEY_UP)        {moveUp();}
            if(key==KEY_DOWN)    {moveDown();}
        }
    }    

    

    m_Position = null;
    m_TitleId = null;
    m_TextureId = null;
    m_Options = null;
    m_CopyOptions = null;
    m_LineHeight = null;
    m_Cur = null;
    m_Page = null;
    m_Showed = null;
    }
EXAMPLE:
Code:
local menu = Menu(3000, 6500, "Trener", 5);
menu.addOption("Siła (+1)");//0
menu.addOption("Siła (+5)");//1
menu.addOption("Zręczność (+1)");//2
menu.addOption("Zręczność (+5)");//3
menu.addOption("(Powrót)");//4

function onKeyMenuExample(key)
    {
        if(!menu.m_Showed && key==KEY_P)        {menu.show();setFreeze(true);}
        if(menu.m_Showed && key == KEY_RETURN)
        {
            switch(menu.m_Cur)
            {
            case 0: print("Siła (+1)");break;
            case 1: print("Siła (+5)");break;
            case 2: print("Zręczność (+1)");break;
            case 3: print("Zręczność (+5)");break;
            case 4:    menu.hide();setFreeze(false);break;            
            }
            
        }
            
    }    
    addEventHandler("onKey", onKeyMenuExample)
Reply


Messages In This Thread
RE: [clientside][dev 8] Simple menu framework - by Son Goku - 07.04.2017, 16:20

Possibly Related Threads…
Thread Author Replies Views Last Post
  [New G2O][Client] GUI.Framework Patrix 0 3,151 07.02.2019, 01:39
Last Post: Patrix
  GUI Framework 2.0 Osmith 7 9,622 27.01.2018, 15:01
Last Post: Osmith
  [Clientside] Simple menu framework Sative 1 4,188 09.05.2016, 06:46
Last Post: Sative

Forum Jump:


Users browsing this thread: 1 Guest(s)