Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1.     #############################################################################################
  2.     ############################## Choix Personnages et Difficulté ######################################
  3.     #############################################################################################
  4.  
  5.     # Auteur : Biward
  6.     # Date : 09/08/2010 15:53
  7.     # Version : 1.0
  8.     # Pour le forum RPG Maker VX BBactif et VX-fan
  9.  
  10.     # Utilité :
  11.     # Permet de choisir le heros et la difficulté du jeu lorsque l'on fait une nouvelle partie !
  12.  
  13.  
  14.     #=========================================================================================#
  15.     #  MODULE  de CONFIGURATION #
  16.     #=========================================================================================#
  17.  
  18.     module BI
  19.       module PERSODIF
  20.        
  21.         ##### APPEL DE SCRIPT = persodif #####
  22.         # TITLE = true or false
  23.         # Si true alors le choix de personnage se fera après l'écran titre ("Nouvelle Partie")
  24.         # Si false, il faudra appeller le choix des persos par un appel de script
  25.         TITLE = false
  26.        
  27.         # PERSO = [ Les heros que l'on peut choisir (leur ID dans la BDD) ]         /!\ N'oubliez pas les virgules !
  28.         PERSO = [2, 4, 6, 8] # Maximun 4 !!
  29.        
  30.         # TEXT_INFO = Texte d'aide pour le choix du personnage               /!\ N'oubliez pas les " " !
  31.         TEXT_INFO = "Choisissez votre heros :"
  32.        
  33.         # DIF = [ Nom des difficultés ]        /!\ N'oubliez pas les virgules !
  34.         DIF = ["Facile", "Normal", "Extreme"]
  35.        
  36.         # VAR_DIF = Variable qui stocke le choix de la difficulté
  37.         VAR_DIF = 1
  38.        
  39.         # Exemple :
  40.         # DIF = [Facile, Extreme]
  41.         # VAR_DIF = 1
  42.         # Si le joueur choisit Facile, la variable 1 sera egale à 0.
  43.         # Si le joueur choisit Extreme, la variable 1 sera egale a 1.
  44.        
  45.         # TEXT_INFO_2 = Texte d'aide pour le choix de la difficulté              /!\ N'oubliez pas les " " !
  46.         TEXT_INFO_2 = "Choisissez le niveau de difficulté :"
  47.       end
  48.     end
  49.  
  50.  
  51.     #############################################################################################
  52.     #\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\#
  53.     #___________________________________________________________________________________________#
  54.     #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> DEBUT DU SCRIPT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>#
  55.     #___________________________________________________________________________________________#
  56.     #////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////#
  57.     #############################################################################################
  58.  
  59.       WLH_2 = 165
  60.  
  61.     #=========================================================================================#
  62.     #  SCENE_TITLE  #
  63.     #=========================================================================================#
  64.  
  65.     class Scene_Title
  66.      
  67.       include BI::PERSODIF
  68.      
  69.       alias command_new_game_dif command_new_game
  70.      
  71.       def command_new_game  
  72.         command_new_game_dif
  73.         if TITLE
  74.           $scene = Scene_PersoDif.new
  75.         end
  76.       end
  77.     end
  78.  
  79.     #=========================================================================================#
  80.     #  PERSODIF #
  81.     #=========================================================================================#
  82.  
  83.     def persodif
  84.       if ! BI::PERSODIF::TITLE
  85.         $scene = Scene_PersoDif.new
  86.       end
  87.     end
  88.  
  89.     #=========================================================================================#
  90.     #  SCENE_PERSODIF #
  91.     #=========================================================================================#
  92.  
  93.     class Scene_PersoDif < Scene_Base
  94.      
  95.         include BI::PERSODIF
  96.  
  97.         def start
  98.           @choix_perso, @choix_dif_perso, @commands_perso, @commands_dif = Array.new(4){[]}
  99.          
  100.           for i in PERSO
  101.             truc = nil
  102.             @commands_perso << truc
  103.           end
  104.          
  105.           for i2 in DIF
  106.             @commands_dif << i2
  107.           end
  108.          
  109.           @choix_perso = Window_Command_PAD.new(445, @commands_perso, 4, 1, 15)
  110.           @choix_perso.opacity = 0
  111.           @choix_perso.x = Graphics.width/2 - 445/2
  112.           @choix_perso.y = Graphics.height/2 - (1*24-32) - WLH_2/2
  113.          
  114.           @choix_dif = Window_Command.new(445, @commands_dif, 1, @commands_dif.size, 15)
  115.           @choix_dif.opacity = 0
  116.           @choix_dif.x = Graphics.width/2 - 455/2
  117.           @choix_dif.y = Graphics.height/2 - (@commands_dif.size*24-32)/2
  118.           @choix_dif.active = false
  119.           @choix_dif.visible = false
  120.           @choix_dif.z = 255    
  121.          
  122.           create_window_perso
  123.         end
  124.          
  125.         def update
  126.           @choix_perso.update
  127.           @choix_dif.update
  128.           if Input.trigger?(Input::B) && @choix_perso.active && ! @choix_dif.active
  129.             Sound.play_buzzer
  130.           elsif Input.trigger?(Input::B) && ! @choix_perso.active && @choix_dif.active
  131.             $perso = nil
  132.             dispose_window_dif
  133.             create_window_perso
  134.             @choix_perso.active = true
  135.             @choix_perso.visible = true
  136.             @choix_dif.active = false
  137.             @choix_dif.visible = false
  138.           end
  139.           if Input.trigger?(Input::C) && @choix_perso.active && ! @choix_dif.active
  140.             $perso = PERSO[@choix_perso.index]
  141.             dispose_window_perso
  142.             create_window_dif
  143.             @choix_perso.active = false
  144.             @choix_perso.visible = false
  145.             @choix_dif.active = true
  146.             @choix_dif.visible = true
  147.           elsif Input.trigger?(Input::C) && ! @choix_perso.active && @choix_dif.active
  148.             change_party
  149.             $game_variables[VAR_DIF] = @choix_dif.index
  150.           end
  151.         end
  152.        
  153.         def change_party
  154.           $game_party.members.size.times { |i|  $game_party.remove_actor(i) }
  155.           $game_party.add_actor($perso)
  156.           $perso = nil
  157.           dispose_window_dif
  158.           @choix_dif.dispose
  159.           $scene = Scene_Map.new
  160.         end
  161.          
  162.           def create_window_perso
  163.             @win_perso = Array.new
  164.             @x = @choix_perso.x + 5
  165.             @y = @choix_perso.y + 5      
  166.             for i in 1..@commands_perso.size
  167.               @win_perso.push(Window_Base.new(@x - 2.5, @y, 110+5, WLH_2+20))
  168.               @win_perso[i.to_i-1].opacity = 100
  169.               @x += 110
  170.               @win_perso[i.to_i-1].draw_face($data_actors[PERSO[i - 1].to_i].face_name, $data_actors[PERSO[i - 1].to_i].face_index, -5, 10)
  171.               @win_perso[i.to_i-1].draw_actor_graphic($data_actors[PERSO[i.to_i-1]], 25, 100)
  172.               end
  173.             @win_info_perso = Window_Base.new(@choix_perso.x, @choix_perso.y - 50, 445, 50)
  174.             @win_info_perso.contents.draw_text(0, -200, 544, 416, TEXT_INFO, 0)
  175.             end
  176.            
  177.             def dispose_window_perso
  178.               @win_perso.each { |i| i.dispose }
  179.               @win_info_perso.dispose
  180.             end
  181.  
  182.             def create_window_dif
  183.               height = @commands_dif.size * 32 + 5
  184.               @win_dif = Window_Base.new(@choix_dif.x , @choix_dif.y + 5, 445, height)
  185.               @win_dif.z = 0
  186.               @win_info_dif = Window_Base.new(@win_dif.x, @win_dif.y - 50, 445, 50)
  187.               @win_info_dif.contents.draw_text(0, -200, 544, 416, TEXT_INFO_2, 0)
  188.             end
  189.            
  190.             def dispose_window_dif
  191.               @win_dif.dispose
  192.               @win_info_dif.dispose
  193.             end
  194.         end
  195.        
  196.  
  197.        
  198.     #==============================================================================
  199.     # ** Window_Selectable_Perso_And_Dif
  200.     #==============================================================================
  201.  
  202.     class Window_Selectable_PAD < Window_Base
  203.       #--------------------------------------------------------------------------
  204.       # * Public Instance Variables
  205.       #--------------------------------------------------------------------------
  206.       attr_reader   :item_max                 # item count
  207.       attr_reader   :column_max               # digit count
  208.       attr_reader   :index                    # cursor position
  209.       attr_reader   :help_window              # help window
  210.       #--------------------------------------------------------------------------
  211.       # * Object Initialization
  212.       #     x       : window X coordinate
  213.       #     y       : window Y coordinate
  214.       #     width   : window width
  215.       #     height  : window height
  216.       #     spacing : width of empty space when items are arranged horizontally
  217.       #--------------------------------------------------------------------------
  218.       def initialize(x, y, width, height, spacing = 32)
  219.         @item_max = 1
  220.         @column_max = 1
  221.         @index = -1
  222.         @spacing = spacing
  223.         super(x, y, width, height)
  224.       end
  225.       #--------------------------------------------------------------------------
  226.       # * Create Window Contents
  227.       #--------------------------------------------------------------------------
  228.       def create_contents
  229.         self.contents.dispose
  230.         self.contents = Bitmap.new(width - 32, [height - 32, row_max * WLH_2].max)
  231.       end
  232.       #--------------------------------------------------------------------------
  233.       # * Set Cursor Position
  234.       #     index : new cursor position
  235.       #--------------------------------------------------------------------------
  236.       def index=(index)
  237.         @index = index
  238.         update_cursor
  239.         call_update_help
  240.       end
  241.       #--------------------------------------------------------------------------
  242.       # * Get Row Count
  243.       #--------------------------------------------------------------------------
  244.       def row_max
  245.         return (@item_max + @column_max - 1) / @column_max
  246.       end
  247.       #--------------------------------------------------------------------------
  248.       # * Get Top Row
  249.       #--------------------------------------------------------------------------
  250.       def top_row
  251.         return self.oy / WLH_2
  252.       end
  253.       #--------------------------------------------------------------------------
  254.       # * Set Top Row
  255.       #     row : row shown on top
  256.       #--------------------------------------------------------------------------
  257.       def top_row=(row)
  258.         row = 0 if row < 0
  259.         row = row_max - 1 if row > row_max - 1
  260.         self.oy = row * WLH_2
  261.       end
  262.       #--------------------------------------------------------------------------
  263.       # * Get Number of Rows Displayable on 1 Page
  264.       #--------------------------------------------------------------------------
  265.       def page_row_max
  266.         return (self.height - 32) / WLH_2
  267.       end
  268.       #--------------------------------------------------------------------------
  269.       # * Get Number of Items Displayable on 1 Page
  270.       #--------------------------------------------------------------------------
  271.       def page_item_max
  272.         return page_row_max * @column_max
  273.       end
  274.       #--------------------------------------------------------------------------
  275.       # * Get bottom row
  276.       #--------------------------------------------------------------------------
  277.       def bottom_row
  278.         return top_row + page_row_max - 1
  279.       end
  280.       #--------------------------------------------------------------------------
  281.       # * Set bottom row
  282.       #     row : Row displayed at the bottom
  283.       #--------------------------------------------------------------------------
  284.       def bottom_row=(row)
  285.         self.top_row = row - (page_row_max - 1)
  286.       end
  287.       #--------------------------------------------------------------------------
  288.       # * Get rectangle for displaying items
  289.       #     index : item number
  290.       #--------------------------------------------------------------------------
  291.       def item_rect(index)
  292.         rect = Rect.new(0, 0, 0, 0)
  293.         rect.width = (contents.width + @spacing) / @column_max - @spacing
  294.         rect.height = WLH_2
  295.         rect.x = index % @column_max * (rect.width + @spacing)
  296.         rect.y = index / @column_max * WLH_2
  297.         return rect
  298.       end
  299.       #--------------------------------------------------------------------------
  300.       # * Set Help Window
  301.       #     help_window : new help window
  302.       #--------------------------------------------------------------------------
  303.       def help_window=(help_window)
  304.         @help_window = help_window
  305.         call_update_help
  306.       end
  307.       #--------------------------------------------------------------------------
  308.       # * Determine if cursor is moveable
  309.       #--------------------------------------------------------------------------
  310.       def cursor_movable?
  311.         return false if (not visible or not active)
  312.         return false if (index < 0 or index > @item_max or @item_max == 0)
  313.         return false if (@opening or @closing)
  314.         return true
  315.       end
  316.       #--------------------------------------------------------------------------
  317.       # * Move cursor down
  318.       #     wrap : Wraparound allowed
  319.       #--------------------------------------------------------------------------
  320.       def cursor_down(wrap = false)
  321.         if (@index < @item_max - @column_max) or (wrap and @column_max == 1)
  322.           @index = (@index + @column_max) % @item_max
  323.         end
  324.       end
  325.       #--------------------------------------------------------------------------
  326.       # * Move cursor up
  327.       #     wrap : Wraparound allowed
  328.       #--------------------------------------------------------------------------
  329.       def cursor_up(wrap = false)
  330.         if (@index >= @column_max) or (wrap and @column_max == 1)
  331.           @index = (@index - @column_max + @item_max) % @item_max
  332.         end
  333.       end
  334.       #--------------------------------------------------------------------------
  335.       # * Move cursor right
  336.       #     wrap : Wraparound allowed
  337.       #--------------------------------------------------------------------------
  338.       def cursor_right(wrap = false)
  339.         if (@column_max >= 2) and
  340.            (@index < @item_max - 1 or (wrap and page_row_max == 1))
  341.           @index = (@index + 1) % @item_max
  342.         end
  343.       end
  344.       #--------------------------------------------------------------------------
  345.       # * Move cursor left
  346.       #     wrap : Wraparound allowed
  347.       #--------------------------------------------------------------------------
  348.       def cursor_left(wrap = false)
  349.         if (@column_max >= 2) and
  350.            (@index > 0 or (wrap and page_row_max == 1))
  351.           @index = (@index - 1 + @item_max) % @item_max
  352.         end
  353.       end
  354.       #--------------------------------------------------------------------------
  355.       # * Move cursor one page down
  356.       #--------------------------------------------------------------------------
  357.       def cursor_pagedown
  358.         if top_row + page_row_max < row_max
  359.           @index = [@index + page_item_max, @item_max - 1].min
  360.           self.top_row += page_row_max
  361.         end
  362.       end
  363.       #--------------------------------------------------------------------------
  364.       # * Move cursor one page up
  365.       #--------------------------------------------------------------------------
  366.       def cursor_pageup
  367.         if top_row > 0
  368.           @index = [@index - page_item_max, 0].max
  369.           self.top_row -= page_row_max
  370.         end
  371.       end
  372.       #--------------------------------------------------------------------------
  373.       # * Frame Update
  374.       #--------------------------------------------------------------------------
  375.       def update
  376.         super
  377.         if cursor_movable?
  378.           last_index = @index
  379.           if Input.repeat?(Input::DOWN)
  380.             cursor_down(Input.trigger?(Input::DOWN))
  381.           end
  382.           if Input.repeat?(Input::UP)
  383.             cursor_up(Input.trigger?(Input::UP))
  384.           end
  385.           if Input.repeat?(Input::RIGHT)
  386.             cursor_right(Input.trigger?(Input::RIGHT))
  387.           end
  388.           if Input.repeat?(Input::LEFT)
  389.             cursor_left(Input.trigger?(Input::LEFT))
  390.           end
  391.           if Input.repeat?(Input::R)
  392.             cursor_pagedown
  393.           end
  394.           if Input.repeat?(Input::L)
  395.             cursor_pageup
  396.           end
  397.           if @index != last_index
  398.             Sound.play_cursor
  399.           end
  400.         end
  401.         update_cursor
  402.         call_update_help
  403.       end
  404.       #--------------------------------------------------------------------------
  405.       # * Update cursor
  406.       #--------------------------------------------------------------------------
  407.       def update_cursor
  408.         if @index < 0                   # If the cursor position is less than 0
  409.           self.cursor_rect.empty        # Empty cursor
  410.         else                            # If the cursor position is 0 or more
  411.           row = @index / @column_max    # Get current row
  412.           if row < top_row              # If before the currently displayed
  413.             self.top_row = row          # Scroll up
  414.           end
  415.           if row > bottom_row           # If after the currently displayed
  416.             self.bottom_row = row       # Scroll down
  417.           end
  418.           rect = item_rect(@index)      # Get rectangle of selected item
  419.           rect.y -= self.oy             # Match rectangle to scroll position
  420.           self.cursor_rect = rect       # Refresh cursor rectangle
  421.         end
  422.       end
  423.       #--------------------------------------------------------------------------
  424.       # * Call help window update method
  425.       #--------------------------------------------------------------------------
  426.       def call_update_help
  427.         if self.active && @help_window
  428.            update_help
  429.         end
  430.       end
  431.       #--------------------------------------------------------------------------
  432.       # * Update help window (contents are defined by the subclasses)
  433.       #--------------------------------------------------------------------------
  434.       def update_help
  435.       end
  436.     end
  437.  
  438.  
  439.     #==============================================================================
  440.     # ** Window_Command_Perso_And_Dif
  441.     #==============================================================================
  442.  
  443.     class Window_Command_PAD < Window_Selectable_PAD
  444.  
  445.       attr_reader   :commands                 # command
  446.  
  447.       def initialize(width, commands, column_max = 1, row_max = 1, spacing = 32)
  448.         super(0, 0, width, row_max * WLH_2 + 32, spacing)
  449.         @commands = commands
  450.         @item_max = commands.size
  451.         @column_max = column_max
  452.         refresh
  453.         self.index = 0
  454.       end
  455.       #--------------------------------------------------------------------------
  456.       # * Refresh
  457.       #--------------------------------------------------------------------------
  458.       def refresh
  459.         self.contents.clear
  460.         create_contents
  461.         @item_max.times { |i| draw_item(i) }
  462.       end
  463.       #--------------------------------------------------------------------------
  464.       # * Draw Item
  465.       #--------------------------------------------------------------------------
  466.       def draw_item(index, enabled = true)
  467.         rect = item_rect(index)
  468.         rect.x += 4
  469.         rect.width -= 8
  470.         self.contents.clear_rect(rect)
  471.         self.contents.font.color = normal_color
  472.         self.contents.font.color.alpha = enabled ? 255 : 128
  473.         self.contents.draw_text(rect, @commands[index])
  474.       end
  475.     end