Advertisement
gerkrt

RPGXP - ENG - Picture Text Command

Sep 14th, 2011
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 12.51 KB | None | 0 0
  1. #==============================================================================
  2. # Picture Text Command
  3. # By gerkrt/gerrtunk
  4. # Version: 2.1
  5. # License: GPL, credits
  6. #==============================================================================
  7.  
  8. =begin
  9.  
  10. ----------------------------------
  11. Instalation and compatiility
  12. ----------------------------------
  13. -Put this script before main.
  14. -To use advance effects install MACL. Here: http://etheon.net/public/dl/macl_complete.txt
  15. Here the forum thread: viewtopic.php?f=11&t=9417
  16. -To install read the instructions. Anyway, you have to put before main but after
  17. this script.
  18.  
  19. ----------------------------------
  20. Instructions
  21. ----------------------------------
  22.  
  23. This script can show pictures based on a text line. The image will be treated like
  24. a normal picture loaded with the show picture event command. It have the same
  25. rules and can be moved, changue tone, erased, etc...
  26.  
  27. A call script example:
  28.  
  29. @m = Message.new
  30. @m.bold = true
  31. @m.size = 48
  32. @m.font = "Arial"
  33. @m.italic = true
  34. @m.color = Color.new(134,176,188,154)
  35. @m.t"Text to show"
  36.  
  37. Then you need to put a command show picture with any image(its not used) and the
  38. values that you will put in a normal event command show picture. The script then creates
  39. creates a bitmap based on your text and options and loading a event picture with it.
  40.  
  41. You have to use this structure of call script+show picture to use this new command.
  42.  
  43. ----------------------------------
  44. Options and meanings
  45. ----------------------------------
  46.  
  47. Basic options. Description before #:
  48.  
  49. @m = Message.new    # Dont changue or remove this. Always the first thing.
  50.  
  51. @m.bold = true   # Bold letter
  52. @m.size = 48   # Size of the font
  53. @m.font = "Arial" # Fontname
  54. @m.italic = true   # Cursive italic
  55. @m.color = Color.new(134,176,188,154)   # Text basic color.
  56. @m.t"Wep" # Text to write in the brackets "".
  57.  
  58. Advanced options. Only with MACL.
  59.  
  60. @m.shadow = true   # Shadowed font
  61. @m.s_color = Color.new(134,176,188,154)   # Shadow color
  62. @m.outline = true   # Shows a outline
  63. @m.o_color = Color.new(134,176,188,154)   # Outline color
  64. @m.horiz_grad = true   # Horizontal gradient with two colors
  65. @m.vert_grad = true   # Vertical gradient with two colors
  66. @m.g1_color = Color.new(134,176,188,154)   # Gradiet Starting color
  67. @m.g2_color = Color.new(1,255,188,154)   #  Gradiet Endig color
  68.  
  69. -The only fixed option is @m = Message.new. If you only put this will chargue
  70. a picture based only in your predefenided values.
  71.  
  72. -Then you have to compose your call scripts adding a option in a new line every time
  73. This a example:
  74.  
  75. Show message "Noooooo", size 16 and horizontal gradient with defined colors:
  76.  
  77. @m = Message.new    
  78. @m.t"Nooooooooooooooooo"
  79. @m.size = 16
  80. @m.horiz_grad = true
  81. @m.g1_color = Color.new(134,176,188,154)
  82. @m.g2_color = Color.new(1,255,188,154)
  83.  
  84. -The order dont care. The only rule is to put the @m = Message.new first.
  85.  
  86. -The two gradients use the same colors values.
  87.  
  88. -Incompatible effects: the two gradients, shadow/outline.
  89.  
  90. -Remember to quit the #'s.
  91.  
  92. -You can make a large call script in two call scripts, simply continue writting
  93. in the next. The other option is:
  94.  
  95. @m.size = 16 ; @m.horiz_grad = true
  96.  
  97. The ; is a ruby line internal separator. Its like they are in different lines.
  98.  
  99. -Some advice about the values:
  100.  
  101. Color.new(134,176,188,154) Red,Green,Blue+alpha Only changue the numbers. 0-255.
  102. "Texts": You must use the "" and the text inside of them.
  103. true/false: It means Active or Inactive. For example to write bold: @m.bold = true
  104.  
  105. If the sucker call script gives you strange errors this is what you can try:
  106.  
  107.     -Recolocate the larger scripts lines: spaces,intros,etc
  108.     -Add a new option at the end, event if its inactive one.
  109.    
  110. --------------------------------------------
  111. Advices to write the text
  112. --------------------------------------------
  113.  
  114. -To only write a event variable value :
  115.   @m.t$game_variables[variable_id].to_s
  116.  
  117. -Complex phrases:
  118.   @m.t"HP:"+$game_variables[variable_id].to_s+" "+"Z"
  119.  
  120. It writes  HP:var Z.
  121.  
  122. -In ruby the + concatenate words to make larger ones.
  123. -Use " " if you need some spaces or aligns
  124. -Respect the "" word delimitators.
  125. -The $game_variables[variable_id].to_s dont use "", but internslly its treated like a word
  126. -variable_id: The number ID of a event variable
  127.  
  128. ----------------------------------
  129. Long lines
  130. ----------------------------------
  131.  
  132. Call script command suck for these. This a example of what you have to do:
  133.  
  134. @m.t"HP:"+$game_variables[variable_id].to_s
  135.  
  136. @m.t" MP:"+$game_variables[variable_id2].to_s
  137.  
  138. @m.t" Limit: "+$game_variables[variable_id3].to_s
  139.  
  140. The script automatically concatenates all. Just write it in order.
  141.  
  142. ------------------------
  143. Default values
  144. ------------------------
  145.  
  146. If you need this, you can make your predefenided values for all the options.
  147. With this, the command can be shorter, removing the lines you dont need.
  148.  
  149. The constants names are Def_font_+ the option of the @ that you alreadyknow.
  150.  
  151. =end
  152. module Wep
  153.   Def_font_name = "Arial"
  154.   Def_font_text = "Wep"
  155.   Def_font_size = 24
  156.   Def_font_bold = false
  157.   Def_font_italic = false
  158.   Def_font_color = Color.new(255, 255, 255, 255)   # The normal color
  159.   Def_font_horiz_grad = false
  160.   Def_font_vert_grad = false
  161.   Def_font_outline = false
  162.   Def_font_shadow = false
  163.   Def_font_s_color = Color.new(0, 0, 0, 100)
  164.   Def_font_o_color = Color.new(0, 0, 0)
  165.   Def_font_g1_color = Color.new(255, 45, 255)
  166.   Def_font_g2_color = Color.new(12, 128, 128)
  167. end
  168.  
  169.  
  170. #==============================================================================
  171. class Message
  172.   attr_accessor   :text
  173.   attr_accessor   :font
  174.   attr_accessor   :size
  175.   attr_accessor   :bold
  176.   attr_accessor   :italic
  177.   attr_accessor   :color
  178.   attr_accessor   :horiz_grad
  179.   attr_accessor   :vert_grad
  180.   attr_accessor   :shadow
  181.   attr_accessor   :outline
  182.   attr_accessor   :s_color
  183.   attr_accessor   :o_color
  184.   attr_accessor   :g1_color
  185.   attr_accessor   :g2_color
  186.   def initialize(text=Wep::Def_font_text,font=Wep::Def_font_name,size=Wep::Def_font_size,bold=Wep::Def_font_bold,italic=Wep::Def_font_italic, color=Wep::Def_font_color, horiz_grad=Wep::Def_font_horiz_grad,vert_grad=Wep::Def_font_vert_grad,outline=Wep::Def_font_outline,shadow=Wep::Def_font_shadow, s_color=Wep::Def_font_s_color, o_color=Wep::Def_font_o_color,g1_color=Wep::Def_font_g1_color,g2_color=Wep::Def_font_g2_color)    @text = text
  187.     @font = font
  188.     @size = size
  189.     @bold = bold
  190.     @italic = italic
  191.     @color = color
  192.     @s_color = s_color
  193.     @o_color = o_color
  194.     @g1_color = g1_color
  195.     @g2_color = g2_color    
  196.     @horiz_grad = horiz_grad
  197.     @vert_grad = vert_grad
  198.     @shadow = shadow
  199.     @text = ""
  200.     @text = text
  201.     @outline = outline
  202.     @first_concat = true
  203.   end
  204.  
  205.   #--------------------------------------------------------------------------
  206.   # *t This metod concatenates the text string.
  207.   # Optimitzed to be very short.
  208.   #--------------------------------------------------------------------------
  209.  
  210.   def t(text)
  211.     # Check if the text is the predefined and its the first time to add
  212.     # and clears it
  213.     if Wep::Def_font_text == @text and @first_concat
  214.       @text = ""
  215.     end
  216.     @first_concat = false
  217.     @text += text
  218.   end
  219. end
  220.  
  221. class Sprite_Picture
  222.   #--------------------------------------------------------------------------
  223.   # * Frame Update
  224.   #--------------------------------------------------------------------------
  225.   def update
  226.     super
  227.     # If picture file name is different from current one and have a message
  228.     if @picture_name != @picture.name and @picture.message
  229.        # Remember file name to instance variables
  230.       @picture_name = @picture.name
  231.        #if @picture_name != ""
  232.         # Get picture graphic
  233.  
  234.        #end
  235.         # Use the testing bitmap to know text size
  236.         testing_bitmap = Bitmap.new(1,1)
  237.         testing_bitmap.font.name = @picture.message.font
  238.         testing_bitmap.font.size = @picture.message.size
  239.         testing_bitmap.font.bold = @picture.message.bold
  240.         testing_bitmap.font.italic = @picture.message.italic
  241.         line = @picture.message.text
  242.         needed_rect = testing_bitmap.text_size(line)
  243.  
  244.         # Changue basic font options
  245.         self.bitmap = Bitmap.new(needed_rect.width, needed_rect.height)
  246.         self.bitmap.font.name = @picture.message.font
  247.         self.bitmap.font.size = @picture.message.size
  248.         self.bitmap.font.bold = @picture.message.bold
  249.         self.bitmap.font.italic = @picture.message.italic
  250.         self.bitmap.font.color = @picture.message.color
  251.         # Exception check if MACL is instaled or not
  252.         begin
  253.           if MACL != nil
  254.              # Changue advanced font options
  255.              self.bitmap.font.horiz_grad = @picture.message.horiz_grad
  256.              self.bitmap.font.vert_grad = @picture.message.vert_grad
  257.              self.bitmap.font.outline = @picture.message.outline
  258.              self.bitmap.font.shadow = @picture.message.shadow
  259.              self.bitmap.font.shadow_color = @picture.message.s_color
  260.              self.bitmap.font.outline_color = @picture.message.o_color
  261.              self.bitmap.font.grad_s_color = @picture.message.g1_color
  262.              self.bitmap.font.grad_e_color = @picture.message.g2_color
  263.           end
  264.         rescue
  265.         end
  266.        self.bitmap.draw_text(0, 0, needed_rect.width, needed_rect.height, line)
  267.  
  268.     end
  269.     # If picture file name is different from current one
  270.     if @picture_name != @picture.name and @picture.message == nil
  271.       # Remember file name to instance variables
  272.       @picture_name = @picture.name
  273.       # If file name is not empty
  274.       if @picture_name != ""
  275.         # Get picture graphic
  276.         self.bitmap = RPG::Cache.picture(@picture_name)
  277.       end
  278.     end
  279.     # If file name is empty
  280.     if @picture_name == ""
  281.       # Set sprite to invisible
  282.       self.visible = false
  283.       return
  284.     end
  285.     # Set sprite to visible
  286.     self.visible = true
  287.     # Set transfer starting point
  288.     if @picture.origin == 0
  289.       self.ox = 0
  290.       self.oy = 0
  291.     else
  292.       self.ox = self.bitmap.width / 2
  293.       self.oy = self.bitmap.height / 2
  294.     end
  295.     # Set sprite coordinates
  296.     self.x = @picture.x
  297.     self.y = @picture.y
  298.     self.z = @picture.number
  299.     # Set zoom rate, opacity level, and blend method
  300.     self.zoom_x = @picture.zoom_x / 100.0
  301.     self.zoom_y = @picture.zoom_y / 100.0
  302.     self.opacity = @picture.opacity
  303.     self.blend_type = @picture.blend_type
  304.     # Set rotation angle and color tone
  305.     self.angle = @picture.angle
  306.     self.tone = @picture.tone
  307.   end
  308. end
  309.  
  310.  
  311. class Game_Picture
  312.   #--------------------------------------------------------------------------
  313.   # * Public Instance Variables
  314.   #--------------------------------------------------------------------------
  315.   attr_reader   :message                    # text
  316.   #--------------------------------------------------------------------------
  317.   # * Object Initialization
  318.   #     number : picture number
  319.   #--------------------------------------------------------------------------
  320.   alias gp_init initialize
  321.   def initialize(number)
  322.     gp_init(number)
  323.     @message = nil
  324.   end
  325.  
  326.   alias gp_show show
  327.   def show(name, origin, x, y, zoom_x, zoom_y, opacity, blend_type, message=nil)
  328.     gp_show(name, origin, x, y, zoom_x, zoom_y, opacity, blend_type)
  329.     @message = message
  330.   end
  331.   alias gp_erase erase
  332.   def erase
  333.     gp_erase
  334.     @message = nil
  335.   end
  336. end
  337.  
  338.  
  339. class Interpreter
  340.   #--------------------------------------------------------------------------
  341.   # * Show Picture
  342.   #--------------------------------------------------------------------------
  343.   def command_231
  344.       # Get picture number
  345.     number = @parameters[0] + ($game_temp.in_battle ? 50 : 0)
  346.     # If appointment method is [direct appointment]
  347.     if @parameters[3] == 0
  348.       x = @parameters[4]
  349.       y = @parameters[5]
  350.     # If appointment method is [appoint with variables]
  351.     else
  352.       x = $game_variables[@parameters[4]]
  353.       y = $game_variables[@parameters[5]]
  354.     end
  355.     # Show picture
  356.    # If message is written
  357.    if @m != nil
  358.     $game_screen.pictures[number].show(@parameters[1], @parameters[2],
  359.     x, y, @parameters[6], @parameters[7], @parameters[8], @parameters[9], @m)
  360.     # Format m for other calls
  361.     @m = nil
  362.    else
  363.     $game_screen.pictures[number].show(@parameters[1], @parameters[2],
  364.     x, y, @parameters[6], @parameters[7], @parameters[8], @parameters[9])
  365.  
  366.    end
  367.     # Continue
  368.     return true
  369.   end
  370. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement