order inc files to folders
This commit is contained in:
8
inc/system/system.input.lua
Normal file
8
inc/system/system.input.lua
Normal file
@@ -0,0 +1,8 @@
|
||||
function Input.up() return btnp(0) end
|
||||
function Input.down() return btnp(1) end
|
||||
function Input.left() return btn(2) end
|
||||
function Input.right() return btn(3) end
|
||||
function Input.player_jump() return btnp(4) end
|
||||
function Input.menu_confirm() return btnp(4) end
|
||||
function Input.player_interact() return btnp(5) end -- B button
|
||||
function Input.menu_back() return btnp(5) end
|
||||
40
inc/system/system.main.lua
Normal file
40
inc/system/system.main.lua
Normal file
@@ -0,0 +1,40 @@
|
||||
local STATE_HANDLERS = {
|
||||
[WINDOW_SPLASH] = function()
|
||||
SplashWindow.update()
|
||||
SplashWindow.draw()
|
||||
end,
|
||||
[WINDOW_INTRO] = function()
|
||||
IntroWindow.update()
|
||||
IntroWindow.draw()
|
||||
end,
|
||||
[WINDOW_MENU] = function()
|
||||
MenuWindow.update()
|
||||
MenuWindow.draw()
|
||||
end,
|
||||
[WINDOW_GAME] = function()
|
||||
GameWindow.update()
|
||||
GameWindow.draw()
|
||||
end,
|
||||
[WINDOW_POPUP] = function()
|
||||
GameWindow.draw()
|
||||
PopupWindow.update()
|
||||
PopupWindow.draw()
|
||||
end,
|
||||
[WINDOW_INVENTORY] = function()
|
||||
InventoryWindow.update()
|
||||
InventoryWindow.draw()
|
||||
end,
|
||||
[WINDOW_INVENTORY_ACTION] = function()
|
||||
InventoryWindow.draw()
|
||||
PopupWindow.draw()
|
||||
PopupWindow.update()
|
||||
end,
|
||||
}
|
||||
|
||||
function TIC()
|
||||
cls(Config.colors.black)
|
||||
local handler = STATE_HANDLERS[Context.active_window]
|
||||
if handler then
|
||||
handler()
|
||||
end
|
||||
end
|
||||
67
inc/system/system.ui.lua
Normal file
67
inc/system/system.ui.lua
Normal file
@@ -0,0 +1,67 @@
|
||||
function UI.draw_top_bar(title)
|
||||
rect(0, 0, Config.screen.width, 10, Config.colors.dark_grey)
|
||||
print(title, 3, 2, Config.colors.green)
|
||||
end
|
||||
|
||||
function UI.draw_dialog()
|
||||
PopupWindow.draw()
|
||||
end
|
||||
|
||||
function UI.draw_menu(items, selected_item, x, y)
|
||||
for i, item in ipairs(items) do
|
||||
local current_y = y + (i-1)*10
|
||||
if i == selected_item then
|
||||
print(">", x - 8, current_y, Config.colors.green)
|
||||
end
|
||||
print(item.label, x, current_y, Config.colors.green)
|
||||
end
|
||||
end
|
||||
|
||||
function UI.update_menu(items, selected_item)
|
||||
if Input.up() then
|
||||
selected_item = selected_item - 1
|
||||
if selected_item < 1 then
|
||||
selected_item = #items
|
||||
end
|
||||
elseif Input.down() then
|
||||
selected_item = selected_item + 1
|
||||
if selected_item > #items then
|
||||
selected_item = 1
|
||||
end
|
||||
end
|
||||
return selected_item
|
||||
end
|
||||
|
||||
function UI.word_wrap(text, max_chars_per_line)
|
||||
if text == nil then return {""} end
|
||||
local lines = {}
|
||||
|
||||
for input_line in (text .. "\n"):gmatch("(.-)\n") do
|
||||
local current_line = ""
|
||||
local words_in_line = 0
|
||||
for word in input_line:gmatch("%S+") do
|
||||
words_in_line = words_in_line + 1
|
||||
if #current_line == 0 then
|
||||
current_line = word
|
||||
elseif #current_line + #word + 1 <= max_chars_per_line then
|
||||
current_line = current_line .. " " .. word
|
||||
else
|
||||
table.insert(lines, current_line)
|
||||
current_line = word
|
||||
end
|
||||
end
|
||||
|
||||
if words_in_line > 0 then
|
||||
table.insert(lines, current_line)
|
||||
else
|
||||
table.insert(lines, "")
|
||||
end
|
||||
end
|
||||
|
||||
if #lines == 0 then
|
||||
return {""}
|
||||
end
|
||||
|
||||
return lines
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user