Advertisement
Guest User

Name Input Processing Add On v1.0

a guest
Jan 29th, 2012
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.80 KB | None | 0 0
  1. #==========================================================================    
  2. #==========================================================================    
  3. #=============    DO NOT EDIT THE CONTENTS OF THIS SCRIPT   ===============    
  4. #==========================================================================
  5. #==========================================================================
  6. # Logan Forrests' Random Name Generator Name Input Processing Add-On
  7. #
  8. #   Date Created   : 29 January 2012
  9. #   Date Finished  : 29 January 2012
  10. #   Last Updated   : 29 January 2012
  11. #   Latest Version : 1.0
  12. #
  13. #--------------------------------------------------------------------------
  14. # Version History
  15. #--------------------------------------------------------------------------
  16. #
  17. #   v1.0 - 01.29.2012
  18. #       Original release of the script
  19. #
  20. #--------------------------------------------------------------------------
  21. # Description
  22. #--------------------------------------------------------------------------
  23. # Generates random names for actors (through the Name Input Processing scene)
  24. # using an algorithm which interprets a data set of given names in a particular
  25. # language to provide fairly good accuracy in actual names used.
  26. #
  27. #--------------------------------------------------------------------------
  28. # Directions On How To Implement
  29. #--------------------------------------------------------------------------
  30. # You need 3 three things:
  31. #
  32. #       This script
  33. #       The Random Name Generator VX script
  34. #       At least 1 data set for reference
  35. #
  36. #
  37. #  The Random Name Generator VX script can be found here:
  38. #       http://rmrk.net/index.php/topic,44971.0.html
  39. #  
  40. #  Data Sets can be found here:
  41. #     http://www.ruf.rice.edu/~pound/
  42. #
  43. #  Data Sets should go into the designated game folder (Data by default).
  44. #  This can be set in the Random Name Generator VX script.
  45. #--------------------------------------------------------------------------
  46. # Script Installation
  47. #--------------------------------------------------------------------------
  48. #
  49. # Simply place the script in the Materials section of the Script Editor,
  50. # somewhere above Main directly below the Random Name Generator VX Script.
  51. #
  52. #--------------------------------------------------------------------------
  53. # Support
  54. #--------------------------------------------------------------------------
  55. # The script has been written and tested with no other scripts in place. As
  56. # such, if you encounted any issues with regards to other scripts,
  57. # first try to resolve the problem by moving this script around. If you are
  58. # still unable to resolve the problem, feel free to contact me on rmrk.net
  59. # under the name LoganForrests (no spaces involved) with the name of the
  60. # script(s) you find no longer work when this script is included and the
  61. # nature of the problem(s) so that I can begin to work on the problem(s)
  62. # being caused.
  63. #==========================================================================
  64. #==========================================================================    
  65. #==========================================================================    
  66. #=============    DO NOT EDIT THE CONTENTS OF THIS SCRIPT   ===============    
  67. #==========================================================================
  68. #==========================================================================
  69.  
  70. class Scene_Name < Scene_Base
  71.  
  72.   alias :lf_rngadd_start_sn_fu47_vx :start
  73.   def start(*args, &block)
  74.     #run original method
  75.     lf_rngadd_start_sn_fu47_vx(*args, &block)
  76.     #make additional window
  77.     commands = ["Mode", "Random", "Delete", "Confirm", "Default"]
  78.     @name_command = Window_NameCommand.new(commands,
  79.                                               Window_NameInput::TABLE.size > 1)
  80.    
  81.     #make Random Name Generator objects
  82.     @argument_parser = ArgumentParser.new
  83.     @data_handler = DataHandler.new
  84.     @name_generator = NameGenerator.new(@data_handler.follower_letters)
  85.    
  86.     #set values
  87.     @name_generator.max_length = $game_temp.name_max_char
  88.     @name_generator.min_length = 1
  89.    
  90.     #call parser to parse arguments
  91.     @argument_parser.parse_arguments
  92.    
  93.     #read data file
  94.     @data_handler.read_data_file(@argument_parser.data_file)
  95.   end
  96.  
  97.   def get_random_name
  98.     @names = @name_generator.generate_names(@data_handler.start_pairs,
  99.                                             @argument_parser.words_to_generate)
  100.     #remove spaces from end of generate name
  101.     to_remove = Array.new
  102.     @names.each { |name|
  103.       if name == ""
  104.         to_remove.push(name)
  105.       else
  106.         name.gsub!(/\s+/) { "" }
  107.       end
  108.     }
  109.     @names -= to_remove
  110.     get_random_name if @names.empty? #redo if empty array
  111.     return @names[rand(@names.length)]
  112.   end
  113.  
  114.   def update
  115.     super
  116.     update_menu_background
  117.     @edit_window.update
  118.     if @name_command.active
  119.       @name_command.update
  120.       update_command_selection
  121.     elsif @input_window.active
  122.       @input_window.update
  123.       update_input_selection
  124.     end
  125.   end
  126.  
  127.   def update_input_selection
  128.     if Input.repeat?(Input::B)
  129.       if @edit_window.index > 0             # Not at the left edge
  130.         Sound.play_cancel
  131.         @edit_window.back
  132.       end
  133.     elsif Input.repeat?(Input::LEFT)
  134.       if @input_window.index % 10 == 0           # If input at left edge
  135.         @input_window.active = false
  136.         @name_command.active = true
  137.       end
  138.     elsif Input.trigger?(Input::C)
  139.       if @input_window.is_decision          # If cursor is positioned on [OK]
  140.         @name_commands.index = 3
  141.         @input_window.active = false
  142.         @name_command.active = true
  143.       elsif @input_window.character != ""   # If text characters are not empty
  144.         if @edit_window.index == @edit_window.max_char    # at the right edge
  145.           Sound.play_buzzer
  146.         else
  147.           Sound.play_decision
  148.           @edit_window.add(@input_window.character)       # Add text character
  149.         end
  150.       end
  151.     end
  152.   end
  153.  
  154.   def update_command_selection
  155.     if Input.trigger?(Input::B)
  156.       Sound.play_cancel
  157.       @name_command.index = 3
  158.     elsif Input.trigger?(Input::RIGHT)
  159.       @input_window.active = true
  160.       @name_command.active = false
  161.     elsif Input.trigger?(Input::C)
  162.       case @name_command.index
  163.       when 0 #Mode
  164.         if @enabled_mode_command
  165.           Sound.play_decision
  166.           @input_window.cursor_pagedown
  167.         else
  168.           Sound.play_buzzer
  169.         end
  170.       when 1 #Random
  171.         @edit_window.clear_name
  172.         random_name = get_random_name
  173.         random_name.scan(/./) { |char| @edit_window.add(char) }
  174.       when 2 #Delete
  175.         @edit_window.clear_name
  176.       when 3 #Confirm
  177.         if @edit_window.name == ""          # If name is empty
  178.           @edit_window.restore_default      # Return to default name
  179.           if @edit_window.name == ""
  180.             Sound.play_buzzer
  181.           else
  182.             Sound.play_decision
  183.           end
  184.         else
  185.           Sound.play_decision
  186.           @actor.name = @edit_window.name   # Change actor name
  187.           return_scene
  188.         end
  189.       when 4 #Default
  190.         Sound.play_decision
  191.         @edit_window.restore_default
  192.       end
  193.     end
  194.   end
  195.  
  196. end
  197.  
  198.  
  199. class Window_NameInput < Window_Base
  200.  
  201.   attr_reader :index   #allow access to index
  202.  
  203.   def initialize(mode = 0)
  204.     super(150, 148, 364, 248)
  205.     @mode = mode
  206.     @index = 0
  207.     refresh
  208.     update_cursor
  209.   end
  210.  
  211.   #--------------------------------------------------------------------------
  212.   # * Move cursor right
  213.   #    unused_arg : not used, but retained for compatibility
  214.   #--------------------------------------------------------------------------
  215.   def cursor_right(unused_arg)
  216.     if @index % 10 < 9
  217.       @index += 1
  218.     end
  219.   end
  220.  
  221.   #--------------------------------------------------------------------------
  222.   # * Move cursor left
  223.   #    unused_arg : not used, but retained for compatibility
  224.   #--------------------------------------------------------------------------
  225.   def cursor_left(unused_arg)
  226.     if @index % 10 > 0
  227.       @index -= 1
  228.     end
  229.   end
  230.  
  231. end
  232.  
  233.  
  234. class Window_NameEdit < Window_Base
  235.  
  236.   def initialize(actor, max_char)
  237.     super(30, 20, 484, 128)
  238.     @actor = actor
  239.     @name = actor.name
  240.     @max_char = max_char
  241.     name_array = @name.split(//)[0...@max_char]   # Fit within max length
  242.     @name = ""
  243.     for i in 0...name_array.size
  244.       @name += name_array[i]
  245.     end
  246.     @default_name = @name
  247.     @index = name_array.size
  248.     self.active = false
  249.     refresh
  250.     update_cursor
  251.   end
  252.  
  253.   #--------------------------------------------------------------------------
  254.   # * Get rectangle for displaying items
  255.   #     index : item number
  256.   #--------------------------------------------------------------------------
  257.   def item_rect(index)
  258.     rect = Rect.new(0, 0, 0, 0)
  259.     start_x = @max_char < 14 ? 85 : 50
  260.     rect.x = start_x + (@max_char + 1) + index * 24
  261.     rect.y = 36
  262.     rect.width = 24
  263.     rect.height = WLH
  264.     return rect
  265.   end
  266.  
  267.   def clear_name(restore=false)
  268.     @name.length.times { back }
  269.     restore_default if restore
  270.   end
  271.  
  272. end
  273.  
  274.  
  275. class Window_NameCommand < Window_Command
  276.  
  277.   def initialize(commands, enable_mode_command=false)
  278.     super(120, commands)
  279.     @enable_mode_command = enable_mode_command
  280.     @index = @enabled_mode_command ? 0 : 1
  281.     self.x = 30
  282.     self.y = 148
  283.     self.active = false
  284.     update_cursor
  285.   end
  286.  
  287.   #--------------------------------------------------------------------------
  288.   # * Refresh
  289.   #--------------------------------------------------------------------------
  290.   def refresh
  291.     self.contents.clear
  292.     for i in 0...@item_max
  293.       if i == 0 #Mode
  294.         draw_item(i, @enable_mode_command)
  295.       else
  296.         draw_item(i)
  297.       end
  298.     end
  299.   end
  300.  
  301. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement