IceDragon200

FRV-MainMenu

May 28th, 2011
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 23.71 KB | None | 0 0
  1. # // Last Modified :11/05/2011
  2. #==============================================================================#
  3. # FRV::MENU_SYSTEM
  4. #==============================================================================#
  5. module FRV
  6.   module MENU_SYSTEM
  7. #==============================================================================#
  8. #                      Start Primary Customization
  9. #------------------------------------------------------------------------------#
  10. #==============================================================================#    
  11.   #--------------------------------------------------------------------------#
  12.   # * MENU_LAYOUT
  13.   #--------------------------------------------------------------------------#
  14.   # This controls the order in which commands appear in the menu
  15.   # Default commands
  16.   # :item, :skill, :equip, :status, :save, :system (AKA end)
  17.   #--------------------------------------------------------------------------#
  18.     MENU_LAYOUT = [
  19.       :item,    # // Default Item Scene
  20.       :skill,   # // Default Skill Scene
  21.       :equip,   # // Default Equip Scene
  22.       :status,  # // Default Status Scene    
  23.       :save,    # // Default Save Scene
  24.       :system   # // Default End Scene
  25.     ] # // DO NOT REMOVE
  26.    
  27. #==============================================================================#
  28. #                        End Primary Customization
  29. #------------------------------------------------------------------------------#
  30. #==============================================================================#      
  31.   end
  32. end
  33.  
  34. #==============================================================================#
  35. # Scene_Menu - IEO030-Lunatic
  36. #==============================================================================#
  37. class Scene_Menu < Scene_Base
  38.  
  39.   #--------------------------------------------------------------------------#
  40.   # * new method :menu_command
  41.   #--------------------------------------------------------------------------#  
  42.   def menu_command( command )
  43.     menulay = $game_system.menu_layout
  44.     case command
  45.     when :item
  46.       $scene = Scene_Item.new
  47.     when :skill
  48.       $scene = Scene_Skill.new(@status_window.index)
  49.     when :equip
  50.       $scene = Scene_Equip.new(@status_window.index)
  51.     when :status
  52.       if $imported["IEO-LotusStatus"]
  53.         $scene = Scene_Status.new(@status_window.index, :menu, Scene_Menu.command_index(:status))
  54.       else
  55.         $scene = Scene_Status.new(@status_window.index)
  56.       end
  57.     when :save
  58.       $scene = Scene_File.new(true, false, false)
  59.     when :system
  60.       $scene = Scene_End.new
  61.     end  
  62.   end
  63.  
  64.   #--------------------------------------------------------------------------#
  65.   # * new class method :hide_command?
  66.   #--------------------------------------------------------------------------#  
  67.   def self.hide_command?( com )
  68.     case com
  69.     when :item   ; return $game_party.members.size == 0
  70.     when :skill  ; return $game_party.members.size == 0
  71.     when :equip  ; return $game_party.members.size == 0
  72.     when :status ; return $game_party.members.size == 0
  73.     when :save   ; return $game_system.save_disabled
  74.     when :system ; return false    
  75.     end
  76.     return false
  77.   end
  78.  
  79.   #--------------------------------------------------------------------------#
  80.   # * new class method :need_actor_selection?
  81.   #--------------------------------------------------------------------------#
  82.   def self.need_actor_selection?( com )
  83.     case com
  84.     when :item   ; return false
  85.     when :skill  ; return true
  86.     when :equip  ; return true
  87.     when :status ; return true
  88.     when :save   ; return false
  89.     when :system ; return false
  90.     # // Party swapping  
  91.     when :swap   ; return true
  92.     end
  93.     return false
  94.   end
  95.  
  96.   #--------------------------------------------------------------------------#
  97.   # * new class method :command_index
  98.   #--------------------------------------------------------------------------#  
  99.   def self.command_index( com )
  100.     return $game_system.menu_layout.index( com )
  101.   end
  102.  
  103.   #--------------------------------------------------------------------------#
  104.   # * new method :before_actor_selection
  105.   #--------------------------------------------------------------------------#  
  106.   def before_actor_selection( lastcommand = :nil )
  107.   end  
  108.  
  109. end
  110.  
  111. #==============================================================================#
  112. # FRV::Vocab
  113. #==============================================================================#
  114. module FRV
  115.   module Vocab
  116.    
  117.     module_function
  118.  
  119.     def menu( command )
  120.       case command
  121.       when :item    ; return ::Vocab.item
  122.       when :skill   ; return ::Vocab.skill
  123.       when :equip   ; return ::Vocab.equip
  124.       when :status  ; return ::Vocab.status
  125.       when :save    ; return ::Vocab.save
  126.       when :system  ; return ::Vocab.game_end
  127.       else          ; return ""
  128.       end  
  129.     end
  130.    
  131.     def menu_help( command )
  132.       case command
  133.       when :item    ; return "Shows the party's inventory"
  134.       when :skill   ; return "Shows party member's skills"
  135.       when :equip   ; return "Shows party member's equipment"
  136.       when :status  ; return "Shows party member's status"
  137.       when :save    ; return "Save file"
  138.       when :system  ; return "System Menu"
  139.       else          ; return ""
  140.       end  
  141.     end
  142.    
  143.   end
  144. end
  145.  
  146. #==============================================================================#
  147. # FRV::Icon
  148. #==============================================================================#
  149. module FRV
  150.   module Icon
  151.     module_function
  152.     def menu( command ) ; return 0 end
  153.   end
  154. end
  155.  
  156. #==============================================================================#
  157. # Game_System
  158. #==============================================================================#
  159. class Game_System
  160.  
  161.   #--------------------------------------------------------------------------#
  162.   # * Public Instance Variables
  163.   #--------------------------------------------------------------------------#  
  164.   attr_accessor :menu_layout
  165.  
  166.   #--------------------------------------------------------------------------#
  167.   # * alias method :initialize
  168.   #--------------------------------------------------------------------------#  
  169.   alias :frv_ms_gs_initialize :initialize unless $@
  170.   def initialize()
  171.     frv_ms_gs_initialize()
  172.     a = FRV::MENU_SYSTEM
  173.     @menu_layout = a::MENU_LAYOUT.clone
  174.   end
  175.  
  176. end
  177.  
  178. #==============================================================================#
  179. # ** Window_ActorMenuStatus
  180. #==============================================================================#
  181. class Window_ActorMenuStatus < Window_Base
  182.  
  183.   BACK_BITMAP_NAME = "" #"Menu_PartyMember" # // Located in System Folder
  184.  
  185.   #--------------------------------------------------------------------------#
  186.   # * Public Instance Variables
  187.   #--------------------------------------------------------------------------#
  188.   attr_accessor :actor
  189.  
  190.   def initialize(x, y, actor)
  191.     super( x, y, 336, 80 )
  192.     @actor = actor
  193.     @back_sprite = Sprite.new( self.viewport )
  194.     unless BACK_BITMAP_NAME.empty?
  195.       @back_sprite.bitmap = Cache.system( BACK_BITMAP_NAME )
  196.       self.opacity = 0
  197.     end  
  198.     @back_sprite.x = self.x
  199.     @back_sprite.y = self.y
  200.     @back_sprite.z = self.z - 4
  201.     refresh()
  202.   end
  203.  
  204.   def x=( new_x )
  205.     @back_sprite.x = new_x unless @back_sprite.nil?()
  206.     super( new_x )
  207.   end
  208.  
  209.   def y=( new_y )
  210.     @back_sprite.y = new_y unless @back_sprite.nil?()
  211.     super( new_y )
  212.   end
  213.  
  214.   def z=( new_z )
  215.     @back_sprite.z = new_z unless @back_sprite.nil?()
  216.     super( new_z )
  217.   end
  218.  
  219.   def dispose()
  220.     @back_sprite.dispose() unless @back_sprite.nil?()
  221.     @back_sprite = nil
  222.     super()
  223.   end
  224.  
  225.   def update()
  226.     super()
  227.     @back_sprite.update() unless @back_sprite.nil?()
  228.   end
  229.  
  230.   def draw_face( face_name, face_index, x, y, wsize = 96, hsize = 96 )
  231.     bitmap = Cache.face(face_name)
  232.     rect = Rect.new( 0, 0, 0, 0 )
  233.     rect.x = face_index % 4 * 96 + (96 - wsize) / 2
  234.     rect.y = face_index / 4 * 96 + (96 - hsize) / 2
  235.     rect.width = wsize
  236.     rect.height = hsize
  237.     self.contents.blt(x, y, bitmap, rect)
  238.     bitmap.dispose
  239.   end
  240.  
  241.   def draw_actor_face( actor, x, y, wsize = 96, hsize = 96 )
  242.     draw_face( actor.face_name, actor.face_index, x, y, wsize, hsize )
  243.   end
  244.  
  245.   def refresh()
  246.     create_contents()
  247.     draw_actor_face( @actor, 0, 0, 96, 48 )
  248.     draw_actor_name( @actor, 100, 0 )
  249.     draw_actor_hp( @actor, 224, 0, 72 )
  250.     draw_actor_mp( @actor, 224, 16, 72 )
  251.     draw_actor_state( @actor, 100, 24, 24*5 )
  252.   end
  253.  
  254. end
  255.  
  256. #==============================================================================#
  257. # MenuStatus_FRV
  258. #==============================================================================#
  259. class MenuStatus_FRV < FRV::Container_Base # // Container
  260.    
  261.   def initialize( sx, sy )
  262.     super( 0, 0, 0, 0 ) # // Dummy Container
  263.     @x, @y, @z = sx, sy, 0
  264.     @index = -1
  265.     @windows = {}
  266.     @actor_windows = []
  267.     @reserve_index_start = 0
  268.     @item_max = 0
  269.     @active = true
  270.     @inactive_ax = 10
  271.     @active_ax   = 24
  272.     refresh()
  273.     @start_up = true
  274.     @windows.values.each { |w| w.x = @x - w.width }
  275.     @start_count = 0
  276.   end
  277.  
  278.   def active=( bool )
  279.     @active = bool
  280.     if bool
  281.       @windows.values.each { |w|
  282.         #w.opacity = 255
  283.         #w.contents_opacity = 255
  284.       }
  285.     else
  286.       @windows.values.each { |w|
  287.         #w.opacity = 128
  288.         #w.contents_opacity = 128
  289.       }
  290.     end  
  291.   end
  292.  
  293.   def active() ; return @active end
  294.    
  295.   def dispose()
  296.     dispose_windows()
  297.   end
  298.  
  299.   def dispose_windows()  
  300.     @actor_windows.clear()
  301.     @windows.values.each { |w| w.dispose }
  302.     @windows.clear()
  303.   end
  304.  
  305.   def x=( new_x )
  306.     return if @x == new_x
  307.     @x = new_x
  308.     @windows.values.each { |w| w.x = @x }
  309.   end
  310.  
  311.   def y=( new_y )
  312.     return if @y == new_y
  313.     @y = new_y
  314.     @windows.values.each { |w| w.y = @y }
  315.   end
  316.  
  317.   def z=( new_z )
  318.     return if @z == new_z
  319.     @z = new_z
  320.     @windows.values.each { |w| w.z = @z }
  321.   end  
  322.  
  323.   def refresh()
  324.     i = 0
  325.     dispose_windows()
  326.     $game_party.members.each { |m|
  327.       winm = "Actor#{i}"
  328.       win = Window_ActorMenuStatus.new( @x + @inactive_ax, 0, m )
  329.       win.y = @y+(win.height*i)
  330.       @windows[winm] = win
  331.       @actor_windows[i] = win
  332.       @actor_windows[i].active = false
  333.       @actor_windows[i].update
  334.       i += 1
  335.     }
  336.     @item_max = @actor_windows.size()
  337.     reset_window_positions()
  338.     update_windows()
  339.   end
  340.  
  341.   def update()
  342.     update_user_input() unless @start_up or !active()
  343.     update_windows()
  344.     if @start_up
  345.       bre = false
  346.       i = 1
  347.       @windows.values.each { |w|
  348.         wp = w.width / 20
  349.         tx = @x + @inactive_ax
  350.         w.x = [w.x + wp, tx].min if (@start_count / i) > 2
  351.         bre = !(w.x == tx)
  352.         i += 1
  353.       }  
  354.       @start_up = bre
  355.       unless @start_up
  356.         update_window_positions()
  357.       end  
  358.       @start_count += 1
  359.     else  
  360.       update_window_positions()
  361.     end  
  362.   end
  363.  
  364.   def update_windows()
  365.     @windows.values.each { |win| win.update() }
  366.   end
  367.  
  368.   def update_window_positions()
  369.     for i in 0...@item_max
  370.       @actor_windows[i].x = @x + @inactive_ax
  371.       @actor_windows[i].y = @y + (@actor_windows[i].height*i)
  372.       @actor_windows[i].active = false
  373.     end    
  374.     if @index > -1
  375.       @actor_windows[@index].x = @x + @active_ax
  376.       @actor_windows[@index].active = true
  377.     end  
  378.   end
  379.  
  380.   def update_user_input()
  381.     return if @item_max == 0
  382.     if Input.trigger?( Input::UP )
  383.       Sound.play_cursor
  384.       @index -= 1
  385.       @index %= @item_max
  386.     elsif Input.trigger?( Input::DOWN )
  387.       Sound.play_cursor
  388.       @index += 1
  389.       @index %= @item_max
  390.     end
  391.   end
  392.  
  393.   def reset_window_positions()
  394.     for i in 0...@item_max
  395.       @actor_windows[i].x = @x + @inactive_ax
  396.     end
  397.   end
  398.  
  399. end
  400.  
  401. #==============================================================================#
  402. # Window_ImageCommand
  403. #==============================================================================#
  404. class Window_ImageCommand < Window_Command
  405.  
  406.   #--------------------------------------------------------------------------#
  407.   # * new method :get_current_command
  408.   #--------------------------------------------------------------------------#    
  409.   def get_current_command() ; return @commands[self.index] end
  410.    
  411.   #--------------------------------------------------------------------------#
  412.   # * overwrite method :refresh
  413.   #--------------------------------------------------------------------------#  
  414.   def refresh()
  415.     self.contents.clear()
  416.     for i in 0...@item_max
  417.       draw_item( i, !Scene_Menu.hide_command?(@commands[i]) )
  418.     end
  419.   end
  420.  
  421.   #--------------------------------------------------------------------------#
  422.   # * overwrite method :item_rect
  423.   #--------------------------------------------------------------------------#
  424.   def item_rect( index, adapt=true )
  425.     rect = Rect.new( 0, 0, 0, 0 )
  426.     rect.width = ( contents.width + @spacing ) / @column_max - @spacing
  427.     rect.height = WLH
  428.     rect.x = index % @column_max * ( rect.width + @spacing )
  429.     rect.y = index / @column_max * WLH
  430.     if $imported["IEO-BugFixesUpgrades"]
  431.       if IEO::UPGRADE::ADAPTIVE_CURSOR    
  432.         if adapt
  433.           tx = FRV::Vocab.menu( @commands[index] )
  434.           rect.width = self.contents.text_size( tx ).width+12
  435.           icon = FRV::Icon.menu( @commands[index] )
  436.           rect.width += 24 if icon > 0
  437.         end  
  438.       end
  439.     end  
  440.     return rect
  441.   end
  442.  
  443.   #--------------------------------------------------------------------------#
  444.   # * overwrite method :draw_item
  445.   #--------------------------------------------------------------------------#  
  446.   def draw_item( index, enabled = true )
  447.     self.contents.font.size = Font.default_size
  448.     rect = item_rect( index, false )
  449.     rect.x += 4
  450.     rect.width -= 8
  451.     self.contents.clear_rect( rect )
  452.     self.contents.font.color = normal_color
  453.     self.contents.font.color.alpha = enabled ? 255 : 128
  454.     icon = FRV::Icon.menu( @commands[index] )
  455.     if icon > 0
  456.       draw_icon( icon, rect.x, rect.y )
  457.       rect.x += 24 ; rect.width -= 24
  458.     end  
  459.     self.contents.draw_text( rect, FRV::Vocab.menu( @commands[index] ) )
  460.   end
  461.  
  462.   def help_text( index=self.index )
  463.     return FRV::Vocab.menu_help( @commands[index] )
  464.   end
  465.  
  466. end
  467.  
  468. #==============================================================================#
  469. # Window_MenuHelp
  470. #==============================================================================#
  471. class Window_MenuHelp < IRS::Sprite_Help ; end
  472.    
  473. #==============================================================================#
  474. # Window_MenuGold
  475. #==============================================================================#
  476. class Window_MenuGold < IRS::Sprite_Gold ; end
  477.  
  478. #==============================================================================#
  479. # Window_MenuLocation
  480. #==============================================================================#
  481. class Window_MenuLocation < IRS::Sprite_Location ; end
  482.  
  483. #==============================================================================#
  484. # Scene_Menu
  485. #==============================================================================#
  486. class Scene_Menu < Scene_Base
  487.    
  488.   #--------------------------------------------------------------------------
  489.   # * overwrite method :start
  490.   #--------------------------------------------------------------------------
  491.   def start()
  492.     super()
  493.     create_menu_background()
  494.     @help_sprite            = Window_MenuHelp.new( 0, 0, Graphics.width, 32 )
  495.     create_command_window()
  496.     @gold_window            = Window_MenuGold.new( 0, 360, 128, 24 )
  497.     @gold_window.x          = Graphics.width - @gold_window.width
  498.     @location_window        = Window_MenuLocation.new( 0, 360, @gold_window.x-4, 32 )
  499.     @status_window          = MenuStatus_FRV.new( 0, @help_sprite.height )
  500.     @status_window.active   = false
  501.     @gold_window.y          = Graphics.height - @gold_window.height
  502.     @location_window.y      = Graphics.height - @location_window.height
  503.     update_help()
  504.     # // ----------------------------------------------------------------- // #
  505.     @menuback_sprite.bitmap = Cache.system( "Menu_background" )
  506.     @menuback_sprite.opacity= 255
  507.   end
  508.  
  509.   #--------------------------------------------------------------------------
  510.   # * Termination Processing
  511.   #--------------------------------------------------------------------------
  512.   def terminate()
  513.     super()
  514.     dispose_menu_background()
  515.     @command_window.dispose
  516.     @gold_window.dispose
  517.     @status_window.dispose
  518.     @location_window.dispose
  519.     @help_sprite.dispose
  520.   end
  521.  
  522.   #--------------------------------------------------------------------------#
  523.   # * overwrite method :create_command_window
  524.   #--------------------------------------------------------------------------#
  525.   def create_command_window()
  526.     coms                  = $game_system.menu_layout
  527.     @command_window       = Window_ImageCommand.new( 160, coms )
  528.     @command_window.index = @menu_index
  529.     @command_window.x     = Graphics.width - @command_window.width
  530.     @command_window.y     = @help_sprite.height
  531.     @command_window.update()
  532.   end
  533.  
  534.   #--------------------------------------------------------------------------#
  535.   # * new method :return_scene
  536.   #--------------------------------------------------------------------------#
  537.   def return_scene()
  538.     $scene = Scene_Map.new()
  539.   end
  540.  
  541.   #--------------------------------------------------------------------------
  542.   # * Frame Update
  543.   #--------------------------------------------------------------------------
  544.   def update()
  545.     super()
  546.     update_menu_background()
  547.     @command_window.update()
  548.     @gold_window.update()
  549.     @status_window.update()
  550.     if @command_window.active
  551.       update_command_selection()
  552.       update_help()
  553.     elsif @status_window.active
  554.       update_actor_selection()
  555.     end
  556.   end
  557.  
  558.   #--------------------------------------------------------------------------#
  559.   # * new method :update_help
  560.   #--------------------------------------------------------------------------#
  561.   def update_help()
  562.     @help_sprite.set_obj( @command_window.help_text() )
  563.   end  
  564.  
  565.   #--------------------------------------------------------------------------#
  566.   # * overwrite method :update_command_selection
  567.   #--------------------------------------------------------------------------#
  568.   def update_command_selection()
  569.     if Input.trigger?( Input::B )
  570.       Sound.play_cancel
  571.       return_scene()
  572.     elsif Input.trigger?( Input::C )
  573.       com = @command_window.get_current_command
  574.       if com == nil
  575.         Sound.play_buzzer
  576.         return
  577.       end
  578.       if Scene_Menu.hide_command?( com )
  579.         Sound.play_buzzer
  580.         return
  581.       end
  582.       Sound.play_decision()
  583.       if Scene_Menu.need_actor_selection?( com )
  584.         before_actor_selection( com )
  585.         start_actor_selection()
  586.       else
  587.         menu_command( com )  
  588.       end
  589.     end
  590.   end
  591.  
  592.   #--------------------------------------------------------------------------#
  593.   # * alias method :start_actor_selection
  594.   #--------------------------------------------------------------------------#  
  595.   alias :frv_ms_start_actor_selection :start_actor_selection unless $@
  596.   def start_actor_selection()
  597.     frv_ms_start_actor_selection()
  598.     imx = @status_window.item_max()
  599.     @status_window.index = imx if @status_window.index > imx
  600.   end  
  601.  
  602.   #--------------------------------------------------------------------------#
  603.   # * overwrite method :update_actor_selection
  604.   #--------------------------------------------------------------------------#
  605.   def update_actor_selection()
  606.     if Input.trigger?( Input::B )
  607.       Sound.play_cancel
  608.       end_actor_selection()
  609.     elsif Input.trigger?( Input::C )
  610.       $game_party.last_actor_index = @status_window.index
  611.       com = @command_window.get_current_command()
  612.       Sound.play_decision
  613.       menu_command( com )
  614.     end
  615.   end
  616.  
  617.   #--------------------------------------------------------------------------#
  618.   # * alias method :end_actor_selection
  619.   #--------------------------------------------------------------------------#  
  620.   alias :frv_ms_end_actor_selection :end_actor_selection unless $@
  621.   def end_actor_selection()
  622.     @status_window.index = -1
  623.     frv_ms_end_actor_selection()
  624.   end
  625.  
  626. end
  627.  
  628. #==============================================================================#
  629. # Scene_Item
  630. #==============================================================================#
  631. class Scene_Item < Scene_Base
  632.   #--------------------------------------------------------------------------#
  633.   # * overwrite method :return_scene
  634.   #--------------------------------------------------------------------------#
  635.   def return_scene
  636.     $scene = Scene_Menu.new( Scene_Menu.command_index(:item) )
  637.   end
  638. end  
  639.  
  640. #==============================================================================#
  641. # Scene_Skill
  642. #==============================================================================#
  643. class Scene_Skill < Scene_Base
  644.   #--------------------------------------------------------------------------#
  645.   # * overwrite method :return_scene
  646.   #--------------------------------------------------------------------------#
  647.   def return_scene
  648.     $scene = Scene_Menu.new( Scene_Menu.command_index(:skill) )
  649.   end
  650. end
  651.  
  652. #==============================================================================#
  653. # Scene_Equip
  654. #==============================================================================#
  655. class Scene_Equip < Scene_Base
  656.   #--------------------------------------------------------------------------#
  657.   # * overwrite method :return_scene
  658.   #--------------------------------------------------------------------------#
  659.   def return_scene
  660.     $scene = Scene_Menu.new( Scene_Menu.command_index(:equip) )
  661.   end
  662. end
  663.  
  664. #==============================================================================#
  665. # Scene_Status
  666. #==============================================================================#
  667. class Scene_Status < Scene_Base
  668.   #--------------------------------------------------------------------------#
  669.   # * overwrite method :return_scene
  670.   #--------------------------------------------------------------------------#
  671.   def return_scene
  672.     $scene = Scene_Menu.new( Scene_Menu.command_index(:status) )
  673.   end
  674. end  
  675.  
  676. #==============================================================================#
  677. # Scene_File
  678. #==============================================================================#
  679. class Scene_File < Scene_Base
  680.   #--------------------------------------------------------------------------#
  681.   # * overwrite method :return_scene
  682.   #--------------------------------------------------------------------------#
  683.   def return_scene
  684.     if @from_title
  685.       $scene = Scene_Title.new
  686.     elsif @from_event
  687.       $scene = Scene_Map.new
  688.     else
  689.       $scene = Scene_Menu.new( Scene_Menu.command_index(:save) )
  690.     end
  691.   end
  692. end  
  693.  
  694. #==============================================================================#
  695. # Scene_End
  696. #==============================================================================#
  697. class Scene_End < Scene_Base
  698.   #--------------------------------------------------------------------------#
  699.   # * overwrite method :return_scene
  700.   #--------------------------------------------------------------------------#
  701.   def return_scene
  702.     $scene = Scene_Menu.new( Scene_Menu.command_index(:system) )
  703.   end
  704. end
  705.  
  706. #=*==========================================================================*=#
  707. # ** END OF FILE
  708. #=*==========================================================================*=#
Advertisement
Add Comment
Please, Sign In to add comment