IceDragon200

BasicMenuStart

May 14th, 2011
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.07 KB | None | 0 0
  1. #==============================================================================#
  2. # Window_ActorMenuStatus
  3. #==============================================================================#
  4. class Window_ActorMenuStatus < Window_Base
  5.  
  6.   attr_accessor :actor
  7.  
  8.   def initialize(x, y, actor)
  9.     super(x, y, 320, 96)
  10.     @actor = actor
  11.     refresh
  12.   end
  13.  
  14.   def refresh
  15.     create_contents()
  16.     draw_actor_name(@actor, 4, 0)
  17.     draw_actor_level(@actor, 4, 32)
  18.     draw_actor_hp(@actor, 128, 0, 96)
  19.     draw_actor_mp(@actor, 128+24, 32, 96)
  20.   end
  21.  
  22. end
  23.  
  24. #==============================================================================#
  25. # Window_ReverseMenuStatus
  26. #==============================================================================#
  27. class Window_ReverseMenuStatus < Window_Selectable
  28.  
  29.   def initialize( x, y, width, height )
  30.     super( x, y, width, height )
  31.     refresh()
  32.     self.index = -1
  33.   end
  34.  
  35.   def refresh()
  36.     @data       = $game_party.members #$game_party.reserve_members() # // You may have to change this
  37.     @item_max   = @data.size
  38.     @column_max = 2
  39.     create_contents()
  40.     for i in 0...@item_max ; draw_item( i ) end
  41.   end
  42.  
  43.   #--------------------------------------------------------------------------
  44.   # * Get rectangle for displaying items
  45.   #     index : item number
  46.   #--------------------------------------------------------------------------
  47.   def item_rect(index)
  48.     rect = Rect.new(0, 0, 0, 0)
  49.     rect.width = (contents.width + @spacing) / @column_max - @spacing
  50.     rect.height = 48 #WLH
  51.     rect.x = index % @column_max * (rect.width + @spacing)
  52.     rect.y = index / @column_max * 48
  53.     return rect
  54.   end
  55.  
  56.   def draw_item( index, enabled=true )
  57.     rect = item_rect( index )
  58.     actor = @data[index]
  59.     return if actor.nil?()
  60.     self.contents.font.size = 18
  61.     draw_actor_name( actor, rect.x+4, rect.y )
  62.     draw_actor_level( actor, rect.x+72, rect.y )
  63.     draw_actor_hp( actor, rect.x+4, rect.y+24, 96 )
  64.     draw_actor_mp( actor, rect.x+6, rect.y+36, 96 )
  65.   end
  66.  
  67.   def cursor_movable? # // stops the actor input
  68.     return false
  69.   end  
  70.  
  71. end  
  72.  
  73. #==============================================================================#
  74. # MenuStatus_FF8
  75. #==============================================================================#
  76. class MenuStatus_FF8 # // Container
  77.  
  78.   attr_reader :x
  79.   attr_reader :y
  80.   attr_accessor :index
  81.   attr_accessor :item_max
  82.  
  83.   def initialize( sx, sy )
  84.     @x, @y = sx, sy
  85.     @index = 0
  86.     @windows = {}
  87.     @actor_windows = []
  88.     @reserve_index_start = 0
  89.     @item_max = 0
  90.     @active = true
  91.     refresh()
  92.   end
  93.  
  94.   def active=( bool )
  95.     @active = bool
  96.     if bool
  97.       @windows.values.each { |w|
  98.         w.opacity = 255
  99.         w.contents_opacity = 255
  100.       }
  101.     else
  102.       @windows.values.each { |w|
  103.         w.opacity = 128
  104.         w.contents_opacity = 128
  105.       }
  106.     end  
  107.   end
  108.  
  109.   def active() ; return @active end
  110.    
  111.   def dispose()
  112.     dispose_windows()
  113.   end
  114.  
  115.   def dispose_windows()  
  116.     @actor_windows.clear()
  117.     @windows.values.each { |w| w.dispose }
  118.     @windows.clear()
  119.   end
  120.  
  121.   def x=( new_x )
  122.     return if @x == new_x
  123.     @x = new_x
  124.     @windows.values.each { |w| w.x = @x }
  125.   end
  126.  
  127.   def y=( new_y )
  128.     return if @y == new_y
  129.     @y = new_y
  130.     @windows.values.each { |w| w.x = @y }
  131.   end
  132.  
  133.   def refresh()
  134.     i = 0
  135.     dispose_windows()
  136.     $game_party.members.each { |m|
  137.       winm = "Actor#{i}"
  138.       win = Window_ActorMenuStatus.new( 20, 0+(96*i), m )
  139.       @windows[winm] = win
  140.       @actor_windows[i] = win
  141.       i += 1
  142.     }
  143.     yadd = @actor_windows.size() * 96
  144.     @windows["Reserve"] = Window_ReverseMenuStatus.new( @x+20, @y+yadd, 320, 192)
  145.     @act_item_max = @actor_windows.size()
  146.     @reserve_index_start = @actor_windows.size()
  147.     @item_max = @actor_windows.size() + @windows["Reserve"].item_max
  148.     reset_window_positions()
  149.     update_windows()
  150.   end
  151.  
  152.   def update()
  153.     return unless active()
  154.     update_user_input()
  155.     update_windows()
  156.     update_window_positions()
  157.     if @index >= @reserve_index_start
  158.       @windows["Reserve"].active = true
  159.       @windows["Reserve"].index = 0 if @windows["Reserve"].index == -1
  160.       @windows["Reserve"].index = @index - @reserve_index_start
  161.     else  
  162.       @windows["Reserve"].active = false
  163.       @windows["Reserve"].index = -1
  164.     end  
  165.   end
  166.  
  167.   def update_windows()
  168.     @windows.values.each { |win| win.update() }
  169.   end
  170.  
  171.   def update_window_positions()
  172.     for i in 0...@act_item_max
  173.       @actor_windows[i].x = @x + 20
  174.     end  
  175.     if @index < @reserve_index_start
  176.       @actor_windows[@index].x = @x + 40
  177.     end  
  178.   end
  179.  
  180.   def update_user_input()
  181.     return if @item_max == 0
  182.     if Input.trigger?( Input::UP )
  183.       Sound.play_cursor
  184.       @index -= 1
  185.       @index %= @item_max
  186.     elsif Input.trigger?( Input::DOWN )
  187.       Sound.play_cursor
  188.       @index += 1
  189.       @index %= @item_max
  190.     end
  191.   end
  192.  
  193.   def reset_window_positions()
  194.     for i in 0...@act_item_max
  195.       @actor_windows[i].x = @x + 20
  196.     end
  197.   end
  198.  
  199. end
  200.  
  201. #==============================================================================#
  202. # Scene_Menu
  203. #==============================================================================#
  204. class Scene_Menu < Scene_Base
  205.  
  206.   #--------------------------------------------------------------------------
  207.   # * overwrite method :start
  208.   #--------------------------------------------------------------------------
  209.   def start
  210.     super
  211.     create_menu_background
  212.     create_command_window
  213.     @gold_window = Window_Gold.new( 0, 360 )
  214.     @status_window = MenuStatus_FF8.new( 160, 0 )
  215.     @status_window.active = false
  216.   end
  217.  
  218.   #--------------------------------------------------------------------------
  219.   # * Create Command Window
  220.   #--------------------------------------------------------------------------
  221.   def create_command_window
  222.     s1 = Vocab::item
  223.     s2 = Vocab::skill
  224.     s3 = Vocab::equip
  225.     s4 = Vocab::status
  226.     s5 = Vocab::save
  227.     s6 = Vocab::game_end
  228.     @command_window = Window_Command.new(160, [s1, s2, s3, s4, s5, s6])
  229.     @command_window.index = @menu_index
  230.     if $game_party.members.size == 0          # If number of party members is 0
  231.       @command_window.draw_item(0, false)     # Disable item
  232.       @command_window.draw_item(1, false)     # Disable skill
  233.       @command_window.draw_item(2, false)     # Disable equipment
  234.       @command_window.draw_item(3, false)     # Disable status
  235.     end
  236.     if $game_system.save_disabled             # If save is forbidden
  237.       @command_window.draw_item(4, false)     # Disable save
  238.     end
  239.   end
  240.   #--------------------------------------------------------------------------
  241.   # * Update Command Selection
  242.   #--------------------------------------------------------------------------
  243.   def update_command_selection
  244.     if Input.trigger?(Input::B)
  245.       Sound.play_cancel
  246.       $scene = Scene_Map.new
  247.     elsif Input.trigger?(Input::C)
  248.       if $game_party.members.size == 0 and @command_window.index < 4
  249.         Sound.play_buzzer
  250.         return
  251.       elsif $game_system.save_disabled and @command_window.index == 4
  252.         Sound.play_buzzer
  253.         return
  254.       end
  255.       Sound.play_decision
  256.       case @command_window.index
  257.       when 0      # Item
  258.         $scene = Scene_Item.new
  259.       when 1,2,3  # Skill, equipment, status
  260.         start_actor_selection
  261.       when 4      # Save
  262.         $scene = Scene_File.new(true, false, false)
  263.       when 5      # End Game
  264.         $scene = Scene_End.new
  265.       end
  266.     end
  267.   end
  268.  
  269.   #--------------------------------------------------------------------------
  270.   # * Start Actor Selection
  271.   #--------------------------------------------------------------------------
  272.   def start_actor_selection
  273.     @command_window.active = false
  274.     @status_window.active = true
  275.     if $game_party.last_actor_index < @status_window.item_max
  276.       @status_window.index = $game_party.last_actor_index
  277.     else
  278.       @status_window.index = 0
  279.     end
  280.   end
  281.   #--------------------------------------------------------------------------
  282.   # * End Actor Selection
  283.   #--------------------------------------------------------------------------
  284.   def end_actor_selection
  285.     @command_window.active = true
  286.     @status_window.active = false
  287.     @status_window.index = -1
  288.   end
  289.   #--------------------------------------------------------------------------
  290.   # * Update Actor Selection
  291.   #--------------------------------------------------------------------------
  292.   def update_actor_selection
  293.     if Input.trigger?(Input::B)
  294.       Sound.play_cancel
  295.       end_actor_selection
  296.     elsif Input.trigger?(Input::C)
  297.       $game_party.last_actor_index = @status_window.index
  298.       Sound.play_decision
  299.       case @command_window.index
  300.       when 1  # skill
  301.         $scene = Scene_Skill.new(@status_window.index)
  302.       when 2  # equipment
  303.         $scene = Scene_Equip.new(@status_window.index)
  304.       when 3  # status
  305.         $scene = Scene_Status.new(@status_window.index)
  306.       end
  307.     end
  308.   end
  309.  
  310. end
Advertisement
Add Comment
Please, Sign In to add comment