Difference between revisions of "Message in a Bottle"

m (Added: Other Languages)
 
(16 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
__FORCETOC__
 
__FORCETOC__
=About=
+
==About==
This is a Message management library for LOVE. This library requires [[MiddleClass]].
+
This is a Message management library for LOVE 0.7.0. It aims to be unobtrusive and easy to use.
  
 
[[File:MessageInABottle.png]]
 
[[File:MessageInABottle.png]]
  
=Contact=
+
===Download===
No forum post yet. Go to the [http://bitbucket.org/dannyfritz/message-in-a-bottle/issues?status=new&status=open Issue Tracker] for bugs. Look around for [[User:Technocat |TechnoCat]] if you have any further questions or concerns.
+
Download the code or sample love from [http://bitbucket.org/dannyfritz/message-in-a-bottle/downloads bitbucket].
  
=Features=
+
This library requires [[MiddleClass]]. It is included.
 +
 
 +
===Contact===
 +
See the [http://love2d.org/forums/viewtopic.php?f=5&t=2153#p22671 forum post] for public questions. Go to the [http://bitbucket.org/dannyfritz/message-in-a-bottle/issues?status=new&status=open Issue Tracker] for bugs. Look around for [[User:Technocat |TechnoCat]] if you have any further questions or concerns.
 +
 
 +
It would be cool if you told me if you use it in your project. I would love to see what this is used for.
 +
 
 +
==Features==
 
* StayBottle, bottles that stay until a button is pressed.
 
* StayBottle, bottles that stay until a button is pressed.
 
* TimedBottle, bottles that stay until a button is pressed or until a duration of time has passed.
 
* TimedBottle, bottles that stay until a button is pressed or until a duration of time has passed.
Line 15: Line 22:
 
* Sleek and Stylish Bottle defaults
 
* Sleek and Stylish Bottle defaults
  
==Missing Features==
+
===Missing Features===
 
Not implemented yet, but plan to.
 
Not implemented yet, but plan to.
 
* Boolean Bottles
 
* Boolean Bottles
 
* Choice Bottles
 
* Choice Bottles
  
=Configuring=
+
==Configuring==
 
Much of the configuration you are going to want to do will take place at the top of MessageInABottle.lua.
 
Much of the configuration you are going to want to do will take place at the top of MessageInABottle.lua.
  
=Example=
+
==Usage==
 +
===Setting up Ocean===
 +
<source lang="lua">
 +
require 'MessageInABottle.lua'
 +
 
 +
function love.load()
 +
  ocean = Ocean:new()
 +
end
 +
 
 +
function love.update(dt)
 +
  ocean:update(dt)
 +
end
 +
 
 +
function love.draw()
 +
  ocean:draw()
 +
end
 +
</source>
 +
===Example===
 
<source lang="lua">
 
<source lang="lua">
 
require 'MessageInABottle.lua'
 
require 'MessageInABottle.lua'
Line 31: Line 55:
 
    
 
    
 
   --Initialize the ocean to manage the bottles.
 
   --Initialize the ocean to manage the bottles.
   --It is going to act as a Queue. FIFO
+
   --It is going to act as a bottle queue.
 
   ocean = Ocean:new()
 
   ocean = Ocean:new()
 
    
 
    
Line 37: Line 61:
 
   ocean:addBottle(TimeBottle:new(nil,"...",nil))
 
   ocean:addBottle(TimeBottle:new(nil,"...",nil))
 
    
 
    
 +
  --Create a stay bottle and add it to the ocean
 
   local bottle = StayBottle:new(nil,"What is this?")
 
   local bottle = StayBottle:new(nil,"What is this?")
 +
  --Change some bottle settings to non-default ones
 
   bottle:setX(310)
 
   bottle:setX(310)
 
   bottle:setVolume(0)
 
   bottle:setVolume(0)
Line 44: Line 70:
  
 
function love.update(dt)
 
function love.update(dt)
 +
  --Required to update the bottles
 
   ocean:update(dt)
 
   ocean:update(dt)
 
end
 
end
  
 
function love.draw()
 
function love.draw()
  background:draw()
 
 
   love.graphics.setColor(0,0,0)
 
   love.graphics.setColor(0,0,0)
 +
  --This is showing some useful variables ocean stores.
 
   love.graphics.print(
 
   love.graphics.print(
 
       'last bottle return was: '..ocean.response..
 
       'last bottle return was: '..ocean.response..
 
       ' at '..(math.floor(ocean.responseTime*10)/10)..
 
       ' at '..(math.floor(ocean.responseTime*10)/10)..
 
       's from '..ocean.responseID,12,12)
 
       's from '..ocean.responseID,12,12)
 +
  --This is all that is needed to draw the current bottle
 
   ocean:draw()
 
   ocean:draw()
 
end
 
end
  
 
function love.keypressed(k,u)
 
function love.keypressed(k,u)
 +
  --You can add a bottle on the fly.
 
   if k=="d" then
 
   if k=="d" then
 
     local x = math.floor(math.random(400))
 
     local x = math.floor(math.random(400))
Line 68: Line 97:
 
</source>
 
</source>
  
=Constructors=
+
==Constructors==
==MessageBottle==
+
===Ocean===
 +
<source lang="lua">
 +
Ocean:new()
 +
</source>
 +
 
 +
===MessageBottle===
 
Do not use this. It is the parent class of all Bottles.
 
Do not use this. It is the parent class of all Bottles.
 
<source lang="lua">
 
<source lang="lua">
Line 77: Line 111:
 
{{param|string|text|The text to display on the Bottle. e.g. "Will you open the door?"}}
 
{{param|string|text|The text to display on the Bottle. e.g. "Will you open the door?"}}
  
==StayBottle==
+
===StayBottle===
 
<source lang="lua">
 
<source lang="lua">
 
StayBottle:new(id, text)
 
StayBottle:new(id, text)
Line 84: Line 118:
 
{{param|string|text|The text to display on the Bottle. e.g. "Will you open the door?"}}
 
{{param|string|text|The text to display on the Bottle. e.g. "Will you open the door?"}}
  
==TimeBottle==
+
===TimeBottle===
 
<source lang="lua">
 
<source lang="lua">
 
TimeBottle:new(id, text, timeout)
 
TimeBottle:new(id, text, timeout)
Line 92: Line 126:
 
{{param|number|timeout|The amount of time the bottle will display for.}}
 
{{param|number|timeout|The amount of time the bottle will display for.}}
  
=Setter Functions=
+
==Setter Functions==
==setX==
+
===Timeout===
 +
<source lang="lua">
 +
TimeBottle:setTimeout(timeout)
 +
</source>
 +
{{param|number|timeout|The time left for a TimeBottle}}
 +
 
 +
===setX===
 
<source lang="lua">
 
<source lang="lua">
 
MessageBottle:setX(x)
 
MessageBottle:setX(x)
Line 99: Line 139:
 
{{param|number|x|The x position of the Bottle}}
 
{{param|number|x|The x position of the Bottle}}
  
==setY==
+
===setY===
 
<source lang="lua">
 
<source lang="lua">
 
MessageBottle:setY(y)
 
MessageBottle:setY(y)
Line 105: Line 145:
 
{{param|number|y|The y position of the Bottle}}
 
{{param|number|y|The y position of the Bottle}}
  
==setPosition==
+
===setPosition===
 
<source lang="lua">
 
<source lang="lua">
 
MessageBottle:setPosition(x, y)
 
MessageBottle:setPosition(x, y)
Line 112: Line 152:
 
{{param|number|y|The y position of the Bottle}}
 
{{param|number|y|The y position of the Bottle}}
  
==setWidt==
+
===setWidth===
 
<source lang="lua">
 
<source lang="lua">
 
MessageBottle:setWidth(width)
 
MessageBottle:setWidth(width)
Line 118: Line 158:
 
{{param|number|width|The width of the Bottle}}
 
{{param|number|width|The width of the Bottle}}
  
==setHeight==
+
===setHeight===
 
<source lang="lua">
 
<source lang="lua">
 
MessageBottle:setHeight(height)
 
MessageBottle:setHeight(height)
Line 124: Line 164:
 
{{param|number|height|The height of the Bottle}}
 
{{param|number|height|The height of the Bottle}}
  
==setButton==
+
===setButton===
 
<source lang="lua">
 
<source lang="lua">
 
MessageBottle:setButton(button)
 
MessageBottle:setButton(button)
Line 130: Line 170:
 
{{param|KeyConstant|button|The button the Bottle will use.}}
 
{{param|KeyConstant|button|The button the Bottle will use.}}
  
==setEase==
+
===setEase===
 
<source lang="lua">
 
<source lang="lua">
 
MessageBottle:setEase(ease)
 
MessageBottle:setEase(ease)
Line 136: Line 176:
 
{{param|function|ease|The ease function to use for easing-in.}}
 
{{param|function|ease|The ease function to use for easing-in.}}
  
==setEaseTime==
+
===setEaseTime===
 
<source lang="lua">
 
<source lang="lua">
 
MessageBottle:setEaseTime(easeTime)
 
MessageBottle:setEaseTime(easeTime)
Line 142: Line 182:
 
{{param|number|easeTime|The time to spend easing-in.}}
 
{{param|number|easeTime|The time to spend easing-in.}}
  
==setFade==
+
===setFade===
 
<source lang="lua">
 
<source lang="lua">
 
MessageBottle:setFade(fade)
 
MessageBottle:setFade(fade)
Line 148: Line 188:
 
{{param|function|fade|The fade function to use for fading-in.}}
 
{{param|function|fade|The fade function to use for fading-in.}}
  
==setFadeTime==
+
===setFadeTime===
 
<source lang="lua">
 
<source lang="lua">
 
MessageBottle:setFadeTime(fadeTime)
 
MessageBottle:setFadeTime(fadeTime)
Line 154: Line 194:
 
{{param|number|fadeTime|The time to spend fading-in.}}
 
{{param|number|fadeTime|The time to spend fading-in.}}
  
==setEnterCallback==
+
===setEnterCallback===
 
<source lang="lua">
 
<source lang="lua">
 
MessageBottle:setEnterCallback(enterCB)
 
MessageBottle:setEnterCallback(enterCB)
Line 160: Line 200:
 
{{param|function|enterCB|The callback function to call on opening a bottle.}}
 
{{param|function|enterCB|The callback function to call on opening a bottle.}}
  
==setExitCallback==
+
===setExitCallback===
 
<source lang="lua">
 
<source lang="lua">
 
MessageBottle:setEnterCallback(exitCB)
 
MessageBottle:setEnterCallback(exitCB)
 
</source>
 
</source>
{{param|function|exitCB|The callback function to call on exiting a bottle.}}
+
{{param|function|exitCB|The callback function to call on exiting a bottle. The return of the bottle is passed to the exitCallback.}}
  
==setSound==
+
===setSound===
 
<source lang="lua">
 
<source lang="lua">
 
MessageBottle:setSound(sound)
 
MessageBottle:setSound(sound)
Line 172: Line 212:
 
{{param|string|sound|The location of a sound file.}}
 
{{param|string|sound|The location of a sound file.}}
  
==setVolume==
+
===setVolume===
 
<source lang="lua">
 
<source lang="lua">
 
MessageBottle:setVolume(volume)
 
MessageBottle:setVolume(volume)
Line 178: Line 218:
 
{{param|number|volume|The volume of the sound. Normal volume is 1.0.}}
 
{{param|number|volume|The volume of the sound. Normal volume is 1.0.}}
  
==setIndicator==
+
===setIndicator===
 
<source lang="lua">
 
<source lang="lua">
 
MessageBottle:setIndicator(indicator)
 
MessageBottle:setIndicator(indicator)
Line 184: Line 224:
 
{{param|string|indicator|The location of the indicator image file. The indicator is the icon that bounces up and down on certain bottles.}}
 
{{param|string|indicator|The location of the indicator image file. The indicator is the icon that bounces up and down on certain bottles.}}
  
==setFgColor==
+
===setFgColor===
 
<source lang="lua">
 
<source lang="lua">
 
MessageBottle:setFgColor(r, g, b, a)
 
MessageBottle:setFgColor(r, g, b, a)
Line 193: Line 233:
 
{{param|number|a|The alpha value from 0-255.}}
 
{{param|number|a|The alpha value from 0-255.}}
  
==setFont==
+
===setFont===
 
<source lang="lua">
 
<source lang="lua">
 
MessageBottle:setFont(font, size)
 
MessageBottle:setFont(font, size)
Line 200: Line 240:
 
{{param|number|size|The point value size.}}
 
{{param|number|size|The point value size.}}
  
==setBgColor==
+
===setAlign===
 +
<source lang="lua">
 +
MessageBottle:setAlign(align)
 +
</source>
 +
{{param|AlignMode|align|The align mode.}}
 +
 
 +
===setBgColor===
 
<source lang="lua">
 
<source lang="lua">
 
MessageBottle:setFgColor(r, g, b, a)
 
MessageBottle:setFgColor(r, g, b, a)
Line 209: Line 255:
 
{{param|number|a|The alpha value from 0-255.}}
 
{{param|number|a|The alpha value from 0-255.}}
  
==setBgRadius==
+
===setBgRadius===
 
<source lang="lua">
 
<source lang="lua">
 
MessageBottle:setBgRadius(r)
 
MessageBottle:setBgRadius(r)
Line 215: Line 261:
 
{{param|number|r|The radius of the corners.}}
 
{{param|number|r|The radius of the corners.}}
  
==setBgRadiusSegments==
+
===setBgRadiusSegments===
 
<source lang="lua">
 
<source lang="lua">
 
MessageBottle:setBgRadiusSegments(n)
 
MessageBottle:setBgRadiusSegments(n)
Line 221: Line 267:
 
{{param|number|n|The number of segments to draw on each corner.}}
 
{{param|number|n|The number of segments to draw on each corner.}}
  
= See Also =
 
* [[Libraries]]
 
  
 
{{#set:LOVE Version=0.7.0}}
 
{{#set:LOVE Version=0.7.0}}
 
{{#set:Description=A message library for LOVE.}}
 
{{#set:Description=A message library for LOVE.}}
 +
{{#set:Keyword=Graphical User Interface}}
 
[[Category:Libraries]]
 
[[Category:Libraries]]
 +
== Other Languages ==
 +
{{i18n|Message in a Bottle}}

Latest revision as of 15:34, 15 December 2019

About

This is a Message management library for LOVE 0.7.0. It aims to be unobtrusive and easy to use.

MessageInABottle.png

Download

Download the code or sample love from bitbucket.

This library requires MiddleClass. It is included.

Contact

See the forum post for public questions. Go to the Issue Tracker for bugs. Look around for TechnoCat if you have any further questions or concerns.

It would be cool if you told me if you use it in your project. I would love to see what this is used for.

Features

  • StayBottle, bottles that stay until a button is pressed.
  • TimedBottle, bottles that stay until a button is pressed or until a duration of time has passed.
  • Ocean, a management object for Bottles
  • Very (and hopefully easily) Configurable Bottles
  • Sleek and Stylish Bottle defaults

Missing Features

Not implemented yet, but plan to.

  • Boolean Bottles
  • Choice Bottles

Configuring

Much of the configuration you are going to want to do will take place at the top of MessageInABottle.lua.

Usage

Setting up Ocean

require 'MessageInABottle.lua'

function love.load()
  ocean = Ocean:new()
end

function love.update(dt)
  ocean:update(dt)
end

function love.draw()
  ocean:draw()
end

Example

require 'MessageInABottle.lua'

function love.load()
  love.graphics.setBackgroundColor(255,255,255)
  
  --Initialize the ocean to manage the bottles.
  --It is going to act as a bottle queue.
  ocean = Ocean:new()
  
  --Create a timed bottle and add it to the ocean
  ocean:addBottle(TimeBottle:new(nil,"...",nil))
  
  --Create a stay bottle and add it to the ocean
  local bottle = StayBottle:new(nil,"What is this?")
  --Change some bottle settings to non-default ones
  bottle:setX(310)
  bottle:setVolume(0)
  ocean:addBottle(bottle)
end

function love.update(dt)
  --Required to update the bottles
  ocean:update(dt)
end

function love.draw()
  love.graphics.setColor(0,0,0)
  --This is showing some useful variables ocean stores.
  love.graphics.print(
      'last bottle return was: '..ocean.response..
      ' at '..(math.floor(ocean.responseTime*10)/10)..
      's from '..ocean.responseID,12,12)
  --This is all that is needed to draw the current bottle
  ocean:draw()
end

function love.keypressed(k,u)
  --You can add a bottle on the fly.
  if k=="d" then
    local x = math.floor(math.random(400))
    local y = math.floor(math.random(150))
    ocean:addBottle(TimeBottle:new("PRESSED_D","Timed Box!"))
  elseif k=="escape" then
    love.event.push("q")
  end
end

Constructors

Ocean

Ocean:new()

MessageBottle

Do not use this. It is the parent class of all Bottles.

MessageBottle:new(id, text)
string id
The unique identifier of the Bottle. e.g. "Open Door"
string text
The text to display on the Bottle. e.g. "Will you open the door?"

StayBottle

StayBottle:new(id, text)
string id
The unique identifier of the Bottle. e.g. "Open Door"
string text
The text to display on the Bottle. e.g. "Will you open the door?"

TimeBottle

TimeBottle:new(id, text, timeout)
string id
The unique identifier of the Bottle. e.g. "Open Door"
string text
The text to display on the Bottle. e.g. "Will you open the door?"
number timeout
The amount of time the bottle will display for.

Setter Functions

Timeout

TimeBottle:setTimeout(timeout)
number timeout
The time left for a TimeBottle

setX

MessageBottle:setX(x)
number x
The x position of the Bottle

setY

MessageBottle:setY(y)
number y
The y position of the Bottle

setPosition

MessageBottle:setPosition(x, y)
number x
The x position of the Bottle
number y
The y position of the Bottle

setWidth

MessageBottle:setWidth(width)
number width
The width of the Bottle

setHeight

MessageBottle:setHeight(height)
number height
The height of the Bottle

setButton

MessageBottle:setButton(button)
KeyConstant button
The button the Bottle will use.

setEase

MessageBottle:setEase(ease)
function ease
The ease function to use for easing-in.

setEaseTime

MessageBottle:setEaseTime(easeTime)
number easeTime
The time to spend easing-in.

setFade

MessageBottle:setFade(fade)
function fade
The fade function to use for fading-in.

setFadeTime

MessageBottle:setFadeTime(fadeTime)
number fadeTime
The time to spend fading-in.

setEnterCallback

MessageBottle:setEnterCallback(enterCB)
function enterCB
The callback function to call on opening a bottle.

setExitCallback

MessageBottle:setEnterCallback(exitCB)
function exitCB
The callback function to call on exiting a bottle. The return of the bottle is passed to the exitCallback.

setSound

MessageBottle:setSound(sound)
string sound
The location of a sound file.

setVolume

MessageBottle:setVolume(volume)
number volume
The volume of the sound. Normal volume is 1.0.

setIndicator

MessageBottle:setIndicator(indicator)
string indicator
The location of the indicator image file. The indicator is the icon that bounces up and down on certain bottles.

setFgColor

MessageBottle:setFgColor(r, g, b, a)
number r
The red value from 0-255.
number g
The green value from 0-255.
number b
The blue value from 0-255.
number a
The alpha value from 0-255.

setFont

MessageBottle:setFont(font, size)
string font
The location of the font file.
number size
The point value size.

setAlign

MessageBottle:setAlign(align)
AlignMode align
The align mode.

setBgColor

MessageBottle:setFgColor(r, g, b, a)
number r
The red value from 0-255.
number g
The green value from 0-255.
number b
The blue value from 0-255.
number a
The alpha value from 0-255.

setBgRadius

MessageBottle:setBgRadius(r)
number r
The radius of the corners.

setBgRadiusSegments

MessageBottle:setBgRadiusSegments(n)
number n
The number of segments to draw on each corner.

Other Languages