Textbook Script

Textbook Script N/A

Pokémon Essentials Version
v18.1 ➖
1615862994033.png

To see this script in action, check out The Last Nurse Joy!

Love lore dumps but hate scrolling through little textboxes? Boy do I have a script for you!

Code
Paste in a new script section above Main!
Ruby:
def textbook(book)
   # oldsprites = pbFadeOutAndHide(@sprites)
    scene = Textbook_Scene.new
    screen = TextbookScreen.new(scene)
    screen.pbStartTextbookScreen(book)
    yield if block_given?
    pbFadeInAndShow(@sprites)#,oldsprites)
end


class TextbookScreen
  def initialize(scene)
    @scene = scene
  end

  def pbStartTextbookScreen(book)
    @scene.pbStartTextbookScene(book)
    ret = @scene.pbTextbookScene
    @scene.pbEndScene
    return ret
  end

end


#books
BookZero = [
"TITLE","This is the text of your book.\nThis is on a new line.<i>This text is italicized</i>, but this is not.",
"PAGE 1","<fs=28>This is the next page. See how the left arrow appears now?\nThe text is also bigger!</fs>",
"PAGE 2","<fs=22>Here's the last page! The right arrow has disappeared. The text is smaller, so I could write a lot more! But I won't.</fs>"
]

BookOne = [
"TITLE","Here's another book! This one only has one page!"
]

Books = [
BookZero,
BookOne
]

class Textbook_Scene

  def pbUpdate
    pbUpdateSpriteHash(@sprites)
  end

  def pbStartTextbookScene(book)
    @viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
    @viewport.z = 99999
    @page = 0
    @book = book
    @bookarray= Books[book]
    @max=Books[book].length#)+4)/2
    #@max+=4
    #@max/=2
    @sprites = {}
    @sprites["background"] = IconSprite.new(0,0,@viewport)
    @sprites["overlay"] = BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
    pbSetSystemFont(@sprites["overlay"].bitmap)
    @sprites["leftarrow"] = AnimatedSprite.new("Graphics/Pictures/leftarrow",8,40,28,2,@viewport)
    @sprites["leftarrow"].x       = -4
    @sprites["leftarrow"].y       = 10
    @sprites["leftarrow"].play
    @sprites["rightarrow"] = AnimatedSprite.new("Graphics/Pictures/rightarrow",8,40,28,2,@viewport)
    @sprites["rightarrow"].x       = (Graphics.width)-36
    @sprites["rightarrow"].y       = 10
    @sprites["rightarrow"].visible = (!@choosing || numfilledpockets>1)
    @sprites["rightarrow"].play
    drawTextbookPage(@page)
    pbFadeInAndShow(@sprites) { pbUpdate }
  end

  def pbEndScene
    pbFadeOutAndHide(@sprites) { pbUpdate }
    pbDisposeSpriteHash(@sprites)
    @viewport.dispose
  end


  def drawTextbookPage(page)
    book   = @book
    @sprites["leftarrow"].visible = (@page>0)
    @sprites["rightarrow"].visible = (@page+3<@max)
    overlay = @sprites["overlay"].bitmap
    overlay.clear
    base   = Color.new(0,0,0)
    #base = Color.new(255,255,255)
    # Set background image
    @sprites["background"].setBitmap("Graphics/Pictures/textbookbg")
    imagepos=[]
    # Write various bits of text
    pagename = @bookarray[page]
    textpos = [
       [pagename,Graphics.width/2,10,2,base]#,shadow]
    ]
    #For title size
    @sprites["overlay"].bitmap.font.size=32
    pbDrawTextPositions(overlay,textpos)
    @sprites["overlay"].bitmap.font.size=26
    text=@bookarray[page+1]
    drawFormattedTextEx(overlay,25,35,Graphics.width-40,text,base)#,shadow)
  end


  def pbTextbookScene
    loop do
      Graphics.update
      Input.update
      pbUpdate
      dorefresh = false
      if Input.trigger?(Input::B)
        pbPlayCloseMenuSE
        break
      elsif Input.trigger?(Input::LEFT)
        oldpage = @page
        @page -= 2
        @page = 0 if @page<0
        if @page!=oldpage   # Move to next page
          pbSEPlay("GUI summary change page")
          dorefresh = true
        end
      elsif Input.trigger?(Input::RIGHT)
        oldpage = @page
        @page += 2
        @page = @max-2 if @page+3>@max
        if @page!=oldpage   # Move to next page
          pbSEPlay("GUI summary change page")
          dorefresh = true
        end
      end
      if dorefresh
        drawTextbookPage(@page)
      end
    end
  end
end

If you're using an earlier Essentials version, change pbPlayCloseMenuSE to pbSEPlay("GUI menu close")

Using the script
Most of what we need to do is at the top of this script! I've included some example books to give a feel for how this works!
Ruby:
BookZero = [
"TITLE","This is the text of your book.\nThis is on a new line.<i>This text is italicized</i>, but this is not.",
"PAGE 1","This is the next page. See how the left arrow appears now?\nThe text is also bigger!",
"PAGE 2","Here's the last page! The right arrow has disappeared. The text is smaller, so I could write a lot more! But I won't."
]
Your book is just defined as an array full of strings! Your text should be in pairs- the first one's your title, and the second is your content! (If you don't want a title on your page, just put "") And you can use all the cool tricks to manipulating text that you can with Show Text- size, fonts, italics, bold, colors, opacity, just about anything! The only exceptions are:
  • Things that affect stuff like the speed of text or the positioning of the menu box, since neither exist here.
  • Things that require another menu box to be displayed- showing money/coins, \f to display a picture, choices, etc.

Remember that the array name has to be capitalized!

After that, just put your array's name in the array Books!
Ruby:
Books = [
BookZero,
BookOne
]

And to call it, just use textbook(book), with book being the number in the Books array! (Remember that it starts at 0!)

You'll need a file titled textbookbg in Graphics/Pictures! If you want to create your own, I do recommend downloading the one linked here all the same, so you can be sure your text will align!


Future Goals
  • Get a page turn sound effect, get a way to easily set custom sound effects
  • Make a way to set custom backgrounds but still be able to default to one
  • Implement a table of contents feature, to jump to pages
Credits
TechSkylander1518 for the code
AnonAlpaca for the graphic, if used
Author
TechSkylander1518
Downloads
83
Views
721
First release
Last update
Rating
5.00 star(s) 2 ratings

More resources from TechSkylander1518

Latest reviews

for me it is giving error when I try to leave the book. my game is 16.2 is it?
TechSkylander1518
TechSkylander1518
Ah, that's because pbPlayCloseMenuSE wasn't defined until v18. Replace that with something like pbSEPlay("GUI menu close",80) and it should be good to go!
I always like to add some lore and details of stuff on my fangame (for example, each single desk, fridge or decoration in every single house, has its own definition, even things like plants or TVs). So having an script like this is super useful for zones like Ruins, Libraries of even the Academy I have on the first City. Thanks for sharing it <3
TechSkylander1518
TechSkylander1518
Aw, I'm really happy you can put it to such good use!
Top