Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==========================================================================
- #==========================================================================
- #============= DO NOT EDIT THE CONTENTS OF THIS SCRIPT ===============
- #==========================================================================
- #==========================================================================
- # Logan Forrests' Random Name Generator Name Input Processing Add-On
- #
- # Date Created : 29 January 2012
- # Date Finished : 29 January 2012
- # Last Updated : 29 January 2012
- # Latest Version : 1.0
- #
- #--------------------------------------------------------------------------
- # Version History
- #--------------------------------------------------------------------------
- #
- # v1.0 - 01.29.2012
- # Original release of the script
- #
- #--------------------------------------------------------------------------
- # Description
- #--------------------------------------------------------------------------
- # Generates random names for actors (through the Name Input Processing scene)
- # using an algorithm which interprets a data set of given names in a particular
- # language to provide fairly good accuracy in actual names used.
- #
- #--------------------------------------------------------------------------
- # Directions On How To Implement
- #--------------------------------------------------------------------------
- # You need 3 three things:
- #
- # This script
- # The Random Name Generator VX script
- # At least 1 data set for reference
- #
- #
- # The Random Name Generator VX script can be found here:
- # http://rmrk.net/index.php/topic,44971.0.html
- #
- # Data Sets can be found here:
- # http://www.ruf.rice.edu/~pound/
- #
- # Data Sets should go into the designated game folder (Data by default).
- # This can be set in the Random Name Generator VX script.
- #--------------------------------------------------------------------------
- # Script Installation
- #--------------------------------------------------------------------------
- #
- # Simply place the script in the Materials section of the Script Editor,
- # somewhere above Main directly below the Random Name Generator VX Script.
- #
- #--------------------------------------------------------------------------
- # Support
- #--------------------------------------------------------------------------
- # The script has been written and tested with no other scripts in place. As
- # such, if you encounted any issues with regards to other scripts,
- # first try to resolve the problem by moving this script around. If you are
- # still unable to resolve the problem, feel free to contact me on rmrk.net
- # under the name LoganForrests (no spaces involved) with the name of the
- # script(s) you find no longer work when this script is included and the
- # nature of the problem(s) so that I can begin to work on the problem(s)
- # being caused.
- #==========================================================================
- #==========================================================================
- #==========================================================================
- #============= DO NOT EDIT THE CONTENTS OF THIS SCRIPT ===============
- #==========================================================================
- #==========================================================================
- class Scene_Name < Scene_Base
- alias :lf_rngadd_start_sn_fu47_vx :start
- def start(*args, &block)
- #run original method
- lf_rngadd_start_sn_fu47_vx(*args, &block)
- #make additional window
- commands = ["Mode", "Random", "Delete", "Confirm", "Default"]
- @name_command = Window_NameCommand.new(commands,
- Window_NameInput::TABLE.size > 1)
- #make Random Name Generator objects
- @argument_parser = ArgumentParser.new
- @data_handler = DataHandler.new
- @name_generator = NameGenerator.new(@data_handler.follower_letters)
- #set values
- @name_generator.max_length = $game_temp.name_max_char
- @name_generator.min_length = 1
- #call parser to parse arguments
- @argument_parser.parse_arguments
- #read data file
- @data_handler.read_data_file(@argument_parser.data_file)
- end
- def get_random_name
- @names = @name_generator.generate_names(@data_handler.start_pairs,
- @argument_parser.words_to_generate)
- #remove spaces from end of generate name
- to_remove = Array.new
- @names.each { |name|
- if name == ""
- to_remove.push(name)
- else
- name.gsub!(/\s+/) { "" }
- end
- }
- @names -= to_remove
- get_random_name if @names.empty? #redo if empty array
- return @names[rand(@names.length)]
- end
- def update
- super
- update_menu_background
- @edit_window.update
- if @name_command.active
- @name_command.update
- update_command_selection
- elsif @input_window.active
- @input_window.update
- update_input_selection
- end
- end
- def update_input_selection
- if Input.repeat?(Input::B)
- if @edit_window.index > 0 # Not at the left edge
- Sound.play_cancel
- @edit_window.back
- end
- elsif Input.repeat?(Input::LEFT)
- if @input_window.index % 10 == 0 # If input at left edge
- @input_window.active = false
- @name_command.active = true
- end
- elsif Input.trigger?(Input::C)
- if @input_window.is_decision # If cursor is positioned on [OK]
- @name_commands.index = 3
- @input_window.active = false
- @name_command.active = true
- elsif @input_window.character != "" # If text characters are not empty
- if @edit_window.index == @edit_window.max_char # at the right edge
- Sound.play_buzzer
- else
- Sound.play_decision
- @edit_window.add(@input_window.character) # Add text character
- end
- end
- end
- end
- def update_command_selection
- if Input.trigger?(Input::B)
- Sound.play_cancel
- @name_command.index = 3
- elsif Input.trigger?(Input::RIGHT)
- @input_window.active = true
- @name_command.active = false
- elsif Input.trigger?(Input::C)
- case @name_command.index
- when 0 #Mode
- if @enabled_mode_command
- Sound.play_decision
- @input_window.cursor_pagedown
- else
- Sound.play_buzzer
- end
- when 1 #Random
- @edit_window.clear_name
- random_name = get_random_name
- random_name.scan(/./) { |char| @edit_window.add(char) }
- when 2 #Delete
- @edit_window.clear_name
- when 3 #Confirm
- if @edit_window.name == "" # If name is empty
- @edit_window.restore_default # Return to default name
- if @edit_window.name == ""
- Sound.play_buzzer
- else
- Sound.play_decision
- end
- else
- Sound.play_decision
- @actor.name = @edit_window.name # Change actor name
- return_scene
- end
- when 4 #Default
- Sound.play_decision
- @edit_window.restore_default
- end
- end
- end
- end
- class Window_NameInput < Window_Base
- attr_reader :index #allow access to index
- def initialize(mode = 0)
- super(150, 148, 364, 248)
- @mode = mode
- @index = 0
- refresh
- update_cursor
- end
- #--------------------------------------------------------------------------
- # * Move cursor right
- # unused_arg : not used, but retained for compatibility
- #--------------------------------------------------------------------------
- def cursor_right(unused_arg)
- if @index % 10 < 9
- @index += 1
- end
- end
- #--------------------------------------------------------------------------
- # * Move cursor left
- # unused_arg : not used, but retained for compatibility
- #--------------------------------------------------------------------------
- def cursor_left(unused_arg)
- if @index % 10 > 0
- @index -= 1
- end
- end
- end
- class Window_NameEdit < Window_Base
- def initialize(actor, max_char)
- super(30, 20, 484, 128)
- @actor = actor
- @name = actor.name
- @max_char = max_char
- name_array = @name.split(//)[0...@max_char] # Fit within max length
- @name = ""
- for i in 0...name_array.size
- @name += name_array[i]
- end
- @default_name = @name
- @index = name_array.size
- self.active = false
- refresh
- update_cursor
- end
- #--------------------------------------------------------------------------
- # * Get rectangle for displaying items
- # index : item number
- #--------------------------------------------------------------------------
- def item_rect(index)
- rect = Rect.new(0, 0, 0, 0)
- start_x = @max_char < 14 ? 85 : 50
- rect.x = start_x + (@max_char + 1) + index * 24
- rect.y = 36
- rect.width = 24
- rect.height = WLH
- return rect
- end
- def clear_name(restore=false)
- @name.length.times { back }
- restore_default if restore
- end
- end
- class Window_NameCommand < Window_Command
- def initialize(commands, enable_mode_command=false)
- super(120, commands)
- @enable_mode_command = enable_mode_command
- @index = @enabled_mode_command ? 0 : 1
- self.x = 30
- self.y = 148
- self.active = false
- update_cursor
- end
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh
- self.contents.clear
- for i in 0...@item_max
- if i == 0 #Mode
- draw_item(i, @enable_mode_command)
- else
- draw_item(i)
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement