Advertisement
mjshi

Draw icon in message box (RMXP/RGSS)

May 9th, 2016
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.66 KB | None | 0 0
  1. #-------------------------------------------------------------------------------
  2. # Draw icon in message box
  3. # for RMXP/RGSS, by mjshi
  4. # OK for use in any project. No configuration necessary.
  5. #-------------------------------------------------------------------------------
  6. # Edits to Window_Message to allow icon-drawing.
  7. # Will conflict with other message window scripts that deal with escape codes.
  8. #-------------------------------------------------------------------------------
  9. # Use the following escape codes in the message box:
  10. #
  11. # \*[id]    draws the icon of the item
  12. # \I[id]    draws the icon as well as the name of the item
  13. # \i[id]    functionally identical to \I[id]
  14. #-------------------------------------------------------------------------------
  15.  
  16. class Window_Message
  17.   def refresh
  18.     self.contents.clear
  19.     self.contents.font.color = normal_color
  20.     x = y = 0
  21.     @cursor_width = 0
  22.     # Indent if choice
  23.     if $game_temp.choice_start == 0
  24.       x = 8
  25.     end
  26.     # If waiting for a message to be displayed
  27.     if $game_temp.message_text != nil
  28.       text = $game_temp.message_text
  29.       # Control text processing
  30.       begin
  31.         last_text = text.clone
  32.         text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  33.       end until text == last_text
  34.       text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
  35.         $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
  36.       end
  37.       # Change "\\\\" to "\000" for convenience
  38.       text.gsub!(/\\\\/) { "\000" }
  39.       # Change "\\C" to "\001" and "\\G" to "\002"
  40.       text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" }
  41.       text.gsub!(/\\[Gg]/) { "\002" }
  42.       # item icon display
  43.       text.gsub!(/\\[Ii]\[([0-9]+)\]/) { "\003[#{$1}]" }
  44.       text.gsub!(/\\\*\[([0-9]+)\]/) { "\004[#{$1}]" }
  45.       # Get 1 text character in c (loop until unable to get text)
  46.       while ((c = text.slice!(/./m)) != nil)
  47.         # If \\
  48.         if c == "\000"
  49.           # Return to original text
  50.           c = "\\"
  51.         end
  52.         # If \C[n]
  53.         if c == "\001"
  54.           # Change text color
  55.           text.sub!(/\[([0-9]+)\]/, "")
  56.           color = $1.to_i
  57.           if color >= 0 and color <= 7
  58.             self.contents.font.color = text_color(color)
  59.           end
  60.           # go to next text
  61.           next
  62.         end
  63.         # If \G
  64.         if c == "\002"
  65.           # Make gold window
  66.           if @gold_window == nil
  67.             @gold_window = Window_Gold.new
  68.             @gold_window.x = 560 - @gold_window.width
  69.             if $game_temp.in_battle
  70.               @gold_window.y = 192
  71.             else
  72.               @gold_window.y = self.y >= 128 ? 32 : 384
  73.             end
  74.             @gold_window.opacity = self.opacity
  75.             @gold_window.back_opacity = self.back_opacity
  76.           end
  77.           # go to next text
  78.           next
  79.         end
  80.        
  81.         # If new line text
  82.         if c == "\n"
  83.           # Update cursor width if choice
  84.           if y >= $game_temp.choice_start
  85.             @cursor_width = [@cursor_width, x].max
  86.           end
  87.           # Add 1 to y
  88.           y += 1
  89.           x = 0
  90.           # Indent if choice
  91.           if y >= $game_temp.choice_start
  92.             x = 8
  93.           end
  94.           # go to next text
  95.           next
  96.         end
  97.        
  98.        
  99.         if c == "\003"
  100.           text.match(/\[([0-9]+)\]/)
  101.           id = $1.to_i
  102.           name = $data_items[id].name
  103.           text.sub!(/\[([0-9]+)\]/, name)
  104.           bitmap = RPG::Cache.icon($data_items[id].icon_name)
  105.           self.contents.blt(x, y * 32 + 2, bitmap, Rect.new(0, 0, 24, 24))
  106.           x += 24
  107.           next
  108.         end
  109.        
  110.         if c == "\004"
  111.           text.sub!(/\[([0-9]+)\]/, "")
  112.           id = $1.to_i
  113.           bitmap = RPG::Cache.icon($data_items[id].icon_name)
  114.           self.contents.blt(x, y * 32 + 2, bitmap, Rect.new(0, 0, 24, 24))
  115.           x += 24
  116.           next
  117.         end
  118.        
  119.         # Draw text
  120.         self.contents.draw_text(4 + x, 32 * y, 40, 32, c)
  121.         # Add x to drawn text width
  122.         x += self.contents.text_size(c).width
  123.       end
  124.     end
  125.     # If choice
  126.     if $game_temp.choice_max > 0
  127.       @item_max = $game_temp.choice_max
  128.       self.active = true
  129.       self.index = 0
  130.     end
  131.     # If number input
  132.     if $game_temp.num_input_variable_id > 0
  133.       digits_max = $game_temp.num_input_digits_max
  134.       number = $game_variables[$game_temp.num_input_variable_id]
  135.       @input_number_window = Window_InputNumber.new(digits_max)
  136.       @input_number_window.number = number
  137.       @input_number_window.x = self.x + 8
  138.       @input_number_window.y = self.y + $game_temp.num_input_start * 32
  139.     end
  140.   end
  141. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement