Invité Invité
| Sujet: [VX] Rajouter des Icons dans ses textes. Mar 9 Aoû 2011 - 15:35 | |
| Un peu comme celui que j'utilise pour mon projet Zeeshan, on me le demande souvent par mp, mais j'ai souvent la flemme de répondre, alors je vais le mettre ici pour la peine. ^^ Premier scriptVous allez avoir besoin de ce script: Auteur: Yanfly Maintenant quand vous allez lancer votre projet, un nouveau menu va faire son apparition et grâce à celà, vous allez pouvoir connaitre toutes les ID de votre Iconset. Screen pour montrer: Et le script: - Spoiler:
#=============================================================================== # # Yanfly Engine Melody - Iconview Melody # Last Date Updated: 2010.05.24 # Level: Easy # # Don't know how to use Photoshop's X and Y coordinates to count your icons or # just too lazy to do it? Well, you can use this tool to make your life easier # by loading up the icons on a static sheet and figuring out what those icons # are indexed as. This script will mark 256 icons per page and allows you to # scroll through those pages as lagless as possible. The icons are displayed # in columns of 16 icons each, following exactly the way your IconSet is made # (or should be made). # #=============================================================================== # Updates # ----------------------------------------------------------------------------- # o 2010.05.24 - Started Script and Finished. #=============================================================================== # Instructions # ----------------------------------------------------------------------------- # To install this script, open up your script editor and copy/paste this script # to an open slot below ▼ Materials but above ▼ Main. Remember to save. # # Iconview only appears in testplay mode. If for some reason your game does not # use the command window in the title screen, there is an alternative way of # entering the Iconview scene by pressing F9 at the title screen. #===============================================================================
$imported = {} if $imported == nil $imported["IconviewMelody"] = true
module YEM module ICONVIEW # If for some reason you wish to change the name of the command that # appears on the title screen, edit this constant. COMMAND_NAME = "IconView" end # ICONVIEW end # YEM
#=============================================================================== # Editting anything past this point may potentially result in causing computer # damage, incontinence, explosion of user's head, coma, death, and/or halitosis. # Therefore, edit at your own risk. #===============================================================================
#=============================================================================== # Window_Command #===============================================================================
class Window_Command < Window_Selectable #-------------------------------------------------------------------------- # public instance variables #-------------------------------------------------------------------------- attr_accessor :commands attr_accessor :item_max end # Window_Command
#=============================================================================== # Window_Iconview #===============================================================================
class Window_Iconview < Window_Selectable #-------------------------------------------------------------------------- # public instance variables #-------------------------------------------------------------------------- attr_accessor :max_pages attr_accessor :page attr_accessor :image #-------------------------------------------------------------------------- # initialize #-------------------------------------------------------------------------- def initialize super(Graphics.width - 416, 0, 416, 416) self.z += 1 @item_max = 256 @column_max = 16 @page = @index = @spacing = 0 @image = Cache.system("IconSet") @max_pages = (@image.height / 384.0).ceil @icon_sprite = Sprite.new @icon_sprite.bitmap = Bitmap.new(384, 384) @icon_sprite.x = self.x + 16 @icon_sprite.y = self.y + 16 @icon_sprite.z = self.z - 1 self.opacity = self.back_opacity = 0 refresh end #-------------------------------------------------------------------------- # dispose #-------------------------------------------------------------------------- def dispose @icon_sprite.bitmap.dispose @icon_sprite.dispose super end #-------------------------------------------------------------------------- # update #-------------------------------------------------------------------------- def update super return unless @max_pages > 1 if Input.repeat?(Input::L) Sound.play_cursor image_page_up elsif Input.repeat?(Input::R) Sound.play_cursor image_page_down end end #-------------------------------------------------------------------------- # refresh #-------------------------------------------------------------------------- def refresh @icon_sprite.bitmap.dispose @icon_sprite.bitmap = Bitmap.new(384, 384) rect = Rect.new(0, @page * 384, 384, 384) @icon_sprite.bitmap.blt(0, 0, @image, rect) end #-------------------------------------------------------------------------- # cursor_down #-------------------------------------------------------------------------- def cursor_down(wrap) if @index < 240 @index += 16 elsif wrap @index -= 240 end end #-------------------------------------------------------------------------- # cursor_up #-------------------------------------------------------------------------- def cursor_up(wrap) if @index >= 16 @index -= 16 elsif wrap @index += 240 end end #-------------------------------------------------------------------------- # cursor_right #-------------------------------------------------------------------------- def cursor_right(wrap) if @index % 16 < 15 @index += 1 elsif wrap @index -= 15 end end #-------------------------------------------------------------------------- # cursor_left #-------------------------------------------------------------------------- def cursor_left(wrap) if @index % 16 > 0 @index -= 1 elsif wrap @index += 15 end end #-------------------------------------------------------------------------- # image_page_up #-------------------------------------------------------------------------- def image_page_up @page = @page == 0 ? @max_pages - 1 : @page - 1 refresh end #-------------------------------------------------------------------------- # image_page_down #-------------------------------------------------------------------------- def image_page_down @page = @page == @max_pages - 1 ? 0 : @page + 1 refresh end end # Window_Iconview
#=============================================================================== # Window_IconPageList #===============================================================================
class Window_IconPageList < Window_Selectable #-------------------------------------------------------------------------- # initialize #-------------------------------------------------------------------------- def initialize(icon_window) @icon_window = icon_window super(0, 128, Graphics.width-@icon_window.width, @icon_window.height-128) self.active = false self.index = 0 refresh end #-------------------------------------------------------------------------- # refresh #-------------------------------------------------------------------------- def refresh @item_max = @icon_window.max_pages create_contents for i in 0...@item_max; draw_item(i); end end #-------------------------------------------------------------------------- # draw_item #-------------------------------------------------------------------------- def draw_item(index) rect = item_rect(index) self.contents.clear_rect(rect) text = sprintf("Page%d", index+1) self.contents.draw_text(rect, text, 1) end #-------------------------------------------------------------------------- # update #-------------------------------------------------------------------------- def update super if self.index != @icon_window.page self.index = @icon_window.page end end end # Window_IconPageList
#=============================================================================== # Window_Icondata #===============================================================================
class Window_Icondata < Window_Base #-------------------------------------------------------------------------- # initialize #-------------------------------------------------------------------------- def initialize(iconview_window) @iconview_window = iconview_window super(0, 0, Graphics.width - @iconview_window.width, 128) end #-------------------------------------------------------------------------- # refresh #-------------------------------------------------------------------------- def refresh self.contents.clear text = 256 * @iconview_window.page + @iconview_window.index text = sprintf("ID:%d", text) self.contents.draw_text(0, WLH*0, contents.width, WLH, text, 1) text = @iconview_window.image.height / 24 * 16 text = sprintf("Total:%d", text) self.contents.draw_text(0, WLH*1, contents.width, WLH, text, 1) text = "L:PageUp" self.contents.draw_text(0, WLH*2, contents.width, WLH, text, 1) text = "R:PageDn" self.contents.draw_text(0, WLH*3, contents.width, WLH, text, 1) end #-------------------------------------------------------------------------- # update #-------------------------------------------------------------------------- def update super if @last_index != @iconview_window.index or @last_page != @iconview_window.page @last_index = @iconview_window.index @last_page = @iconview_window.page refresh end end end # Window_Icondata
#=============================================================================== # Scene_Title #===============================================================================
class Scene_Title < Scene_Base
#-------------------------------------------------------------------------- # alias method: create_command_window #-------------------------------------------------------------------------- alias create_command_window_iconview create_command_window unless $@ def create_command_window create_command_window_iconview return unless $TEST return if @command_window == nil @command_window.commands.push(YEM::ICONVIEW::COMMAND_NAME) @command_window.item_max += 1 @command_window.create_contents @command_window.height += 24 @command_window.y -= 24 @command_window.refresh x = @command_window.commands.index(Vocab.continue) @command_window.draw_item(x, false) unless @continue_enabled end #-------------------------------------------------------------------------- # alias method: update #-------------------------------------------------------------------------- alias update_iconview update unless $@ def update text = YEM::ICONVIEW::COMMAND_NAME if (Input.trigger?(Input::C) and @command_window != nil and @command_window.commands[@command_window.index] == text) or Input.press?(Input::F9) command_iconview else update_iconview end end #-------------------------------------------------------------------------- # new method: command_iconview #-------------------------------------------------------------------------- def command_iconview return unless $TEST Sound.play_decision $scene = Scene_Iconview.new end end # Scene_Title
#=============================================================================== # Scene_Iconview #===============================================================================
class Scene_Iconview < Scene_Base #-------------------------------------------------------------------------- # start #-------------------------------------------------------------------------- def start super create_menu_background @iconview_window = Window_Iconview.new dx = @iconview_window.x dy = @iconview_window.y dw = @iconview_window.width dh = @iconview_window.height @dummy_window = Window_Base.new(dx, dy, dw, dh) @data_window = Window_Icondata.new(@iconview_window) @page_window = Window_IconPageList.new(@iconview_window) end #-------------------------------------------------------------------------- # terminate #-------------------------------------------------------------------------- def terminate super dispose_menu_background @iconview_window.dispose @dummy_window.dispose @data_window.dispose @page_window.dispose end #-------------------------------------------------------------------------- # update #-------------------------------------------------------------------------- def update super update_menu_background @iconview_window.update @data_window.update @page_window.update if Input.trigger?(Input::B) Sound.play_cancel $scene = Scene_Title.new end end end # Scene_Iconview
#=============================================================================== # # END OF FILE # #=============================================================================== Deuxième scriptsAuteur: modern algebra Ce script permet de faire encore plus de choses que de mettre un simple icon dans ses textes xD. Comme le nom d'un variable, d'un actor etc... Mais ce qui nous intéresses c'est le code de l'icon, qui est: - Code:
-
\ic[x] X est à remplacer par le numéro de votre icon La marche à suivre est aussi simple que ça: Le script - Code:
-
#============================================================================== # Global Text Codes # Version: 1.0 # Author: modern algebra (rmrk.net) # Date: December 8, 2009 #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # Description: # # This script allows you to use some of the special message codes in any # window or scene. Want to bold the name of the lead actor or colour the name # of special skills? You can do that with this script. For a full list of the # codes you can use and what they do, look at the instructions. You can also # create your own replacement codes with a minimum of scripting knowledge # through a simple interface. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # Instructions: # # All you need to do is put the script in the editor above Main and below # your default scripts and it should work. You can now use the following # codes in most windows (unless they parse texts out character by character # before drawing, as Window_Message does. You would need a custom message # system if you wanted to change that). But it would work in things like item # windows, the menu generally, shops and so on - everywhere there is a # bitmap pretty much. Again, a significant exception is Window_Message and # other custom scripts that already have a similar feature, such as my Diary # script. Anyway, the codes that can be used from the getgo are: # \v[x] - Shows the value located in the variable x # \n[x] - Shows the name of the Actor with ID x # \c[x] - Changes the colour of the text to x. x can be 0 - 31 # \pid[x] - Shows Actor ID of Party Member in position X (0-3) # \nc[x]- Shows the name of class with ID x # \np[x]- Shows the name of the Party Member with index x # \ne[x]- Shows the name of Event with ID x on the map # \nm[x]- Shows the name of Monster with ID x # \ni[x]- Shows the name of Item with ID x # \nw[x]- Shows the name of Weapon with ID x # \na[x]- Shows the name of Armour with ID x # \pi[x]- Shows the price of Item with ID x # \pw[x]- Shows the price of Weapon with ID x # \pa[x]- Shows the price of Armour with ID x # \iicon[x] - Shows the Icon of Item with ID x # \wicon[x] - Shows the Icon of Weapon with ID x # \aicon[x] - Shows the Icon of Armour with ID x # \icon[x] - Shows the Icon with ID x # \fn[font name] - Changes the font to font name chosen # \fs[x] - Changes the font size to x # \vocab[value] - prints vocab for that item type. Suitable values for this # are: level, level_a, hp, hp_a, mp, mp_a, atk, def, spi, # agi, weapon, armor1, armor2, armor3, armor4, weapon1, # weapon2, attack, skill, guard, item, equip, status, save, # game_end, fight, escape, new_game, shutdown, to_title, # continue, cancel, gold # \f[key] - Show Filter phrase attached to key # \b - Toggles Bold # \i - Toggles Italic # \u - Toggles Underline # \s - Toggles Shadow # \ac[x]- Shows class of actor with ID x # \a..[x] - Shows the .. of Actor X. .. can be any of the following: # hp, maxhp, mp, maxmp, atk, def, spi, agi, exp_s, next_exp_s, # next_rest_exp_s, level, weapon_id, armor1_id, armor2_id, # armor3_id, armor4_id - and any other methods from Game_Actor. # \Gold - shows current gold of party # # The filters can be set at line 82 # You can also create your own replacement codes, though it is a little # complicated. To see how, go to like 91 #==============================================================================
#============================================================================== # *** MA GLOBAL CODES #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # This module is used for configuring the settings for the script. It also # interprets and saves the special user-defined replacement codes. #==============================================================================
module MA_GlobalCodes #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # * CONSTANTS #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ FILTERS = { # FILTERS allows you to set a filter and replace any \F[x] code with it's # corresponding Entry in the Hash. Leave the FILTERS = {} line alone and # below it, you can set all of the codes you will want to be able to put # as an argument in the \F code. 'PF3' => '\c[1]Paragraph Formatter\c[0], Version 2.0: Formatter_3', 0 => 'Numbered filters work too' } USER_CODES = { #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Here you can create your own special codes for your own nefarious # purposes. The format is: # "code" => ["replacement", "arguments"] # This can probably be understood best by comparing it to codes you already # know of (and are included. Take, for instance the variable code: # \V[x] # shows the value of variable with ID x. # If that were being added as a user code, then the code would be: # "V" => [$game_variables[~1~], "%d"] # # So, the first part,"code", is what goes after the "" for the code to be # identified. The "replacement" is what that code is replaced with when it # appears, and the "arguments" are what goes in the brackets that are then # used in the replacement by identifying where they go with the ~x~ codes, # where x is a digit referring to what comes first. The codes for the # arguments are: # %d - this means that the argument must be a number # %w - this includes all word characters, including numbers. Thus, it # would be ideal if you need filenames for arguments, for instance. # %. - this accepts any type of character, including whitespace # # Thus to put this in more concrete terms, a code like the following: # "LX" => ["3*~1~ + 5*~2~", "%d%d"] # would correspond to the code: # \LX[x, y], where x and y are numbers # and would be replaced with the result of the evaluation of # 3*x + 5*y # It's obviously, a useless code, but hopefully that is a reasonable example. # Also, if you don't need any arguments, you can write simply: # "code" => "replacement" #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # The two following codes are additional examples # \VM[x, y] would be replaced by the product of variable x and variable y "VM" => ["$game_variables[~1~]*$game_variables[~2~]", "%d%d"], # \GOLD would be replaced by the amount of gold the party currently has "GOLD" => "$game_party.gold" } #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # * User Code # key : the key to check #`````````````````````````````````````````````````````````````````````````` # This method interprets and saves appropriate coding, thus avoiding # repetitious interpretation. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def self.user_code (key) @interpreted_hash = {} if @interpreted_hash.nil? if @interpreted_hash[key].nil? value = USER_CODES[key] return "", nil if value.nil? if value.is_a? (Array) # Get correct replacement value replacement = value[0].dup args = value[1].dup # Put arguments into the replacement i = 1 while i < args.size ext = args[i, 1] == "d" ? "i" : "s" replacement.sub! (/~(#{(i + 1) / 2})~/) { "$#{$1.to_i}.to_#{ext}" } i += 2 end args.gsub! (/%d/) { "(-?\\d+?),\\s*?" } args.gsub! (/%w/) { "(\\w+?),\\s*?" } args.gsub! (/%\./) { "(.+?),\\s*?" } args.slice! (-5, 5) @interpreted_hash[key] = [replacement, args] else @interpreted_hash[key] = [value, nil] end end return *@interpreted_hash[key] end end
#============================================================================== # ** Bitmap #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ # Summary of Changes: # aliased method - draw_text # new methods - convert_special_characters; perform_substitution; # execute_special_code #==============================================================================
class Bitmap #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # * Draw Text #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ alias malgr_glbl_msgcdes_drwtxt_8kf2 draw_text def draw_text (*args) # Retrieve Arguments if args[0].is_a? (Rect) tx, ty, tw, th = args[0].x, args[0].y, args[0].width, args[0].height string = args[1].to_s.dup align = args[2].nil? ? 0 : args[2] else tx, ty, tw, th = *args[0, 4] string = args[4].to_s.dup align = args[5].nil? ? 0 : args[5] end text = convert_special_characters (string) text, codes, indices, icon_count = extract_special_codes (text) if codes.empty? # Underline if @underline uy = ty + self.font.size + (Window_Base::WLH - self.font.size) / 2 ul_lngth = [tw, self.text_size (text)].min tx += align == 1 ? (tw - ul_lngth) / 2 : align == 2 ? (tw - ul_lngth) : 0 self.fill_rect (tx, uy, ul_lngth, 2, self.font.color) end # Run original method exactly if there are no special codes malgr_glbl_msgcdes_drwtxt_8kf2 (tx, ty, tw, th, text, align) else i = 0 room_w = tw - (24*icon_count) ts = self.text_size (text).width if ts < room_w && align != 0 tx += align == 1 ? (room_w - ts) / 2 : room_w - ts end room_w = [tw.to_f / room_w.to_f, 1.0].min while !codes.empty? code = codes.shift j = indices.shift if i != j txt = text[i, j-i] rw = (self.text_size (txt).width*room_w).to_i if @underline uy = ty + self.font.size + (Window_Base::WLH - self.font.size) / 2 self.fill_rect (tx, uy, rw, 2, self.font.color) end # Run Original Method on portion malgr_glbl_msgcdes_drwtxt_8kf2 (tx, ty, rw, th, txt) tx += rw end tx = execute_special_code (tx, ty, code) i = j end return if i == text.size - 1 txt = text[i, text.size - i] rw = (self.text_size (txt).width*room_w).to_i if @underline uy = ty + self.font.size + (Window_Base::WLH - self.font.size) / 2 self.fill_rect (tx, uy, rw, 2, self.font.color) end # Run Original Method on final portion malgr_glbl_msgcdes_drwtxt_8kf2 (tx, ty, rw, th, txt) end end #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # * Execute Special Code # x, y : coordinates for execution # code : code to be executed #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def execute_special_code (x, y, code) case code[0,1] when "\x01" # Colour code[/<(#?[\dABCDEF]+)>/i] if $1.include? ("#") r, g, b = $1[1, 2].to_i (16), $1[3, 2].to_i (16), $1[5, 2].to_i (16) self.font.color = Color.new (r, g, b) else wx = 64 + ($1.to_i % 8) * 8 wy = 96 + ($1.to_i / 8) * 8 windowskin = Cache.system ("Window") self.font.color = windowskin.get_pixel(wx, wy) end when "\x02" code[/<(\d+)>/] bitmap = Cache.system("Iconset") rect = Rect.new($1.to_i % 16 * 24, $1.to_i / 16 * 24, 24, 24) self.blt(x, y, bitmap, rect, 255) x += 24 when "\x03" then self.font.bold = !self.font.bold # Bold when "\x04" then self.font.italic = !self.font.italic # Italic when "\x05" then self.font.shadow = !self.font.shadow # Shadow when "\x06" then @underline = !@underline # Underline when "\x09" # Change Font Name code[/<(.*?)>/] self.font.name = $1.to_s if Font.exist? ($1.to_s) when "\x10" # Change Font Size code[/<(\d*)>/] self.font.size = $1.to_i end return x end #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # * Convert Special Characters # text : the text to convert #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def convert_special_characters (text) return "" if text == nil text = perform_substitution (text) # Get substitutions text.gsub! (/\\C\[(\d+)\]/i) { "\x01<#{$1.to_i}>" } # Palette Color text.gsub! (/\\C\[#([\dABCDEF]+)\]/i) { "\x01<##{$1.to_s}>" } # Hex Color text.gsub! (/\\IIC?O?N?\[(\d+)\]/i) { $1.to_i.between? (1, $data_items.size - 1) ? "\x02<#{$data_items[$1.to_i].icon_index}>" : "" } # Item Icon text.gsub! (/\\WIC?O?N?\[(\d+)\]/i) { $1.to_i.between? (1, $data_weapons.size - 1) ? "\x02<#{$data_weapons[$1.to_i].icon_index}>" : "" } # Weapon Icon text.gsub! (/\\AIC?O?N?\[(\d+)\]/i) { $1.to_i.between? (1, $data_armors.size - 1) ? "\x02<#{$data_armors[$1.to_i].icon_index}>" : "" } # Armor Icon text.gsub! (/\\IC?O?N?\[(\d+)\]/i) { "\x02<#{$1.to_s}>" } # Icon text.gsub! (/\\B/i) { "\x03" } # Bold text.gsub! (/\\I/i) { "\x04" } # Italic text.gsub! (/\\S/i) { "\x05" } # Shadow text.gsub! (/\\U/i) { "\x06" } # Underline text.gsub! (/\\FN\[(.+?)\]/i) { "\x09<#{$1.to_s}>" } # Font Name text.gsub! (/\\FS\[(\d+)\]/i) { "\x10<#{$1.to_s}>" } # Font Size return text end #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # * Perform Substitution #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def perform_substitution (text = @string) text.gsub!(/\\V\[([0-9]+)\]/i) { $game_variables[$1.to_i] } # Variable # FILTERS text.gsub!(/\\F\[["'](.+?)["']\]/i) { MA_GlobalCodes::FILTERS[$1.to_s] } text.gsub!(/\\F\[(.+?)\]/i) { MA_GlobalCodes::FILTERS[$1.to_i] } # Party ID to Actor ID text.gsub!(/\\PID\[(\d+)\]/i) { $game_party.members[$1.to_i].id } # Old Codes text.gsub!(/\\N\[([0-9]+)\]/i) { $1.to_i > 0 ? $game_actors[$1.to_i].name : ""} # Actor Name # New Codes begin text.gsub! (/\\VOCAB\[(\w+)\]/i) { Vocab.send ($1.downcase) } # Vocab rescue end text.gsub! (/\\AC\[(\d+)\]/i) { $game_actors[$1.to_i].class.name } # Actor Class # Actor Stats begin text.gsub! (/\\A([^\[]+?)\[(\d+)\]/i) { $game_actors[$2.to_i].send ($1.to_s.downcase) } rescue end text.gsub! (/\\NC\[(\d+)\]/i) { $1.to_i > 0 ? $data_classes[$1.to_i].name : "" } # Class Name text.gsub! (/\\NE\[(\d+)\]/i) { $1.to_i > 0 ? $game_map.events[$1.to_i].name : "" } # Event Name text.gsub! (/\\NM\[(\d+)\]/i) { $1.to_i > 0 ? $data_enemies[$1.to_i].name : "" } # Monster Name text.gsub! (/\\NI\[(\d+)\]/i) { $1.to_i > 0 ? $data_items[$1.to_i].name : "" } # Item Name text.gsub! (/\\NW\[(\d+)\]/i) { $1.to_i > 0 ? $data_weapons[$1.to_i].name : "" } # Weapon Name text.gsub! (/\\NA\[(\d+)\]/i) { $1.to_i > 0 ? $data_armors[$1.to_i].name : "" } # Armor Name text.gsub! (/\\PI\[(\d+)\]/i) { $1.to_i > 0 ? $data_items[$1.to_i].price.to_s : "" } # Item Price text.gsub! (/\\PW\[(\d+)\]/i) { $1.to_i > 0 ? $data_weapons[$1.to_i].price.to_s : "" } # Weapon Price text.gsub! (/\\PA\[(\d+)\]/i) { $1.to_i > 0 ? $data_armors[$1.to_i].price.to_s : "" } # Armor Price # Parse custom replacement codes MA_GlobalCodes::USER_CODES.keys.each { |key| replacement, args = MA_GlobalCodes.user_code (key) if args != nil begin text.gsub! (/\\#{key}\[#{args}\]/i) { eval (replacement) } rescue end else begin text.gsub! (/\\#{key}/i) { eval (replacement) } rescue end end } text.gsub! (/\\V\[([0-9]+)\]/i) { $game_variables[$1.to_i] } # Variable text.gsub! (/\\\\/) { "\" } return text end #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # * No Argument Codes #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def no_args_codes return ["\x03", "\x04", "\x05", "\x06"] end #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # * Argument Codes #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def args_codes return ["\x01", "\x02", "\x09", "\x10"] end #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # * Extract Special Codes #`````````````````````````````````````````````````````````````````````````` # This parses the text and removes the special codes, while retaining # their position in order to be inserted when the time comes. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ def extract_special_codes (text) codes = [] code_indices = [] icon_count = 0 i = 0 while i < text.size # Work from the end of the string c = text[i, 1] if no_args_codes.include? (c) text.sub!(c, "") codes.push (c) code_indices.push (i) elsif args_codes.include? (c) a = text.sub! (/(#{c}<.*?>)/, "") # If nothing is replaced if a == nil i += 1 else codes.push ($1) code_indices.push (i) icon_count += 1 if c == "\x02" end else i += 1 end end return text, codes, code_indices, icon_count end end Enjoy's |
|