Advertisement
Zouzaka

Systeme de Note

Jul 1st, 2014
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.89 KB | None | 0 0
  1. =begin
  2. Auteur: Zouzaka
  3. Requiert ce script de "Keroro" :
  4. http://www.rpg2s.net/forum/index.php/topic/14903-keyboard-input-v-30-by-keroro/
  5. =end
  6. class Scene_Note < Scene_MenuBase
  7.   def start
  8.     super
  9.     @insert_title = false
  10.     @insert_text = false
  11.     creat_window
  12.   end
  13.   def update
  14.     super
  15.     insert_text_cmd
  16.     update_notes
  17.   end
  18.   def creat_window
  19.     @edition = Window_Editing.new(0,0)
  20.     @note_list = Window_NoteList.new(0,@edition.height)
  21.     @note_title = Window_NoteTitle.new(@note_list.width,@edition.height,Graphics.width-@note_list.width)
  22.     @note_text = Window_NoteText.new(@note_list.width,@edition.height+@note_title.height,Graphics.width-@note_list.width,Graphics.height-(@edition.height+@note_title.height))
  23.     @edition.set_handler(:add,      method(:cmd_add))
  24.     @edition.set_handler(:del,      method(:cmd_del))
  25.     @edition.set_handler(:exit,      method(:return_scene))
  26.   end
  27.   def cmd_add
  28.     @title = ""
  29.     @text = ""
  30.     @note_text.set_text("Appui sur Echap pour valider") if @text.empty?
  31.     @note_title.set_text("Inserez Titre") if @title.empty?
  32.     $game_note[:title] << "Inserez Titre"
  33.     $game_note[:text] << "Inserez Text"
  34.     @note_list.deactivate
  35.     @insert_title = true
  36.   end
  37.   def cmd_del
  38.     $game_note[:title].slice!(-1)
  39.     $game_note[:text].slice!(-1)
  40.     @edition.activate
  41.     @note_list.refresh
  42.     @note_list.height = @note_list.window_height unless @note_list.height >= (Graphics.height-@edition.height-25)
  43.   end
  44.   def update_notes
  45.     unless @insert_title == true || @insert_text == true
  46.       @note_title.set_text($game_note[:title][@note_list.index])
  47.       @note_text.set_text($game_note[:text][@note_list.index])
  48.     end
  49.   end
  50.   def insert_text_cmd
  51.     #------------------------------------------------------
  52.     #Title Zone
  53.     #------------------------------------------------------
  54.     if @insert_title == true
  55.       Input::LETTERS.each do |k|
  56.         if Input.trigger?(k)
  57.           @title += k.to_s[3].downcase
  58.         end
  59.       end
  60.       if Input.trigger?(:ESC)
  61.         @insert_title = false
  62.         $game_note[:title].slice!(-1)
  63.         $game_note[:title] << @title.capitalize
  64.         @insert_text = true
  65.         5.times{|i| update_basic}
  66.       end
  67.       if Input.trigger?(:BACK)
  68.         @title.slice!(-1)
  69.       end
  70.       if Input.trigger?(:SPACE)
  71.         @title += " "
  72.       end
  73.       @note_title.set_text(@title.capitalize)
  74.     end
  75.     #-------------------------------------------------------
  76.     #Text Zone
  77.     #-------------------------------------------------------
  78.     if @insert_text == true
  79.       Input::LETTERS.each do |k|
  80.         if Input.trigger?(k)
  81.           @text += k.to_s[3].downcase
  82.         end
  83.       end
  84.       if Input.trigger?(:ENTER)
  85.         @text += "
  86. "
  87.       end
  88.       if Input.trigger?(:BACK)
  89.         @text.slice!(-1)
  90.       end
  91.       if Input.trigger?(:SPACE)
  92.         @text += " "
  93.       end
  94.       if Input.trigger?(:ESC)
  95.         @insert_text = false
  96.         $game_note[:text].slice!(-1)
  97.         $game_note[:text] << @text.capitalize
  98.         @note_list.refresh
  99.         @note_list.height = @note_list.window_height unless @note_list.height >= (Graphics.height-@edition.height-25)
  100.         @edition.activate
  101.         @note_list.activate
  102.       end
  103.       @note_text.set_text(@text.capitalize)
  104.     end
  105.   end
  106. end
  107. #===============================================================================
  108. # Windows
  109. #===============================================================================
  110. class Window_NoteList < Window_Command
  111.   def make_command_list
  112.     $game_note[:title].each{|t| add_command(t, :title)}
  113.   end
  114. end
  115. class Window_Editing < Window_HorzCommand
  116.   def make_command_list
  117.     add_command("Nouveau", :add)
  118.     add_command("Supprimer", :del)
  119.     add_command("Quitter", :exit)
  120.   end
  121.   def window_width
  122.     return Graphics.width
  123.   end
  124.   def process_handling
  125.     return unless open? && active
  126.     return process_ok       if ok_enabled?        && Input.trigger?(:SPACE)
  127.     return process_cancel   if cancel_enabled?    && Input.trigger?(:B)
  128.     return process_pagedown if handle?(:pagedown) && Input.trigger?(:R)
  129.     return process_pageup   if handle?(:pageup)   && Input.trigger?(:L)
  130.   end
  131. end
  132. class Window_NoteTitle < Window_Base
  133.   def initialize(x, y, width)
  134.     super(x, y, width, fitting_height(1))
  135.     @text = ""
  136.   end
  137.   def update
  138.     super
  139.     contents.clear
  140.     @text_pos = (self.width-text_size(@text).width)/2
  141.     draw_text_ex(@text_pos, 0, @text)
  142.   end
  143.   def set_text(text)
  144.     @text = text
  145.   end
  146. end
  147. class Window_NoteText < Window_Base
  148.   def initialize(x, y, width, height)
  149.     super(x, y, width, height)
  150.     @text = ""
  151.   end
  152.   def update
  153.     super
  154.     contents.clear
  155.     draw_text_ex(0, 0, @text)
  156.   end
  157.   def set_text(text)
  158.     @text = text
  159.   end
  160. end
  161.  
  162. #===============================================================================
  163. #Modification des sauvgardes
  164. #===============================================================================
  165. module DataManager
  166.   #-------------------------------------------------------------------------
  167.   # * Aliased methods
  168.   #-------------------------------------------------------------------------
  169.   class << self
  170.     alias :make_note_save :make_save_contents
  171.     alias :extract_note_save :extract_save_contents
  172.     alias :creat_note_object :create_game_objects
  173.     def make_save_contents
  174.       make_note_save.merge({:note =>$game_note})
  175.     end
  176.     #--------------------------------------------------------------------------
  177.     # * Extract Save Contents
  178.     #--------------------------------------------------------------------------
  179.     def extract_save_contents(contents)
  180.       extract_note_save(contents)
  181.       $game_note        = contents[:note]
  182.     end
  183.     def create_game_objects
  184.       $game_note          = {:title => [],
  185.                              :text => [] }
  186.       creat_note_object
  187.     end
  188.   end
  189. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement