A simple message box system for LÖVE, a rewrite of Moan.lua
Talkies.say("Title", "Hello world!")- Multiple-choice prompts
- Typing effect + sounds
- Pauses
- UTF-8 support
- Message box icons
- Auto-wrapped text
- General theming and per-message theming
- Mouse support
Break overflow into a new message. Currently, if your message is too large for the message box, it will overflow the box and will not be displayed. Be careful and make sure all your messages work on all of the resolutions you use.
Download the talkies.lua and place it in your project directory.
local Talkies = require('talkies')
function love.load()
Talkies.say("Title", "Hello World!")
end
function love.update(dt)
Talkies.update(dt)
end
function love.draw()
Talkies.draw()
end
function love.keypressed(key)
if key == "space" then Talkies.onAction()
elseif key == "up" then Talkies.prevOption()
elseif key == "down" then Talkies.nextOption()
end
endCreate a new dialog of messages and return that dialog.
- title : string; if set to
"", title box will not appear - messages, a string or a table that contains strings
- config, table that contains message configs, takes:
image, message icon image e.g.love.graphics.newImage("img.png")imageOnLeft, boolean; whentruethe image is drawn on the left, otherwise on the righttitleOnLeft, boolean; whentruethe title box is aligned left, otherwise rightonstart(dialog), function to be executed on message startonmessage(dialog, messages_left), function called after every message that is acknowledgedoncomplete(dialog), function executed on message endoptions, table, contains multiple-choice options- [1], string, a label for the option
- [2], function to be called if option is selected
On the final message in the array of messages, the options will be displayed. Upon pressing return, the function relative to the option will be called. There can be "infinite" options, however the options will probably overflow depending on your UI configuration.
To change the appearance of each message, pass in the theming values described below.
A double dash -- causes the message to stop typing, and will only continue when
Talkies.onAction() is called (e.g. your “advance” key/button). (Be sure to follow
each -- with a space if you want text to wrap correctly!)
Updates the UI with dt and animates typing.
Draw the UI of the dialog
Advances to the next message in the current dialog (and closes the dialog when finished).
Removes all dialogs from the queue and closes the message box.
Will move the option selector to the previous option. This can be safely called at any time so you can bind your actions all at once.
Will move the option selector to the next option. This can be safely called at any time so you can bind your actions all at once.
This is the main interaction with the dialog. If the message is fully displayed, it will show the next message. If the message is paused, it will resume. If the message has options shown, it will select the option. This can safely be called at any time.
Selects an option by its 1-based index (primarily for mouse support).
Returns the option index under the given coordinates, or nil if none.
isOpen will return true if Talkies is currently drawing dialogs. It will return false otherwise.
The options below can be set as Talkies.[attribute] defaults. Most of them can also
be overridden per-dialog by passing them in the config table to Talkies.say(...).
For instance, to set a default text speed for all message boxes you would call
Talkies.textSpeed = "fast" but then if you wanted a single message to go slower you
would create it like this:
Talkies.say("Old man", "I talk very slow", {textSpeed = "slow"})
The following are all of the message theme options:
textSpeed- typing speed. One of"instant","slow","medium","fast", or a number (seconds per character).talkSound- sound to play while text is typing (a short clip works best), e.g.Talkies.talkSound = love.audio.newSource("typeSound.wav", "static")optionSwitchSound- sound to play when an option changes/gets selectedindicatorCharacter- character in the bottom-right indicating more content (string), default:">"indicatorDelay- controls the indicator blink rate (higher = slower). Note: this is a global setting (useTalkies.indicatorDelay), not a per-dialog config override.optionCharacter- character before the selected option (string), default:"-"inlineOptions- whether options are displayed inside the message box or in a separate box, default:trueselectedTextColor- text color for the highlighted option, default:{0.2, 0.2, 0.2, 0.8}selectedBackgroundColor- background color for the highlighted option, default:{1, 1, 1, 0.8}selectedWidth- highlight width for inline options (in pixels), default:300imageOnLeft- whether the message image is drawn on the left, default:truetitleOnLeft- whether the title box is aligned left, default:trueheight- fixed height of the message box (number); whennil, uses one third of the screenfont- message box font (e.g.Talkies.font = love.graphics.newFont("Talkies/main.ttf", 32))padding- padding on the inside of the box, default:10thickness- thickness of box borders, default:0(no border)rounding- radius in pixels of box corners, default:0(no rounding)titleColor- title text color, default:{1, 1, 1, 1}(whennil, uses message text color)titleBackgroundColor- background color for title box, default:nil(whennil, uses message background color)titleBorderColor- border color for title box, default:nil(whennil, uses message border color)messageColor- message text color, default:{1, 1, 1, 1}messageBackgroundColor- background color of the message box, default:{0, 0, 0, 0.8}messageBorderColor- border color of the message box, default:nil(whennil, uses message background color)typedNotTalked- when making a sound while talking, if this is set to true the noise will be made for every character. If set to false the noise will be looped, and the pitch will be oscillated randomly between the pitchValues setting. Default:true.pitchValues- IftypedNotTalkedis set to false then this table value will be used to choose values of pitch while talking. If you want no pitch change set it to{1}. Default is{0.7, 0.8, 1.0, 1.2, 1.3}
isShown will return true if the dialog is currently the dialog on the screen and false otherwise
Example:
local firstdialog = Talkies.say("title", "message")
local seconddialog = Talkies.say("title", "message")
firstdialog:isShown() -- true
seconddialog:isShown() -- false, will return true when Talkies.onAction() is calledErogodic (or my updated fork Erogodic) is a library for scripting branching interactive narrative in Lua, you can check out its use by running the main.lua in that repo.
Talkies includes helper functions for mouse-driven option selection. A simple pattern is:
function love.mousemoved(x, y)
local idx = Talkies.optionXY(x, y)
if idx then Talkies.selectOption(idx) end
end
function love.mousepressed(x, y, button)
if button == 1 then
local idx = Talkies.optionXY(x, y)
if idx then
Talkies.selectOption(idx)
Talkies.onAction()
end
end
end