Hello, i want to release my old menu framework so here it is.
Example of usage. (It uses my NPC class but you should know how to use this by your own way.)
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);
- }
- }
- };