Advertisement
Guest User

Battle Equip

a guest
Jan 16th, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.15 KB | None | 0 0
  1. class Window_BattleEquip < Window_Selectable
  2.   #--------------------------------------------------------------------------
  3.   # * Public Instance Variables
  4.   #--------------------------------------------------------------------------
  5.   attr_reader   :status_window            # Status window
  6.   attr_reader   :item_window              # Item window
  7.   #--------------------------------------------------------------------------
  8.   # * Object Initialization
  9.   #--------------------------------------------------------------------------
  10.   def initialize(x, y, width)
  11.     super(x, y, width, window_height)
  12.     @actor = nil
  13.     refresh
  14.   end
  15.   #--------------------------------------------------------------------------
  16.   # * Get Window Height
  17.   #--------------------------------------------------------------------------
  18.   def window_height
  19.     fitting_height(visible_line_number)
  20.   end
  21.   #--------------------------------------------------------------------------
  22.   # * Get Number of Lines to Show
  23.   #--------------------------------------------------------------------------
  24.   def visible_line_number
  25.     return 1
  26.   end
  27.  
  28.   def col_max
  29.     return 2
  30.   end  
  31.   #--------------------------------------------------------------------------
  32.   # * Set Actor
  33.   #--------------------------------------------------------------------------
  34.   def actor=(actor)
  35.     return if @actor == actor
  36.     @actor = actor
  37.     refresh
  38.   end
  39.   #--------------------------------------------------------------------------
  40.   # * Frame Update
  41.   #--------------------------------------------------------------------------
  42.   def update
  43.     super
  44.     @item_window.slot_id = index if @item_window
  45.   end
  46.   #--------------------------------------------------------------------------
  47.   # * Get Number of Items
  48.   #--------------------------------------------------------------------------
  49.   def item_max
  50.     2
  51.     #@actor ? @actor.equip_slots.size : 0
  52.   end
  53.   #--------------------------------------------------------------------------
  54.   # * Get Item
  55.   #--------------------------------------------------------------------------
  56.   def item
  57.     @actor ? @actor.equips[index] : nil
  58.   end
  59.   #--------------------------------------------------------------------------
  60.   # * Draw Item
  61.   #--------------------------------------------------------------------------
  62.   def draw_item(index)
  63.     return unless @actor
  64.     rect = item_rect_for_text(index)
  65.     change_color(system_color, enable?(index))
  66.     contents.font.size = 14
  67.     draw_text(rect.x, rect.y, 92, line_height * 0.5, slot_name(index))
  68.     contents.font.size = 20
  69.     draw_item_name(@actor.equips[index], rect.x + 54, rect.y, enable?(index))
  70.   end
  71.   #--------------------------------------------------------------------------
  72.   # * Get Equipment Slot Name
  73.   #--------------------------------------------------------------------------
  74.   def slot_name(index)
  75.     @actor ? Vocab::etype(@actor.equip_slots[index]) : ""
  76.   end
  77.   #--------------------------------------------------------------------------
  78.   # * Display Equipment Slot in Enabled State?
  79.   #--------------------------------------------------------------------------
  80.   def enable?(index)
  81.     @actor ? @actor.equip_change_ok?(index) : false
  82.   end
  83.   #--------------------------------------------------------------------------
  84.   # * Get Activation State of Selection Item
  85.   #--------------------------------------------------------------------------
  86.   def current_item_enabled?
  87.     enable?(index)
  88.   end
  89.  
  90.   def item_window=(item_window)
  91.     @item_window = item_window
  92.     update
  93.   end
  94.  
  95. end
  96.  
  97. class Scene_BattleEquip < Scene_MenuBase
  98.   #--------------------------------------------------------------------------
  99.   # * Start Processing
  100.   #--------------------------------------------------------------------------
  101.   def start
  102.     super
  103.     create_slot_window
  104.     create_item_window
  105.   end
  106.  
  107.   #--------------------------------------------------------------------------
  108.   # * Create Slot Window
  109.   #--------------------------------------------------------------------------
  110.   def create_slot_window
  111.     wx = 0
  112.     wy = 248
  113.     ww = Graphics.width
  114.     wh = 200
  115.     @slot_window = Window_BattleEquip.new(wx, wy, ww)
  116.     @slot_window.viewport = @viewport
  117.     @slot_window.actor = @actor
  118.     @slot_window.activate
  119.     @slot_window.select(0)
  120.     @slot_window.set_handler(:ok,       method(:on_slot_ok))
  121.     @slot_window.set_handler(:cancel,   method(:return_scene))
  122.   end
  123.   #--------------------------------------------------------------------------
  124.   # * Create Item Window
  125.   #--------------------------------------------------------------------------
  126.   def create_item_window
  127.     wx = 0
  128.     wy = @slot_window.y + @slot_window.height
  129.     ww = Graphics.width
  130.     wh = 120
  131.     @item_window = Window_EquipItem.new(wx, wy, ww, wh)
  132.     @item_window.viewport = @viewport
  133.     @item_window.actor = @actor
  134.     @item_window.set_handler(:ok,     method(:on_item_ok))
  135.     @item_window.set_handler(:cancel, method(:on_item_cancel))
  136.     @slot_window.item_window = @item_window
  137.   end
  138.   #--------------------------------------------------------------------------
  139.   # * Slot [OK]
  140.   #--------------------------------------------------------------------------
  141.   def on_slot_ok
  142.     @item_window.activate
  143.     @item_window.select(0)
  144.   end
  145.   #--------------------------------------------------------------------------
  146.   # * Slot [Cancel]
  147.   #--------------------------------------------------------------------------
  148.   def on_slot_cancel
  149.     @slot_window.unselect
  150.   end
  151.   #--------------------------------------------------------------------------
  152.   # * Item [OK]
  153.   #--------------------------------------------------------------------------
  154.   def on_item_ok
  155.     Sound.play_equip
  156.     @actor.change_equip(@slot_window.index, @item_window.item)
  157.     @slot_window.activate
  158.     @slot_window.refresh
  159.     @item_window.unselect
  160.     @item_window.refresh
  161.   end
  162.   #--------------------------------------------------------------------------
  163.   # * Item [Cancel]
  164.   #--------------------------------------------------------------------------
  165.  def on_item_cancel
  166.     @slot_window.activate
  167.     @item_window.unselect
  168.   end
  169.  
  170.  def on_actor_change
  171.   end
  172.  end
  173.  
  174.  
  175. class Scene_Battle
  176.  
  177.  alias scene_battle_create_item_window_ry create_item_window
  178.   def create_item_window
  179.     scene_battle_create_item_window_ry
  180.     @item_window.set_handler(:equip, method(:command_equip))
  181.   end  
  182.  
  183.  def command_equip
  184.     Graphics.freeze
  185.     @info_viewport.visible = false
  186.     actor = $game_party.battle_members[@status_window.index]
  187.     $game_party.menu_actor = actor
  188.     previous_equips = actor.equips.clone
  189.     SceneManager.snapshot_for_battle
  190.     @item_window.close.deactivate
  191.     #---
  192.     SceneManager.call(Scene_BattleEquip)
  193.     SceneManager.scene.main
  194.     #SceneManager.force_recall(self)
  195.     #---
  196.     @item_window.open.activate
  197.     @info_viewport.visible = true
  198.     @status_window.refresh
  199.     perform_transition
  200.   end
  201.  
  202. end
  203.  
  204. class Window_BattleItem < Window_ItemList
  205.  
  206.    def help_show
  207.    if @help_window.visible
  208.      @help_window.hide
  209.      @help_window.width = Graphics.width - 375
  210.    else
  211.      @help_window.width = Graphics.width
  212.      @help_window.show
  213.    end  
  214.  end  
  215.  
  216.   def update
  217.     return process_equip if @index <= 1 and Input.trigger?(:UP) and open? && active # perform check to go to equip
  218.     super # run superclass method for update, contains cursor movement and other processing checks
  219.   end
  220.  
  221.   def process_handling
  222.     return unless open? && active
  223.     return process_ok       if ok_enabled?        && Input.trigger?(:C)
  224.     return help_show        if         Input.trigger?(:Z)
  225.     return process_cancel   if cancel_enabled?    && Input.trigger?(:B)
  226.     return process_pagedown if handle?(:pagedown) && Input.trigger?(:R)
  227.     return process_pageup   if handle?(:pageup)   && Input.trigger?(:L)
  228.   end
  229.  
  230.   def process_equip
  231.     Sound.play_cursor
  232.     Input.update
  233.     deactivate
  234.     call_handler(:equip)
  235.   end
  236. end
  237.  
  238. module SceneManager
  239.     def self.snapshot_for_battle
  240.     @background_bitmap.dispose if @background_bitmap
  241.     @background_bitmap = Graphics.snap_to_bitmap
  242.   end
  243. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement