SHARE
TWEET

Ksi Menu

Zalerinian Oct 14th, 2013 2,161 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module Zale
  2.   module KsiMenu
  3.     Window_Skin = "" # if this is not empty, it will set the windowskin to this.
  4.     line_height = 24 #24 is the default
  5.     Face_WP = 2# Add additional padding here
  6.     Face_HP = 2
  7.     Win_W = 96 * 3 + 24 + (Face_WP * 3)
  8.     Win_H = 96 * 2 + 24 + Face_HP
  9.     Pos_X = Graphics.width / 2 - (Win_W / 2) # Center it on screen
  10.     Pos_Y = Graphics.height * 0.1
  11.     Face_W = 96
  12.     Face_H = 96
  13.    
  14.     Arrows = false # Show arrows on the help window? (they're there because we shrunk the window
  15.                    # And it thinks that something is there).
  16.   end
  17. end
  18.  
  19. class Window_MenuHCommand < Window_HorzCommand
  20.   # We include Zale::KsiMenu in ever class because it's faster
  21.   # to write out 'Variable' rather than 'Zale::KsiMenu::Variable' for everything
  22.   include Zale::KsiMenu
  23.  
  24.   # Initialize is called whenever any object is make. It's built into ruby to do
  25.   # that, so this is where you would put everything to set up what you're making.
  26.   # In this case, we call this window's superclass, which we see above is
  27.   # Window_HorzCommand (Horizontal command window). It needs to know where to place
  28.   # the window, so we use the variables x and y, which we got when the object was
  29.   # originally made.
  30.   # Then we check if the Window_Skin variable is "" (empty). If it is, don't do
  31.   # anything. If it is different though, use that as our window skin. Then we
  32.   #use self.width = blah to change how wide the window is. We want all the windows
  33.   # to be the same width, so we use the same variable (Technically, variables that
  34.   # start with capital letters are constants, we're not allowed to change them,
  35.   # though there is *technically* a way to).
  36.   # Next we call the refresh method, and then update the cursor.
  37.   #
  38.   # The refresh method is not in this class, so where is it? Kind of like when we
  39.   # called super in initialize, if we don't define a method in out class, and then
  40.   # some other script calls this method (such as refresh), we see if the superclass
  41.   # has it. If it does, we do that, if not, check its superclass. This keeps going
  42.   # until we find the method or we run out of classes, in which case we'll get an
  43.   # error saying we can't find this method.
  44.   # These types of errors are 'undefined local variable or method `something' for
  45.   # MyClass:0xItsMemoryAddress.
  46.   def initialize(x, y)
  47.     super(x, y)
  48.     if Zale::KsiMenu::Window_Skin != ""
  49.       self.windowskin = Cache.system(Window_Skin)
  50.     end
  51.     self.width = Win_W
  52.     refresh
  53.     update_cursor
  54.   end
  55.  
  56.   # We use the add_command method, defined in Window_Command to add a command to the
  57.   # window so we can select it later. We give it a symbol, the thing with the : in front
  58.   # so that we can handle that specifically later. Vocab.whatever is the set of terms that
  59.   # are defined in the Terms tab of the database. You can see the available terms at the
  60.   # Vocab script at the top of the script editor. Check the bottom for the ones you can use
  61.   # They'll look like:
  62.   # def self.item;        command(4);   end   # Items
  63.   def make_command_list
  64.     add_command(Vocab.item,     :item)
  65.     add_command(Vocab.save,     :save)
  66.     add_command(Vocab.shutdown, :quit)
  67.   end
  68.  
  69.   # Here we define how many columns out window will have. By default, a Window_HorzCommand
  70.   # window will have four columns, but we only want 3, item, save, and quit. So this is how
  71.   # we set that up.
  72.   def col_max
  73.     return 3
  74.   end
  75. end
  76.  
  77. class Window_KsiStatus < Window_Selectable
  78.   include Zale::KsiMenu
  79.  
  80.   # Same as above.
  81.   # @index = -1 is used to make sure we don't have a cursor over any
  82.   # of the actor's faces (even though it shouldn't be there anyway).
  83.   def initialize
  84.     super(Pos_X, Pos_Y, Win_W, Win_H)
  85.     if Window_Skin != ""
  86.       self.windowskin = Cache.system(Window_Skin)
  87.     end
  88.     @index = -1
  89.     draw_actors
  90.   end
  91.  
  92.   # Here's an example of a refresh method. This will clear the contents
  93.   # of a window, which is just a bitmap, a picture. It's refered to by
  94.   # a method named 'contents'. So we clear it using contents.clear, and
  95.   # then we use the create_contents method which will make a new bitmap
  96.   # to use. This will make it whatever size we need and make sure it's
  97.   # cleared. Then we redraw the actor's faces.
  98.   def refresh
  99.     contents.clear
  100.     create_contents
  101.     draw_actors
  102.   end
  103.  
  104.   # First we setup variables for position, since we'll be changing them
  105.   # based on how many faces we've already drawn. Then, for the size of
  106.   # our party, we go through all the people. 'i' starts at 0 whenever you
  107.   # use the 'times' method, and it increases by one each time the loop end
  108.   # until it has done the number of loops. So we want to see, if i is greater
  109.   # than 5(it drew 6 faces), then we just skip to the next iteration by using
  110.   # 'next' This will keep happening until we run out of actors. We do this
  111.   # because we won't fit them onto the screen anyway, so don't waste the time
  112.   # to draw them.
  113.   def draw_actors
  114.     x = y = 0
  115.     $game_party.members.size.times{ |i|
  116.       if i > 5
  117.         next # index starts at 0, greater than 5 won't be drawn on the screen unless you change the dimensions.
  118.       end
  119.       act = $game_party.members[i]
  120.       draw_face(act.face_name, act.face_index, x, y)
  121.       x += Face_W + Face_WP
  122.       if x >= Face_W * 3 + (Face_WP * 3)
  123.         x = 0
  124.         y += Face_H + Face_HP
  125.       end
  126.     }
  127.   end
  128. end
  129.  
  130. class Scene_Menu < Scene_MenuBase
  131.   include Zale::KsiMenu
  132.   def start
  133.     super
  134.     create_status
  135.     create_command
  136.   end
  137.  
  138.   # Create the window that we use to select our commands. This is where
  139.   # we use those symbols to handle processing separately. First, though,
  140.   # we make the command window with the x position, and the y position
  141.   # PLUS the height of the status window, because we want the command
  142.   # window to be on the bottom of the status window.
  143.  
  144.   # Then we use the set_handler command for window so we can tell
  145.   # Ruby what to do when we select an option. We need to specify the
  146.   # symbol we gave them when we added the commands, and then a method
  147.   # to handle the option. the method() command is part of Ruby's kernel
  148.   # which will give you a way to call a method from anyway. We can pass
  149.   # the method around from class to class, and still use it. So in this
  150.   # case we're putting the method 'command_item' into another class,
  151.   # because that's where its held until we select the option. They're
  152.   # all stored in Window_Command. It has a container (A simple Hash)
  153.   # to hold them all.
  154.   def create_command
  155.     @cmd = Window_MenuHCommand.new(Pos_X, Pos_Y + @stat.height)
  156.     @cmd.set_handler(:item, method(:command_item))
  157.     @cmd.set_handler(:save, method(:command_save))
  158.     @cmd.set_handler(:quit, method(:command_quit))
  159.   end
  160.  
  161.   # Create the status menu, which sets itself up automatically, we don't
  162.   # need to pass any values to its initialize method for it to finish
  163.   # properly.
  164.   def create_status
  165.     @stat = Window_KsiStatus.new
  166.   end
  167.  
  168.   # The SceneManager is what handles all the scenes in the game. As such,
  169.   # that's how we change them too. The command_whatever methods just change
  170.   # the scene.
  171.   def command_item
  172.     SceneManager.call(Scene_Items)
  173.   end
  174.  
  175.   def command_save
  176.     SceneManager.call(Scene_Save)
  177.   end
  178.  
  179.   def command_quit
  180.     SceneManager.call(Scene_End)
  181.   end
  182.  
  183.   # Update is called by Scene_Base every frame. In this scene, we're going
  184.   # to run Scene_Base's update so that the game doesn't crash, and then we
  185.   # check to see if we press the :B key, which is the escape key by default.
  186.   # If we do press it, we return to the scene that was up before this.
  187.   def update
  188.     super
  189.     if Input.trigger?(:B)
  190.       SceneManager.return
  191.     end
  192.   end
  193.  
  194.   # When the scene is being closed, we need to clean up, so we dispose our
  195.   # windows so that we can free up the memory they used.
  196.   def terminate
  197.     super
  198.     @stat.dispose
  199.     @cmd.dispose
  200.   end
  201.  
  202. end
  203.  
  204. class Window_KsiItem < Window_Selectable
  205.   # This class is mostly recycled from the Window_ItemList class, as it mainly still all
  206.   # applied, I just took out the category window. The attr_accessor is saying to let
  207.   # a class that has a KsiItem window to change or see what we have for our @help_window
  208.   # variable. We use this to give it the window under the item list in the item scene
  209.   # so that it can update the description.
  210.   attr_accessor :help_window
  211.   include Zale::KsiMenu
  212.   def initialize
  213.     @items = []
  214.     super(Pos_X, Pos_Y, Win_W, Win_H)
  215.     refresh
  216.     select(0)
  217.     activate
  218.   end
  219.  
  220.   def make_item_list
  221.     @items = $game_party.all_items
  222.     @items.empty? ? @items.push(nil) : nil
  223.   end
  224.  
  225.   def col_max
  226.     return 2
  227.   end
  228.  
  229.   def enable?(item)
  230.     $game_party.usable?(item)
  231.   end
  232.  
  233.   def draw_item(index)
  234.     item = @items[index]
  235.     if item
  236.       rect = item_rect(index)
  237.       rect.width -= 4
  238.       draw_item_name(item, rect.x, rect.y, enable?(item), rect.width - 24)
  239.       draw_item_number(rect, item)
  240.     end
  241.   end
  242.  
  243.   def draw_item_number(rect, item)
  244.     # draw_text(rect, sprintf(":%2d", $game_party.item_number(item)), 2)
  245.   end
  246.  
  247.   def item
  248.     @items && index >= 0 ? @items[index] : nil
  249.   end
  250.  
  251.   def update_help
  252.     @help_window.set_item(item)
  253.   end
  254.  
  255.   def cursor_move
  256.     super
  257.     update_help
  258.   end
  259.  
  260.   def item_max
  261.     return @items.size
  262.   end
  263.  
  264.   def refresh
  265.     make_item_list
  266.     create_contents
  267.     draw_all_items
  268.   end
  269. end
  270.  
  271. class Scene_Items < Scene_ItemBase
  272.   # The Item scene class. In the initialize method, we setup the help window
  273.   # that displays the item's description, as well as create the item window.
  274.   include Zale::KsiMenu
  275.   def start
  276.     super
  277.     create_help_window
  278.     create_item
  279.     @actor_window.hide
  280.     @help_window.x = Pos_X
  281.     @help_window.y = Pos_Y + Win_H
  282.     @help_window.height = @help_window.fitting_height(1)
  283.     @help_window.width = Win_W
  284.     @help_window.arrows_visible = Arrows
  285.     if Window_Skin != ""
  286.       @help_window.windoskin = Cache.system(Window_Skin)
  287.       @item_window.windowskin = Cache.system(Window_Skin)
  288.     end
  289.   end
  290.  
  291.   # We create the item window, set its help window using the attr_accessor we made
  292.   # earlier, and then update the help window so that the description is updated and
  293.   # ready when the scene starts.
  294.   def create_item
  295.     @item_window = Window_KsiItem.new
  296.     @item_window.help_window = @help_window
  297.     @item_window.update_help
  298.   end
  299.  
  300.   # Check to see if we want to leave the item scene!
  301.   def update
  302.     super
  303.     if Input.trigger?(:B)
  304.       SceneManager.return
  305.     end
  306.   end
  307.  
  308.   # Clean up our item window. The help window was made by the superclass, so we
  309.   # letit take care of that.
  310.   def terminate
  311.     super
  312.     @item_window.dispose
  313.   end
  314. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top