Skip to content

Commit

Permalink
Added get.(width/height/lines), scroll
Browse files Browse the repository at this point in the history
Added get.(width/height/lines), scroll, added line-height default setting
  • Loading branch information
sysl-dev committed Apr 25, 2021
1 parent 6182ee6 commit 0101db1
Show file tree
Hide file tree
Showing 8 changed files with 306 additions and 1,548 deletions.
2 changes: 1 addition & 1 deletion example/font/earth_illusion.fnt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
info face="Earth Illusion" size=22 bold=0 italic=0 charset="" unicode=1 stretchH=100 smooth=0 aa=1 padding=2,2,2,2 spacing=2,1 outline=0
common lineHeight=17 base=18 scaleW=512 scaleH=512 pages=1 packed=0 alphaChnl=1 redChnl=0 greenChnl=0 blueChnl=0
common lineHeight=19 base=18 scaleW=512 scaleH=512 pages=1 packed=0 alphaChnl=1 redChnl=0 greenChnl=0 blueChnl=0
page id=0 file="earth_illusion_0.png"
chars count=214
char id=-1 x=91 y=0 width=15 height=26 xoffset=-2 yoffset=-2 xadvance=11 page=0 chnl=15
Expand Down
2 changes: 1 addition & 1 deletion example/font/golden_apple.fnt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
info face="Golden Apple" size=18 bold=0 italic=0 charset="" unicode=1 stretchH=100 smooth=0 aa=0 padding=2,2,2,2 spacing=2,1 outline=0
common lineHeight=15 base=15 scaleW=512 scaleH=256 pages=1 packed=0 alphaChnl=1 redChnl=0 greenChnl=0 blueChnl=0
common lineHeight=18 base=15 scaleW=512 scaleH=256 pages=1 packed=0 alphaChnl=1 redChnl=0 greenChnl=0 blueChnl=0
page id=0 file="golden_apple_0.png"
chars count=388
char id=-1 x=471 y=46 width=11 height=22 xoffset=-2 yoffset=-2 xadvance=7 page=0 chnl=15
Expand Down
205 changes: 140 additions & 65 deletions example/library/slog-text.lua

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions example/longtext.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,4 @@ This will even work for other languages!
[font=shinonome_12]こんにちは![/font][font=shinonome_14]こんにちは![/font][font=shinonome_16]こんにちは![/font]
You can even draw an image directly in the text!
[image=frame=default_8][image=frame=eb_8][image=frame=m3_8]
]]
[image=frame=default_8][image=frame=eb_8][image=frame=m3_8] ]]
51 changes: 44 additions & 7 deletions example/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ Text.configure.add_text_sound(Audio.text.neue, 0.2)
--[[-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------]]--
example = {
display_mode = 1,
maxmodes = 8,
maxmodes = 9,
long_text_block = require('longtext'),
ex5_textboxsize = 64,
bop = true,
Expand All @@ -153,17 +153,17 @@ function love.load()
example1box = Text.new("left", { color = {1,1,1,1}, shadow_color = {0.5,0.5,1,0.4}, default_underline_position = -2, default_strikethrough_position = 1})
example1box:send(example.long_text_block, 320*4, true)
-- Example 2 // Golden Apple Font // Earthbound Style Box
example2box = Text.new("left", { color = {1,1,1,1}, shadow_color = {0.5,0.5,1,0.4}, font = Fonts.golden_apple, character_sound = true})
example2box = Text.new("left", { color = {1,1,1,1}, shadow_color = {0.5,0.5,1,0.4}, font = Fonts.golden_apple, character_sound = true, adjust_line_height = -3})
example2box:send("• Do you like eggs?[newline]• I think they are [pad=6]eggzelent![audio=sfx=laugh]", 100, false)
-- Example 3 // Golden Apple Font // Mother 3 Style Bottom
example3box = Text.new("left", { color = {1,1,1,1}, shadow_color = {0.5,0.5,1,0.4}, font = Fonts.golden_apple, character_sound = false, print_speed = 0.02})
example3box = Text.new("left", { color = {1,1,1,1}, shadow_color = {0.5,0.5,1,0.4}, font = Fonts.golden_apple, character_sound = false, print_speed = 0.02, adjust_line_height = -3})
example3box:send("I am a very cute [color=#00ff00]green frog[/color]. Would you like to eat dinner with me? It's [rainbow][bounce]fresh[/bounce] [u]fly[/u] [shake]soup[/shake]![/rainbow]", 316, false)
--Example 4 // Earth Illusion // Bubble Style Box
example4box = Text.new("left", { color = {0,0,0,0.95}, shadow_color = {0.5,0.5,1,0.4}, font = Fonts.earth_illusion})
example4box = Text.new("left", { color = {0,0,0,0.95}, shadow_color = {0.5,0.5,1,0.4}, font = Fonts.earth_illusion, adjust_line_height = -2})
example4box:send("[dropshadow=2][b]Old Man:[/b][newline]Hello young man. How are you?", 74, true)
--Example 5 // Earth Illusion // Final Fantasy Style
example5box = Text.new("left", { color = {0.9,0.9,0.9,0.95}, shadow_color = {0.5,0.5,1,0.4}, font = Fonts.earth_illusion, character_sound = true, sound_every = 5, sound_number = 2})
example5box:send("[dropshadow=3][function=example.ex5_textboxsize=64][textspeed=0.02]With the Power of Queens, they challenged the Snakes. Garry's mighty waves peeled apart their diamond scales. The Wizards woke[waitforinput][audio=sfx=ui] [function=example.ex5_textboxsize=example.ex5_textboxsize+16]mighty windstorms. Niza brought the deadly wine[waitforinput][audio=sfx=ui] [function=example.ex5_textboxsize=example.ex5_textboxsize+16]and cheese. [audio=sfx=ui]", 320-16, false)
example5box = Text.new("left", { color = {0.9,0.9,0.9,0.95}, shadow_color = {0.5,0.5,1,0.4}, font = Fonts.earth_illusion, character_sound = true, sound_every = 5, sound_number = 2, adjust_line_height = -2})
example5box:send("[dropshadow=3][function=example.ex5_textboxsize=64][textspeed=0.02]With the Power of Queens, they challenged the Snakes. Garry's mighty waves peeled apart their diamond scales. The Wízärds woke[waitforinput][audio=sfx=ui] [function=example.ex5_textboxsize=example.ex5_textboxsize+16]mighty windstorms. Niza brought the deadly wine[waitforinput][audio=sfx=ui] [function=example.ex5_textboxsize=example.ex5_textboxsize+16]and cheese. [audio=sfx=ui]", 320-16, false)
--Example 6 // Comic Neue / Center Box
example6box = Text.new("left", { color = {0.9,0.9,0.9,0.95}, shadow_color = {0.5,0.5,1,0.4}, font = Fonts.comic_neue, character_sound = true, sound_every = 5, sound_number = 2})
example6box:send("Oh wow, you found the [bounce][rainbow]high-res[/rainbow][/bounce] text! [icon=1][icon=2][icon=3][icon=4] [icon=5][icon=6][icon=7][icon=8] [icon=9][icon=10][icon=11][icon=12][/]", 320*4-16, true)
Expand All @@ -173,6 +173,9 @@ example7box:send("[warble=-5][textspeed=0.02][image=witch][pad=32]There's someth
--Example 8 // Comic Neue / Undertale Style
example8box = Text.new("left", { color = {0.9,0.9,0.9,0.95}, shadow_color = {0.5,0.5,1,0.4}, font = Fonts.comic_neue_small, character_sound = true, print_speed = 0.04, sound_every = 2, sound_number = 4})
example8box:send("[function=example.bop=true]Did you hear about the [color=#FF0000]bad puns?[/color][pause=0.5] You did?![pause=0.5] That's [color=#FFFF00]great[/color][pause=0.8]! [shake]Now I don't have to tell you about them![/shake][pause=1][function=example.bop=false][audio=sfx=laugh]", 320-80, false)
--Example 9 // Comic Neue / Pocket Monsters Scroll Style
example9box = Text.new("left", { color = {0.9,0.9,0.9,0.95}, shadow_color = {0.5,0.5,1,0.4}, font = Fonts.comic_neue_small, character_sound = true, print_speed = 0.04, sound_every = 2, sound_number = 4})
example9box:send("Hello! Welcome to the world of Pocket Creatures![waitforinput][scroll][newline]My name is Professor Tree![newline][waitforinput][scroll][scroll]And you are?", 150, false)
end

--[[-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------]]--
Expand Down Expand Up @@ -219,7 +222,7 @@ end

if example.display_mode == 5 then
Screen.start()
example_text = "Final Fantasy Style Textbox - R to Reset View - C to continue when prompted"
example_text = "Final Enixy Style Textbox - R to Reset View - C to continue when prompted"
love.graphics.draw(images.bg)
Frame.draw("ff", 0, 0, 320, example.ex5_textboxsize)
example5box:draw(8, 0)
Expand Down Expand Up @@ -269,6 +272,28 @@ example8box:draw(14 + 40, 15 )
Screen.stop()
end

if example.display_mode == 9 then
Screen.start()
example_text = "Catching Monsters Style Textbox / C to continue text"
love.graphics.draw(images.bg)

Frame.draw("utp", 320/2 - 150/2 - 4, 180 - 40, example9box.get.width + 8, 2 * 17)
local bop = 1
love.graphics.setScissor( 320/2 - 150/2, 180 - 40 + 4, example9box.get.width, 2 * 17 )
example9box:draw(320/2 - 150/2, 180 - 40 + 4)
love.graphics.setScissor()

if example9box:is_finished() and math.floor(love.timer.getTime()*10) % 2 == 0 then
love.graphics.setColor(1,0,0,1)
love.graphics.print("-", 320/2 - 150/2 + example9box.get.width - 8, 180 - 20 )
love.graphics.print("-", 320/2 - 150/2 + example9box.get.width - 8, 180 - 19 )
love.graphics.print("-", 320/2 - 150/2 + example9box.get.width - 8, 180 - 18 )
love.graphics.setColor(1,1,1,1)
end

Screen.stop()
end

-- Draw Information Bar At the Bottom
love.graphics.setColor(0.95,0.95,0.95,1)
love.graphics.rectangle("fill", 0, 180*4 - 25, 320*4, 40)
Expand Down Expand Up @@ -309,6 +334,9 @@ function love.update(dt)
example8box:update(dt)
example.boptimer = example.boptimer + dt * 10
end
if example.display_mode == 9 then
example9box:update(dt)
end
end

--[[-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------]]--
Expand All @@ -326,6 +354,15 @@ function love.keypressed( key, scancode, isrepeat )
if key == "r" then
example2box:send("[|•] Do you like eggs?[newline][|•] I think they are [pad=6]eggzelent!", 100, false)
end

end
if example.display_mode == 9 then
if key == "r" then
example9box:send("Hello! Welcome to the world of Pocket Creatures![waitforinput][scroll][newline]My name is Professor Tree![newline][waitforinput][scroll][scroll]And you are?", 150, false)
end
if key == "c" then
example9box:continue()
end
end
if example.display_mode == 3 then
if key == "r" then
Expand Down
126 changes: 119 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
![Quick Demo of Examples](/screenshots/ex.gif?raw=true "Quick Demo of Examples")

# Update Notes
* New ```[scroll]``` command, will scroll the text up by line-height or a set value. Works well with ```love.graphics.setScissor```.
* You have access to the basic calculated width, height and linecount for each textbox. Access is under the ```get``` table.
- ```my_cool_textbox.get.width, my_cool_textbox.get.height, my_cool_textbox.get.lines ```
- If you are using autowrap, the width calculation is more accurate.
* Text animation commands now allow you to change the speed, or even reverse it.
* It is no longer required to wrap UTF8 characters. You can send them without the wrapping and the library will scan and wrap extended characters without any manual input.

# Setup
Expand Down Expand Up @@ -40,39 +45,109 @@ SYSL-Text supports tags in ```[these brackets]``` and will use them to apply eff
## Tags with Screenshot Examples
![Example 1](/screenshots/1.gif?raw=true "Example of Library")
```lua
example2box = Text.new("left", { color = {1,1,1,1}, shadow_color = {0.5,0.5,1,0.4}, font = Fonts.golden_apple, character_sound = true})
example2box = Text.new("left",
{
color = {1,1,1,1},
shadow_color = {0.5,0.5,1,0.4},
font = Fonts.golden_apple,
character_sound = true,
adjust_line_height = -3
})
example2box:send("• Do you like eggs?[newline]• I think they are [pad=6]eggzelent![audio=sfx=laugh]", 100, false)
```
![Example 2](/screenshots/2.gif?raw=true "Example of Library")
```lua
example3box = Text.new("left", { color = {1,1,1,1}, shadow_color = {0.5,0.5,1,0.4}, font = Fonts.golden_apple, character_sound = false, print_speed = 0.02})
example3box = Text.new("left",
{
color = {1,1,1,1},
shadow_color = {0.5,0.5,1,0.4},
font = Fonts.golden_apple,
character_sound = false,
print_speed = 0.02,
adjust_line_height = -3
})
example3box:send("I am a very cute [color=#00ff00]green frog[/color]. Would you like to eat dinner with me? It's [rainbow][bounce]fresh[/bounce] [u]fly[/u] [shake]soup[/shake]![/rainbow]", 316, false)
```
![Example 3](/screenshots/3.png?raw=true "Example of Library")
```lua
example4box = Text.new("left", { color = {0,0,0,0.95}, shadow_color = {0.5,0.5,1,0.4}, font = Fonts.earth_illusion})
example4box = Text.new("left",
{
color = {0,0,0,0.95},
shadow_color = {0.5,0.5,1,0.4},
font = Fonts.earth_illusion,
adjust_line_height = -2
})
example4box:send("[dropshadow=2][b]Old Man:[/b][newline]Hello young man. How are you?", 74, true)
```
![Example 4](/screenshots/4.png?raw=true "Example of Library")
```lua
example6box = Text.new("left", { color = {0.9,0.9,0.9,0.95}, shadow_color = {0.5,0.5,1,0.4}, font = Fonts.comic_neue, character_sound = true, sound_every = 5, sound_number = 2})
example6box = Text.new("left",
{
color = {0.9,0.9,0.9,0.95},
shadow_color = {0.5,0.5,1,0.4},
font = Fonts.comic_neue, character_sound = true,
sound_every = 5,
sound_number = 2
})
example6box:send("Oh wow, you found the [bounce][rainbow]high-res[/rainbow][/bounce] text! [icon=1][icon=2][icon=3][icon=4] [icon=5][icon=6][icon=7][icon=8] [icon=9][icon=10][icon=11][icon=12][/]", 320*4-16, true)
```
![Example 5](/screenshots/5.gif?raw=true "Example of Library")
```lua
example7box = Text.new("left", { color = {0.9,0.9,0.9,0.95}, shadow_color = {0.5,0.5,1,0.4}, font = Fonts.comic_neue_big, character_sound = true, sound_every = 3, sound_number = 3})
example7box = Text.new("left",
{
color = {0.9,0.9,0.9,0.95},
shadow_color = {0.5,0.5,1,0.4},
font = Fonts.comic_neue_big,
character_sound = true,
sound_every = 3,
sound_number = 3
})
example7box:send("[warble=-5][textspeed=0.02][image=witch][pad=32]There's something I have to say,[pause=0.7] [warble=5]this witch will save the day!", 320*4-16, false)
```
![Example 6](/screenshots/6.gif?raw=true "Example of Library")
```lua
example8box = Text.new("left", { color = {0.9,0.9,0.9,0.95}, shadow_color = {0.5,0.5,1,0.4}, font = Fonts.comic_neue_small, character_sound = true, print_speed = 0.04, sound_every = 2, sound_number = 4})
example8box = Text.new("left",
{
color = {0.9,0.9,0.9,0.95},
shadow_color = {0.5,0.5,1,0.4},
font = Fonts.comic_neue_small,
character_sound = true,
print_speed = 0.04,
sound_every = 2,
sound_number = 4
})
example8box:send("[function=example.bop=true]Did you hear about the [color=#FF0000]bad puns?[/color][pause=0.5] You did?![pause=0.5] That's [color=#FFFF00]great[/color]![pause=0.8] [shake]Now I don't have to tell you about them![/shake][pause=1][function=example.bop=false][audio=sfx=laugh]", 320-80, false)
```
![Example 7](/screenshots/7.gif?raw=true "Example of Library")
```lua
example5box = Text.new("left", { color = {0.9,0.9,0.9,0.95}, shadow_color = {0.5,0.5,1,0.4}, font = Fonts.earth_illusion, character_sound = true, sound_every = 5, sound_number = 2})
example5box = Text.new("left",
{
color = {0.9,0.9,0.9,0.95},
shadow_color = {0.5,0.5,1,0.4},
font = Fonts.earth_illusion,
character_sound = true,
sound_every = 5,
sound_number = 2,
adjust_line_height = -2,
})
example5box:send("[dropshadow=3][function=example.ex5_textboxsize=64][textspeed=0.02]With the Power of Queens, they challenged the Snakes. Garry's mighty waves peeled apart their diamond scales. The Wizards woke[waitforinput][audio=sfx=ui] [function=example.ex5_textboxsize=example.ex5_textboxsize+16]mighty windstorms. Niza brought the deadly wine[waitforinput][audio=sfx=ui] [function=example.ex5_textboxsize=example.ex5_textboxsize+16]and cheese. [audio=sfx=ui]", 320-16, false)

```
![Example 8](/screenshots/8.gif?raw=true "Example of Library")
```lua
example9box = Text.new("left",
{
color = {0.9,0.9,0.9,0.95},
shadow_color = {0.5,0.5,1,0.4},
font = Fonts.comic_neue_small,
character_sound = true,
print_speed = 0.04,
sound_every = 2,
sound_number = 4
})
example9box:send("Hello! Welcome to the world of Pocket Creatures![waitforinput][scroll][newline]My name is Professor Tree![newline][waitforinput][scroll][scroll]And you are?", 150, false)


```
# Default Textbox Settings
```lua
Expand All @@ -82,6 +157,7 @@ local default_settings = {
color = {1,1,1,1}, -- Default text color.
shadow_color = {1,1,1,1}, -- Default Drop Shadow Color.
print_speed = 0.2, -- How fast text prints.
adjust_line_height = 0, -- Adjust the default line spacing.
default_strikethrough_position = 0, -- Adjust the position of the strikethough line.
default_underline_position = 0, -- Adjust the position of the underline line.
character_sound = false, -- Use a voice when printing characters? True or false.
Expand All @@ -92,6 +168,38 @@ local default_settings = {
-- You can set some defaults for each textbox object to make things easier.
textbox = Text.new("left", default_settings)
```
# Textbox Information
## Width, Height, Lines
You can get the width, height and the number of lines after sending text to a textbox.
```lua
my_cool_textbox = Text.new()

my_cool_textbox:send("Oh, gee, I hope this print out one by one!")
local textbox_x = 0
local textbox_y = 0
local textbox_w = my_cool_textbox.get.width
local textbox_h = my_cool_textbox.get.height
local textbox_l = my_cool_textbox.get.lines
-- in love.draw()
love.graphics.rectangle("fill", textbox_x, textbox_y, textbox_w, textbox_h)
my_cool_textbox:draw(textbox_x, textbox_y)
```
# is_finished()
Returns ```true``` if the textbox is done printing, or ```false``` if the textbox is still printing.

It will also return as ```true``` if ```[waitforinput]``` is in the text string.
```lua
are_you_done = my_cool_textbox:is_finished()
```

# continue()
Continue will continue printing after ```[waitforinput]``` pauses it.

```lua
-- You only need to send this once.
my_cool_textbox:continue()
```

# Tag Notes
Some tags will not work until you let the library know something about your game.

Expand Down Expand Up @@ -356,4 +464,8 @@ Note, all numbers are optional. You can use the ```[tag]``` without them, it wil
```lua
"[rainbow=number(speed)=number(brightness of color)]rainbow[/rainbow]"
```
### scroll
```lua
"[scroll] or [scroll=-int]" -- Scrolls the text in the textbox.
```

Binary file added screenshots/8.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0101db1

Please sign in to comment.