Advertisement
diamondandplatinum3

Character's Name Window ~ RGSS3

Jan 18th, 2013
2,890
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 11.17 KB | None | 0 0
  1. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  2. #             Character's Name Window
  3. #             Version: 1.0
  4. #             Authors: DiamondandPlatinum3
  5. #             Date: January 19, 2013
  6. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. #  Description:
  8. #
  9. #    This script creates a character name window for when someone is talking.
  10. #    Using a script call or an Escape Character is your ticket to changing
  11. #    the displayed name.
  12. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  13. #------------------------------------------------------------------------------
  14. #  Instructions:
  15. #  
  16. #     Edit the two options in the editable region below. Once done, to display a
  17. #     name in your game you simply either have to use the following script call:
  18. #         change_charactername( name )
  19. #     Replacing 'name' with the "Name' you wish to be displayed.
  20. #
  21. #     The other way is to use an escape character when you show a message box
  22. #         \n{NAME}
  23. #
  24. #
  25. #     Screenshot Example can be found here: http://goo.gl/PRpo5
  26. #
  27. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  28. module DiamondandPlatinum3
  29.   module CharacterNamesForWindows
  30.     #=======================================
  31.     #     Editable Region
  32.     #=======================================
  33.    
  34.     # Turning on this event switch turns off the name window
  35.     EventSwitchID = 10
  36.    
  37.     # RGB Values for the colour of the text in the window.
  38.     Colour = [ 255, 214, 104 ]
  39.    
  40.     #=======================================
  41.     #   End Editable Region
  42.     #=======================================
  43.    
  44.    
  45.    
  46.    
  47.    
  48.    
  49.    
  50.    
  51.    
  52.    
  53.    
  54.     CharacterName = "???"
  55.     ShowWindow    = true    
  56.     def self.change_character_name( name )
  57.       self.const_set(:CharacterName, name) if name.is_a?(String)
  58.     end
  59.     def self.change_show_window( bool )
  60.       self.const_set(:ShowWindow, bool)
  61.     end
  62.   end
  63. end
  64.  
  65.  
  66.  
  67.  
  68.  
  69. #==============================================================================
  70. # ** Window_Message
  71. #------------------------------------------------------------------------------
  72. #  This message window is used to display text.
  73. #==============================================================================
  74.  
  75. class Window_Message < Window_Base
  76.   #--------------------------------------------------------------------------
  77.   # * Alias Listings
  78.   #--------------------------------------------------------------------------
  79.   alias dp3_characternames_windowmessage_fibermain_02isk0u                   fiber_main
  80.   alias dp3_characternames_windowmessage_convertescapecharacter_02isk0u      convert_escape_characters
  81.   #--------------------------------------------------------------------------
  82.   # * Main Processing of Fiber
  83.   #--------------------------------------------------------------------------
  84.   def fiber_main
  85.     dp3_characternames_windowmessage_fibermain_02isk0u() # Call Original Method
  86.     @dp3_charaname_window.dispose() if @dp3_charaname_window && !@dp3_charaname_window.disposed?
  87.   end
  88.   #--------------------------------------------------------------------------
  89.   # * Preconvert Control Characters
  90.   #--------------------------------------------------------------------------
  91.   def convert_escape_characters( *args )
  92.     result = dp3_characternames_windowmessage_convertescapecharacter_02isk0u( *args )
  93.     result.gsub!(/\eN{(.+)}/i, "")
  94.    
  95.     DiamondandPlatinum3::CharacterNamesForWindows::change_character_name( $1 ) if $1 && $1 != ""
  96.     @dp3_charaname_window.dispose() if @dp3_charaname_window && !@dp3_charaname_window.disposed?
  97.     @dp3_charaname_window = Window_DP3_CharacterNames.new( self.x, self.y, self.height, @position )
  98.    
  99.     return result
  100.   end
  101. end
  102.  
  103.  
  104.  
  105.  
  106. #==============================================================================
  107. # ** Window_DP3_CharacterNames
  108. #------------------------------------------------------------------------------
  109. #  This Window is used to display character names where they are to be located
  110. #==============================================================================
  111.  
  112. class Window_DP3_CharacterNames < Window_Base
  113.   include DiamondandPlatinum3::CharacterNamesForWindows
  114.   #--------------------------------------------------------------------------
  115.   # * Initialize
  116.   #--------------------------------------------------------------------------
  117.   def initialize( x, y, h, position )
  118.     appropriate_scene = SceneManager.scene_is?(Scene_Map) || SceneManager.scene_is?(Scene_Battle)
  119.     if $game_switches[EventSwitchID] || !ShowWindow || !appropriate_scene
  120.       self.dispose()
  121.       return
  122.     end
  123.     @text = " " + CharacterName
  124.     self_width  = (@text.length * 11) + 32
  125.     self_height = 45
  126.     if position == 0
  127.       super(x, h, self_width, self_height)
  128.     else
  129.       super(x, y - self_height, self_width, self_height)
  130.     end
  131.     self.z = 201
  132.     self.opacity = $game_message.background == 0 ? 255 : 0
  133.     create_back_sprite()
  134.     self.refresh
  135.   end
  136.   #--------------------------------------------------------------------------
  137.   # * Dispose
  138.   #--------------------------------------------------------------------------
  139.   def dispose()
  140.     if @back_sprite
  141.       @back_sprite.bitmap.dispose
  142.       @back_sprite.dispose
  143.     end
  144.     super()
  145.   end
  146.   #--------------------------------------------------------------------------
  147.   # * Refresh
  148.   #--------------------------------------------------------------------------
  149.   def refresh()
  150.     self.contents.clear
  151.     self.change_color(Color.new(*Colour))
  152.     self.draw_text(0, 0, self.width - 32, line_height, @text)
  153.   end
  154.   #--------------------------------------------------------------------------
  155.   # * Create Background Sprite
  156.   #--------------------------------------------------------------------------
  157.   def create_back_sprite()
  158.     if $game_message.background == 1
  159.      
  160.       back_bitmap = Bitmap.new(width, height)
  161.       rect1 = Rect.new(0, 0, width, 12)
  162.       rect2 = Rect.new(0, 12, width, height - 24)
  163.       rect3 = Rect.new(0, height - 12, width, 12)
  164.       back_bitmap.gradient_fill_rect(rect1, back_color2, back_color1, true)
  165.       back_bitmap.fill_rect(rect2, back_color1)
  166.       back_bitmap.gradient_fill_rect(rect3, back_color1, back_color2, true)
  167.      
  168.       @back_sprite          = Sprite.new
  169.       @back_sprite.bitmap   = back_bitmap
  170.       @back_sprite.visible  = true
  171.       @back_sprite.y        = y
  172.       @back_sprite.z        = z - 1
  173.       @back_sprite.opacity  = openness
  174.     end
  175.   end
  176.   #--------------------------------------------------------------------------
  177.   # * Get Background Colours
  178.   #--------------------------------------------------------------------------
  179.   def back_color1();  Color.new(0, 0, 0, 160);  end
  180.   def back_color2();  Color.new(0, 0, 0, 0);    end
  181. end
  182.  
  183.  
  184.  
  185.  
  186.  
  187. #==============================================================================
  188. # ** Scene_Battle
  189. #------------------------------------------------------------------------------
  190. #  This class performs battle screen processing.
  191. #==============================================================================
  192.  
  193. class Scene_Battle < Scene_Base
  194.   #--------------------------------------------------------------------------
  195.   # * Alias Listings
  196.   #--------------------------------------------------------------------------
  197.   alias dp3_characternames_scenebattle_start_02isk0u                start
  198.   alias dp3_characternames_scenebattle_terminate_02isk0u            terminate
  199.   #--------------------------------------------------------------------------
  200.   # * Start Processing
  201.   #--------------------------------------------------------------------------
  202.   def start
  203.     DiamondandPlatinum3::CharacterNamesForWindows::change_show_window(false)
  204.     dp3_characternames_scenebattle_start_02isk0u() # Call Original Method
  205.   end
  206.   #--------------------------------------------------------------------------
  207.   # * Termination Processing
  208.   #--------------------------------------------------------------------------
  209.   def terminate
  210.     DiamondandPlatinum3::CharacterNamesForWindows::change_show_window(true)
  211.     dp3_characternames_scenebattle_terminate_02isk0u() # Call Original Method
  212.   end
  213. end
  214.  
  215.  
  216.  
  217.  
  218.  
  219. #==============================================================================
  220. # ** Scene_Title
  221. #------------------------------------------------------------------------------
  222. #  This class performs the title screen processing.
  223. #==============================================================================
  224.  
  225. class Scene_Title < Scene_Base
  226.   #--------------------------------------------------------------------------
  227.   # * Alias Listings
  228.   #--------------------------------------------------------------------------
  229.   alias dp3_characternames_scenetitle_cmdnewgame_02isk0u     command_new_game
  230.   alias dp3_characternames_scenetitle_cmdcontinue_02isk0u    command_continue
  231.   #--------------------------------------------------------------------------
  232.   # * [New Game] Command
  233.   #--------------------------------------------------------------------------
  234.   def command_new_game
  235.     DiamondandPlatinum3::CharacterNamesForWindows::change_character_name( "???" )
  236.     DiamondandPlatinum3::CharacterNamesForWindows::change_show_window( true )
  237.     dp3_characternames_scenetitle_cmdnewgame_02isk0u() # Call Original Method
  238.   end
  239.   #--------------------------------------------------------------------------
  240.   # * [Continue] Command
  241.   #--------------------------------------------------------------------------
  242.   def command_continue
  243.     DiamondandPlatinum3::CharacterNamesForWindows::change_character_name( "???" )
  244.     DiamondandPlatinum3::CharacterNamesForWindows::change_show_window( true )
  245.     dp3_characternames_scenetitle_cmdcontinue_02isk0u() # Call Original Method
  246.   end
  247. end
  248.  
  249.  
  250.  
  251.  
  252.  
  253. #==============================================================================
  254. # ** Game_Interpreter
  255. #------------------------------------------------------------------------------
  256. #  An interpreter for executing event commands. This class is used within the
  257. # Game_Map, Game_Troop, and Game_Event classes.
  258. #==============================================================================
  259.  
  260. class Game_Interpreter
  261.   #--------------------------------------------------------------------------
  262.   # * Aliased Method: Show Text
  263.   #--------------------------------------------------------------------------
  264.   alias dp3_characternames_gameinterpreter_command101_02isk0u     command_101
  265.   def command_101()
  266.     DiamondandPlatinum3::CharacterNamesForWindows::change_show_window(true) if SceneManager.scene_is?(Scene_Battle)
  267.     dp3_characternames_gameinterpreter_command101_02isk0u() # Call Original Method
  268.     DiamondandPlatinum3::CharacterNamesForWindows::change_show_window(false) if SceneManager.scene_is?(Scene_Battle)
  269.   end
  270.   #--------------------------------------------------------------------------
  271.   # * New Method: Change Character Name
  272.   #--------------------------------------------------------------------------
  273.   def change_charactername( text )
  274.     DiamondandPlatinum3::CharacterNamesForWindows::change_character_name( text )
  275.   end
  276. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement