[clientside][dev 8] Simple menu framework - Nubzior - 28.03.2017
Hello, i want to release my old menu framework so here it is.
Squirrel Script class Menu { constructor(x, y, title, lineHeight) { m_Position = { x = x, y = y }; m_TitleId = createDraw(title, "Font_Old_20_White_Hi.TGA", x, y, 123, 118, 94); m_TextureId = createTexture(x - 100, y - 100, 3000, 1500, "ramka_gui.tga"); m_Options = []; m_CopyOptions = []; m_LineHeight = lineHeight m_Cur = 0; m_CurTitle = ""; m_Page = 0; m_Showed = false; local m_This = this; addEvent("onKey", function(key, letter) {m_This.onKey(key, letter);}); } function addOption(title) { if(m_Options.len() == 0) { m_Position.y += 300; m_Options.append(createDraw(title, "Font_Old_10_White_Hi.TGA", m_Position.x + 50, m_Position.y, 255, 255, 255)); m_CopyOptions.append(title); m_CurTitle = title; } else { m_Position.y += 150; m_Options.append(createDraw(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; setDrawVisible(m_TitleId, true); setTextureVisible(m_TextureId, true); for(local i = 0; i < m_LineHeight; i++) { setDrawVisible(m_Options[i], true); } } function hide() { m_Showed = false; setDrawVisible(m_TitleId, false); setTextureVisible(m_TextureId, false); for(local i = 0; i < m_LineHeight; i++) { setDrawVisible(m_Options[i], false); } } function moveUp() { if(m_Cur % m_LineHeight == 0 && m_Page > 0) m_Page -= m_LineHeight; if(m_Cur > 0) m_Cur--; refresh(); } function moveDown() { if(m_Cur == (m_Options.len() - 1)) return false; m_Cur++; if(m_Cur % m_LineHeight == 0) m_Page += m_LineHeight; refresh(); } function refresh() { for(local i = 0; i < m_LineHeight; i++) { try { setDrawText(m_Options[i], m_CopyOptions[i + m_Page]); setDrawColor(m_Options[i], 111, 106, 81); } catch(error) { setDrawText(m_Options[i], ""); setDrawColor(m_Options[i], 111, 106, 81); } } if(m_Page > 0) setDrawColor(m_Options[m_Cur - m_Page], 255, 255, 255); else setDrawColor(m_Options[m_Cur], 255, 255, 255); m_CurTitle = m_CopyOptions[m_Cur]; } function onKey(key, letter) { switch(key) { case KEY_UP: moveUp(); break; case KEY_DOWN: moveDown(); break; } } m_Position = null; m_TitleId = null; m_TextureId = null; m_Options = null; m_CopyOptions = null; m_LineHeight = null; m_Cur = null; m_CurTitle = null; m_Page = null; m_Showed = null; }
Example of usage. (It uses my NPC class but you should know how to use this by your own way.)
Squirrel Script local Npc = Npcs("Trener"); local menu = Menu(3000, 6500, "Trener", 5); menu.addOption("Siła (+1)"); menu.addOption("Siła (+5)"); menu.addOption("Zręczność (+1)"); menu.addOption("Zręczność (+5)"); menu.addOption("(Powrót)"); addEvent("onKey", function(key, letter) { Npc.onCtrl(key, letter); }); addEvent("onTakeFocus", function(id, name) { Npc.setFocus(name, true); }); addEvent("onLostFocus", function(id, name) { Npc.setFocus(name, false); if(menu.m_Showed) { menu.hide(); setFreeze(false); } }); Npc.onCtrl = function(key, letter) { if(menu.m_Showed && key == KEY_RETURN) { if(menu.m_CurTitle == "(Powrót)") { menu.hide(); setFreeze(false); } } if(Npc.isFocused() && key == KEY_LCONTROL) { if(!menu.m_Showed) { callServerFunc(RELIABLE, "botAngleToPos", FOCUS_ID, getID()); menu.show(); setFreeze(true); } else { menu.hide(); setFreeze(false); } } };
RE: [clientside][dev 8] Simple menu framework - Son Goku - 07.04.2017
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)
|