Also posting this here as this looks cool af. (by BDC_Osiris)
Pesquisa resultou em 2 ocorrências
Voltar para “Função para criar menus facilmente em LUA.”
- 04 Jul 2020, 22:17
- Fórum: Utilidades
- Tópico: Função para criar menus facilmente em LUA.
- Respostas: 11
- Exibições: 2445
- Gênero:
- 14 Jan 2020, 05:46
- Fórum: Utilidades
- Tópico: Função para criar menus facilmente em LUA.
- Respostas: 11
- Exibições: 2445
- Gênero:
Re: Função para criar menus facilmente em LUA.
I think the ability to scroll if there are more than 11 columns would be better.
Something similar to this,
----------------------------------------
I tried to recreate the menu from scratch following how junior did his shinegui.
You can basically create a table and the menu will generate itself.
Download
Something similar to this,
SpoilerAbrir
Código: Selecionar tudo
function simple_menu(table_name,pos_x,pos_y,return_text,button)
local index = 3 -- first column at 3
if button == nil then button = 11 end -- yes
local labels = {};
setPlayerControl(PLAYER_HANDLE,false);
setCameraBehindPlayer();
for i=1, #table_name do
if table_name[i] then
labels[i] = setFreeGxtEntry(table_name[i]);
else
labels[i] = "DUMMY";
end
end
local menu = createMenu(labels[1],pos_x,pos_y,300.0,1,true,true,1);
setMenuColumn(menu,0,labels[2],labels[3],labels[4],labels[5],labels[6],labels[7],labels[8],labels[9],labels[10],labels[11],labels[12],labels[13]);
while not isButtonPressed(PLAYER_HANDLE,button) do
wait(0);
local selected_item = getMenuItemSelected(menu)
if isKeyDown(0x53) or isKeyDown(0x28) then -- S/Down
if selected_item == 10 then
if (index+11) <= #labels then
index = index+1
selected_item = 10
else
if index == (#labels-10) then
index = 3
selected_item = 0
end
end
while isKeyDown(0x53) or isKeyDown(0x28) do
wait(0);
end
setMenuColumn(menu,0,labels[2],labels[index],labels[index+1],labels[index+2],labels[index+3],labels[index+4],labels[index+5],labels[index+6],labels[index+7],labels[index+8],labels[index+9],labels[index+10]);
setActiveMenuItem(0,selected_item)
end
end
if isKeyDown(0x57) or isKeyDown(0x26) then -- W/Up
if selected_item == 0 then
if index > 3 then
index = index-1
selected_item = 0
else
if index == 3 then
index = #labels - 10
selected_item = 10
end
end
while isKeyDown(0x57) or isKeyDown(0x26) do
wait(0);
end
setMenuColumn(menu,0,labels[2],labels[index],labels[index+1],labels[index+2],labels[index+3],labels[index+4],labels[index+5],labels[index+6],labels[index+7],labels[index+8],labels[index+9],labels[index+10]);
setActiveMenuItem(0,selected_item)
end
end
end
local option = getMenuItemSelected(menu);
deleteMenu(menu);
while isButtonPressed(PLAYER_HANDLE,button) do
wait(0);
end
setPlayerControl(PLAYER_HANDLE,true);
restoreCamera();
for i=1, #labels do
if labels[i]~="DUMMY" then
clearGxtEntry(labels[i]);
end
end
if return_text then
return table_name[option+index];
end
return option;
end[/i][/i][/i][/i][/i][/i]
----------------------------------------
I tried to recreate the menu from scratch following how junior did his shinegui.
You can basically create a table and the menu will generate itself.
SpoilerAbrir
Código: Selecionar tudo
script_name 'Simple Ui'
script_author("Grinch_")
local main_menu = {
["Entry 1"] = {
["Help Message Test"] = function() printHelpString("Help Message") end,
["Other stuff"] = function() --[[ do stuff ]] end,
},
["Entry 2"] = {
["Sub entry 1"] =
{
["TEST"] = {}, -- shows empty menu
},
["Sub entry 2"] = nil, -- won't appear in menu
},
}
--------------------------------
-- These are used in runtine
local show_menu = false
local selected_item = 1
local start_index = 1
local current_table = main_menu
local tables = {}
--------------------------------
function getElementCount(table)
i = 0
for key,value in pairs(table) do
i = i + 1
end
return i
end
function getStringIndex(name,table)
local index = 0
for key,value in pairs(table) do
index = index + 1
if key == name then
return index
end
end
end
function getIndexString(index,table)
local count = 0
for key,value in pairs(table) do
count = count + 1
if count == index then
return key
end
end
end
function SimpleUi(title,posX,posY,width,padding,column_spacing,font,display_text_count,text_rgba,text_active_rgba,box_rgba,h_rgba)
------------------------------------------
-- Default values
posX = posX or 70.0
posY = posY or 70.0
width = width or 150.0
box_rgba = box_rgba or {0,0,0,150}
h_rgba = h_rgba or {120, 120, 120,200} -- header rgba
padding = padding or 10.0
column_spacing = column_spacing or 15.0
display_text_count = display_text_count or 15
font = font or 3
text_rgba = text_rgba or {200,200,200,255}
text_active_rgba = text_active_rgba or {100,200,255,255}
------------------------------------------
drawMenu = function()
local header_height = padding+column_spacing
local current_spacing = 0
setSpritesDrawBeforeFade(true)
-- Header
drawRect(posX+width/2,posY,width,header_height,h_rgba[1],h_rgba[2],h_rgba[3],h_rgba[4])
useRenderCommands(true)
setTextFont(font)
setTextWrapx(640.0)
setTextScale(0.5,2)
setTextDropshadow(1,0,0,0,200)
displayText(posX+width/2-5*string.len(title),posY-header_height/2,setFreeGxtEntry(title)) -- Header text
-- Text drawing stuff
for name,redirect in pairs(current_table) do
useRenderCommands(true)
setTextFont(font)
setTextWrapx(640.0)
setTextScale(0.3,1.2)
setTextDropshadow(0,0,0,0,0)
if getStringIndex(name,current_table) == selected_item then
setTextColour(text_active_rgba[1],text_active_rgba[2],text_active_rgba[3],text_active_rgba[4])
setTextEdge(1,0,0,0,255)
else
setTextColour(text_rgba[1],text_rgba[2],text_rgba[3],text_rgba[4])
end
local gxt = name
if type(redirect) == "table" then
gxt = gxt .. " >"
end
displayText(posX+padding,posY+column_spacing+header_height/2+current_spacing,setFreeGxtEntry(gxt))
clearGxtEntry(name)
current_spacing = current_spacing + column_spacing
end
local mainboxY = posY+(header_height+current_spacing)/2 + column_spacing
-- Main box
drawRect(posX+width/2,mainboxY,width,current_spacing + column_spacing*2,box_rgba[1],box_rgba[2],box_rgba[3],box_rgba[4])
end
drawMenu()
if isKeyDown(0x53) or isKeyDown(0x28) then -- S/Down
while isKeyDown(0x53) or isKeyDown(0x28) do
wait(0)
drawMenu()
end
if (selected_item-start_index+1) == display_text_count then
if (start_index+display_text_count) < getElementCount(current_table) then
start_index = start_index + 1
end
end
if selected_item < getElementCount(current_table) then
selected_item = selected_item + 1
else
selected_item = 1
start_index = 1
end
end
if isKeyDown(0x57) or isKeyDown(0x26) then -- W/Up
while isKeyDown(0x57) or isKeyDown(0x26) do
wait(0)
drawMenu()
end
if (selected_item-start_index+1) == 1 then
if start_index > 1 then
start_index = start_index - 1
end
end
if selected_item > 1 then
selected_item = selected_item - 1
else
selected_item = getElementCount(current_table)
start_index = getElementCount(current_table) - display_text_count
end
end
if isKeyDown(0x20) then -- Space
while isKeyDown(0x20) do
wait(0)
drawMenu()
end
local table_ = current_table[getIndexString(selected_item,current_table)]
if type(table_) == "table" then
table.insert(tables,current_table)
current_table = table_
selected_item = 1
start_index = 1
else
if table_ ~= nil then
table_() -- execute the function
end
end
end
if isKeyDown(0x0D) then -- Enter
while isKeyDown(0x0D) do
wait(0)
drawMenu()
end
current_table = tables[#tables]
if #tables > 1 then
table.remove(tables)
else
show_menu = false
end
end
end
function main()
while true do
wait(0);
if show_menu then
SimpleUi("Simple Ui")
end
if testCheat("Menu") then
show_menu = not show_menu
end
end
end