estriole

EST - ADV TEXT READER

Dec 13th, 2012
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 12.06 KB | None | 0 0
  1. #==============================================================================
  2. # [VXACE] Advance Text Reader EX by Estriole
  3. #-------------------------------------------------------------------------
  4. # EST - Advance Text Reader
  5. # Version: 1.2
  6. # Released on: 26/07/2012
  7. # Author : Estriole ([email protected])
  8. # also credits : Woratana for VX version
  9. #
  10. #
  11. =begin
  12. ################################################################################
  13. # Version History:
  14. #  v 1.00 - 2012.07.22 > First relase
  15. #  v 1.01 - 2012.07.23 > replace the old decorate text with escape code usage  
  16. #  v 1.02 - 2012.07.26 > make switch togle between old decorate text and new
  17. #                                               escape code version
  18. ###############################################################################
  19.  
  20. ==================================
  21. +[Features in Version 1.2]+
  22.  
  23. ** Start Read Text File by call script:
  24. SceneManager.callplus(Text_Reader,"filename with file type")
  25.  
  26. * For example, you want to read file "test.txt", call script:
  27. SceneManager.callplus(Text_Reader,"test.txt")
  28.  
  29. * ability to use almost all msg system escape codes
  30. such as \c[4], \n[3]. default or custom message system
  31. (known so far yanfly, victor, modern algebra ats)
  32.  
  33. * Advanced syntax to call is like this
  34. SceneManager.callplus(Text_Reader,filename,[actorid],[type],[infocontent])
  35.  
  36. [actorid] & [type] & [infocontent] is optional
  37. [infocontent] will print inside info window when some type chosen max [41char].
  38.  
  39. list of [type]: (what the content of info window)
  40. "default"          - just draw face window (if there is no actorid) without info window then draw text reader window
  41. "simple_status" - info window containing simple actor status
  42. "text_title"    - info window containing titles for the text centered and yellow color
  43. still building more [type]
  44.  
  45. example of some variation to call advanced syntax:
  46. SceneManager.callplus(Text_Reader,"test.txt",11,"simple_status")
  47. means it will draw actor 11 face and actor 11 simple status then below
  48. is test.txt content.
  49.  
  50. or
  51.  
  52. SceneManager.callplus(Text_Reader,"test.txt",nil,"text_title","Stupid Tutorial")
  53. which translate to : only info window containing text "Stupid Tutorial" with larger
  54. font and yellow color centered (vertical and horizontal). and below it is the
  55. test.txt content. (no actor face window because you put nil)
  56.  
  57. or
  58. SceneManager.callplus(Text_Reader,"test.txt",12)
  59. translate to : test.txt content with actor face window (small square at top left
  60. of the test.txt (means it will block any text that below it. but its not a problem
  61. if you center the text (manualy or using decorate text if you didn't need icons, color, etc)
  62.  
  63. ** Custom Folder for Text File
  64. You can change Text File's folder at line:
  65. TEXT_FOLDER = "folder you want"
  66.  
  67. "" << for no folder, text file should be in your game's folder.
  68. "Files/" << for folder "Your Game Folder > Files"
  69. "Data/Files/" << for folder "Your Game Folder > Data > Files"
  70.  
  71. ==================================
  72. decorate text feature below can be used by editing :
  73.  
  74. TR_old_mode_switch = 0
  75. change to switch you want.
  76. if the switch turn on you can use decorate text feature below but lost ability
  77. to use all the escape code (such as \c[5] \n[3] etc)
  78.  
  79. so basicly you can switch between using decorate text and using escape codes.
  80.  
  81. +[Decorate Text]+ [if you still want to use this feature instead nice icon and pics]
  82. You can decorate your text by following features:
  83.  
  84. [b] << Bold Text
  85. [/b] << Not Bold Text
  86.  
  87. [i] << Italic Text
  88. [/i] << Not Italic Text
  89.  
  90. [s] << Text with Shadow
  91. [/s] << Text without Shadow
  92.  
  93. [cen] << Show Text in Center
  94. [left] << Show Text in Left side
  95. [right] << Show Text in Right side
  96.  
  97. * Note: Don't put features that have opposite effects in same line...
  98. For example, [b] that make text bold, and [/b] that make text not bold
  99.  
  100. * Note2: The decoration effect will be use in the next lines,
  101. Until you use opposite effect features... For example,
  102.  
  103. [b]text1
  104. text2
  105. [/b]text3
  106.  
  107. text1 and text2 will be bold text, and text3 will be thin text.
  108.  
  109. ==================================
  110. +[Configuration]+
  111.  
  112. OPEN_SPEED = Speed when Reader Window is Opening/Closing
  113. SCROLL_SPEED = Speed when player Scroll Reader Window up/down
  114.  
  115. TEXT_FOLDER = Folder for Text Files
  116. e.g. "Data/Texts/" for Folder "Your Project Folder > Data > Texts"
  117.  
  118. ================================================================================
  119. compatibility list
  120. ================================================================================
  121. message system
  122. - yanfly ace msg system
  123. - victor msg system
  124. - modern algebra ats msg system
  125. and i'm using loooottss of script and no conflict but i won't list them there
  126. because it's not necessary (the one who can conflict only the one who alter
  127. window_base or scene_base heavily like overwriting the method without mercy lol)
  128.  
  129. ================================================================================
  130. =end
  131. # editable region
  132. module ESTRIOLE
  133.    TR_old_mode_switch = 12 # switch if on use old decorate text mode change to 0
  134.                                                   # you dont want to use the decorate text mode at all
  135.    TEXT_FOLDER = "Texts/" # Folder for Text Files -> this means at your project folder/text
  136.    OPEN_SPEED = 30 # Open/Close Speed of Reader Window (Higher = Faster)
  137.    SCROLL_SPEED = 30 # Scroll Up/Down Speed
  138. end
  139.  
  140. #===========================================================================
  141. # do not edit below this line except you know what you're doing
  142. #===========================================================================
  143.  
  144. module SceneManager
  145.   def self.callplus(scene_class,filename,actor = nil,type="default",infocontent="")
  146.         @stack.push(@scene)
  147.         @scene = scene_class.new(filename,actor,type,infocontent)
  148.   end  
  149. end
  150.  
  151.  
  152.  
  153. class Text_Reader < Scene_MenuBase
  154.  
  155.   OPEN_SPEED = ESTRIOLE::OPEN_SPEED
  156.   SCROLL_SPEED = ESTRIOLE::SCROLL_SPEED
  157.   TEXT_FOLDER = ESTRIOLE::TEXT_FOLDER  
  158.   def initialize(file_name,actor = nil,type="default",infocontent="",mode = 0)
  159.         @filename = file_name
  160.         @infocontent = infocontent
  161.         if actor == nil
  162.         @actorx = nil
  163.         else
  164.         @actorx = $game_actors[actor]
  165.         end
  166.         @mode = mode
  167.         @type = type
  168.   end
  169.  
  170.   def start
  171.         super
  172.         file = File.open(TEXT_FOLDER + @filename)
  173.         @text = []
  174.         for i in file.readlines
  175.           @text.push i.sub(/\n/) {}
  176.         end
  177.         if @mode == 1
  178.           @text[0] = @text[0].sub(/^./m) {}
  179.         end
  180.        
  181.         @window = Window_Reader.new(@text,@actorx,@type)
  182.         @window.visible = true
  183.        
  184.         if @actorx == nil
  185.          
  186.         else
  187.         @actor_face_window = Window_Top_Reader_Face.new(@actorx)
  188.         end
  189.  
  190.         case @type
  191.         when "default"
  192.         else;
  193.           @info_window = Window_Top_Reader_Info.new(@actorx,@type,@infocontent)
  194.         end
  195.  
  196.   end
  197.          
  198.   def update
  199.         super
  200.         @window.update
  201.         process_exit if Input.trigger?(:B)/> or Input.trigger?(:C)
  202.         process_down if Input.repeat?(:DOWN)
  203.         process_up if Input.repeat?(:UP)
  204.   end
  205.  
  206.   def process_exit
  207.           Sound.play_cancel
  208.           SceneManager.call(Scene_Map)
  209.   end
  210.  
  211.   def process_down
  212.           Sound.play_cursor if (@window.oy + 272) < @window.contents.height
  213.           @window.oy += SCROLL_SPEED if (@window.oy + 272) < @window.contents.height
  214.   end
  215.  
  216.   def process_up
  217.           Sound.play_cursor if (@window.oy + 272) < @window.contents.height
  218.           @window.oy -= SCROLL_SPEED if @window.oy > 0
  219.   end  
  220.  
  221.   def scene_changing?
  222.         SceneManager.scene != self
  223.   end
  224. end
  225.  
  226. class Window_Top_Reader_Face < Window_Base
  227.   def initialize(actor)
  228.         super(0,0,116,116)
  229.         draw_actor_face(actor,0,0,true)
  230.   end
  231. end
  232.  
  233. class Window_Top_Reader_Info < Window_Base
  234.   def initialize(actor,type,infocontent)
  235.         if actor == nil
  236.         super(0,0,544,116)
  237.         @infowidth = 544
  238.         else
  239.         super(116,0,428,116)
  240.         @infowidth = 428
  241.         end
  242.         case type
  243.         when "simple_status"
  244.           draw_actor_simple_status(actor, 20, 20) if actor != nil
  245.         when "text_title"
  246.           make_font_bigger
  247.           make_font_bigger if actor == nil
  248.           change_color(text_color(6))
  249.           draw_text(0, 28, @infowidth - 40, 40, infocontent, 1) if actor == nil
  250.           draw_text(0, 32, @infowidth - 40, 32, infocontent, 1) if actor != nil
  251.         else;
  252.         end
  253.   end
  254. end
  255.  
  256. class Window_Reader < Window_Base
  257.   attr_accessor :firstline, :nowline
  258.  
  259.   def initialize(text,actorx,type)
  260.         if actorx == nil
  261.           case type
  262.                 when "default"
  263.                   super(0,0,544,416)
  264.                 else;
  265.                   super(0,116,544,300)  
  266.           end
  267.         else
  268.           case type
  269.                 when "default"
  270.                   super(0,0,544,416)
  271.                 else;
  272.                   super(0,116,544,300)  
  273.           end
  274.         end
  275.  
  276.         #
  277.         @firstline = @nowline = 0
  278.         @text = text
  279.         @align = 0
  280.         @extra_lines = 0
  281.         @line_index = 0
  282.         draw_text_reader
  283.   end
  284.  
  285.   def update
  286.         if self.openness < 255
  287.           self.openness += Text_Reader::OPEN_SPEED
  288.         end
  289.   end
  290.  
  291.   def draw_text_reader
  292.         self.contents = Bitmap.new(width - 32, @text.size * 24 + 32)
  293.         @line_index = 0
  294.         for i in 0..@text.size
  295.           if @text[i] == nil
  296.           else
  297.                 text = decorate_text(@text[i])
  298.                 if $game_switches[ESTRIOLE::TR_old_mode_switch] == true
  299.                   self.contents.draw_text(0, @line_index * 24, width - 32, 24, text, @align)
  300.                 else
  301.                   self.draw_text_ex_mod(0, @line_index * 24, text)
  302.                 end
  303.           end
  304.           @line_index += 1
  305.         end      
  306.   end
  307.  
  308.   def draw_text_ex_mod(x, y, text)
  309.         #reset_font_settings
  310.         text = convert_escape_characters(text)
  311.         @pos = {:x => x, :y => y, :new_x => x, :height => calc_line_height(text)}
  312.         process_character_mod(text.slice!(0, 1), text, @pos) until text.empty?
  313.   end
  314.  
  315.   def process_character_mod(c, text, pos)
  316.         if pos[:x] >500
  317.           process_new_line(text, pos)
  318.           @line_index += 1
  319.           @extra_lines += 1
  320.         end
  321.         case c
  322.         when "\n"  
  323.           process_new_line(text, pos)
  324.         when "\f"  
  325.           process_new_page(text, pos)
  326.         when "\e"  
  327.           process_escape_character(obtain_escape_code(text), text, pos)
  328.         else            
  329.           process_normal_character(c, pos)
  330.         end
  331.   end
  332.  
  333.   def decorate_text(text)
  334.          a = text.scan(/(\[\/b\])/)
  335.          if $1.to_s != ""
  336.            self.contents.font.bold = false
  337.            text.sub!(/\[\/b\]/) {}
  338.          end
  339.        
  340.          a = text.scan(/(\[b\])/)
  341.          if $1.to_s != ""
  342.            self.contents.font.bold = true
  343.            text.sub!(/\[b\]/) {}
  344.          end
  345.        
  346.         a = text.scan(/(\[\/i\])/)
  347.          if $1.to_s != ""
  348.            self.contents.font.italic = false
  349.            text.sub!(/\[\/i\]/) {}
  350.          end
  351.        
  352.          a = text.scan(/(\[i\])/)
  353.          if $1.to_s != ""
  354.            self.contents.font.italic = true
  355.            text.sub!(/\[i\]/) {}
  356.          end
  357.        
  358.          a = text.scan(/(\[\/s\])/)
  359.          if $1.to_s != ""
  360.            self.contents.font.shadow = false
  361.            text.sub!(/\[\/s\]/) {}
  362.          end
  363.        
  364.          a = text.scan(/(\[s\])/)
  365.          if $1.to_s != ""
  366.            self.contents.font.shadow = true
  367.            text.sub!(/\[s\]/) {}
  368.          end
  369.        
  370.          a = text.scan(/(\[cen\])/)
  371.          if $1.to_s != ""
  372.            @align = 1
  373.            text.sub!(/\[cen\]/) {}
  374.          end
  375.        
  376.         a = text.scan(/(\[left\])/)
  377.          if $1.to_s != ""
  378.            @align = 0
  379.            text.sub!(/\[left\]/) {}
  380.          end
  381.        
  382.         a = text.scan(/(\[right\])/)
  383.          if $1.to_s != ""
  384.            @align = 2
  385.            text.sub!(/\[right\]/) {}
  386.          end
  387.        
  388.          return text
  389.   end
  390.  
  391. end
Advertisement
Add Comment
Please, Sign In to add comment