UltimaForum

Pomoc [VXAce] - Konwersja skryptu

Angius - Czw 12 Kwi, 2012 00:20
Temat postu: Konwersja skryptu
Z VX na Ace oczywiście :)
Jeśli nie da rady go konwertować, czy coś, to może być prostszy, byle by:
    1. Miał trzy możliwości wyświetlania - książka, sterta notatek i zwój
    2. Używał grafik jako kolejnych stron książek
    3. Odtwarzał SE przy przewracaniu strony
    4. Umożliwiał przewijanie zwoju strzałkami
    5. Notatki nie zawierały 'okładki', a by każda notatka ze stosu była osobną grafiką
    6. Zawierał konfigurację typu ID => ['grafika1', 'grafika2', 'grafika3'] dla książki i ID => ['grafika'] dla zwoju

I to chyba tyle :)

Skrypt:
Spoiler:

Kod:
################################################################################
# Name:         Read!
#
# By:           SojaBird
# Version:      2.5
# Site:         http://www.nestcast.blogspot.com
# Discription:  Read! A script that makes your players read something you
#               like! Make books or scrolls with any picture program and make
#               them appear, ready to be read!
#
# How-to-use:   Make your book/scroll as an item. In the note field of the item,
#               or just in a call script, use the following;
#                 read_book(book, *back, *draw_style, *from_item)
#                 read_scroll(scroll, *from_item)
#               For the variables "book" and "scroll", you'll have to set the
#               name of the book/scroll ('picturename'). For the variable
#               "back", you can setthe name of the back images of a book. If you
#               leave it for what is, it'll use the default settings from the
#               script-setup ("BACK_PIC"). For the "draw_style", you can change
#               the way of how you've set up the pictures. This variable is
#               optional. You do have to set "back" if you want to use this. If
#               you leave it empty, it'll use the default you've set in the
#               script-setup ("DRAW_STYLE"). For the variable "from_item", you
#               can set if you want to return to the item window when you close
#               the book/scroll. But if you leave it for what it is, it'll see
#               for itself if the code came from an item or not (recommented).
#
# File-names:  ~Use correct filenames for your book! First of all check the
#               script-setup and make it to how you want it before making your
#               pictures. Look at the "BOOK_MAP", this is the place where you're
#               going to put your pictures. Now you can make the pictures...
#               Though be aware! You need a to make a background for your pages
#               to show on. Size it (max) 544*416 and name it whatever you want.
#               Go to the scriptsetup and put the name of that background after
#               "BACK_PIC". Next you are going to make the pages with your text
#               and/or pictures and all, that's all up to you since they are
#               pictures, so everything is possible. Just go and start making
#               your pages with any size you like (change the "DRAW_STYLE" in
#               the script-setup to your style). Every page should have it's own
#               picture! When you're done with a page, and you're going to save
#               and name it, set the name like this; 'bookname-pagenumber'. So
#               if you just created the 2nd page of your book called 'ghost',
#               the name of the picture must be 'ghost-1'. Make sure you see
#               that the second page of the book, has the number 1. So the first
#               page has the number 0.
#              ~For the scrolls, first check in wich map the pictures need to
#               come. After that, just go and make some nifty looking pictures
#               that will be shown and can be scrolled by the user in all 4
#               directions.
#                 PS: RPGMakerVX only supports png/jpg/jpeg picture-files.
#
# More setup:  ~The last 3 settings of the setup; CENTER_OFFSET, NEXT_PAGE and
#               PREV_PAGE, are explaind below.
#                {CENTER_OFFSET}
#                  The center_offset setting defermens the y-offset of the pages
#                  from the middle. So if you want your pages not to be drawn at
#                  the very middle of the back-picture, you'll have to set the
#                  center_offset to any given number you want the pages to be
#                  offset from the middle. For example if you have page-pictures
#                  that are sized 270*412, and you want them to be shown, not
#                  directly on the center of your background, but in the center
#                  of each half, you want to set the center_offset to 2 since
#                  this will center them out on every half.
#                {NEXT_PAGE}
#                  This setting determens wich key needs to be pressed to move
#                  the pages to the next. You can only use known inputs by the
#                  game. Though, you can extend this by useing various other
#                  scripts that will allow you to use all inputs from your whole
#                  keyboard.
#                {PREV_PAGE}
#                  This is actualy the same as the next_page setting, only this
#                  will bring the reader to the previous page.
#              ~For the scrolling part of the setup, the 4 SCROLL_directions and
#               SCROLL_SPEED remains.
#                 {SCROLL_UP/DOWN/RIGHT/LEFT}
#                   For the directions, just changes the input to what you
#                   prefer, though the default are the most usefull (in my
#                   opinion).
#                 {SCROLL_SPEED}
#                   The scrollspeed, is the amount of pixels the scroll moves
#                   when the player presses one of the direction-buttons once.
#
################################################################################
module SojaBird_Read
#------------------------------#
# Module: Book
#------------------------------#
module Book
#------------------------------#
# Setup Book
#------------------------------#
  BOOK_MAP = "Graphics/Pictures/Book/"
  BACK_PIC = "back"
# Draw-style:
#   0=Without offset (pages are same size as back)
#   1=With offset (pages have different size than back)
#   2=Spreads (2 pages, 1 picture)
  DRAW_STYLE = 0
  CENTER_OFFSET = 4 #22 #Only with draw-style 1
  NEXT_PAGE = Input::RIGHT
  PREV_PAGE = Input::LEFT
end
#------------------------------#
# Module: Scroll
#------------------------------#
module Scroll
#------------------------------#
# Setup Scroll
#------------------------------#
  SCROLL_MAP = "Graphics/Pictures/Scroll/"
  SCROLL_DOWN = Input::DOWN
  SCROLL_UP = Input::UP
  SCROLL_RIGHT = Input::RIGHT
  SCROLL_LEFT = Input::LEFT
  SCROLL_SPEED = 10
end
#------------------------------#
end
###############################
##############################
#############################
############################
##############START|#######
############OF     |######
#########THE       |#####
##|SCRIPT          |####
##|~~~~~~~~~~~~~~~~|###
##|              DO|##
##|           NOT####
##|      TOUCH######
##|BELOW!##########
##################
#################
################
###############
##############
#############
############
###########
##########
#########
########
#######
######
#####
####
###
##
#
##
###
####
#####
######
#######
########
#########
##########
###########
############
#############
##############
###############
################
#################
##################
##|START###########
##|     OF##########
##|       THE########
##|          SCRIPT|##
##|~~~~~~~~~~~~~~~~|###
##|DO              |####
#####NOT           |#####
########TOUCH      |######
#############BELOW!|#######
############################
#############################
##############################
###############################
#------------------------------#
# Check File Type
#------------------------------#
def check_file_type(file, type)
  file_type_array = [".png", ".jpg", ".jpeg"]
  nth = 0
  file_type_array.each do |i|
    if type == "book"
      @file_type = file_type_array[nth] if FileTest.exist?("#{SojaBird_Read::Book::BOOK_MAP}/#{file}-0#{i}")
    elsif type == "scroll"
      @file_type = file_type_array[nth] if FileTest.exist?("#{SojaBird_Read::Scroll::SCROLL_MAP}/#{file}#{i}")
    end
    nth += 1
  end
end
#------------------------------#
# Call Script : Read Book
#------------------------------#
def read_book(book, back = SojaBird_Read::Book::BACK_PIC, draw_style = SojaBird_Read::Book::DRAW_STYLE, from_item = $game_temp.from_item)
  @pages = 0
  check_file_type(book, "book")
  if @file_type != nil
    for i in 0..99
      if draw_style == 2; amount = 2; else; amount = 1; end
      @pages += amount if FileTest.exist?("#{SojaBird_Read::Book::BOOK_MAP}/#{book}-#{i}#{@file_type}")
    end
    $scene = Scene_Book.new(book, @pages, draw_style, from_item, back) if @pages > 0
  end
end
#------------------------------#
# Class : Scene Book
#------------------------------#
class Scene_Book < Scene_Base
  #------------------------------#
  # Include List
  #------------------------------#
  include SojaBird_Read::Book
  #------------------------------#
  # Initialize
  #------------------------------#
  def initialize(book, size, draw_style, from_item, back)
    @book = book
    @size = size
    @draw_style = draw_style
    @from_item = from_item
    @back = back
    @index = 0
  end
  #------------------------------#
  # Start
  #------------------------------#
  def start
    create_menu_background
    @viewport = Viewport.new(0, 0, 544, 416)
    @book_window = Window_Book.new(@book, @back, @draw_style, @index)
    @book_window.viewport = @viewport
  end
  #------------------------------#
  # Terminate
  #------------------------------#
  def terminate
    dispose_menu_background
    @viewport.dispose
    @book_window.dispose
  end
  #------------------------------#
  # Return Scene
  #------------------------------#
  def return_scene
    if @from_item; $scene = Scene_Item.new; else; $scene = Scene_Map.new; end
  end
  #------------------------------#
  # Update
  #------------------------------#
  def update
    super
    @book_window.update
    input_update
  end
  #------------------------------#
  # Input Update
  #------------------------------#
  def input_update
    if Input.trigger?(Input::B)
      Sound.play_cancel
      return_scene
    elsif Input.trigger?(PREV_PAGE)
      if @index == 0
        Sound.play_buzzer
      else
        Audio.se_play("Audio/SE/Book", 80)
        prev_page
      end
    elsif Input.trigger?(NEXT_PAGE)
      if @index == @size / 2 or @index == ((@size + 1) / 2) - 1
        Sound.play_buzzer
      else
        Audio.se_play("Audio/SE/Book", 80)
        next_page
      end
    end
  end
  #------------------------------#
  # Prev Page
  #------------------------------#
  def prev_page
    @index -= 1
    new_window
  end
  #------------------------------#
  # Next Page
  #------------------------------#
  def next_page
    @index += 1
    new_window
  end
  #------------------------------#
  # New Window
  #------------------------------#
  def new_window
    @book_window.dispose
    @book_window = Window_Book.new(@book, @back, @draw_style, @index)
    @book_window.viewport = @viewport
  end
end

#------------------------------#
# Class: Window Book
#------------------------------#
class Window_Book < Window_Base
  #------------------------------#
  # Include List
  #------------------------------#
  include SojaBird_Read::Book
  #------------------------------#
  # Initialize
  #------------------------------#
  def initialize(book, back, draw_style, index)
    super(0, 0, 544, 416)
    self.opacity = 0
    @book = book
    @back = back
    @draw_style = draw_style
    @index = index; @index *= 2 if @draw_style != 2
    check_file_type(book, "book")
    refresh
  end
  #------------------------------#
  # Refresh
  #------------------------------#
  def refresh
    self.contents.clear
    book_back
    book_page_left(@index)
    book_page_right(@index) if @draw_style != 2
  end
  #------------------------------#
  # Dispose
  #------------------------------#
  def dispose
    $game_temp.from_item = false
    @book_back.dispose if @book_back != nil
    @l.dispose if @l != nil
    @r.dispose if @r != nil
  end
  #------------------------------#
  # Book Back
  #------------------------------#
  def book_back
    pic = Cache.book(@back)
    @book_back = Sprite.new
    @book_back.bitmap = pic
    @book_back.x = 272 - (pic.width / 2)
    @book_back.y = 208 - (pic.height / 2)
    @book_back.z = 1
  end
  #------------------------------#
  # Book Page Left
  #------------------------------#
  def book_page_left(index)
    if FileTest.exist?("#{SojaBird_Read::Book::BOOK_MAP}/#{@book}-#{index}#{@file_type}")
      pic = Cache.book("#{@book}-#{index}")
      @l = Sprite.new
      @l.bitmap = pic
      if @draw_style == 1; @l.x = 272 - pic.width - CENTER_OFFSET; else; @l.x = 272 - (pic.width / 2); end
      @l.y = 208 - (pic.height / 2)
      @l.z = 2
    end
  end
  #------------------------------#
  # Book Page Right
  #------------------------------#
  def book_page_right(index)
    if FileTest.exist?("#{SojaBird_Read::Book::BOOK_MAP}/#{@book}-#{(index + 1)}#{@file_type}")
      pic = Cache.book("#{@book}-#{(index + 1)}")
      @r = Sprite.new
      @r.bitmap = pic
      if @draw_style == 1; @r.x = 272 + CENTER_OFFSET; else; @r.x = 272 - (pic.width / 2); end
      @r.y = 208 - (pic.height / 2)
      @r.z = 2
    end
  end
end

#------------------------------#
# Module: Cache
#------------------------------#
module Cache
  #------------------------------#
  # Book
  #------------------------------#
  def self.book(filename)
    load_bitmap(SojaBird_Read::Book::BOOK_MAP, filename)
  end
end
####################################################################
#------------------------------#
# Call Script : Read Scroll
#------------------------------#
def read_scroll(scroll, from_item = $game_temp.from_item)
  check_file_type(scroll, "scroll")
  if @file_type != nil
    $scene = Scene_Scroll.new(scroll, from_item) if FileTest.exist?("#{SojaBird_Read::Scroll::SCROLL_MAP}/#{scroll}#{@file_type}")
  end
end
#------------------------------#
# Class : Scene Scroll
#------------------------------#
class Scene_Scroll < Scene_Base
  #------------------------------#
  # Include List
  #------------------------------#
  include SojaBird_Read::Scroll
  #------------------------------#
  # Initialize
  #------------------------------#
  def initialize(scroll, from_item)
    @scroll = scroll
    @from_item = from_item
  end
  #------------------------------#
  # Start
  #------------------------------#
  def start
    create_menu_background
    @viewport = Viewport.new(0, 0, 544, 416)
    @scroll_window = Window_Scroll.new(@scroll)
    @scroll_window.viewport = @viewport
  end
  #------------------------------#
  # Terminate
  #------------------------------#
  def terminate
    dispose_menu_background
    @viewport.dispose
    @scroll_window.dispose
  end
  #------------------------------#
  # Return Scene
  #------------------------------#
  def return_scene
    if @from_item; $scene = Scene_Item.new; else; $scene = Scene_Map.new; end
  end
  #------------------------------#
  # Update
  #------------------------------#
  def update
    super
    @scroll_window.scrolling
    input_update
  end
  #------------------------------#
  # Input Update
  #------------------------------#
  def input_update
    if Input.trigger?(Input::B)
      Sound.play_cancel
      return_scene
    end
  end
end

#------------------------------#
# Class: Window Scroll
#------------------------------#
class Window_Scroll < Window_Base
  #------------------------------#
  # Include List
  #------------------------------#
  include SojaBird_Read::Scroll
  #------------------------------#
  # Initialize
  #------------------------------#
  def initialize(scroll)
    super(0, 0, 544, 416)
    self.opacity = 0
    @scroll_name = scroll
    check_file_type(scroll, "scroll")
    refresh
  end
  #------------------------------#
  # Scrolling
  #------------------------------#
  def scrolling
    if Input.press?(SCROLL_DOWN)
      @scroll.oy += SCROLL_SPEED if @scroll.oy < @scroll.height - 416
    end
    if Input.press?(SCROLL_UP)
      @scroll.oy -= SCROLL_SPEED if @scroll.oy > 0
    end
    if Input.press?(SCROLL_RIGHT)
      @scroll.ox += SCROLL_SPEED if @scroll.ox < @scroll.width - 544
    end
    if Input.press?(SCROLL_LEFT)
      @scroll.ox -= SCROLL_SPEED if @scroll.ox > 0
    end
  end
  #------------------------------#
  # Refresh
  #------------------------------#
  def refresh
    self.contents.clear
    draw_scroll
  end
  #------------------------------#
  # Dispose
  #------------------------------#
  def dispose
    $game_temp.from_item = false
    @scroll.dispose if @scroll != nil
  end
  #------------------------------#
  # Draw Scroll
  #------------------------------#
  def draw_scroll
    @scroll = Sprite.new
    pic = Cache.scroll(@scroll_name)
    @scroll.bitmap = pic
    @scroll.x = 272 - (pic.width / 2) if pic.width < self.width
    @scroll.y = 208 - (pic.height / 2) if pic.height < self.height
  end
end

#------------------------------#
# Module: Cache
#------------------------------#
module Cache
  #------------------------------#
  # Scroll
  #------------------------------#
  def self.scroll(filename)
    load_bitmap(SojaBird_Read::Scroll::SCROLL_MAP, filename)
  end
end

#------------------------------#
# Class: Scene Item
#------------------------------#
class Scene_Item < Scene_Base
  #------------------------------#
  # Alias List
  #------------------------------#
  alias old_determine_item determine_item
  #------------------------------#
  # Determine Item
  #------------------------------#
  def determine_item
    @item_note = $data_items[@item.id].note
    if @item_note.include?("read")
      $game_temp.from_item = true
      eval(@item_note.to_s)
    end
    old_determine_item
  end
end

#------------------------------#
# Class: Game Temp
#------------------------------#
class Game_Temp
  #------------------------------#
  # Local Variables
  #------------------------------#
  attr_accessor  :from_item
  #------------------------------#
  # Alias List
  #------------------------------#
  alias old_initialize initialize
  #------------------------------#
  # Initialize
  #------------------------------#
  def initialize
    old_initialize
    @from_item = false
  end
end


Ayene - Czw 12 Kwi, 2012 21:56

Dobrze przetestuj:
Spoiler:

Kod:
################################################################################
# Name:         Read!
#
# By:           SojaBird
# Version:      2.5
# Site:         http://www.nestcast.blogspot.com
# Discription:  Read! A script that makes your players read something you
#               like! Make books or scrolls with any picture program and make
#               them appear, ready to be read!
#
# How-to-use:   Make your book/scroll as an item. In the note field of the item,
#               or just in a call script, use the following;
#                 read_book(book, * pages, *back, *draw_style)
#                 read_scroll(scroll)
#               For the variables "book" and "scroll", you'll have to set the
#               name of the book/scroll ('picturename'). For the variable
#               "back", you can setthe name of the back images of a book. If you
#               leave it for what is, it'll use the default settings from the
#               script-setup ("BACK_PIC"). For the "draw_style", you can change
#               the way of how you've set up the pictures. This variable is
#               optional. You do have to set "back" if you want to use this. If
#               you leave it empty, it'll use the default you've set in the
#               script-setup ("DRAW_STYLE").
#
# File-names:  ~Use correct filenames for your book! First of all check the
#               script-setup and make it to how you want it before making your
#               pictures. Look at the "BOOK_MAP", this is the place where you're
#               going to put your pictures. Now you can make the pictures...
#               Though be aware! You need a to make a background for your pages
#               to show on. Size it (max) 544*416 and name it whatever you want.
#               Go to the scriptsetup and put the name of that background after
#               "BACK_PIC". Next you are going to make the pages with your text
#               and/or pictures and all, that's all up to you since they are
#               pictures, so everything is possible. Just go and start making
#               your pages with any size you like (change the "DRAW_STYLE" in
#               the script-setup to your style). Every page should have it's own
#               picture! When you're done with a page, and you're going to save
#               and name it, set the name like this; 'bookname-pagenumber'. So
#               if you just created the 2nd page of your book called 'ghost',
#               the name of the picture must be 'ghost-1'. Make sure you see
#               that the second page of the book, has the number 1. So the first
#               page has the number 0.
#              ~For the scrolls, first check in wich map the pictures need to
#               come. After that, just go and make some nifty looking pictures
#               that will be shown and can be scrolled by the user in all 4
#               directions.
#                 PS: RPGMakerVX only supports png/jpg/jpeg picture-files.
#
# More setup:  ~The last 3 settings of the setup; CENTER_OFFSET, NEXT_PAGE and
#               PREV_PAGE, are explaind below.
#                {CENTER_OFFSET}
#                  The center_offset setting defermens the y-offset of the pages
#                  from the middle. So if you want your pages not to be drawn at
#                  the very middle of the back-picture, you'll have to set the
#                  center_offset to any given number you want the pages to be
#                  offset from the middle. For example if you have page-pictures
#                  that are sized 270*412, and you want them to be shown, not
#                  directly on the center of your background, but in the center
#                  of each half, you want to set the center_offset to 2 since
#                  this will center them out on every half.
#                {NEXT_PAGE}
#                  This setting determens wich key needs to be pressed to move
#                  the pages to the next. You can only use known inputs by the
#                  game. Though, you can extend this by useing various other
#                  scripts that will allow you to use all inputs from your whole
#                  keyboard.
#                {PREV_PAGE}
#                  This is actualy the same as the next_page setting, only this
#                  will bring the reader to the previous page.
#              ~For the scrolling part of the setup, the 4 SCROLL_directions and
#               SCROLL_SPEED remains.
#                 {SCROLL_UP/DOWN/RIGHT/LEFT}
#                   For the directions, just changes the input to what you
#                   prefer, though the default are the most usefull (in my
#                   opinion).
#                 {SCROLL_SPEED}
#                   The scrollspeed, is the amount of pixels the scroll moves
#                   when the player presses one of the direction-buttons once.
#
################################################################################
module SojaBird_Read
#------------------------------#
# Module: Book
#------------------------------#
module Book
#------------------------------#
# Setup Book
#------------------------------#
  BOOK_MAP = "Graphics/Pictures/Book/"
  BACK_PIC = "back"
# Draw-style:
#   0=Without offset (pages are same size as back)
#   1=With offset (pages have different size than back)
#   2=Spreads (2 pages, 1 picture)
  DRAW_STYLE = 0
  CENTER_OFFSET = 4 #22 #Only with draw-style 1
  NEXT_PAGE = Input::RIGHT
  PREV_PAGE = Input::LEFT
end
#------------------------------#
# Module: Scroll
#------------------------------#
module Scroll
#------------------------------#
# Setup Scroll
#------------------------------#
  SCROLL_MAP = "Graphics/Pictures/Scroll/"
  SCROLL_DOWN = Input::DOWN
  SCROLL_UP = Input::UP
  SCROLL_RIGHT = Input::RIGHT
  SCROLL_LEFT = Input::LEFT
  SCROLL_SPEED = 10
end
#------------------------------#
end
###############################
##############################
#############################
############################
##############START|#######
############OF     |######
#########THE       |#####
##|SCRIPT          |####
##|~~~~~~~~~~~~~~~~|###
##|              DO|##
##|           NOT####
##|      TOUCH######
##|BELOW!##########
##################
#################
################
###############
##############
#############
############
###########
##########
#########
########
#######
######
#####
####
###
##
#
##
###
####
#####
######
#######
########
#########
##########
###########
############
#############
##############
###############
################
#################
##################
##|START###########
##|     OF##########
##|       THE########
##|          SCRIPT|##
##|~~~~~~~~~~~~~~~~|###
##|DO              |####
#####NOT           |#####
########TOUCH      |######
#############BELOW!|#######
############################
#############################
##############################
###############################
#------------------------------#
# Check File Type
#------------------------------#
def check_file_type(file, type)
  file_type_array = [".png", ".jpg", ".jpeg"]
  nth = 0
  file_type_array.each do |i|
    if type == "book"
      @file_type = file_type_array[nth] if FileTest.exist?("#{SojaBird_Read::Book::BOOK_MAP}/#{file}-0#{i}")
    elsif type == "scroll"
      @file_type = file_type_array[nth] if FileTest.exist?("#{SojaBird_Read::Scroll::SCROLL_MAP}/#{file}#{i}")
    end
    nth += 1
  end
end
#------------------------------#
# Call Script : Read Book
#------------------------------#
def read_book(book, back = SojaBird_Read::Book::BACK_PIC, draw_style = SojaBird_Read::Book::DRAW_STYLE)
  @pages = 0
  check_file_type(book, "book")
  if @file_type != nil
    for i in 0..99
      if draw_style == 2; amount = 2; else; amount = 1; end
      @pages += amount if FileTest.exist?("#{SojaBird_Read::Book::BOOK_MAP}/#{book}-#{i}#{@file_type}")
    end
    if @pages > 0
      SceneManager.call(Scene_Book)
      SceneManager.scene.prepare(book, @pages, draw_style, back)
    end
  end
end
#------------------------------#
# Class : Scene Book
#------------------------------#
class Scene_Book < Scene_MenuBase
  #------------------------------#
  # Include List
  #------------------------------#
  include SojaBird_Read::Book
  #------------------------------#
  # Initialize
  #------------------------------#
  def prepare(book, size, draw_style, back)
    @book = book
    @size = size
    @draw_style = draw_style
    @back = back
    @index = 0
  end
  #------------------------------#
  # Start
  #------------------------------#
  def start
    super
    @viewport = Viewport.new(0, 0, 544, 416)
    @book_window = Window_Book.new(@book, @back, @draw_style, @index)
    @book_window.viewport = @viewport
  end
  #------------------------------#
  # Terminate
  #------------------------------#
  def terminate
    super
    @viewport.dispose
    @book_window.dispose
  end
  #------------------------------#
  # Update
  #------------------------------#
  def update
    super
    @book_window.update
    @book_window.set_handler(:cancel,   method(:return_scene))
    input_update
  end
  #------------------------------#
  # Input Update
  #------------------------------#
  def input_update
    if Input.trigger?(PREV_PAGE)
      if @index == 0
        Sound.play_buzzer
      else
        Audio.se_play("Audio/SE/Book", 80)
        prev_page
      end
    elsif Input.trigger?(NEXT_PAGE)
      if @index == @size / 2 or @index == ((@size + 1) / 2) - 1
        Sound.play_buzzer
      else
        Audio.se_play("Audio/SE/Book", 80)
        next_page
      end
    end
  end
  #------------------------------#
  # Prev Page
  #------------------------------#
  def prev_page
    @index -= 1
    new_window
  end
  #------------------------------#
  # Next Page
  #------------------------------#
  def next_page
    @index += 1
    new_window
  end
  #------------------------------#
  # New Window
  #------------------------------#
  def new_window
    @book_window.dispose
    @book_window = Window_Book.new(@book, @back, @draw_style, @index)
    @book_window.viewport = @viewport
  end
end

#------------------------------#
# Class: Window Book
#------------------------------#
class Window_Book < Window_Selectable
  #------------------------------#
  # Include List
  #------------------------------#
  include SojaBird_Read::Book
  #------------------------------#
  # Initialize
  #------------------------------#
  def initialize(book, back, draw_style, index)
    super(0, 0, 544, 416)
    self.opacity = 0
    @book = book
    @back = back
    @draw_style = draw_style
    @index = index; @index *= 2 if @draw_style != 2
    check_file_type(book, "book")
    refresh
    activate
  end
  #------------------------------#
  # Refresh
  #------------------------------#
  def refresh
    self.contents.clear
    book_back
    book_page_left(@index)
    book_page_right(@index) if @draw_style != 2
  end
  #------------------------------#
  # Dispose
  #------------------------------#
  def dispose
    @book_back.dispose if @book_back != nil
    @l.dispose if @l != nil
    @r.dispose if @r != nil
  end
  #------------------------------#
  # Book Back
  #------------------------------#
  def book_back
    pic = Cache.book(@back)
    @book_back = Sprite.new
    @book_back.bitmap = pic
    @book_back.x = 272 - (pic.width / 2)
    @book_back.y = 208 - (pic.height / 2)
    @book_back.z = 1
  end
  #------------------------------#
  # Book Page Left
  #------------------------------#
  def book_page_left(index)
    if FileTest.exist?("#{SojaBird_Read::Book::BOOK_MAP}/#{@book}-#{index}#{@file_type}")
      pic = Cache.book("#{@book}-#{index}")
      @l = Sprite.new
      @l.bitmap = pic
      if @draw_style == 1; @l.x = 272 - pic.width - CENTER_OFFSET; else; @l.x = 272 - (pic.width / 2); end
      @l.y = 208 - (pic.height / 2)
      @l.z = 2
    end
  end
  #------------------------------#
  # Book Page Right
  #------------------------------#
  def book_page_right(index)
    if FileTest.exist?("#{SojaBird_Read::Book::BOOK_MAP}/#{@book}-#{(index + 1)}#{@file_type}")
      pic = Cache.book("#{@book}-#{(index + 1)}")
      @r = Sprite.new
      @r.bitmap = pic
      if @draw_style == 1; @r.x = 272 + CENTER_OFFSET; else; @r.x = 272 - (pic.width / 2); end
      @r.y = 208 - (pic.height / 2)
      @r.z = 2
    end
  end
end

#------------------------------#
# Module: Cache
#------------------------------#
module Cache
  #------------------------------#
  # Book
  #------------------------------#
  def self.book(filename)
    load_bitmap(SojaBird_Read::Book::BOOK_MAP, filename)
  end
end
####################################################################
#------------------------------#
# Call Script : Read Scroll
#------------------------------#
def read_scroll(scroll)
  check_file_type(scroll, "scroll")
  if @file_type != nil
    if FileTest.exist?("#{SojaBird_Read::Scroll::SCROLL_MAP}/#{scroll}#{@file_type}")
      SceneManager.call(Scene_Scroll)
      SceneManager.scene.prepare(scroll)
    end   
  end
end
#------------------------------#
# Class : Scene Scroll
#------------------------------#
class Scene_Scroll < Scene_MenuBase
  #------------------------------#
  # Include List
  #------------------------------#
  include SojaBird_Read::Scroll
  #------------------------------#
  # Initialize
  #------------------------------#
  def prepare(scroll)   
    @scroll = scroll
  end
  #------------------------------#
  # Start
  #------------------------------#
  def start
    super
    @viewport = Viewport.new(0, 0, 544, 416)
    @scroll_window = Window_Scroll.new(@scroll)
    @scroll_window.viewport = @viewport
  end
  #------------------------------#
  # Terminate
  #------------------------------#
  def terminate
    super
    @viewport.dispose
    @scroll_window.dispose
  end
  #------------------------------#
  # Update
  #------------------------------#
  def update
    super
    @scroll_window.scrolling
    @scroll_window.set_handler(:cancel,   method(:return_scene))
  end
end

#------------------------------#
# Class: Window Scroll
#------------------------------#
class Window_Scroll < Window_Selectable
  #------------------------------#
  # Include List
  #------------------------------#
  include SojaBird_Read::Scroll
  #------------------------------#
  # Initialize
  #------------------------------#
  def initialize(scroll)
    super(0, 0, 544, 416)
    self.opacity = 0
    @scroll_name = scroll
    check_file_type(scroll, "scroll")
    refresh
    activate
  end
  #------------------------------#
  # Scrolling
  #------------------------------#
  def scrolling
    if Input.press?(SCROLL_DOWN)
      @scroll.oy += SCROLL_SPEED if @scroll.oy < @scroll.height - 416
    end
    if Input.press?(SCROLL_UP)
      @scroll.oy -= SCROLL_SPEED if @scroll.oy > 0
    end
    if Input.press?(SCROLL_RIGHT)
      @scroll.ox += SCROLL_SPEED if @scroll.ox < @scroll.width - 544
    end
    if Input.press?(SCROLL_LEFT)
      @scroll.ox -= SCROLL_SPEED if @scroll.ox > 0
    end
  end
  #------------------------------#
  # Refresh
  #------------------------------#
  def refresh
    self.contents.clear
    draw_scroll
  end
  #------------------------------#
  # Dispose
  #------------------------------#
  def dispose
    @scroll.dispose if @scroll != nil
  end
  #------------------------------#
  # Draw Scroll
  #------------------------------#
  def draw_scroll
    @scroll = Sprite.new
    pic = Cache.scroll(@scroll_name)
    @scroll.bitmap = pic
    @scroll.x = 272 - (pic.width / 2) if pic.width < self.width
    @scroll.y = 208 - (pic.height / 2) if pic.height < self.height
  end
end

#------------------------------#
# Module: Cache
#------------------------------#
module Cache
  #------------------------------#
  # Scroll
  #------------------------------#
  def self.scroll(filename)
    load_bitmap(SojaBird_Read::Scroll::SCROLL_MAP, filename)
  end
end

#------------------------------#
# Class: Scene Item
#------------------------------#
class Scene_ItemBase < Scene_MenuBase
  #------------------------------#
  # Alias List
  #------------------------------#
  alias old_determine_item determine_item
  #------------------------------#
  # Determine Item
  #------------------------------#
  def determine_item
    @item_note = $data_items[item.id].note
    if @item_note.include?("read")
      eval(@item_note.to_s)
    end
    old_determine_item
  end
end


Angius - Pią 13 Kwi, 2012 00:10

Scroll działa bez zarzutu, book przetestuję jutro, wymaga nieco więcej grafik ;-)

Powered by phpBB modified by Przemo © 2003 phpBB Group