Advertisement
mjshi

Message Box Icons [XP]

Sep 20th, 2016
912
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.40 KB | None | 0 0
  1. #-------------------------------------------------------------------------------
  2. # Message Box Icons [XP] v1.0
  3. # by mjshi. OK for use in any project.
  4. #-------------------------------------------------------------------------------
  5. # Edits to Window_Message to draw icons for items/weapons/armors.
  6. # Will conflict with other message window scripts that deal with escape codes.
  7. #-------------------------------------------------------------------------------
  8. # Use the following escape codes in the message box.
  9. # These are not case-sensitive. (so \I[2] = \i[2])
  10. #
  11. # \*[id]    draws the icon of the item
  12. # \I[id]    draws the icon as well as the name of the item
  13. # \W*[id]   draws the icon of a weapon
  14. # \W[id]    draws the icon as well as the name of the weapon
  15. # \A*[id]   draws the icon of an armor
  16. # \A[id]    draws the icon as well as the name of the armor
  17. #-------------------------------------------------------------------------------
  18.  
  19. class Window_Message
  20.   def refresh
  21.     self.contents.clear
  22.     self.contents.font.color = normal_color
  23.     x = y = 0
  24.     @cursor_width = 0
  25.     # Indent if choice
  26.     if $game_temp.choice_start == 0
  27.       x = 8
  28.     end
  29.     # If waiting for a message to be displayed
  30.     if $game_temp.message_text != nil
  31.       text = $game_temp.message_text
  32.       # Control text processing
  33.       begin
  34.         last_text = text.clone
  35.         text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  36.       end until text == last_text
  37.       text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
  38.         $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
  39.       end
  40.       # Change "\\\\" to "\000" for convenience
  41.       text.gsub!(/\\\\/) { "\000" }
  42.       # Change "\\C" to "\001" and "\\G" to "\002"
  43.       text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" }
  44.       text.gsub!(/\\[Gg]/) { "\002" }
  45.       # item icon display
  46.       text.gsub!(/\\[Ii]\[([0-9]+)\]/) { "\003[#{$1}]" }
  47.       text.gsub!(/\\\*\[([0-9]+)\]/) { "\004[#{$1}]" }
  48.       # weapon icon display
  49.       text.gsub!(/\\[Ww]\[([0-9]+)\]/) { "\005[#{$1}]" }
  50.       text.gsub!(/\\[Ww]\*\[([0-9]+)\]/) { "\006[#{$1}]" }
  51.       # armor icon display
  52.       text.gsub!(/\\[Aa]\[([0-9]+)\]/) { "\007[#{$1}]" }
  53.       text.gsub!(/\\[Aa]\*\[([0-9]+)\]/) { "\010[#{$1}]" }
  54.       # Get 1 text character in c (loop until unable to get text)
  55.       while ((c = text.slice!(/./m)) != nil)
  56.         # If \\
  57.         if c == "\000"
  58.           # Return to original text
  59.           c = "\\"
  60.         end
  61.         # If \C[n]
  62.         if c == "\001"
  63.           # Change text color
  64.           text.sub!(/\[([0-9]+)\]/, "")
  65.           color = $1.to_i
  66.           if color >= 0 and color <= 7
  67.             self.contents.font.color = text_color(color)
  68.           end
  69.           # go to next text
  70.           next
  71.         end
  72.         # If \G
  73.         if c == "\002"
  74.           # Make gold window
  75.           if @gold_window == nil
  76.             @gold_window = Window_Gold.new
  77.             @gold_window.x = 560 - @gold_window.width
  78.             if $game_temp.in_battle
  79.               @gold_window.y = 192
  80.             else
  81.               @gold_window.y = self.y >= 128 ? 32 : 384
  82.             end
  83.             @gold_window.opacity = self.opacity
  84.             @gold_window.back_opacity = self.back_opacity
  85.           end
  86.           # go to next text
  87.           next
  88.         end
  89.        
  90.         # If new line text
  91.         if c == "\n"
  92.           # Update cursor width if choice
  93.           if y >= $game_temp.choice_start
  94.             @cursor_width = [@cursor_width, x].max
  95.           end
  96.           # Add 1 to y
  97.           y += 1
  98.           x = 0
  99.           # Indent if choice
  100.           if y >= $game_temp.choice_start
  101.             x = 8
  102.           end
  103.           # go to next text
  104.           next
  105.         end
  106.        
  107.        
  108.         if c == "\003"
  109.           text.match(/\[([0-9]+)\]/)
  110.           id = $1.to_i
  111.           name = $data_items[id].name
  112.           text.sub!(/\[([0-9]+)\]/, name)
  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.         if c == "\004"
  120.           text.sub!(/\[([0-9]+)\]/, "")
  121.           id = $1.to_i
  122.           bitmap = RPG::Cache.icon($data_items[id].icon_name)
  123.           self.contents.blt(x, y * 32 + 2, bitmap, Rect.new(0, 0, 24, 24))
  124.           x += 24
  125.           next
  126.         end
  127.        
  128.         if c == "\005"
  129.           text.match(/\[([0-9]+)\]/)
  130.           id = $1.to_i
  131.           name = $data_weapons[id].name
  132.           text.sub!(/\[([0-9]+)\]/, name)
  133.           bitmap = RPG::Cache.icon($data_weapons[id].icon_name)
  134.           self.contents.blt(x, y * 32 + 2, bitmap, Rect.new(0, 0, 24, 24))
  135.           x += 24
  136.           next
  137.         end
  138.        
  139.         if c == "\006"
  140.           text.sub!(/\[([0-9]+)\]/, "")
  141.           id = $1.to_i
  142.           bitmap = RPG::Cache.icon($data_weapons[id].icon_name)
  143.           self.contents.blt(x, y * 32 + 2, bitmap, Rect.new(0, 0, 24, 24))
  144.           x += 24
  145.           next
  146.         end
  147.        
  148.         if c == "\007"
  149.           text.match(/\[([0-9]+)\]/)
  150.           id = $1.to_i
  151.           name = $data_armors[id].name
  152.           text.sub!(/\[([0-9]+)\]/, name)
  153.           bitmap = RPG::Cache.icon($data_armors[id].icon_name)
  154.           self.contents.blt(x, y * 32 + 2, bitmap, Rect.new(0, 0, 24, 24))
  155.           x += 24
  156.           next
  157.         end
  158.        
  159.         if c == "\010"
  160.           text.sub!(/\[([0-9]+)\]/, "")
  161.           id = $1.to_i
  162.           bitmap = RPG::Cache.icon($data_armors[id].icon_name)
  163.           self.contents.blt(x, y * 32 + 2, bitmap, Rect.new(0, 0, 24, 24))
  164.           x += 24
  165.           next
  166.         end
  167.        
  168.         # Draw text
  169.         self.contents.draw_text(4 + x, 32 * y, 40, 32, c)
  170.         # Add x to drawn text width
  171.         x += self.contents.text_size(c).width
  172.       end
  173.     end
  174.     # If choice
  175.     if $game_temp.choice_max > 0
  176.       @item_max = $game_temp.choice_max
  177.       self.active = true
  178.       self.index = 0
  179.     end
  180.     # If number input
  181.     if $game_temp.num_input_variable_id > 0
  182.       digits_max = $game_temp.num_input_digits_max
  183.       number = $game_variables[$game_temp.num_input_variable_id]
  184.       @input_number_window = Window_InputNumber.new(digits_max)
  185.       @input_number_window.number = number
  186.       @input_number_window.x = self.x + 8
  187.       @input_number_window.y = self.y + $game_temp.num_input_start * 32
  188.     end
  189.   end
  190. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement