Thanks to visit codestin.com
Credit goes to github.com

Skip to content

unreal79/talkies

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Talkies

A simple message box system for LÖVE, a rewrite of Moan.lua

Talkies.say("Title", "Hello world!")

Features

  • Multiple-choice prompts
  • Typing effect + sounds
  • Pauses
  • UTF-8 support
  • Message box icons
  • Auto-wrapped text
  • General theming and per-message theming
  • Mouse support

To do:

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.

How to

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
end

API

Talkies.say(title, messages, config)

Create 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; when true the image is drawn on the left, otherwise on the right
    • titleOnLeft, boolean; when true the title box is aligned left, otherwise right
    • onstart(dialog), function to be executed on message start
    • onmessage(dialog, messages_left), function called after every message that is acknowledged
    • oncomplete(dialog), function executed on message end
    • options, 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.

Pauses

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!)

Talkies.update(dt)

Updates the UI with dt and animates typing.

Talkies.draw()

Draw the UI of the dialog

Talkies.advanceMsg()

Advances to the next message in the current dialog (and closes the dialog when finished).

Talkies.clearMessages()

Removes all dialogs from the queue and closes the message box.

Talkies.prevOption()

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.

Talkies.nextOption()

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.

Talkies.onAction()

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.

Talkies.selectOption(index)

Selects an option by its 1-based index (primarily for mouse support).

Talkies.optionXY(x, y)

Returns the option index under the given coordinates, or nil if none.

Talkies.isOpen()

isOpen will return true if Talkies is currently drawing dialogs. It will return false otherwise.

Theming your message box

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 selected
  • indicatorCharacter - character in the bottom-right indicating more content (string), default: ">"
  • indicatorDelay - controls the indicator blink rate (higher = slower). Note: this is a global setting (use Talkies.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: true
  • selectedTextColor - 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: 300
  • imageOnLeft - whether the message image is drawn on the left, default: true
  • titleOnLeft - whether the title box is aligned left, default: true
  • height - fixed height of the message box (number); when nil, uses one third of the screen
  • font - message box font (e.g. Talkies.font = love.graphics.newFont("Talkies/main.ttf", 32))
  • padding - padding on the inside of the box, default: 10
  • thickness - 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} (when nil, uses message text color)
  • titleBackgroundColor - background color for title box, default: nil (when nil, uses message background color)
  • titleBorderColor - border color for title box, default: nil (when nil, 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 (when nil, 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 - If typedNotTalked is 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}

dialog:isShown()

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 called

Building a script

Erogodic (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.

Mouse support (options)

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

About

A dialog system for Löve2D

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Lua 100.0%