Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ###############################################################################
- # SES: Window_Book
- # ***Scripter's Resource (Minimal scripting knowledge required!)***
- # v1.4
- # 11.20.2012
- # Compatibility: VXAce/RGSS3
- # Author: Enelvon
- #===============================================================================
- # Terms of Use:
- #
- # This script may be used for free in any game, whether it's commercial or not.
- # The only requirement is that I be credited in some visible manner. You may not
- # claim this script as your own work. You are free to modify this script, but
- # may not redistribute it except for in a thread that I have started that relates
- # to it in some way.
- #===============================================================================
- # Changelog:
- # 11.18.2012: v1.0 - Script written.
- # 11.19.2012: v1.1 - Fixed a bug with escape characters where only the first one
- # would be processed for each word.
- # 11.19.2012: v1.2 - Fixed a second escape character bug where they were not
- # being applied correctly.
- # 11.19.2012: v1.3 - Added in [Scene_Book] to allow simple books to be displayed
- # a little more easily.
- # 11.20.2012: v1.4 - Modified [write_page_text] to be able to take parameters.
- #===============================================================================
- # This script is my darling. It's a versatile way to create multi-page windows -
- # and it is definitely NOT plug-and-play. You need to at (at the very least)
- # read the instructions to get any use out of it, but after that even a
- # non-scripter should be able to create wonderful books.
- #
- # *clears her throat* Now that I have that out of the way, this script is
- # essentially a scripter's resource. It provides a parent class for multi-page
- # windows, with a focus on those used to display information (though it is also
- # possible, with some additions, to include pages with selectable areas). Its
- # write_page_text method draws text with the draw_text_ex method, allowing
- # you to use any control character that you would normally use in game text.
- # Further down, I have included a tutorial on creating a basic game controls
- # guide as an example of a simple use of the script.
- #===============================================================================
- # Required Scripts: None
- # Known Incompatibilities: None, and as this is a new class (and thus contains
- # no redefinitions of the base scripts), it should never have any.
- #===============================================================================
- # Installation: Place below Materials and above all other custom scripts, or
- # with the Window_* classes if you want to keep things organized.
- #===============================================================================
- # Instructions:
- #
- # This script serves as a resource to create multi-page windows. I will use
- # this space to give an example of how to make and display a simple book that
- # contains the controls for the game.
- #
- # The first thing that we have to do is create a new window class. Let's call
- # it Guide.
- #
- # class Guide < Window_Book
- #
- # Okay, so we've opened our class. Now we need to define our initialize method.
- # It will contain our definition of @pagetext.
- #
- # class Guide < Window_Book
- #
- # def initialize
- # @pagetext = {
- # 2 => ["In this mini guide you will be given a basic introduction to playing the game. I hope it proves informative."],
- # 3 => ["\\c[16]Button Controls:", "", "\\c[16]Movement:",
- # "Use the direction keys to move your character on the map, and your cursor when in menus. Hold down Shift to run. When you are in a character-related menu, you can use Q, W, PgDn, and PgUp to move between characters.",
- # "", "\\c[16]Opening the Menu:",
- # "Press X, 0 on the number pad, or Esc to open the menu when you are on the map.",
- # "", "\\c[16]Selection:",
- # "Press Z, Space or Enter to interact with characters and items on the map, or to make a selection when in a menu.",
- # "", "\\c[16]Cancelling:",
- # "Press X, 0 on the number pad, or Esc to go back in a menu or cancel a choice."],
- # 4 => ["\\c[16]File Operations:", "", "\\c[16]Saving Your Game:",
- # "Select \\c[16]Save \\c[0]from the in-game menu and choose a slot in which to save your game.",
- # "", "\\c[16]Loading Your Game:",
- # "If you are currently in the game, return to the title screen. Select \\c[16]Load Game \\c[0]and choose the slot you want to load."],
- # 5 => ["Have fun, and good luck!"]
- # }
- # super
- # end
- #
- # Sorry about how long those text lines are, but going down to a new line and
- # having indentations causes the formatting to be hideous when the text is
- # drawn. Anyway, as you can see, we're able to use control characters from
- # the game's message windows in our text. Always make sure to use two (rather
- # than one) backslashes for the control character, and that it is attached to
- # the first word/character that it is intended to affect. I skipped page 1
- # because we'll do that a little differently - we're going to center the text
- # for it and place it near the top of the page, as it's the cover of the book.
- #
- # def initialize
- # @pagetext = {
- # 2 => ["In this mini guide you will be given a basic introduction to playing the game. I hope it proves informative."],
- # 3 => ["\\c[16]Button Controls:", "", "\\c[16]Movement:",
- # "Use the direction keys to move your character on the map, and your cursor when in menus. Hold down Shift to run. When you are in a character-related menu, you can use Q, W, PgDn, and PgUp to move between characters.",
- # "", "\\c[16]Opening the Menu:",
- # "Press X, 0 on the number pad, or Esc to open the menu when you are on the map.",
- # "", "\\c[16]Selection:",
- # "Press Z, Space or Enter to interact with characters and items on the map, or to make a selection when in a menu.",
- # "", "\\c[16]Cancelling:",
- # "Press X, 0 on the number pad, or Esc to go back in a menu or cancel a choice."],
- # 4 => ["\\c[16]File Operations:", "", "\\c[16]Saving Your Game:",
- # "Select \\c[16]Save \\c[0]from the in-game menu and choose a slot in which to save your game.",
- # "", "\\c[16]Loading Your Game:",
- # "If you are currently in the game, return to the title screen. Select \\c[16]Load Game \\c[0]and choose the slot you want to load."],
- # 5 => ["Have fun, and good luck!"]
- # }
- # super
- # end
- #
- # def draw_page1
- # x = (contents_width - text_size("Game Guide").width) / 2
- # y = (contents_height - line_height) / 4
- # draw_text_ex(x, y, "\\c[14]Game Guide")
- # end
- #
- # Here we find the center of the book page horizontally and 1/4 of the page
- # vertically, then draw the text there. Now, we have five pages in our
- # @pagetext hash, so the next thing we should do is define max_pages.
- #
- # def initialize
- # @pagetext = {
- # 2 => ["In this mini guide you will be given a basic introduction to playing the game. I hope it proves informative."],
- # 3 => ["\\c[16]Button Controls:", "", "\\c[16]Movement:",
- # "Use the direction keys to move your character on the map, and your cursor when in menus. Hold down Shift to run. When you are in a character-related menu, you can use Q, W, PgDn, and PgUp to move between characters.",
- # "", "\\c[16]Opening the Menu:",
- # "Press X, 0 on the number pad, or Esc to open the menu when you are on the map.",
- # "", "\\c[16]Selection:",
- # "Press Z, Space or Enter to interact with characters and items on the map, or to make a selection when in a menu.",
- # "", "\\c[16]Cancelling:",
- # "Press X, 0 on the number pad, or Esc to go back in a menu or cancel a choice."],
- # 4 => ["\\c[16]File Operations:", "", "\\c[16]Saving Your Game:",
- # "Select \\c[16]Save \\c[0]from the in-game menu and choose a slot in which to save your game.",
- # "", "\\c[16]Loading Your Game:",
- # "If you are currently in the game, return to the title screen. Select \\c[16]Load Game \\c[0]and choose the slot you want to load."],
- # 5 => ["Have fun, and good luck!"]
- # }
- # super
- # end
- #
- # def draw_page1
- # x = (contents_width - text_size("Game Guide").width) / 2
- # y = (contents_height - line_height) / 4
- # draw_text_ex(x, y, "\\c[14]Game Guide")
- # end
- #
- # def max_pages; 5; end
- # end
- #
- # There we go! As you can see, I ended the Guide class after defining
- # max_pages. Why? Because it's done! We created a five-page book in 20 lines,
- # and 7 of those were used to define the contents of the pages! Isn't that
- # easy?
- #
- # We're not quite done, though. We have one more task ahead of us: calling the
- # window for display. Prior to version 1.3, this had to be done by creating
- # a new class and calling that. 1.3 introduced the Scene_Book class, which
- # simplified this for basic users - advanced books will still need their own
- # classes if they're going to be used for anything but simple reading. To call
- # the default book scene with the guide, put this in an event:
- #
- # show_book(Guide)
- #
- # That will display the book, as I've added the show_book command to the Game
- # Interpreter class. You could also use this:
- #
- # SceneManager.goto(Scene_Book)
- # SceneManager.scene.set_book(Guide)
- #
- # show_book is a little faster, though. You can replace Guide with the name of
- # your book to show whatever you'd like - let's say we have a book window
- # named Biology_Textbook. We would use this:
- #
- # show_book(Biology_Textbook)
- #
- # Note that show_book will return to the scene it was called from when the
- # book is closed.
- #
- # That's it! Congratulations, you've created a guide! Your players will never
- # have to puzzle over the controls again!
- #
- # Anyway, I hope you can see how easy it is to use this as a base to make your
- # own books. I can't wait to see what you come up with - make sure to let me
- # know if you use it! Feel free to read over the rest of the script - it's
- # my most thoroughly commented to date, and I am very proud of it. Let me
- # know if anything is unclear, and I will do my best to help you understand.
- #
- ################################################################################
- $imported = {} if $imported.nil?
- $imported["SES - Window_Book"] = 1.4
- #==============================================================================
- # Window_Book
- # This is a parent class for multi-page windows of various kinds. The most
- # basic use for it is to make books.
- #==============================================================================
- class Window_Book < Window_Base
- #=============================================================================
- # Local Variables
- # The most important one of these, as well as the only one that is
- # initialized here, is @pagetext. @pagetext is a hash of arrays, one per
- # page of the book. The arrays contain stringss that represent the text
- # on the page. The text will automatically wrap to avoid going off of the
- # screen. Each separate string moves down to a new line - \n will not work
- # in the text strings. Any of the standard control characters for a VXAce
- # message window will, however. When write_page_text is called, the text
- # for the current page will be drawn onto the window.
- #=============================================================================
- attr_accessor :pagetext
- #=============================================================================
- # Initialize - sets up the window.
- # Takes an x-coordinate, a y-coordinate, the width of the window,
- # the height of the window, the wrap type, and the name of the windowskin
- # you want the book to use (optional, must be a Bitmap [the class, not the
- # file type]). The wrap type can be either :word or :char. :word wrapping
- # will wrap text to a new line at word boundaries, while :letter wrapping
- # will wrap it at character boundaries, which can avoid issues with
- # absurdly long words - though it is unlikely to ever be necessary, as not
- # many (real) words would be wider than the game window. It is only likely
- # to be an issue if your child window is very small. By default, the
- # window will cover the entire game screen. Please also note that escape
- # characters are not available in :letter wrap mode, which should be
- # obvious as it processes letter-by-letter. I may include handling to
- # alter that later, but for now stick to word wrap mode if you're using
- # escape characters.
- #=============================================================================
- def initialize(x = 0, y = 0, width = 544, height = 416, wrap_type = :word, skin = nil)
- #===========================================================================
- # Here we set the windowskin for the book. It can be provided in the
- # constructor of your window when it calls super, or you can rely on this
- # default setting which will, if my Window Swap script is active, cause
- # it to use a file called "Book Window" found in the Graphics/Windows
- # folder. If you are not using the aforementioned script, it will use the
- # default windowskin. You may modify this section to change the default
- # setting if you wish, but I would leave in the "skin ||" part so that
- # children of this class can still provide their own windows.
- #
- # If you choose to provide a windowskin from a child class, it must be as
- # a Bitmap rather than a file name, so remember to load it up. A child
- # window's call to this method that provides a windowskin would look
- # something like this:
- # super(0, 0, 544, 416, Cache.windows("Child Window"))
- #
- # We also set @wrap to our desired wrap type and initialize @pagetext to
- # an empty hash with an empty array as its default value, though if
- # @pagetext has already been initialized (which it should have in a child
- # class) it will only set the default, not empty the hash.
- #===========================================================================
- @skin = skin || ($imported["SES - Window Swap"] ? Cache.windows("Book Window") : Cache.system("Window"))
- @wrap = wrap_type; @pagetext ||= {}; @pagetext.default = []
- super(x, y, width, height)
- #===========================================================================
- # This sets the Z-value of the window to 255, to make sure
- # that it displays on top of everything else, and defaults @page (a local
- # variable that holds an integer that determines the current page) to 1.
- # It then builds the window's contents and sets it as the active window.
- #===========================================================================
- self.z, @page = 255, 1; refresh; activate
- end
- #=============================================================================
- # Update - updates the window.
- #=============================================================================
- def update
- super
- #===========================================================================
- # Here we check for action from the directional keys - scrolling between
- # pages and up/down within a page, if applicable. It also updates the
- # page number display at the bottom of the window.
- #===========================================================================
- process_cursor_move; scrolldata.each_key do |k| eval("@#{k}.update") end
- end
- #=============================================================================
- # Dispose - disposes the window.
- #=============================================================================
- def dispose
- #===========================================================================
- # This disposes the page number display at the bottom of the window when
- # the window is closed. It has to be done before the call to super, or
- # the window will be disposed first, which prevents us from disposing
- # any remaining pieces of it. That would leave the numbers and page arrows
- # floating on the screen, which we do not want.
- #===========================================================================
- scrolldata.each_key do |k| eval("@#{k}.dispose") end
- super
- end
- #=============================================================================
- # Max Pages - the total number of pages that the book contains.
- # Override this in your child class and have it return the number of pages
- # that your book has. I chose to do this with a method rather than a
- # variable as by using a method logic can be implemented, varying the
- # number of pages in different situations.
- #=============================================================================
- def max_pages; 1; end
- #=============================================================================
- # Dy - how far from the top of the window the first text will be drawn.
- # Override this in your child class and have it return the height (often
- # in lines - this method is typically defined as # * line_height) that you
- # wish to have as the offset. My reasoning for having this as a method is
- # the same as my reasoning for having Max Pages as a method.
- #=============================================================================
- def dy; 0; end
- #=============================================================================
- # Refresh - refreshes the window.
- #=============================================================================
- def refresh
- #===========================================================================
- # Here we set the Y-origin for the window's display to 0, so that the new
- # page will display from the top even if the player had scrolled all the
- # way to the bottom of the previous page. We also build the contents for
- # the current page, draw the page number display, and then draw whatever
- # the page is intended to contain. When creating a child window for this
- # class, make sure to create a draw_page# method for each page in the
- # window. I've set things up so that a page will remain blank (or display
- # its text from @pagetext, if it has any) if the method doesn't exist
- # rather than throwing an error and crashing, but that's no excuse to
- # leave a poor little page without a handler! Well, unless you're just
- # displaying text, but still. Try to be creative! You can create
- # encyclopedias with pictures, or magazines with articles set in various
- # column styles, or dozens of other things! Don't limit yourself to just
- # plain books - though those are good, too.
- #===========================================================================
- self.oy = 0; create_contents; draw_scroll; eval("draw_page#{@page}")
- end
- #=============================================================================
- # Contents Height - returns the height of the window's contents.
- # This is used to calculate whether or not the window needs to be able to
- # scroll, among other things.
- #
- # If you create a child window that uses more than just text, you will
- # probably have to overwrite this method. Make sure to include a call to
- # the super somewhere in your method - you will likely want to add
- # something to the result of the super to get the height of the window.
- # For example, say we have a page with an image that is 54 pixels tall,
- # and we want to include it as well as a 3 pixel border at the top and
- # bottom in addition to some text from @pagetext. The picture is only on
- # page 2. We would have a method that looks something like this inside of
- # our child class:
- # def contents_height
- # addedHeight = if @page == 2 then 60
- # else 0 end
- # super + addedHeight
- # end
- #
- # It takes a padding value, used to determine the amount of vertical
- # padding to give the window.
- #=============================================================================
- def contents_height(padding = 2)
- #===========================================================================
- # Here we set i equal to dy / line_height + 1, or the number of lines that
- # appear above our text as well as a line of padding at the bottom. i is
- # an integer that holds the number of rows of text that the page contains.
- # It is multiplied by 24 to find the height of the contents in pixels. We
- # also create b, a dummy bitmap used to test the size of the text to help
- # determine whether or not we need to wrap to a new row. b is necessary
- # because the contents of the window, which would normally be used for the
- # text_size method, are disposed during the create_contents method, which
- # is where this is most needed.
- #===========================================================================
- i, b = dy / line_height + 1, Bitmap.new(1,1)
- #===========================================================================
- # In here we loop through the strings in @pagetext's array for the current
- # page. In word wrap mode we break them apart into words by splitting them
- # at spaces, then test if adding the next word would cause the line to run
- # off of the window. If it would, we instead add a new line. In character
- # wrap mode, we break it apart at each character instead of each space.
- # If wrapping occurs, we ignore leading spaces in order to avoid
- # unnecessary white space.
- #===========================================================================
- @page ||= 1
- @pagetext[@page].each do |l|
- if @wrap == :word then t = l.split(/\s/)
- else t = []; l.each_char do |c| t.push(c) end end
- x = 0
- t.each do |w|
- dw = convert_escape_characters(w).gsub(/\\(\w)(\[(\w+)\])?/) { "" }
- (i += 1; x = 0) if x + b.text_size(dw + (@wrap == :word ? " " : "")).width > contents_width
- next if x == 0 && w == " "
- x += b.text_size(dw + (@wrap == :word ? " " : "")).width
- end
- i += 1
- end
- #===========================================================================
- # Here we return the number of lines as a number of pixels, if it's larger
- # than the default height given. If not, it uses the default height.
- #===========================================================================
- return [line_height*i, height - standard_padding * padding].max
- end
- #=============================================================================
- # Method Missing - this is where I handle missing draw_page# methods to
- # prevent errors.
- #=============================================================================
- def method_missing(method)
- #===========================================================================
- # Here we check whether the missing method is a draw_page# method. If it
- # is, we default to using write_page_text to print the page's information
- # from @pagetext. If it's not, an error will be thrown.
- #===========================================================================
- if method =~ /^draw_page(\d+)$/ then write_page_text
- else super end
- end
- #=============================================================================
- # Write Page Text - writes the current page's information from @pagetext to
- # the window.
- # I love all of my daughter here dearly, but this is, without a doubt, my
- # favourite feature of hers. It's pretty much the script equivalent of a
- # beautiful singing voice. We take the strings contained in @pagetext
- # and write them to the screen, wrapping to the next line at word
- # boundaries when it becomes necessary. The one potential issue with this
- # method is that if you have a word that's longer than the window is wide,
- # it will never display and the window will hang. This can be avoided by
- # using :letter wrap mode, but that doesn't allow for the use of escape
- # characters. You can also call this method with an array and a starting
- # line in order to place text wherever you'd like. Additionally, you may
- # specify a newline boundary to add to the front of any wrapped line,
- # allowing you to tab long lines in lists.
- #=============================================================================
- def write_page_text(text = @pagetext[@page], i = 0, newline_boundary = "", mode = :ex)
- #===========================================================================
- # In here we loop through the strings in the text array for the current
- # page. In word wrap mode we break them apart into words by splitting them
- # at spaces, then test if adding the next word would cause the line to run
- # off of the window. If it does not, we write the word to the screen. If
- # it would, we add a new line and then write the word. In character wrap
- # mode, we break it apart at each character instead of each space. If
- # wrapping occurs, we ignore leading spaces in order to avoid unnecessary
- # white space. It returns the index of the next empty row.
- #===========================================================================
- @page ||= 1
- text.each do |l|
- if @wrap == :word then t = l.split(/\s/)
- else t = []; l.each_char do |c| t.push(c) end end
- cc, x = "", 0
- t.each do |w|
- w = convert_escape_characters(w).gsub(/\e(\w)(\[(\w+)\])?/) { |s| cc += s; "" }
- (i += 1; x = 0; w.insert(0, newline_boundary)) if x + text_size(w + (@wrap == :word ? " " : "")).width > contents_width
- rect = Rect.new(x, i * line_height + dy, contents_width, line_height)
- next if x == 0 && w == " "
- if mode == :ex then draw_text_ex(rect.x, rect.y, cc + w + (@wrap == :word ? " " : ""))
- else draw_text(rect, w + (@wrap == :word ? " " : "")) end
- x += text_size(w + (@wrap == :word ? " " : "")).width
- end
- i += 1
- end
- return i
- end
- #=============================================================================
- # Arrow Bitmap - defines the bitmap from which the window's arrows will be
- # taken.
- # This will provide the arrow sprites with the windowskin in order to get
- # their arrows if they should be visible.
- #=============================================================================
- def arrow_bitmap(d)
- #===========================================================================
- # Here we check what page we're on. If we're past the first page we'll
- # give the left arrow the windowskin so that it will be visible, and if
- # we're not on the last page we'll give it to the right arrow.
- #===========================================================================
- self.windowskin if (@page < max_pages && d == :r) || (@page > 1 && d == :l)
- end
- #=============================================================================
- # Sx - the base X position for the page number data.
- # This calculates where in the X plane the page number and arrows generated
- # by draw_scroll should be placed.
- #=============================================================================
- def sx
- #===========================================================================
- # We take the maximum possible size for the page number display and devise
- # a starting X coordinate based on that.
- #===========================================================================
- self.x +
- (contents_width - text_size("#{max_pages}/#{max_pages}").width + 4) / 2 - 5
- end
- #=============================================================================
- # Scrolldata - information about the page number display, including the
- # source information for the arrows.
- # This returns a hash of information, all of which will be drawn by
- # draw_scroll when it is run.
- #=============================================================================
- def scrolldata
- #===========================================================================
- # First we calculate an X value to help us display the right arrow. After
- # that, we calculate the y value at which the information should be drawn.
- #===========================================================================
- x = text_size("#{max_pages}/#{max_pages}").width + 4
- y = if Graphics.height - height == 0 then height - 28
- else self.y + height - 28 end
- #===========================================================================
- # Here's the meat of the method. You may need to edit the src_rect
- # information for the arrows if you're using a custom windowskin - it's
- # configured to use the base. Note that each of the keys in this hash
- # will become a Sprite object when draw_scroll is called.
- #
- # Each key in the main hash is linked to a second hash. There are 5
- # possible values in that second hash:
- # :x => Easy enough. This is the X coordinate at which the item will be
- # drawn.
- # :y => Also easy - the Y coordinate for drawing.
- # :bitmap => The Sprite's bitmap. For :pagecount, this should be an empty
- # bitmap placed at the x we calculated earlier. Its height should be
- # equivalent to line_height - I simply set it at 24 (the default
- # value for line_height) for visibility.
- # :src_rect => The visible portion of the Sprite's bitmap. You'll need to
- # change this for :rarrow and :larrow if you're using a custom
- # windowskin that has arrows of a different size than those in the
- # default window.
- # :d_rect => :pagecount only. This should be the same as :src_rect. It
- # exists to simplify drawing the page numbers and so that if you
- # overwrite/extend this method with new Sprites you can have the
- # page numbers drawn in the way you want.
- #===========================================================================
- { :pagecount => { :x => sx + 10, :y => y - 7,
- :bitmap => Bitmap.new(x, 24), :src_rect => Rect.new(0,0,x+4,line_height),
- :d_rect => Rect.new(0, 0, x + 4, line_height) },
- :rarrow => { :x => sx + x + 28, :y => y,
- :bitmap => arrow_bitmap(:r), :src_rect => Rect.new(104,25,7,12) },
- :larrow => { :x => sx - 12, :y => y,
- :bitmap => arrow_bitmap(:l), :src_rect => Rect.new(80,25,7,12) } }
- end
- #=============================================================================
- # Draw Scroll - draws the sprites defined in Scrolldata.
- # This takes the hash from Scrolldata and creates a sprite for each key,
- # using the values defined in the key's hash.
- #=============================================================================
- def draw_scroll
- #===========================================================================
- # First we get the key and value pair from the hash. If the Sprite
- # currently exists, we dispose it so that we can redraw it in a new way.
- # We then create the Sprite and set its x, y, and z values as well as its
- # bitmap and src_rect. After that, we draw the page numbers in any Sprite
- # that has a d_rect defined.
- #===========================================================================
- scrolldata.each_pair do |k,v|
- eval("@#{k}.dispose if !@#{k}.nil?
- @#{k}, @#{k}.x, @#{k}.y, @#{k}.z, @#{k}.bitmap, @#{k}.src_rect =
- Sprite.new, v[:x], v[:y], 255, v[:bitmap], v[:src_rect]
- @#{k}.bitmap.draw_text(v[:d_rect], '#{@page}/#{max_pages}', 1) if v[:d_rect]
- ")
- end
- end
- #=============================================================================
- # Process Cursor Move - this is where we check if the player is scrolling
- # through the window.
- # It checks for direction key input and performs actions based on whether
- # or not there is.
- #=============================================================================
- def process_cursor_move
- #===========================================================================
- # First we set oldpage to the current page number, so that we can check
- # if the page ended up changing. Then we check if the player has pressed
- # left - if they have and we are not on the first page, we go back a page.
- # After that we check if they have pressed right, and go forward if we
- # are not on the last page. Then we move on to scrolling up and down
- # within a page - if they hit up and are not at the top of the page, it
- # will scroll up, and if they hit down and are not at the bottom of the
- # page it will scroll down. After we are done checking for input, we
- # redraw the page if the page has changed.
- #===========================================================================
- (@changed = false; return) if @changed
- oldpage = @page
- if Input.trigger?(:LEFT) && 1 < @page then @page -= 1
- elsif Input.trigger?(:RIGHT) && @page < max_pages then @page += 1
- elsif ((Input.press?(:UP)) if Input.repeat?(:UP)) && self.oy > 0
- self.oy -= 24; draw_scroll
- elsif ((Input.press?(:DOWN)) if Input.repeat?(:DOWN)) && contents_height(4) + 24 - height >= self.oy
- draw_scroll; self.oy += 24 end
- (refresh; @changed = true) if oldpage != @page
- end
- end
- #===============================================================================
- # Game_Interpreter
- # This is a default class that handles event processing. I have defined the
- # show_book method in here to allow for quick display of simple books.
- #===============================================================================
- class Game_Interpreter
- #=============================================================================
- # Show Book - this method calls the Scene_Book class.
- # This method takes the name of a book class (and potentially a second
- # scene to go to after the player closes the book - if no second scene is
- # entered it will default to Scene_Map) and displays the book contained
- # in the class.
- #=============================================================================
- def show_book(book)
- SceneManager.goto(Scene_Book); SceneManager.scene.set_book(book)
- end
- end
- #===============================================================================
- # Scene_Book
- # This is a class that displays simple books. It allows the player to read
- # the book, and will return to the given scene when closed.
- #===============================================================================
- class Scene_Book < Scene_Base
- #=============================================================================
- # Set Book - this method selects the book that the class should display, as
- # well as what class the game should go to when the player closes the
- # book.
- # This method takes the name of a book class and sets the scene's book
- # object to the given book. It also takes the name of a class, and sets
- # the class that will open when the book is closed to that class.
- #=============================================================================
- def set_book(book)
- @book = book.new
- end
- #=============================================================================
- # Update - this method updates the class.
- # If the scene contains a book, it updates the book. If there is no book,
- # it will wait for one to be given with set_book. If the player presses
- # a Cancel button, it will close the book and go to the next scene.
- #=============================================================================
- def update
- super
- @book.update if @book
- SceneManager.return if Input.trigger?(:B)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment