Compare commits
2 Commits
a5ed57777a
...
2c79da5244
| Author | SHA1 | Date | |
|---|---|---|---|
| 2c79da5244 | |||
| 7c5997cd00 |
@@ -3,7 +3,7 @@
|
|||||||
-- desc: Life of a programmer in the Vector
|
-- desc: Life of a programmer in the Vector
|
||||||
-- site: https://github.com/rastasi/mranderson
|
-- site: https://github.com/rastasi/mranderson
|
||||||
-- license: MIT License
|
-- license: MIT License
|
||||||
-- version: 0.8
|
-- version: 0.9
|
||||||
-- script: lua
|
-- script: lua
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
@@ -549,45 +549,36 @@ function UI.update_menu(items, selected_item)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function UI.word_wrap(text, max_chars_per_line)
|
function UI.word_wrap(text, max_chars_per_line)
|
||||||
local result_lines = {}
|
if text == nil then return {""} end
|
||||||
local segments = {}
|
local lines = {}
|
||||||
|
|
||||||
-- Split the input text by explicit newline characters first
|
for input_line in (text .. "\n"):gmatch("(.-)\n") do
|
||||||
for segment in text:gmatch("([^\\n]*)\\n?") do
|
|
||||||
table.insert(segments, segment)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Process each segment for word wrapping
|
|
||||||
for _, segment_text in ipairs(segments) do
|
|
||||||
local current_line = ""
|
local current_line = ""
|
||||||
local words = {}
|
local words_in_line = 0
|
||||||
|
for word in input_line:gmatch("%S+") do
|
||||||
-- Split segment into words
|
words_in_line = words_in_line + 1
|
||||||
for word in segment_text:gmatch("%S+") do
|
|
||||||
table.insert(words, word)
|
|
||||||
end
|
|
||||||
|
|
||||||
local i = 1
|
|
||||||
while i <= #words do
|
|
||||||
local word = words[i]
|
|
||||||
if #current_line == 0 then
|
if #current_line == 0 then
|
||||||
current_line = word
|
current_line = word
|
||||||
elseif #current_line + 1 + #word <= max_chars_per_line then
|
elseif #current_line + #word + 1 <= max_chars_per_line then
|
||||||
current_line = current_line .. " " .. word
|
current_line = current_line .. " " .. word
|
||||||
else
|
else
|
||||||
table.insert(result_lines, current_line)
|
table.insert(lines, current_line)
|
||||||
current_line = word
|
current_line = word
|
||||||
end
|
end
|
||||||
i = i + 1
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Add the last line of the segment if not empty
|
if words_in_line > 0 then
|
||||||
if #current_line > 0 then
|
table.insert(lines, current_line)
|
||||||
table.insert(result_lines, current_line)
|
else
|
||||||
|
table.insert(lines, "")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return result_lines
|
if #lines == 0 then
|
||||||
|
return {""}
|
||||||
|
end
|
||||||
|
|
||||||
|
return lines
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
@@ -782,9 +773,7 @@ function Player.update()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function GameWindow.update()
|
function GameWindow.update()
|
||||||
|
|
||||||
Player.update() -- Call the encapsulated player update logic
|
Player.update() -- Call the encapsulated player update logic
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function GameWindow.set_state(new_state)
|
function GameWindow.set_state(new_state)
|
||||||
@@ -792,8 +781,6 @@ function GameWindow.set_state(new_state)
|
|||||||
-- Add any state-specific initialization/cleanup here later if needed
|
-- Add any state-specific initialization/cleanup here later if needed
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function PopupWindow.set_dialog_node(node_key)
|
function PopupWindow.set_dialog_node(node_key)
|
||||||
local npc = Context.dialog.active_entity
|
local npc = Context.dialog.active_entity
|
||||||
local node = npc.dialog[node_key]
|
local node = npc.dialog[node_key]
|
||||||
@@ -894,8 +881,8 @@ local STATE_HANDLERS = {
|
|||||||
end,
|
end,
|
||||||
[WINDOW_POPUP] = function()
|
[WINDOW_POPUP] = function()
|
||||||
GameWindow.draw() -- Draw game behind dialog
|
GameWindow.draw() -- Draw game behind dialog
|
||||||
PopupWindow.draw()
|
|
||||||
PopupWindow.update()
|
PopupWindow.update()
|
||||||
|
PopupWindow.draw()
|
||||||
end,
|
end,
|
||||||
[WINDOW_INVENTORY] = function()
|
[WINDOW_INVENTORY] = function()
|
||||||
InventoryWindow.update()
|
InventoryWindow.update()
|
||||||
|
|||||||
Reference in New Issue
Block a user