IceDragon200

Cheap-Knockup-IEO-Menusystem

Mar 25th, 2011
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 19.17 KB | None | 0 0
  1. # 03/25/2011
  2. #==============================================================================#
  3. # IEO::MENU_SYSTEM
  4. #==============================================================================#
  5. module IEO
  6.   module MENU_SYSTEM
  7.     MENU_LAYOUT = [
  8.       :item,
  9.       :skill,
  10.       :equip,
  11.       :status,      
  12.       :swap,
  13.       :save,
  14.       :system
  15.     ]
  16.    
  17.     MS_YSPACING   = 128 #96
  18.     MS_RECTHEIGHT = 96
  19.    
  20.     MAX_MEMBERS   = 3
  21.     TOTAL_MEMBERS = 4
  22.    
  23.   end
  24. end
  25.  
  26. #==============================================================================#
  27. # Scene_Menu
  28. #==============================================================================#
  29. class Scene_Menu < Scene_Base
  30.  
  31.   def menu_command(command)
  32.     menulay = IEO::MENU_SYSTEM::MENU_LAYOUT
  33.     case command
  34.     when :item
  35.       $scene = Scene_Item.new
  36.     when :skill
  37.       $scene = Scene_Skill.new(@status_window.index)
  38.     when :equip
  39.       $scene = Scene_Equip.new(@status_window.index)
  40.     when :status
  41.       $scene = Scene_Status.new(@status_window.index)
  42.     when :save
  43.       $scene = Scene_File.new(true, false, false)
  44.     when :system
  45.       $scene = Scene_End.new
  46.     # // Party swapping
  47.     when :swap
  48.       start_swap_window
  49.       @status_window.active = false
  50.     end  
  51.   end
  52.  
  53.   def self.hide_command?(com)
  54.     case com
  55.     when :item   ; return $game_party.members.size == 0
  56.     when :skill  ; return $game_party.members.size == 0
  57.     when :equip  ; return $game_party.members.size == 0
  58.     when :status ; return $game_party.members.size == 0
  59.     when :save   ; return $game_system.save_disabled
  60.     when :system ; return false
  61.     # // Party swapping  
  62.     when :swap   ; return $game_party.all_members.size < 4
  63.      
  64.     end
  65.   end
  66.  
  67.   def self.need_actor_selection?(com)
  68.     case com
  69.     when :item   ; return false
  70.     when :skill  ; return true
  71.     when :equip  ; return true
  72.     when :status ; return true
  73.     when :save   ; return false
  74.     when :system ; return false
  75.     # // Party swapping  
  76.     when :swap   ; return true
  77.     end
  78.   end
  79.  
  80.   #--------------------------------------------------------------------------#
  81.   # * new method :start_swap_window
  82.   #--------------------------------------------------------------------------#
  83.   def start_swap_window
  84.     @partyswap_window = Window_MenuPartySwap.new(0, 0)
  85.     @partyswap_window.x = (Graphics.width - @partyswap_window.width) / 2
  86.     @partyswap_window.y = (Graphics.height - @partyswap_window.height) / 2
  87.     @partyswap_window.active = true
  88.   end
  89.  
  90.   #--------------------------------------------------------------------------#
  91.   # * overwrite method :update
  92.   #--------------------------------------------------------------------------#
  93.   def update
  94.     super
  95.     update_menu_background
  96.     @command_window.update
  97.     @gold_window.update
  98.     @status_window.update
  99.     if @command_window.active
  100.       update_command_selection
  101.     elsif @status_window.active
  102.       update_actor_selection
  103.     else
  104.       update_swap_window unless @partyswap_window.nil?
  105.     end
  106.   end
  107.  
  108.   #--------------------------------------------------------------------------#
  109.   # * new method :update_swap_window
  110.   #--------------------------------------------------------------------------#  
  111.   def update_swap_window
  112.     unless @partyswap_window.nil?
  113.       @partyswap_window.update
  114.       sindex = @status_window.index
  115.       raid = @partyswap_window.current_actor
  116.       raid = raid.nil? ? 0 : raid.id
  117.       if Input.trigger?(Input::C)
  118.         Sound.play_equip
  119.         $game_party.change_battler_at(sindex, raid)
  120.         end_swap_window
  121.         @status_window.active = true
  122.         @status_window.refresh
  123.       elsif Input.trigger?(Input::B)
  124.         Sound.play_cancel
  125.         end_swap_window
  126.         @status_window.active = true
  127.         @status_window.refresh
  128.       end  
  129.     end  
  130.   end
  131.  
  132.   #--------------------------------------------------------------------------#
  133.   # * new method :end_swap_window
  134.   #--------------------------------------------------------------------------#  
  135.   def end_swap_window
  136.     @partyswap_window.dispose unless @partyswap_window.nil?
  137.   end
  138.  
  139. end
  140.  
  141. #==============================================================================#
  142. # IEO::Vocab
  143. #==============================================================================#
  144. module IEO
  145.   module Vocab
  146.    
  147.     module_function
  148.  
  149.     def menu(command)
  150.       case command
  151.       when :item    ; return ::Vocab.item
  152.       when :skill   ; return ::Vocab.skill
  153.       when :equip   ; return ::Vocab.equip
  154.       when :status  ; return ::Vocab.status
  155.       when :save    ; return ::Vocab.save
  156.       when :system  ; return ::Vocab.game_end
  157.       # // Party swapping    
  158.       when :swap    ; return "Party"  
  159.       else          ; return ""
  160.       end  
  161.     end
  162.    
  163.   end
  164. end
  165.  
  166. #==============================================================================#
  167. # IEO::Icon
  168. #==============================================================================#
  169. module IEO
  170.   module Icon
  171.     module_function
  172.     def menu(command) ; return 0 end
  173.   end
  174. end
  175.  
  176. #==============================================================================
  177. # ** Game_Actor
  178. #------------------------------------------------------------------------------
  179. #==============================================================================
  180. class Game_Actor
  181.  
  182.   attr_accessor :party_lock
  183.  
  184.   alias ieo030_setup setup unless $@
  185.   def setup(actor_id)
  186.       @party_lock = false
  187.     ieo030_setup(actor_id)
  188.   end
  189.    
  190. end # Game_Actor
  191.  
  192. #==============================================================================
  193. # ** Game_Party
  194. #------------------------------------------------------------------------------
  195. # credit to Yanfly for almost everything following
  196. #==============================================================================
  197. class Game_Party < Game_Unit
  198.  
  199.   #--------------------------------------------------------------------------
  200.   # * constants
  201.   #--------------------------------------------------------------------------
  202.   TOTAL_MEMBERS = IEO::MENU_SYSTEM::TOTAL_MEMBERS
  203.   MAX_MEMBERS   = IEO::MENU_SYSTEM::MAX_MEMBERS
  204.  
  205.   #--------------------------------------------------------------------------
  206.   # * public instance variables
  207.   #--------------------------------------------------------------------------
  208.   attr_accessor :actors
  209.   attr_accessor :battlers
  210.  
  211.   #--------------------------------------------------------------------------
  212.   # * overwrite method: members
  213.   #--------------------------------------------------------------------------
  214.   def members ; return battle_members end
  215.    
  216.   #--------------------------------------------------------------------------
  217.   # * new method: battle_members
  218.   #--------------------------------------------------------------------------
  219.   def battle_members
  220.       if @battlers == nil
  221.         @battlers = Array.new(MAX_MEMBERS).map! { |ele| ele = 0}
  222.         for i in 0..([@actors.size, MAX_MEMBERS].min - 1)
  223.             @battlers[i] = @actors[i]
  224.         end
  225.     end  
  226.       result = []
  227.       for id in @battlers
  228.         result.push($game_actors[id]) unless $game_actors[id] == nil
  229.       end
  230.       return result
  231.   end
  232.  
  233.   def all_battle_members
  234.     battle_members if @battlers == nil
  235.     result = []
  236.     for id in @battlers
  237.       result.push($game_actors[id])
  238.     end  
  239.     return result
  240.   end  
  241.   #--------------------------------------------------------------------------
  242.   # * new method: party_members
  243.   #--------------------------------------------------------------------------
  244.   def party_members
  245.     result = []
  246.     for member in battle_members
  247.       result.push(member)
  248.     end
  249.     for member in all_members
  250.       result.push(member) unless result.include?(member)
  251.       end
  252.       return result
  253.   end
  254.  
  255.   #--------------------------------------------------------------------------
  256.   # * new method: all_members
  257.   #--------------------------------------------------------------------------
  258.   def all_members
  259.     result = []
  260.     @actors.each { |aid| result << $game_actors[aid] if aid > 0}
  261.     return result
  262.   end
  263.  
  264.   def battle_party_size ; return MAX_MEMBERS end
  265.  
  266.   def add_actor(actor_id)
  267.       if @actors.size < TOTAL_MEMBERS and !@actors.include?(actor_id)
  268.         @actors.push(actor_id)
  269.         $game_player.refresh
  270.       end
  271.   end
  272.  
  273.   #--------------------------------------------------------------------------
  274.   # * new method: set_battlers
  275.   #--------------------------------------------------------------------------
  276.   def set_battlers(*args)
  277.     battle_members if @battlers == nil
  278.     old_bats = @battlers.clone
  279.     @battlers.clear
  280.     bats = *args
  281.     for i in 0...battle_party_size
  282.       bat = old_bats[i]
  283.       @battlers[i] = 0
  284.       @battlers[i] = old_bats[bat] if @actors.include?(bat)
  285.     end  
  286.     $game_player.refresh
  287.   end
  288.  
  289.   def change_battler_at(index, aid)
  290.     battle_members if @battlers == nil
  291.     @battlers[index] = aid
  292.   end  
  293.  
  294.   def get_empty_index
  295.     for i in 0...battle_party_size
  296.       return i if @battlers[i] == 0
  297.     end  
  298.     return nil
  299.   end  
  300.   #--------------------------------------------------------------------------
  301.   # * alias method: add_actor
  302.   #--------------------------------------------------------------------------
  303.   alias add_actor_pss add_actor unless $@
  304.   def add_actor(actor_id)
  305.     last_size = @actors.size
  306.     add_actor_pss(actor_id)
  307.       if last_size < @actors.size
  308.         battle_members if @battlers == nil
  309.         for i in 0..(@battlers.size-1)
  310.             if @battlers[i] == 0
  311.               @battlers[i] = actor_id unless battle_members.size == battle_party_size
  312.               break
  313.             end
  314.         end
  315.       end
  316.   end
  317.  
  318.   #--------------------------------------------------------------------------
  319.   # * alias method: remove_actor
  320.   #--------------------------------------------------------------------------
  321.   alias remove_actor_pss remove_actor unless $@
  322.   def remove_actor(actor_id)
  323.     battle_members if @battlers == nil
  324.     @battlers[@battlers.index(actor_id)] = 0 if @battlers.include?(actor_id)
  325.     remove_actor_pss(actor_id)
  326.   end
  327.  
  328.   def battle_members_full?
  329.     return battle_members.compact.size >= battle_party_size
  330.   end
  331.  
  332. end
  333.  
  334. #==============================================================================#
  335. # Window_MenuStatus
  336. #==============================================================================#
  337. class Window_MenuStatus < Window_Selectable
  338.  
  339.   #--------------------------------------------------------------------------
  340.   # * Object Initialization
  341.   #     x : window X coordinate
  342.   #     y : window Y coordinate
  343.   #--------------------------------------------------------------------------
  344.   def initialize(x, y)
  345.     super(x, y, 384, 416)
  346.     @y_spacing   = IEO::MENU_SYSTEM::MS_YSPACING
  347.     @rect_height = IEO::MENU_SYSTEM::MS_RECTHEIGHT
  348.     refresh
  349.     self.active = false
  350.     self.index = -1
  351.   end
  352.  
  353.   #--------------------------------------------------------------------------
  354.   # * Refresh
  355.   #--------------------------------------------------------------------------
  356.   def refresh
  357.     self.contents.clear
  358.     @item_max = $game_party.members.size
  359.     for actor in $game_party.members
  360.       draw_actor_face(actor, 2, actor.index * @y_spacing + 2, 92)
  361.       x = 104
  362.       y = actor.index * @y_spacing + WLH / 2
  363.       draw_actor_name(actor, x, y)
  364.       draw_actor_class(actor, x + 120, y)
  365.       draw_actor_level(actor, x, y + WLH * 1)
  366.       draw_actor_state(actor, x, y + WLH * 2)
  367.       draw_actor_hp(actor, x + 120, y + WLH * 1)
  368.       draw_actor_mp(actor, x + 120, y + WLH * 2)
  369.       if $imported["IEO-SkillLevelSystem"]
  370.         rect = Rect.new(x+24, y, 96, 24)
  371.         draw_actor_skl_p(actor, rect)
  372.       end
  373.     end
  374.   end
  375.  
  376.   #--------------------------------------------------------------------------
  377.   # * Update cursor
  378.   #--------------------------------------------------------------------------
  379.   def update_cursor
  380.     if @index < 0               # No cursor
  381.       self.cursor_rect.empty
  382.     elsif @index < @item_max    # Normal
  383.       self.cursor_rect.set(0, @index * @y_spacing, contents.width, @rect_height)
  384.     elsif @index >= 100         # Self
  385.       self.cursor_rect.set(0, (@index - 100) * @y_spacing, contents.width, @rect_height)
  386.     else                        # All
  387.       self.cursor_rect.set(0, 0, contents.width, self.height-32)
  388.     end
  389.   end
  390.  
  391. end
  392.  
  393. #==============================================================================#
  394. # Window_MenuCommand
  395. #==============================================================================#
  396. class Window_MenuCommand < Window_Command
  397.  
  398.   def get_current_command ; return @commands[self.index] end
  399.    
  400.   #--------------------------------------------------------------------------
  401.   # * Refresh
  402.   #--------------------------------------------------------------------------
  403.   def refresh
  404.     self.contents.clear
  405.     for i in 0...@item_max
  406.       draw_item(i, !Scene_Menu.hide_command?(@commands[i]))
  407.     end
  408.   end
  409.   #--------------------------------------------------------------------------
  410.   # * Draw Item
  411.   #     index   : item number
  412.   #     enabled : enabled flag. When false, draw semi-transparently.
  413.   #--------------------------------------------------------------------------
  414.   def draw_item(index, enabled = true)
  415.     rect = item_rect(index)
  416.     rect.x += 4
  417.     rect.width -= 8
  418.     self.contents.clear_rect(rect)
  419.     self.contents.font.color = normal_color
  420.     self.contents.font.color.alpha = enabled ? 255 : 128
  421.     icon = IEO::Icon.menu(@commands[index])
  422.     draw_icon(icon, rect.x, rect.y)
  423.     if icon > 0
  424.       rect.x += 24 ; rect.width -= 24
  425.     end  
  426.     self.contents.draw_text(rect, IEO::Vocab.menu(@commands[index]))
  427.   end
  428.  
  429. end  
  430.  
  431. class Window_MenuPartySwap < Window_Selectable
  432.  
  433.   HEIGHT_PUSH = 72
  434.  
  435.   def initialize(px, py)
  436.     @character_rect = Rect.new(0, 0, 32, 32)
  437.       super(px, py, Graphics.width, HEIGHT_PUSH+32)
  438.     @actors = $game_party.battle_members
  439.     @item_max = $game_party.battle_party_size
  440.     self.index = 0
  441.     @smindex = nil
  442.     refresh if init_refresh?
  443.   end
  444.  
  445.   def init_refresh? ; return true end
  446.  
  447.   def current_actor ; return @actors[self.index] end
  448.   def get_actor_at(index) ; return @actors[index] end
  449.    
  450.   def refresh
  451.       self.contents.clear
  452.     @actors = []
  453.       for mem in $game_party.all_members.compact
  454.       @actors.push(mem) unless $game_party.battle_members.include?(mem)
  455.     end
  456.     @actors.push(nil)
  457.       @item_max = @actors.size
  458.     @column_max = [1, @item_max].max
  459.     create_contents
  460.       for i in 0...@item_max
  461.         draw_item(i)
  462.       end
  463.   end  
  464.  
  465.   def draw_item(index)
  466.     rect = item_rect(index)
  467.     self.contents.clear_rect(rect)
  468.       actor = @actors[index]
  469.     unless actor.nil?
  470.         aname  = actor.name
  471.         aclass = actor.class.name
  472.         alevel = actor.level
  473.       ash = (rect.height-@character_rect.height)/2
  474.         locked = actor.party_lock
  475.       ch = @character_rect.height
  476.       draw_actor_graphic(actor, rect.x+16, rect.y+@character_rect.height+ash+4, !locked)
  477.         self.contents.font.color.alpha = locked ? 128 : 255
  478.         self.contents.font.size = 12
  479.         self.contents.draw_text(rect.x+3,rect.y - 4,rect.width,24,aname)
  480.         self.contents.draw_text(rect.x,rect.y+18,rect.width-2,24,"Lv.",2)
  481.         self.contents.draw_text(rect.x,rect.y+28,rect.width-2,24,alevel,2)
  482.         self.contents.draw_text(rect.x,rect.y+17+ch,rect.width-3,24,aclass,2)
  483.       end
  484.   end
  485.  
  486.   def item_rect(index)
  487.     rect = Rect.new(0, 0, 0, 0)
  488.     rect.width = @character_rect.width + 32
  489.     rect.height = @character_rect.height + (HEIGHT_PUSH-32)
  490.     rect.x = index * (rect.width + 10)
  491.     rect.y = 0
  492.     return rect
  493.   end
  494.  
  495.   #--------------------------------------------------------------------------
  496.   # * Draw Actor Walking Graphic
  497.   #     actor : actor
  498.   #     x     : draw spot x-coordinate
  499.   #     y     : draw spot y-coordinate
  500.   #--------------------------------------------------------------------------
  501.   def draw_actor_graphic(actor, x, y, enabled=true)
  502.     draw_character(actor.character_name, actor.character_index, x, y, enabled)
  503.   end
  504.  
  505.   #--------------------------------------------------------------------------
  506.   # * Draw Character Graphic
  507.   #     character_name  : Character graphic filename
  508.   #     character_index : Character graphic index
  509.   #     x     : draw spot x-coordinate
  510.   #     y     : draw spot y-coordinate
  511.   #--------------------------------------------------------------------------
  512.   def draw_character(character_name, character_index, x, y, enabled=true)
  513.     return if character_name == nil
  514.     bitmap = Cache.character(character_name)
  515.     sign = character_name[/^[\!\$]./]
  516.     if sign != nil and sign.include?('$')
  517.       cw = bitmap.width / 3
  518.       ch = bitmap.height / 4
  519.     else
  520.       cw = bitmap.width / 12
  521.       ch = bitmap.height / 8
  522.     end
  523.     n = character_index
  524.     src_rect = Rect.new((n%4*3+1)*cw, (n/4*4)*ch, cw, ch)
  525.     self.contents.blt(x - cw / 2, y - ch, bitmap, src_rect, enabled ? 255 : 128)
  526.   end
  527.  
  528. end  
  529. #==============================================================================#
  530. # Scene_Menu
  531. #==============================================================================#
  532. class Scene_Menu < Scene_Base
  533.  
  534.   #--------------------------------------------------------------------------
  535.   # * Object Initialization
  536.   #     menu_index : command cursor's initial position
  537.   #--------------------------------------------------------------------------
  538.   def initialize(menu_index = 0)
  539.     @menu_index = menu_index
  540.   end
  541.  
  542.   #--------------------------------------------------------------------------
  543.   # * Create Command Window
  544.   #--------------------------------------------------------------------------
  545.   def create_command_window
  546.     s1 = Vocab::item
  547.     s2 = Vocab::skill
  548.     s3 = Vocab::equip
  549.     s4 = Vocab::status
  550.     s5 = Vocab::save
  551.     s6 = Vocab::game_end
  552.     coms = IEO::MENU_SYSTEM::MENU_LAYOUT
  553.     @command_window = Window_MenuCommand.new(160, coms)
  554.     @command_window.index = @menu_index
  555.   end
  556.    
  557.   #--------------------------------------------------------------------------
  558.   # * Update Command Selection
  559.   #--------------------------------------------------------------------------
  560.   def update_command_selection
  561.     if Input.trigger?(Input::B)
  562.       Sound.play_cancel
  563.       $scene = Scene_Map.new
  564.     elsif Input.trigger?(Input::C)
  565.       com = @command_window.get_current_command
  566.       if com == nil
  567.         Sound.play_buzzer
  568.         return
  569.       end
  570.       if Scene_Menu.hide_command?(com)
  571.         Sound.play_buzzer
  572.         return
  573.       end
  574.       Sound.play_decision
  575.       if Scene_Menu.need_actor_selection?(com)
  576.         start_actor_selection
  577.       else
  578.         menu_command(com)
  579.       end
  580.     end
  581.   end
  582.  
  583.   #--------------------------------------------------------------------------
  584.   # * Update Actor Selection
  585.   #--------------------------------------------------------------------------
  586.   def update_actor_selection
  587.     if Input.trigger?(Input::B)
  588.       Sound.play_cancel
  589.       end_actor_selection
  590.     elsif Input.trigger?(Input::C)
  591.       $game_party.last_actor_index = @status_window.index
  592.       com = @command_window.get_current_command
  593.       Sound.play_decision
  594.       menu_command(com)
  595.     end
  596.   end
  597.  
  598. end
Advertisement
Add Comment
Please, Sign In to add comment