Advertisement
diamondandplatinum3

Synopsis Scene ~ Tutorial Version

Mar 3rd, 2014
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 13.94 KB | None | 0 0
  1. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  2. #                   Synopsis Scene
  3. #                   Version 1.0
  4. #                   Author: You
  5. #                   Date: 13th March, 2013
  6. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. # Description:
  8. #    
  9. #     This Script allows you to maintain a database signifying what your
  10. #     current objective is, as well as provided a brief summary of recent
  11. #     events.
  12. #
  13. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  14. #--------------------------------------------------------------------------
  15. # Instructions:
  16. #
  17. #   -  Head into the editable region and modify things as appropriate.
  18. #
  19. #   -  To change Description Text during game, use the following in a
  20. #      script call:
  21. #           change_synopsis_description_text("Text")
  22. #      Replacing "Text" with the text you wish to have in your description.
  23. #
  24. #   -  To change Objective Text during game, use the following in a
  25. #      script call:
  26. #           change_synopsis_objective_text("Text")
  27. #      Replacing "Text" with the text you wish to have in your description.
  28. #
  29. #   -  To change Background_Image during game, use the following in a
  30. #      script call:
  31. #           change_synopsis_backgroundimage("Filename")
  32. #      Picture must be located in your pictures folder.
  33. #
  34. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  35. module DiamondandPlatinum3
  36.   module SynopsisScene
  37.    
  38.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  39.     #                                             #
  40.     #   EDITABLE REGION ///////                   #
  41.     #                                             #
  42.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  43.     Description_Window_Opacity  = 255   # Opacity for Objective Window,
  44.                                         # 255 means fully visible,
  45.                                         # 0 means fully transparent
  46.     Objective_Window_Opacity    = 255   # Objective Window Opacity, same as above
  47.    
  48.    
  49.    
  50.     Default_Background_Image    = ""    # If Backgroud Image has an error, use
  51.                                         # this default image.
  52.    
  53.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  54.     #                                             #
  55.     #   END EDITABLE REGION ///////               #
  56.     #                                             #
  57.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  58.    
  59.    
  60.    
  61.    
  62.    
  63.    
  64.    
  65.    
  66.    
  67.    
  68.     #======================================
  69.     # * New Method: Word Wrapping
  70.     #======================================
  71.     def self.word_wrapping(window, text)
  72.       # Current Text Position
  73.       current_text_position = 0    
  74.      
  75.       for i in 0..(text.length - 1)
  76.        
  77.         if text[i] == "\n"
  78.           current_text_position = 0
  79.           next
  80.         end
  81.        
  82.         # Current Position += character width
  83.         current_text_position += window.text_size(text[i]).width
  84.        
  85.         # If Current Position > Window Width
  86.         if current_text_position >= window.width - 32
  87.           # Then Format the Sentence to fit Line
  88.           current_element = i
  89.           while(text[current_element] != " ")
  90.             break if current_element == 0
  91.             current_element -= 1
  92.           end
  93.          
  94.           temp_text = ""
  95.           for j in 0..(text.length - 1)
  96.             temp_text += text[j]
  97.             temp_text += "\n" if j == current_element
  98.           end
  99.           text = temp_text
  100.           i = current_element
  101.           current_text_position = 0
  102.         end
  103.       end
  104.       return text
  105.     end
  106.   end
  107. end
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116. class Scene_Synopsis < Scene_Base
  117.   #--------------------------------------------------------------------------
  118.   # * Start Processing
  119.   #--------------------------------------------------------------------------
  120.   def start
  121.     super()
  122.  
  123.     if $game_system.synopsis_background_image != "" || DiamondandPlatinum3::SynopsisScene::Default_Background_Image != ""
  124.     # Background Image ------------------
  125.       background_image = nil
  126.       if $game_system.synopsis_background_image != ""
  127.         background_image = $game_system.synopsis_background_image
  128.       else
  129.         background_image = DiamondandPlatinum3::SynopsisScene::Default_Background_Image
  130.       end
  131.    
  132.       @background_image        = Sprite.new()
  133.       @background_image.bitmap = Cache.picture(background_image)
  134.       @background_image.x      = 0
  135.       @background_image.y      = 0
  136.       @background_image.zoom_x = Graphics.width.to_f  / @background_image.bitmap.width
  137.       @background_image.zoom_y = Graphics.height.to_f / @background_image.bitmap.height
  138.     #-------------------------------------
  139.   end
  140.  
  141.  
  142.   @window_synopsis_description = Window_Sypnopsis_Description.new()
  143.   @window_synopsis_objective = Window_Sypnopsis_Objective.new()
  144.  
  145.   @window_synopsis_description.x = -400
  146.   @window_synopsis_objective.x = 400
  147.  
  148.   @window_synopsis_description.opacity = DiamondandPlatinum3::SynopsisScene::Description_Window_Opacity
  149.   @window_synopsis_objective.opacity = DiamondandPlatinum3::SynopsisScene::Objective_Window_Opacity
  150.  
  151.  
  152.   end
  153.   #--------------------------------------------------------------------------
  154.   # * Post-Start Processing
  155.   #--------------------------------------------------------------------------
  156.   def post_start
  157.     super()
  158.    
  159.     while(@window_synopsis_description.x < 0)
  160.       @window_synopsis_description.x += 5
  161.       @window_synopsis_objective.x -= 5
  162.       Graphics.update()
  163.     end
  164.   end
  165.   #--------------------------------------------------------------------------
  166.   # * Frame Update
  167.   #--------------------------------------------------------------------------
  168.   def update
  169.     super()
  170.     return_scene() if Input.trigger?(:B)
  171.    
  172.     @window_synopsis_description.update()
  173.   end
  174.   #--------------------------------------------------------------------------
  175.   # * Pre-Termination Processing
  176.   #--------------------------------------------------------------------------
  177.   def pre_terminate
  178.   end
  179.   #--------------------------------------------------------------------------
  180.   # * Termination Processing
  181.   #--------------------------------------------------------------------------
  182.   def terminate
  183.     super()
  184.     if @background_image
  185.       @background_image.bitmap.dispose()
  186.       @background_image.dispose()
  187.     end
  188.    
  189.     @window_synopsis_description.dispose()
  190.     @window_synopsis_objective.dispose()
  191.   end  
  192. end
  193.  
  194.  
  195.  
  196.  
  197.  
  198. #==============================================================================
  199. # ** Window_MenuCommand
  200. #------------------------------------------------------------------------------
  201. #  This command window appears on the menu screen.
  202. #==============================================================================
  203.  
  204. class Window_MenuCommand < Window_Command
  205.   #--------------------------------------------------------------------------
  206.   # * For Adding Original Commands
  207.   #--------------------------------------------------------------------------
  208.   alias dp3_custscene_windowmenucommand_addorigcomnd_023fj    add_original_commands
  209.   #--------------------------------------------------------------------------
  210.   def add_original_commands
  211.     dp3_custscene_windowmenucommand_addorigcomnd_023fj() # Call Original Method
  212.     add_command("Custom Scene", :synosis_scene, true)
  213.   end
  214. end
  215.  
  216.  
  217. #==============================================================================
  218. # ** Window_Message
  219. #------------------------------------------------------------------------------
  220. #  This message window is used to display text.
  221. #==============================================================================
  222.  
  223. class Window_Sypnopsis_Description < Window_ScrollText
  224.  
  225.   def initialize()
  226.     super()#(0, 0, Graphics.width, (Graphics.height * 0.7))
  227.     self.height = (Graphics.height * 0.7)
  228.     self.opacity = 255
  229.     show()
  230.     draw_description()
  231.     @scroll_pos = 0
  232.     @page = 1
  233.   end
  234.  
  235.   def draw_description()
  236.     text = DiamondandPlatinum3::SynopsisScene::word_wrapping(self, $game_system.synopsis_description_text)
  237.     draw_text_ex(0, 0, text)
  238.   end
  239.  
  240.  
  241.   #--------------------------------------------------------------------------
  242.   # * Frame Update
  243.   #--------------------------------------------------------------------------
  244.   def update
  245.     super()
  246.     page         = @page
  247.    
  248.     @page       -= 1 if Input.trigger?(:LEFT) && @page > 1
  249.     @page       += 1 if Input.trigger?(:RIGHT)
  250.     @scroll_pos -= 1 if Input.press?(:UP)
  251.     @scroll_pos += 1 if Input.press?(:DOWN)
  252.     self.oy = @scroll_pos
  253.    
  254.     if @page != page
  255.       create_contents # Remove all text in window & resize contents bitmap
  256.       @scroll_pos = 0 # ScrollPos back to default
  257.      
  258.       # Draw Page number if not main page
  259.       draw_text_ex(0, 0, "Page #{@page.to_s}") if @page != 1
  260.      
  261.       # Draw Description if main Page
  262.       draw_description() if @page == 1
  263.     end
  264.   end
  265.  
  266.   def contents_height
  267.     return Graphics.width - 32 #~ complete size of all text ~#
  268.   end
  269. end
  270.  
  271.  
  272.  
  273.  
  274.  
  275.  
  276. #==============================================================================
  277. # ** Window_Message
  278. #------------------------------------------------------------------------------
  279. #  This message window is used to display text.
  280. #==============================================================================
  281.  
  282. class Window_Sypnopsis_Objective < Window_Base
  283.   def initialize()
  284.     super(0, (Graphics.height * 0.7), Graphics.width, (Graphics.height * 0.3))
  285.     draw_objective()
  286.   end
  287.  
  288.   def draw_objective()    
  289.     text = DiamondandPlatinum3::SynopsisScene::word_wrapping(self, $game_system.synopsis_objective_text)
  290.     draw_text_ex(0, 0, text)
  291.   end
  292. end
  293.  
  294.  
  295.  
  296.  
  297.  
  298. #==============================================================================
  299. # ** Scene_Menu
  300. #------------------------------------------------------------------------------
  301. #  This class performs the menu screen processing.
  302. #==============================================================================
  303.  
  304. class Scene_Menu < Scene_MenuBase
  305.   #--------------------------------------------------------------------------
  306.   # * Create Command Window
  307.   #--------------------------------------------------------------------------
  308.   alias dp3_custscene_scenemenu_createcmmdwindow_023fj    create_command_window
  309.   #--------------------------------------------------------------------------
  310.   def create_command_window
  311.     dp3_custscene_scenemenu_createcmmdwindow_023fj() # Call Original Method
  312.     @command_window.set_handler(:synosis_scene, method(:command_scenesynopsis))
  313.   end
  314.  
  315.   def command_scenesynopsis
  316.     SceneManager.call(Scene_Synopsis)
  317.   end
  318. end
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330. #==============================================================================
  331. # ** Game_System
  332. #------------------------------------------------------------------------------
  333. #  This class handles system data. It saves the disable state of saving and
  334. # menus. Instances of this class are referenced by $game_system.
  335. #==============================================================================
  336.  
  337. class Game_System
  338.   #--------------------------------------------------------------------------
  339.   # * Public Instance Variables
  340.   #--------------------------------------------------------------------------
  341.   attr_accessor   :synopsis_description_text
  342.   attr_accessor   :synopsis_objective_text
  343.   attr_accessor   :synopsis_background_image
  344.   #--------------------------------------------------------------------------
  345.   # * Object Initialization
  346.   #--------------------------------------------------------------------------
  347.   alias dp3_gamesystem_sypnopsis_initialize_p1d9y   initialize
  348.   def initialize
  349.     @synopsis_description_text = "Should we choose to continue on this line and break it here \nWhat you will encounter is that once we get up to a certain point the word wrapper pushes text onto a new line for apparently no reason" +
  350.                                  "Should we choose to continue on this line and break it here \nWhat you will encounter is that once we get up to a certain point the word wrapper pushes text onto a new line for apparently no reason" +
  351.                                  "Should we choose to continue on this line and break it here \nWhat you will encounter is that once we get up to a certain point the word wrapper pushes text onto a new line for apparently no reason" +
  352.                                  "Should we choose to continue on this line and break it here \nWhat you will encounter is that once we get up to a certain point the word wrapper pushes text onto a new line for apparently no reason" +
  353.                                  "Should we choose to continue on this line and break it here \nWhat you will encounter is that once we get up to a certain point the word wrapper pushes text onto a new line for apparently no reason"
  354.     @synopsis_objective_text   = "Objective Text in here"
  355.     @synopsis_background_image = ""
  356.     dp3_gamesystem_sypnopsis_initialize_p1d9y() # Call Original Method
  357.   end
  358. end
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368. #==============================================================================
  369. # ** Game_Interpreter
  370. #------------------------------------------------------------------------------
  371. #  An interpreter for executing event commands. This class is used within the
  372. # Game_Map, Game_Troop, and Game_Event classes.
  373. #==============================================================================
  374.  
  375. class Game_Interpreter
  376.   def change_synopsis_description_text( text )
  377.     return unless text.is_a?(String)
  378.     $game_system.synopsis_description_text = text
  379.   end
  380.   def change_synopsis_objective_text( text )
  381.     return unless text.is_a?(String)
  382.     $game_system.synopsis_objective_text = text
  383.   end
  384.   def change_synopsis_backgroundimage( text )
  385.     return unless text.is_a?(String)
  386.     $game_system.synopsis_background_image = text
  387.   end
  388. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement