Menu
Eclipso logo
Merry Christmas !
25/04/2024 08:16:36

Faire, chercher, persévérer et s'appliquer sont les verbes du maker - lidenvice

Modification script balloon pour RPG MAKER XP. (Résolu)

Delta

Star
Delta
  • Messages : 2420

Modification script balloon pour RPG MAKER XP. (Résolu)


mer. 02 juil. 2014 - 01h12

Voilà sur un nouveau projet je souhaite utiliser le script balloon de MoonPearl seulement voilà j'utilise des character Ragnarok online plus grand de 50 qu'un chara normal du coup je souhaitais déplacer la bulle. J'ai modifier aux lignes 50 en enlevant 50 [code] y = (y / 32 * SPACING_BALLOON_TEXT)- 50[/code] et également à la ligne 256 [code] viewport = Viewport.new(0, -50, 640, 480)[/code] Cependant voilà les 50 premiers pixels du texte ne se voient pas. J'ai enlevé des 50 pixels à tous les y mais soit cela ne fait rien, soit c'est le window qui bugue. Voilà un screen : [img]http://img104.xooimage.com/files/b/e/d/essai-467afde.png[/img] [img]http://img106.xooimage.com/files/8/c/0/essai2-467afe6.png[/img] Et les ressouces à mettre dans un dossier balloonskins à renommer 000.png [img]http://img107.xooimage.com/files/9/d/1/000-467b01e.png[/img] [code]# Game variables IDs # Variable holding the event ID to which anchor the balloon VAR_EVENT_ID_ANCHOR = 2 # Variable holding the ID of the balloonskin to be used VAR_BALLOONSKIN = 3 # Variable holding the ID of the current processing event VAR_CURRENT_EVENT_ID = 4 # Game switches IDs # Switch enabling ballon display SW_ENABLE_BALLOONS = 2 # Switch enabling message skip (mainly to display multiple balloons at once) SW_MESSAGE_SKIP = 3 # Default font for balloon text FONT_BALLOON_TEXT = Font.new(Font.default_name, 16) # Edit the following line for your own custom font, or remove it to keep the default # FONT_BALLOON_TEXT = Font.new("OdaBalloon", 12) # Edit the following line to custom the spacing between lines, or keep as is for # automatic calculation SPACING_BALLOON_TEXT = 32 - (Font.default_size - FONT_BALLOON_TEXT.size) * 2 # Specify whether you want lines cut in two for more square-shaped balloons CUT_LINES_IN_TWO = true # Max number of characters per line for smart line cutting (changing not # recommended) MAX_CHARACTERS_PER_LINE = 25 # For each balloonskin, number of frames needed to complete a blinking cycle # Input nil to disable blinking for that balloonskin FRAMES_BALLOON_BLINK = { "000" => 40, "001" => 80, "002" => 20 } # Number of frames for the waiting sprite to animate FRAMES_BALLOON_WAIT = 20 # Bubbles opacity OPACITY_BALLOON = 192 # Right padding to avoid last character being out of the frame PADDING_RIGHT = 16 # Setting this to false will cause small latencies upon using a balloonskin for # the first time, because they need prior treatment before the can be used. # Setting this to true makes the game compile all balloonskins upon launching # the game, which avoids latencies in-game but causes latencies when the # game starts. PRECOMPILE_BALLOONSKINS = false#true module RPG module Cache def self.balloonskin(filename) self.load_bitmap("Graphics/Balloonskins/", filename) end end end class Bitmap def trim(start_x, start_y, w, mask) x = 0 y = 0 for i in 0...mask.size if mask[i] self.set_pixel(start_x + x, start_y + y, Color::TRANSPARENT) end x += 1 if x == w x = 0 y += 1 end end return self end end class Color TRANSPARENT = Color.new(0, 0, 0, 0) end class Balloon_Bitmap < Bitmap def initialize(width, height) super(width, height) self.font = FONT_BALLOON_TEXT end def draw_text(x, y, width, height, text, align = 0) y = (y / 32 * SPACING_BALLOON_TEXT)- 50 super(x, y, width, height, text, align) end end class Interpreter alias mp_balloon_setup setup def setup(list, event_id) mp_balloon_setup(list, event_id) $game_variables[VAR_CURRENT_EVENT_ID] = event_id unless event_id == 0 end alias mp_balloon_initialize initialize def initialize(depth = 0, main = false) mp_balloon_initialize(depth, main) @balloon_windows = [] end alias mp_balloon_update update def update mp_balloon_update for window in @balloon_windows.clone window.update if window.terminated window.dispose @balloon_windows.delete(window) end end end #-------------------------------------------------------------------------- # * Show Text #-------------------------------------------------------------------------- alias mp_balloon_command_101 command_101 def command_101 return false if @message_waiting if $game_switches[SW_ENABLE_BALLOONS] # Set message end waiting flag and callback #@message_waiting = true @message_waiting = !$game_switches[SW_MESSAGE_SKIP] window = Window_Balloon.new window.message_proc = Proc.new { @message_waiting = false } @balloon_windows << window # Set message text on first line text = @list[@index].parameters[0] + "\n" line_count = 1 # Loop loop do # If next event command text is on the second line or after if @list[@index+1].code == 401 # Add the second line or after to message_text text += @list[@index+1].parameters[0] + "\n" line_count += 1 # If event command is not on the second line or after else window.set_message(text) return true end @index += 1 end end return mp_balloon_command_101 end end module Balloonskin TOP = 1 BOTTOM = 2 LEFT = 4 RIGHT = 8 TOP_LEFT = 16 TOP_RIGHT = 32 BOTTOM_LEFT = 64 BOTTOM_RIGHT = 128 COLOR_TRANSPARENT = Color.new(0, 0, 0, 0) @masks = {} @width = {} @height = {} class << self attr_reader :width attr_reader :height def compile(balloonskin_name) # Load bitmap @bitmap = RPG::Cache.balloonskin(balloonskin_name) # Compute cell width and height w = @width[balloonskin_name] = @bitmap.width >> 3 h = @height[balloonskin_name] = @bitmap.height / 3 # Compute cells cells = [] for i in 0...4 a = [] for j in 0...3 a << Rect.new(i * w, j * h, w, h) end cells << a end # Compute masks masks = [] masks << make_mask(cells[0][0], [[0, 0]]) masks << make_mask(cells[1][0], [[0, 0], [w - 1, 0]]) masks << make_mask(cells[2][0], [[0, 0], [w - 1, 0]]) masks << make_mask(cells[3][0], [[w - 1, 0]]) masks << make_mask(cells[0][1], [[0, 0], [0, h - 1]]) masks << make_mask(cells[1][1], [[0, 0], [w - 1, 0], [0, h - 1], [w - 1, h - 1]]) masks << make_mask(cells[2][1], [[0, 0], [w - 1, 0], [0, h - 1], [w - 1, h - 1]]) masks << make_mask(cells[3][1], [[w - 1, 0], [w - 1, h - 1]]) masks << make_mask(cells[0][2], [[0, h - 1]]) masks << make_mask(cells[1][2], [[0, h - 1], [w - 1, h - 1]]) masks << make_mask(cells[2][2], [[0, h - 1], [w - 1, h - 1]]) masks << make_mask(cells[3][2], [[w - 1, h - 1]]) return @masks[balloonskin_name] = masks end def make_mask(cell, to_process) start_x = cell.x start_y = cell.y w = cell.width w1 = cell.width - 1 h1 = cell.height - 1 processed = Bitmask.new(w * cell.height) mask = Bitmask.new(w * cell.height) max = 0 until to_process.empty? x, y = to_process.shift i = y * w + x max = [max, i].max if @bitmap.get_pixel(start_x + x, start_y + y).alpha != 255 if x != 0 to_process << [x - 1, y] if not processed[i - 1] and not to_process.include?([x - 1, y]) end if x != w1 to_process << [x + 1, y] if not processed[i + 1] and not to_process.include?([x + 1, y]) end if y != 0 to_process << [x, y - 1] if not processed[i - w] and not to_process.include?([x, y - 1]) end if y != h1 to_process << [x, y + 1] if not processed[i + w] and not to_process.include?([x, y + 1]) end mask[i] = true end processed[i] = true end mask.resize(max) return mask end def mask(balloonskin_name, n) if @masks[balloonskin_name].nil? compile(balloonskin_name) end return @masks[balloonskin_name][n] end end if PRECOMPILE_BALLOONSKINS for entry in Dir.entries("Graphics/Balloonskins") next if entry == "." or entry == ".." self.compile(entry.split(".").first) # Update graphics to prevent script hanging error Graphics.update end end def balloonskin_initialize # Make viewport viewport = Viewport.new(0, -50, 640, 480) # Make skin sprite @skin = Sprite.new(viewport) # Make border sprite @border = Sprite.new(viewport) @border.color = Color.new(255, 255, 255, 0) # Make waiting sprite @sprite_wait = Sprite.new(viewport) @sprite_wait.visible = false @wait_count = 0 @blink_count = 0 end def balloonskin_name=(name) @balloonskin_name = name bitmap = RPG::Cache.balloonskin(name) @sprite_wait.bitmap = bitmap @wait_rect = [ Rect.new(bitmap.width * 7 / 8, 0, bitmap.width / 16, bitmap.height / 6), Rect.new(bitmap.width * 15 / 16, 0, bitmap.width / 16, bitmap.height / 6), Rect.new(bitmap.width * 7 / 8, bitmap.height / 6, bitmap.width / 16, bitmap.height / 6), Rect.new(bitmap.width * 15 / 16, bitmap.height / 6, bitmap.width / 16, bitmap.height / 6) ] @wait_rect_index = 3 end def render_balloonskin # Load skin bitmap bitmap = RPG::Cache.balloonskin(@balloonskin_name) # Compute cell width and height w = bitmap.width >> 3 h = bitmap.height / 3 # Compute cells cells = [] for i in 0...4 a = [] for j in 0...3 a << Rect.new(i * w, j * h, w, h) end cells << a end # Dispose graphics if previously rendered @skin.bitmap.dispose if @skin.bitmap @border.bitmap.dispose if @border.bitmap # Adjust position @skin.oy = @border.oy = h # Make skin bitmap @skin.bitmap = Bitmap.new(self.width, self.height + 2 * h) @skin.bitmap.stretch_blt(@skin.bitmap.rect, bitmap, Rect.new(4 * w, 0, 3 * w, 3 * h)) # Clear outside corners @skin.bitmap.fill_rect(0, 0, w, h, Color::TRANSPARENT) @skin.bitmap.fill_rect(self.width - w, 0, w, h, Color::TRANSPARENT) @skin.bitmap.fill_rect(0, self.height + h, w, h, Color::TRANSPARENT) @skin.bitmap.fill_rect(self.width - w, self.height + h, w, h, Color::TRANSPARENT) # Make border bitmap @border.bitmap = Bitmap.new(self.width, self.height + 2 * h) # Draw upper-left corner @skin.bitmap.trim(0, h, w, mask(0)) @border.bitmap.blt(0, h, bitmap, cells[0][0]) # Draw upper-right corner @skin.bitmap.trim(self.width - w, h, w, mask(3)) @border.bitmap.blt(self.width - w, h, bitmap, cells[3][0]) # Draw lower-left corner @skin.bitmap.trim(0, self.height, w, mask(8)) @border.bitmap.blt(0, self.height, bitmap, cells[0][2]) # Draw lower-right corner @skin.bitmap.trim(self.width - w, self.height, w, mask(11)) @border.bitmap.blt(self.width - w, self.height, bitmap, cells[3][2]) # Draw left side for i in 2..self.height / h - 1 y = i * h @skin.bitmap.trim(0, y, w, mask(4)) @border.bitmap.blt(0, y, bitmap, cells[0][1]) end # Draw right side x = self.width - w for i in 2..self.height / h - 1 y = i * h @skin.bitmap.trim(x, y, w, mask(7)) @border.bitmap.blt(x, y, bitmap, cells[3][1]) end # Compute where to put the tail for i in 1..self.width / w - 2 x_quote = i if @event.real_x / 4 - $game_map.display_x / 4 < self.x + i * w break end end # Draw lower side y = self.height for i in 1..self.width / w - 2 x = i * w if @event.real_y / 4 - 32 - $game_map.display_y / 4 > self.y if i == x_quote @skin.bitmap.trim(x, y, w, mask(10)) @border.bitmap.blt(x, y, bitmap, cells[2][2]) @skin.bitmap.trim(x, y + h, w, mask(5)) @border.bitmap.blt(x, y + h, bitmap, cells[1][1]) next end end @skin.bitmap.trim(x, y, w, mask(9)) @border.bitmap.blt(x, y, bitmap, cells[1][2]) @skin.bitmap.fill_rect(x, y + h, w, h, Color::TRANSPARENT) end # Draw upper side y = h for i in 1..self.width / w - 2 x = i * w if @event.real_y / 4 - 32 - $game_map.display_y / 4 < self.y if i == x_quote @skin.bitmap.trim(x, y, w, mask(2)) @border.bitmap.blt(x, y, bitmap, cells[2][0]) @skin.bitmap.trim(x, 0, w, mask(6)) @border.bitmap.blt(x, 0, bitmap, cells[2][1]) next end end @skin.bitmap.trim(x, y, w, mask(1)) @border.bitmap.blt(x, y, bitmap, cells[1][0]) @skin.bitmap.fill_rect(x, 0, w, h, Color::TRANSPARENT) end end def mask(n) return Balloonskin.mask(@balloonskin_name, n) end def dispose @skin.bitmap.dispose @skin.dispose @border.bitmap.dispose @border.dispose @sprite_wait.dispose super end def x=(x) @sprite_wait.x = x + self.width - 32 @skin.x = @border.x = super(x) end def y=(y) @sprite_wait.y = y + self.height - 32 @skin.y = @border.y = super(y) end def z=(z) @skin.z = @border.z = @sprite_wait.z = super(z) end def opacity=(opacity) @skin.opacity = @border.opacity = super(opacity) end def back_opacity=(opacity) @skin.opacity = super(opacity) end end class Window_Balloon < Window_Message include Balloonskin attr_accessor :message_proc attr_reader :terminated def initialize balloonskin_initialize super self.windowskin = nil self.opacity = OPACITY_BALLOON end def update super update_position if @sprite_wait.visible = $game_temp.message_window_showing if @wait_count == 0 @wait_rect_index += 1 @wait_rect_index %= 4 @sprite_wait.src_rect = @wait_rect[@wait_rect_index] @wait_count = FRAMES_BALLOON_WAIT end @wait_count -= 1 end if f = FRAMES_BALLOON_BLINK[@balloonskin_name] if @blink_count == 0 @blink_count = f end @border.color.alpha = (f - (2 * @blink_count - f).abs) * 128 / f @blink_count -= 1 end end def update_position down = @event.real_y / 4 - 32 - $game_map.display_y / 4 <= self.y self.y = @event.real_y / 4 + 32 - $game_map.display_y / 4 if @event.real_y / 4 - 32 - $game_map.display_y / 4 > self.height self.y -= self.height + 64 if down render_balloonskin end else unless down render_balloonskin end end self.x = [ [@event.real_x / 4 - self.width / 2 + 16 - $game_map.display_x / 4, 0].max, 640 - self.width].min #@skin.x = @border.x = self.x #@skin.y = @border.y = self.y end def set_message(text) if $game_variables[VAR_EVENT_ID_ANCHOR] == 0 @event = $game_player else @event = $game_map.events[$game_variables[VAR_EVENT_ID_ANCHOR]] end #$game_temp.choice_max text = parse_text(text) lines = text.split("\n") if CUT_LINES_IN_TWO old_lines = lines lines = [] for line in old_lines if line.size <= MAX_CHARACTERS_PER_LINE lines << line else n = line[0, MAX_CHARACTERS_PER_LINE].reverse.index(" ") n = MAX_CHARACTERS_PER_LINE - (n.nil? ? 0 : n) p = line[MAX_CHARACTERS_PER_LINE, line.size - MAX_CHARACTERS_PER_LINE].index(" ") p = line.size - n if p == nil if MAX_CHARACTERS_PER_LINE - n > p n = MAX_CHARACTERS_PER_LINE + p end lines << line[0, n] lines << line[n, line.size - n].lstrip end end text = lines.join("\n") end bitmap = Balloon_Bitmap.new(640, 480) size = 0 lines.each do |str| size = [size, bitmap.text_size(str).width + PADDING_RIGHT].max # * FONT_BALLOON_TEXT.size / Font.default_size end bitmap.dispose self.width = 32 + size self.height = 32 + (Font.default_size - FONT_BALLOON_TEXT.size) * 2 + SPACING_BALLOON_TEXT * lines.size self.contents = Balloon_Bitmap.new(size, height - 32) self.balloonskin_name = sprintf("%03d", $game_variables[VAR_BALLOONSKIN]) bitmap = RPG::Cache.balloonskin(@balloonskin_name) w = bitmap.width >> 3 h = bitmap.height / 3 # Round up width and height to avoid gaps in balloonskin if self.width % w != 0 self.width = (self.width / w + 1) * w end if self.height % h != 0 self.height = (self.height / h + 1) * h end # Displace content self.ox = (-self.width + 32 + self.contents.width) / 2 self.oy = (-self.height + 32 + self.contents.height) / 2 #self.balloonskin = RPG::Cache.balloonskin(@balloonskin_name) update_position render_balloonskin $game_temp.message_text = text @contents_showing = true $game_temp.message_window_showing = true #reset_window refresh Graphics.frame_reset self.visible = true self.contents_opacity = 0 #if @input_number_window != nil # @input_number_window.contents_opacity = 0 #end @fade_in = true $game_temp.message_text = nil end def parse_text(text) # Control text processing begin last_text = text.clone text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] } end until text == last_text text.gsub!(/\\[Nn]\[([0-9]+)\]/) do $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : "" end #-------------------------------------------------------------------------- text.gsub!(/\\[Ff]\[([ \w\=\+\-\*\/\$\(\)\!\.\,\'\:\%\@]+)\]/) { eval $1 } #-------------------------------------------------------------------------- # Change "\\\\" to "\000" for convenience text.gsub!(/\\\\/) { "\000" } # Change "\\C" to "\001" and "\\G" to "\002" text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" } text.gsub!(/\\[Gg]/) { "\002" } return text end def terminate_message $game_temp.message_proc = self.message_proc super @terminated = true # self.dispose $game_temp.message_proc = nil end def normal_color return Color.new(0, 0, 0) end #-------------------------------------------------------------------------- # * Get Text Color # n : text color number (0-7) #-------------------------------------------------------------------------- def text_color(n) case n when 0 return Color.new(0, 0, 0, 255) when 1 return Color.new(64, 64, 128, 255) when 2 return Color.new(128, 64, 64, 255) when 3 return Color.new(64, 128, 64, 255) when 4 return Color.new(64, 128, 128, 255) when 5 return Color.new(128, 64, 128, 255) when 6 return Color.new(128, 128, 64, 255) when 7 return Color.new(96, 96, 96, 255) else normal_color end end end[/code] Voilà si quelqu'un peut m'aider je voulais vraiment me démarquer au niveau des charas et des windowskins. Merci.


[size=15] Mon site perso et la démo http://deltaproduction.free-h.net/index.html Téléchargez Yggdrasil la quête du dragon de sang: (05/08/2016) 28 Heures de jeu[/size] [center][url=http://www.alexdor.info/?p=jeu&id=878][img]http://delta.comics.pagesperso-orange.fr/barre.gif[/img][/url][/center] [size=15]Nouvelle démo Sentinelles du (20/07/2016) Environ 6H de jeu[/size] [center][url=http://www.alexdor.info/?p=jeu&id=876][img]http://delta.comics.pagesperso-orange.fr/sentinelles.png[/img][/url][/center] [size=15]Nouvelle démo La Chute d'Atalanta du (18/06/2016) Environ 1H30 de jeu[/size] [center][url=http://www.alexdor.info/?p=jeu&id=874][img]http://delta.comics.pagesperso-orange.fr/Atalanta.png[/img][/url][/center]

Ssozi

Expert
Ssozi
  • Messages : 1166

Modification script balloon pour RPG MAKER XP. (Résolu)


mer. 02 juil. 2014 - 01h36

Il semblerait qu'il manque une partie du script pour que je puisse tester.. [img]http://i.gyazo.com/68026faf6b9190023e24962684d65a63.png[/img]


Delta

Star
Delta
  • Messages : 2420

Modification script balloon pour RPG MAKER XP. (Résolu)


mer. 02 juil. 2014 - 10h54

C'est ce que je me suis dis avant d'aller me coucher, il y a en effet un script supplémentaire à rajouter au dessus. Je ne peux pas te l'envoyer tout de suite, je l’envoi vers 13Heures.


[size=15] Mon site perso et la démo http://deltaproduction.free-h.net/index.html Téléchargez Yggdrasil la quête du dragon de sang: (05/08/2016) 28 Heures de jeu[/size] [center][url=http://www.alexdor.info/?p=jeu&id=878][img]http://delta.comics.pagesperso-orange.fr/barre.gif[/img][/url][/center] [size=15]Nouvelle démo Sentinelles du (20/07/2016) Environ 6H de jeu[/size] [center][url=http://www.alexdor.info/?p=jeu&id=876][img]http://delta.comics.pagesperso-orange.fr/sentinelles.png[/img][/url][/center] [size=15]Nouvelle démo La Chute d'Atalanta du (18/06/2016) Environ 1H30 de jeu[/size] [center][url=http://www.alexdor.info/?p=jeu&id=874][img]http://delta.comics.pagesperso-orange.fr/Atalanta.png[/img][/url][/center]

Delta

Star
Delta
  • Messages : 2420

Modification script balloon pour RPG MAKER XP. (Résolu)


mer. 02 juil. 2014 - 12h56

Voici le 1er script le 2eme non modifié et les ressources manquantes à mettre dans le dossier ballonskins et à renommer 001.png et 002.png [code]# ****************************************************************************** # Basic commands # part of Moonpearl's works # ****************************************************************************** VAR_TEMP = 1 # index of the temporary buffer variable SW_TEMP = 1 # index of the temporary buffer switch def temp return $game_variables[VAR_TEMP] end def set_temp(v) $game_variables[VAR_TEMP] = v return $game_variables[VAR_TEMP] end def sw_temp return $game_switches[SW_TEMP] end def set_sw_temp(v) $game_switches[SW_TEMP] = v return $game_switches[SW_TEMP] end class Object alias :display :inspect end class String def break_into_lines(amount) if self.size <= amount yield self else i = 0 until i >= self.size n = self[i, amount].reverse.index(" ") n = amount - (n.nil? ? 0 : n) yield self[i, n] i += n end end end def symbolize return :empty if self.empty? return self.downcase.gsub(" ", "_").to_sym end end class Symbol def display str = "" name = self.to_s name.split("_").each { |s| str += s.capitalize + " " } str = str.rstrip return str end def ===(other) return (self <=> other) == 0 end def >(other) case other when Numeric return nil end return (self <=> other) == 1 end def <(other) case other when Numeric return nil end return (self <=> other) == -1 end def <=>(other) return self.to_s <=> other.to_s end end class Bitmask attr_reader :size def initialize(size = 1) @data = [0] resize(size) end def [](i) if i >= @size raise RangeError, "Bit ##{i} not defined (max = #{@size - 1}) in Bitmask#[]" end return @data[i >> 5][i % 32] == 1 end def []=(i, b) case b when TrueClass, FalseClass if self[i] == b return nil else @data[i >> 5] ^= 2 ** (i % 32) return b end else raise TypeError, "TrueClass or FalseClass expected as parameters in Bitmask#[]=" end end def resize(size) while (size >> 5) >= @data.size @data << 0 end @size = size end def to_s str = String.new for i in 0...@size if i & 7 == 0 str << " " end str << @data[i >> 5][i & 31].to_s end return str end alias inspect to_s end class String def break_into_lines(amount) if self.size <= amount yield self else i = 0 until i >= self.size n = self[i, amount].reverse.index(" ") n = amount - (n.nil? ? 0 : n) yield self[i, n] i += n end end end def symbolize return :empty if self.empty? return self.downcase.gsub(" ", "_").to_sym end end # --------------------------------------- # HACKS # > Modifies the Window Message class # to add the \f[] function. # > This allows to display the result of # a script in an event message. # --------------------------------------- class Window_Message < Window_Selectable #-------------------------------------------------------------------------- # * Refresh #-------------------------------------------------------------------------- def refresh self.contents.clear self.contents.font.color = normal_color x = y = 0 @cursor_width = 0 # Indent if choice if $game_temp.choice_start == 0 x = 8 end # If waiting for a message to be displayed if $game_temp.message_text != nil text = $game_temp.message_text # Control text processing begin last_text = text.clone text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] } end until text == last_text text.gsub!(/\\[Nn]\[([0-9]+)\]/) do $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : "" end #-------------------------------------------------------------------------- text.gsub!(/\\[Ff]\[([ \w\=\+\-\*\/\$\(\)\!\.\,\'\:\%\@]+)\]/) { eval $1 } #-------------------------------------------------------------------------- # Change "\\\\" to "\000" for convenience text.gsub!(/\\\\/) { "\000" } # Change "\\C" to "\001" and "\\G" to "\002" text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" } text.gsub!(/\\[Gg]/) { "\002" } # Get 1 text character in c (loop until unable to get text) while ((c = text.slice!(/./m)) != nil) # If \\ if c == "\000" # Return to original text c = "\\" end # If \C[n] if c == "\001" # Change text color text.sub!(/\[([0-9]+)\]/, "") color = $1.to_i if color >= 0 and color <= 7 self.contents.font.color = text_color(color) end # go to next text next end # If \G if c == "\002" # Make gold window if @gold_window == nil @gold_window = Window_Gold.new @gold_window.x = 560 - @gold_window.width if $game_temp.in_battle @gold_window.y = 192 else @gold_window.y = self.y >= 128 ? 32 : 384 end @gold_window.opacity = self.opacity @gold_window.back_opacity = self.back_opacity end # go to next text next end # If new line text if c == "\n" # Update cursor width if choice if y >= $game_temp.choice_start @cursor_width = [@cursor_width, x].max end # Add 1 to y y += 1 x = 0 # Indent if choice if y >= $game_temp.choice_start x = 8 end # go to next text next end # Draw text self.contents.draw_text(4 + x, 32 * y, 40, 32, c) # Add x to drawn text width x += self.contents.text_size(c).width end end # If choice if $game_temp.choice_max > 0 @item_max = $game_temp.choice_max self.active = true self.index = 0 end # If number input if $game_temp.num_input_variable_id > 0 digits_max = $game_temp.num_input_digits_max number = $game_variables[$game_temp.num_input_variable_id] @input_number_window = Window_InputNumber.new(digits_max) @input_number_window.number = number @input_number_window.x = self.x + 8 @input_number_window.y = self.y + $game_temp.num_input_start * 32 end end end # ============================================================================== # AUTOMATIC WINDOWSKIN # ------------------------------------------------------------------------------ # Modifies the Window_Base class so that each type of window searches the # windowskin folder for a specific windowskin, selects it if found, selects # the default windowskin otherwise. # ------------------------------------------------------------------------------ # EXAMPLE: the Window_Menu will search for Windowskins/Menu.png and automatically # put it on if it exists. # ============================================================================== class Window_Base < Window def initialize(x, y, width, height) super() #-------------------------------------------------------------------------- str = type.to_s str.slice!("Window_") @windowskin_name = FileTest.exist?("Graphics/Windowskins/#{str}.png") ? str : $game_system.windowskin_name #-------------------------------------------------------------------------- self.windowskin = RPG::Cache.windowskin(@windowskin_name) self.x = x self.y = y self.width = width self.height = height self.z = 100 end def update super end end # ============================================================================== # AUTOMATIC TRANSITION # ------------------------------------------------------------------------------ # Modifies the Scene_Base class so that each type of scene searches the # transition folder for a specific transition, selects it if found, selects # the default transition otherwise. You may use a different transition for # fade-in and fade-out. # ------------------------------------------------------------------------------ # EXAMPLE: the Scene_Menu will search for Transitions/Menu.png and automatically # use it if it exists. # EXAMPLE 2: when exiting the menu, the Scene_Menu will search for # Transitions/Menu-out.png and automatically use it if it exists. # ============================================================================== class Scene_Base FRAMES_TRANSITION = 40 def main setup str = type.to_s str.slice!("Scene_") # Execute transition if FileTest.exist?("Graphics/Transitions/#{str}.png") Graphics.transition(FRAMES_TRANSITION, "Graphics/Transitions/" + str) else Graphics.transition end # Main loop while $scene == self # Update game screen Graphics.update # Update input information Input.update # Frame update update end terminate str = type.to_s str.slice!("Scene_") str += "-out" # Execute transition if FileTest.exist?("Graphics/Transitions/#{str}.png") Graphics.transition(FRAMES_TRANSITION, "Graphics/Transitions/" + str) Graphics.freeze end end end[/code] Le 2eme non modifié [code]# Game variables IDs # Variable holding the event ID to which anchor the balloon VAR_EVENT_ID_ANCHOR = 2 # Variable holding the ID of the balloonskin to be used VAR_BALLOONSKIN = 3 # Variable holding the ID of the current processing event VAR_CURRENT_EVENT_ID = 4 # Game switches IDs # Switch enabling ballon display SW_ENABLE_BALLOONS = 2 # Switch enabling message skip (mainly to display multiple balloons at once) SW_MESSAGE_SKIP = 3 # Default font for balloon text FONT_BALLOON_TEXT = Font.new(Font.default_name, 16) # Edit the following line for your own custom font, or remove it to keep the default # FONT_BALLOON_TEXT = Font.new("OdaBalloon", 12) # Edit the following line to custom the spacing between lines, or keep as is for # automatic calculation SPACING_BALLOON_TEXT = 32 - (Font.default_size - FONT_BALLOON_TEXT.size) * 2 # Specify whether you want lines cut in two for more square-shaped balloons CUT_LINES_IN_TWO = true # Max number of characters per line for smart line cutting (changing not # recommended) MAX_CHARACTERS_PER_LINE = 25 # For each balloonskin, number of frames needed to complete a blinking cycle # Input nil to disable blinking for that balloonskin FRAMES_BALLOON_BLINK = { "000" => 40, "001" => 80, "002" => 20 } # Number of frames for the waiting sprite to animate FRAMES_BALLOON_WAIT = 20 # Bubbles opacity OPACITY_BALLOON = 192 # Right padding to avoid last character being out of the frame PADDING_RIGHT = 16 # Setting this to false will cause small latencies upon using a balloonskin for # the first time, because they need prior treatment before the can be used. # Setting this to true makes the game compile all balloonskins upon launching # the game, which avoids latencies in-game but causes latencies when the # game starts. PRECOMPILE_BALLOONSKINS = false#true module RPG module Cache def self.balloonskin(filename) self.load_bitmap("Graphics/Balloonskins/", filename) end end end class Bitmap def trim(start_x, start_y, w, mask) x = 0 y = 0 for i in 0...mask.size if mask[i] self.set_pixel(start_x + x, start_y + y, Color::TRANSPARENT) end x += 1 if x == w x = 0 y += 1 end end return self end end class Color TRANSPARENT = Color.new(0, 0, 0, 0) end class Balloon_Bitmap < Bitmap def initialize(width, height) super(width, height) self.font = FONT_BALLOON_TEXT end def draw_text(x, y, width, height, text, align = 0) y = y / 32 * SPACING_BALLOON_TEXT super(x, y, width, height, text, align) end end class Interpreter alias mp_balloon_setup setup def setup(list, event_id) mp_balloon_setup(list, event_id) $game_variables[VAR_CURRENT_EVENT_ID] = event_id unless event_id == 0 end alias mp_balloon_initialize initialize def initialize(depth = 0, main = false) mp_balloon_initialize(depth, main) @balloon_windows = [] end alias mp_balloon_update update def update mp_balloon_update for window in @balloon_windows.clone window.update if window.terminated window.dispose @balloon_windows.delete(window) end end end #-------------------------------------------------------------------------- # * Show Text #-------------------------------------------------------------------------- alias mp_balloon_command_101 command_101 def command_101 return false if @message_waiting if $game_switches[SW_ENABLE_BALLOONS] # Set message end waiting flag and callback #@message_waiting = true @message_waiting = !$game_switches[SW_MESSAGE_SKIP] window = Window_Balloon.new window.message_proc = Proc.new { @message_waiting = false } @balloon_windows << window # Set message text on first line text = @list[@index].parameters[0] + "\n" line_count = 1 # Loop loop do # If next event command text is on the second line or after if @list[@index+1].code == 401 # Add the second line or after to message_text text += @list[@index+1].parameters[0] + "\n" line_count += 1 # If event command is not on the second line or after else window.set_message(text) return true end @index += 1 end end return mp_balloon_command_101 end end module Balloonskin TOP = 1 BOTTOM = 2 LEFT = 4 RIGHT = 8 TOP_LEFT = 16 TOP_RIGHT = 32 BOTTOM_LEFT = 64 BOTTOM_RIGHT = 128 COLOR_TRANSPARENT = Color.new(0, 0, 0, 0) @masks = {} @width = {} @height = {} class << self attr_reader :width attr_reader :height def compile(balloonskin_name) # Load bitmap @bitmap = RPG::Cache.balloonskin(balloonskin_name) # Compute cell width and height w = @width[balloonskin_name] = @bitmap.width >> 3 h = @height[balloonskin_name] = @bitmap.height / 3 # Compute cells cells = [] for i in 0...4 a = [] for j in 0...3 a << Rect.new(i * w, j * h, w, h) end cells << a end # Compute masks masks = [] masks << make_mask(cells[0][0], [[0, 0]]) masks << make_mask(cells[1][0], [[0, 0], [w - 1, 0]]) masks << make_mask(cells[2][0], [[0, 0], [w - 1, 0]]) masks << make_mask(cells[3][0], [[w - 1, 0]]) masks << make_mask(cells[0][1], [[0, 0], [0, h - 1]]) masks << make_mask(cells[1][1], [[0, 0], [w - 1, 0], [0, h - 1], [w - 1, h - 1]]) masks << make_mask(cells[2][1], [[0, 0], [w - 1, 0], [0, h - 1], [w - 1, h - 1]]) masks << make_mask(cells[3][1], [[w - 1, 0], [w - 1, h - 1]]) masks << make_mask(cells[0][2], [[0, h - 1]]) masks << make_mask(cells[1][2], [[0, h - 1], [w - 1, h - 1]]) masks << make_mask(cells[2][2], [[0, h - 1], [w - 1, h - 1]]) masks << make_mask(cells[3][2], [[w - 1, h - 1]]) return @masks[balloonskin_name] = masks end def make_mask(cell, to_process) start_x = cell.x start_y = cell.y w = cell.width w1 = cell.width - 1 h1 = cell.height - 1 processed = Bitmask.new(w * cell.height) mask = Bitmask.new(w * cell.height) max = 0 until to_process.empty? x, y = to_process.shift i = y * w + x max = [max, i].max if @bitmap.get_pixel(start_x + x, start_y + y).alpha != 255 if x != 0 to_process << [x - 1, y] if not processed[i - 1] and not to_process.include?([x - 1, y]) end if x != w1 to_process << [x + 1, y] if not processed[i + 1] and not to_process.include?([x + 1, y]) end if y != 0 to_process << [x, y - 1] if not processed[i - w] and not to_process.include?([x, y - 1]) end if y != h1 to_process << [x, y + 1] if not processed[i + w] and not to_process.include?([x, y + 1]) end mask[i] = true end processed[i] = true end mask.resize(max) return mask end def mask(balloonskin_name, n) if @masks[balloonskin_name].nil? compile(balloonskin_name) end return @masks[balloonskin_name][n] end end if PRECOMPILE_BALLOONSKINS for entry in Dir.entries("Graphics/Balloonskins") next if entry == "." or entry == ".." self.compile(entry.split(".").first) # Update graphics to prevent script hanging error Graphics.update end end def balloonskin_initialize # Make viewport viewport = Viewport.new(0, 0, 640, 480) # Make skin sprite @skin = Sprite.new(viewport) # Make border sprite @border = Sprite.new(viewport) @border.color = Color.new(255, 255, 255, 0) # Make waiting sprite @sprite_wait = Sprite.new(viewport) @sprite_wait.visible = false @wait_count = 0 @blink_count = 0 end def balloonskin_name=(name) @balloonskin_name = name bitmap = RPG::Cache.balloonskin(name) @sprite_wait.bitmap = bitmap @wait_rect = [ Rect.new(bitmap.width * 7 / 8, 0, bitmap.width / 16, bitmap.height / 6), Rect.new(bitmap.width * 15 / 16, 0, bitmap.width / 16, bitmap.height / 6), Rect.new(bitmap.width * 7 / 8, bitmap.height / 6, bitmap.width / 16, bitmap.height / 6), Rect.new(bitmap.width * 15 / 16, bitmap.height / 6, bitmap.width / 16, bitmap.height / 6) ] @wait_rect_index = 3 end def render_balloonskin # Load skin bitmap bitmap = RPG::Cache.balloonskin(@balloonskin_name) # Compute cell width and height w = bitmap.width >> 3 h = bitmap.height / 3 # Compute cells cells = [] for i in 0...4 a = [] for j in 0...3 a << Rect.new(i * w, j * h, w, h) end cells << a end # Dispose graphics if previously rendered @skin.bitmap.dispose if @skin.bitmap @border.bitmap.dispose if @border.bitmap # Adjust position @skin.oy = @border.oy = h # Make skin bitmap @skin.bitmap = Bitmap.new(self.width, self.height + 2 * h) @skin.bitmap.stretch_blt(@skin.bitmap.rect, bitmap, Rect.new(4 * w, 0, 3 * w, 3 * h)) # Clear outside corners @skin.bitmap.fill_rect(0, 0, w, h, Color::TRANSPARENT) @skin.bitmap.fill_rect(self.width - w, 0, w, h, Color::TRANSPARENT) @skin.bitmap.fill_rect(0, self.height + h, w, h, Color::TRANSPARENT) @skin.bitmap.fill_rect(self.width - w, self.height + h, w, h, Color::TRANSPARENT) # Make border bitmap @border.bitmap = Bitmap.new(self.width, self.height + 2 * h) # Draw upper-left corner @skin.bitmap.trim(0, h, w, mask(0)) @border.bitmap.blt(0, h, bitmap, cells[0][0]) # Draw upper-right corner @skin.bitmap.trim(self.width - w, h, w, mask(3)) @border.bitmap.blt(self.width - w, h, bitmap, cells[3][0]) # Draw lower-left corner @skin.bitmap.trim(0, self.height, w, mask(8)) @border.bitmap.blt(0, self.height, bitmap, cells[0][2]) # Draw lower-right corner @skin.bitmap.trim(self.width - w, self.height, w, mask(11)) @border.bitmap.blt(self.width - w, self.height, bitmap, cells[3][2]) # Draw left side for i in 2..self.height / h - 1 y = i * h @skin.bitmap.trim(0, y, w, mask(4)) @border.bitmap.blt(0, y, bitmap, cells[0][1]) end # Draw right side x = self.width - w for i in 2..self.height / h - 1 y = i * h @skin.bitmap.trim(x, y, w, mask(7)) @border.bitmap.blt(x, y, bitmap, cells[3][1]) end # Compute where to put the tail for i in 1..self.width / w - 2 x_quote = i if @event.real_x / 4 - $game_map.display_x / 4 < self.x + i * w break end end # Draw lower side y = self.height for i in 1..self.width / w - 2 x = i * w if @event.real_y / 4 - 32 - $game_map.display_y / 4 > self.y if i == x_quote @skin.bitmap.trim(x, y, w, mask(10)) @border.bitmap.blt(x, y, bitmap, cells[2][2]) @skin.bitmap.trim(x, y + h, w, mask(5)) @border.bitmap.blt(x, y + h, bitmap, cells[1][1]) next end end @skin.bitmap.trim(x, y, w, mask(9)) @border.bitmap.blt(x, y, bitmap, cells[1][2]) @skin.bitmap.fill_rect(x, y + h, w, h, Color::TRANSPARENT) end # Draw upper side y = h for i in 1..self.width / w - 2 x = i * w if @event.real_y / 4 - 32 - $game_map.display_y / 4 < self.y if i == x_quote @skin.bitmap.trim(x, y, w, mask(2)) @border.bitmap.blt(x, y, bitmap, cells[2][0]) @skin.bitmap.trim(x, 0, w, mask(6)) @border.bitmap.blt(x, 0, bitmap, cells[2][1]) next end end @skin.bitmap.trim(x, y, w, mask(1)) @border.bitmap.blt(x, y, bitmap, cells[1][0]) @skin.bitmap.fill_rect(x, 0, w, h, Color::TRANSPARENT) end end def mask(n) return Balloonskin.mask(@balloonskin_name, n) end def dispose @skin.bitmap.dispose @skin.dispose @border.bitmap.dispose @border.dispose @sprite_wait.dispose super end def x=(x) @sprite_wait.x = x + self.width - 32 @skin.x = @border.x = super(x) end def y=(y) @sprite_wait.y = y + self.height - 32 @skin.y = @border.y = super(y) end def z=(z) @skin.z = @border.z = @sprite_wait.z = super(z) end def opacity=(opacity) @skin.opacity = @border.opacity = super(opacity) end def back_opacity=(opacity) @skin.opacity = super(opacity) end end class Window_Balloon < Window_Message include Balloonskin attr_accessor :message_proc attr_reader :terminated def initialize balloonskin_initialize super self.windowskin = nil self.opacity = OPACITY_BALLOON end def update super update_position if @sprite_wait.visible = $game_temp.message_window_showing if @wait_count == 0 @wait_rect_index += 1 @wait_rect_index %= 4 @sprite_wait.src_rect = @wait_rect[@wait_rect_index] @wait_count = FRAMES_BALLOON_WAIT end @wait_count -= 1 end if f = FRAMES_BALLOON_BLINK[@balloonskin_name] if @blink_count == 0 @blink_count = f end @border.color.alpha = (f - (2 * @blink_count - f).abs) * 128 / f @blink_count -= 1 end end def update_position down = @event.real_y / 4 - 32 - $game_map.display_y / 4 <= self.y self.y = @event.real_y / 4 + 32 - $game_map.display_y / 4 if @event.real_y / 4 - 32 - $game_map.display_y / 4 > self.height self.y -= self.height + 64 if down render_balloonskin end else unless down render_balloonskin end end self.x = [ [@event.real_x / 4 - self.width / 2 + 16 - $game_map.display_x / 4, 0].max, 640 - self.width].min #@skin.x = @border.x = self.x #@skin.y = @border.y = self.y end def set_message(text) if $game_variables[VAR_EVENT_ID_ANCHOR] == 0 @event = $game_player else @event = $game_map.events[$game_variables[VAR_EVENT_ID_ANCHOR]] end #$game_temp.choice_max text = parse_text(text) lines = text.split("\n") if CUT_LINES_IN_TWO old_lines = lines lines = [] for line in old_lines if line.size <= MAX_CHARACTERS_PER_LINE lines << line else n = line[0, MAX_CHARACTERS_PER_LINE].reverse.index(" ") n = MAX_CHARACTERS_PER_LINE - (n.nil? ? 0 : n) p = line[MAX_CHARACTERS_PER_LINE, line.size - MAX_CHARACTERS_PER_LINE].index(" ") p = line.size - n if p == nil if MAX_CHARACTERS_PER_LINE - n > p n = MAX_CHARACTERS_PER_LINE + p end lines << line[0, n] lines << line[n, line.size - n].lstrip end end text = lines.join("\n") end bitmap = Balloon_Bitmap.new(640, 480) size = 0 lines.each do |str| size = [size, bitmap.text_size(str).width + PADDING_RIGHT].max # * FONT_BALLOON_TEXT.size / Font.default_size end bitmap.dispose self.width = 32 + size self.height = 32 + (Font.default_size - FONT_BALLOON_TEXT.size) * 2 + SPACING_BALLOON_TEXT * lines.size self.contents = Balloon_Bitmap.new(size, height - 32) self.balloonskin_name = sprintf("%03d", $game_variables[VAR_BALLOONSKIN]) bitmap = RPG::Cache.balloonskin(@balloonskin_name) w = bitmap.width >> 3 h = bitmap.height / 3 # Round up width and height to avoid gaps in balloonskin if self.width % w != 0 self.width = (self.width / w + 1) * w end if self.height % h != 0 self.height = (self.height / h + 1) * h end # Displace content self.ox = (-self.width + 32 + self.contents.width) / 2 self.oy = (-self.height + 32 + self.contents.height) / 2 #self.balloonskin = RPG::Cache.balloonskin(@balloonskin_name) update_position render_balloonskin $game_temp.message_text = text @contents_showing = true $game_temp.message_window_showing = true #reset_window refresh Graphics.frame_reset self.visible = true self.contents_opacity = 0 #if @input_number_window != nil # @input_number_window.contents_opacity = 0 #end @fade_in = true $game_temp.message_text = nil end def parse_text(text) # Control text processing begin last_text = text.clone text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] } end until text == last_text text.gsub!(/\\[Nn]\[([0-9]+)\]/) do $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : "" end #-------------------------------------------------------------------------- text.gsub!(/\\[Ff]\[([ \w\=\+\-\*\/\$\(\)\!\.\,\'\:\%\@]+)\]/) { eval $1 } #-------------------------------------------------------------------------- # Change "\\\\" to "\000" for convenience text.gsub!(/\\\\/) { "\000" } # Change "\\C" to "\001" and "\\G" to "\002" text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" } text.gsub!(/\\[Gg]/) { "\002" } return text end def terminate_message $game_temp.message_proc = self.message_proc super @terminated = true # self.dispose $game_temp.message_proc = nil end def normal_color return Color.new(0, 0, 0) end #-------------------------------------------------------------------------- # * Get Text Color # n : text color number (0-7) #-------------------------------------------------------------------------- def text_color(n) case n when 0 return Color.new(0, 0, 0, 255) when 1 return Color.new(64, 64, 128, 255) when 2 return Color.new(128, 64, 64, 255) when 3 return Color.new(64, 128, 64, 255) when 4 return Color.new(64, 128, 128, 255) when 5 return Color.new(128, 64, 128, 255) when 6 return Color.new(128, 128, 64, 255) when 7 return Color.new(96, 96, 96, 255) else normal_color end end end[/code] Le 001.png[img]http://img103.xooimage.com/files/7/4/1/001-467c249.png[/img] Le 002.png[img]http://img108.xooimage.com/files/7/3/4/002-467c24b.png[/img] Voilà merci d'avance.


[size=15] Mon site perso et la démo http://deltaproduction.free-h.net/index.html Téléchargez Yggdrasil la quête du dragon de sang: (05/08/2016) 28 Heures de jeu[/size] [center][url=http://www.alexdor.info/?p=jeu&id=878][img]http://delta.comics.pagesperso-orange.fr/barre.gif[/img][/url][/center] [size=15]Nouvelle démo Sentinelles du (20/07/2016) Environ 6H de jeu[/size] [center][url=http://www.alexdor.info/?p=jeu&id=876][img]http://delta.comics.pagesperso-orange.fr/sentinelles.png[/img][/url][/center] [size=15]Nouvelle démo La Chute d'Atalanta du (18/06/2016) Environ 1H30 de jeu[/size] [center][url=http://www.alexdor.info/?p=jeu&id=874][img]http://delta.comics.pagesperso-orange.fr/Atalanta.png[/img][/url][/center]

Ssozi

Expert
Ssozi
  • Messages : 1166

Modification script balloon pour RPG MAKER XP. (Résolu)


mer. 02 juil. 2014 - 15h15

[spoiler][code] # Game variables IDs # Variable holding the event ID to which anchor the balloon VAR_EVENT_ID_ANCHOR = 2 # Variable holding the ID of the balloonskin to be used VAR_BALLOONSKIN = 3 # Variable holding the ID of the current processing event VAR_CURRENT_EVENT_ID = 4 # Game switches IDs # Switch enabling ballon display SW_ENABLE_BALLOONS = 2 # Switch enabling message skip (mainly to display multiple balloons at once) SW_MESSAGE_SKIP = 3 # Default font for balloon text FONT_BALLOON_TEXT = Font.new(Font.default_name, 16) # Edit the following line for your own custom font, or remove it to keep the default # FONT_BALLOON_TEXT = Font.new("OdaBalloon", 12) # Edit the following line to custom the spacing between lines, or keep as is for # automatic calculation SPACING_BALLOON_TEXT = 32 - (Font.default_size - FONT_BALLOON_TEXT.size) * 2 # Specify whether you want lines cut in two for more square-shaped balloons CUT_LINES_IN_TWO = true # Max number of characters per line for smart line cutting (changing not # recommended) MAX_CHARACTERS_PER_LINE = 25 # For each balloonskin, number of frames needed to complete a blinking cycle # Input nil to disable blinking for that balloonskin FRAMES_BALLOON_BLINK = { "000" => 40, "001" => 80, "002" => 20 } # Number of frames for the waiting sprite to animate FRAMES_BALLOON_WAIT = 20 # Bubbles opacity OPACITY_BALLOON = 192 # Right padding to avoid last character being out of the frame PADDING_RIGHT = 16 # Setting this to false will cause small latencies upon using a balloonskin for # the first time, because they need prior treatment before the can be used. # Setting this to true makes the game compile all balloonskins upon launching # the game, which avoids latencies in-game but causes latencies when the # game starts. PRECOMPILE_BALLOONSKINS = false#true module RPG module Cache def self.balloonskin(filename) self.load_bitmap("Graphics/Balloonskins/", filename) end end end class Bitmap def trim(start_x, start_y, w, mask) x = 0 y = 0 for i in 0...mask.size if mask[i] self.set_pixel(start_x + x, start_y + y, Color::TRANSPARENT) end x += 1 if x == w x = 0 y += 1 end end return self end end class Color TRANSPARENT = Color.new(0, 0, 0, 0) end class Balloon_Bitmap < Bitmap def initialize(width, height) super(width, height) self.font = FONT_BALLOON_TEXT end def draw_text(x, y, width, height, text, align = 0) y = (y / 32 * SPACING_BALLOON_TEXT) super(x, y, width, height, text, align) end end class Interpreter alias mp_balloon_setup setup def setup(list, event_id) mp_balloon_setup(list, event_id) $game_variables[VAR_CURRENT_EVENT_ID] = event_id unless event_id == 0 end alias mp_balloon_initialize initialize def initialize(depth = 0, main = false) mp_balloon_initialize(depth, main) @balloon_windows = [] end alias mp_balloon_update update def update mp_balloon_update for window in @balloon_windows.clone window.update if window.terminated window.dispose @balloon_windows.delete(window) end end end #-------------------------------------------------------------------------- # * Show Text #-------------------------------------------------------------------------- alias mp_balloon_command_101 command_101 def command_101 return false if @message_waiting if $game_switches[SW_ENABLE_BALLOONS] # Set message end waiting flag and callback #@message_waiting = true @message_waiting = !$game_switches[SW_MESSAGE_SKIP] window = Window_Balloon.new window.message_proc = Proc.new { @message_waiting = false } @balloon_windows << window # Set message text on first line text = @list[@index].parameters[0] + "\n" line_count = 1 # Loop loop do # If next event command text is on the second line or after if @list[@index+1].code == 401 # Add the second line or after to message_text text += @list[@index+1].parameters[0] + "\n" line_count += 1 # If event command is not on the second line or after else window.set_message(text) return true end @index += 1 end end return mp_balloon_command_101 end end module Balloonskin TOP = 1 BOTTOM = 2 LEFT = 4 RIGHT = 8 TOP_LEFT = 16 TOP_RIGHT = 32 BOTTOM_LEFT = 64 BOTTOM_RIGHT = 128 COLOR_TRANSPARENT = Color.new(0, 0, 0, 0) @masks = {} @width = {} @height = {} class << self attr_reader :width attr_reader :height def compile(balloonskin_name) # Load bitmap @bitmap = RPG::Cache.balloonskin(balloonskin_name) # Compute cell width and height w = @width[balloonskin_name] = @bitmap.width >> 3 h = @height[balloonskin_name] = @bitmap.height / 3 # Compute cells cells = [] for i in 0...4 a = [] for j in 0...3 a << Rect.new(i * w, j * h, w, h) end cells << a end # Compute masks masks = [] masks << make_mask(cells[0][0], [[0, 0]]) masks << make_mask(cells[1][0], [[0, 0], [w - 1, 0]]) masks << make_mask(cells[2][0], [[0, 0], [w - 1, 0]]) masks << make_mask(cells[3][0], [[w - 1, 0]]) masks << make_mask(cells[0][1], [[0, 0], [0, h - 1]]) masks << make_mask(cells[1][1], [[0, 0], [w - 1, 0], [0, h - 1], [w - 1, h - 1]]) masks << make_mask(cells[2][1], [[0, 0], [w - 1, 0], [0, h - 1], [w - 1, h - 1]]) masks << make_mask(cells[3][1], [[w - 1, 0], [w - 1, h - 1]]) masks << make_mask(cells[0][2], [[0, h - 1]]) masks << make_mask(cells[1][2], [[0, h - 1], [w - 1, h - 1]]) masks << make_mask(cells[2][2], [[0, h - 1], [w - 1, h - 1]]) masks << make_mask(cells[3][2], [[w - 1, h - 1]]) return @masks[balloonskin_name] = masks end def make_mask(cell, to_process) start_x = cell.x start_y = cell.y w = cell.width w1 = cell.width - 1 h1 = cell.height - 1 processed = Bitmask.new(w * cell.height) mask = Bitmask.new(w * cell.height) max = 0 until to_process.empty? x, y = to_process.shift i = y * w + x max = [max, i].max if @bitmap.get_pixel(start_x + x, start_y + y).alpha != 255 if x != 0 to_process << [x - 1, y] if not processed[i - 1] and not to_process.include?([x - 1, y]) end if x != w1 to_process << [x + 1, y] if not processed[i + 1] and not to_process.include?([x + 1, y]) end if y != 0 to_process << [x, y - 1] if not processed[i - w] and not to_process.include?([x, y - 1]) end if y != h1 to_process << [x, y + 1] if not processed[i + w] and not to_process.include?([x, y + 1]) end mask[i] = true end processed[i] = true end mask.resize(max) return mask end def mask(balloonskin_name, n) if @masks[balloonskin_name].nil? compile(balloonskin_name) end return @masks[balloonskin_name][n] end end if PRECOMPILE_BALLOONSKINS for entry in Dir.entries("Graphics/Balloonskins") next if entry == "." or entry == ".." self.compile(entry.split(".").first) # Update graphics to prevent script hanging error Graphics.update end end def balloonskin_initialize # Make viewport viewport = Viewport.new(0, 0, 640, 480) # Make skin sprite @skin = Sprite.new(viewport) # Make border sprite @border = Sprite.new(viewport) @border.color = Color.new(255, 255, 255, 0) # Make waiting sprite @sprite_wait = Sprite.new(viewport) @sprite_wait.visible = false @wait_count = 0 @blink_count = 0 end def balloonskin_name=(name) @balloonskin_name = name bitmap = RPG::Cache.balloonskin(name) @sprite_wait.bitmap = bitmap @wait_rect = [ Rect.new(bitmap.width * 7 / 8, 0, bitmap.width / 16, bitmap.height / 6), Rect.new(bitmap.width * 15 / 16, 0, bitmap.width / 16, bitmap.height / 6), Rect.new(bitmap.width * 7 / 8, bitmap.height / 6, bitmap.width / 16, bitmap.height / 6), Rect.new(bitmap.width * 15 / 16, bitmap.height / 6, bitmap.width / 16, bitmap.height / 6) ] @wait_rect_index = 3 end def render_balloonskin # Load skin bitmap bitmap = RPG::Cache.balloonskin(@balloonskin_name) # Compute cell width and height w = bitmap.width >> 3 h = bitmap.height / 3 # Compute cells cells = [] for i in 0...4 a = [] for j in 0...3 a << Rect.new(i * w, j * h, w, h) end cells << a end # Dispose graphics if previously rendered @skin.bitmap.dispose if @skin.bitmap @border.bitmap.dispose if @border.bitmap # Adjust position @skin.oy = @border.oy = h # Make skin bitmap @skin.bitmap = Bitmap.new(self.width, self.height + 2 * h) @skin.bitmap.stretch_blt(@skin.bitmap.rect, bitmap, Rect.new(4 * w, 0, 3 * w, 3 * h)) # Clear outside corners @skin.bitmap.fill_rect(0, 0, w, h, Color::TRANSPARENT) @skin.bitmap.fill_rect(self.width - w, 0, w, h, Color::TRANSPARENT) @skin.bitmap.fill_rect(0, self.height + h, w, h, Color::TRANSPARENT) @skin.bitmap.fill_rect(self.width - w, self.height + h, w, h, Color::TRANSPARENT) # Make border bitmap @border.bitmap = Bitmap.new(self.width, self.height + 2 * h) # Draw upper-left corner @skin.bitmap.trim(0, h, w, mask(0)) @border.bitmap.blt(0, h, bitmap, cells[0][0]) # Draw upper-right corner @skin.bitmap.trim(self.width - w, h, w, mask(3)) @border.bitmap.blt(self.width - w, h, bitmap, cells[3][0]) # Draw lower-left corner @skin.bitmap.trim(0, self.height, w, mask(8)) @border.bitmap.blt(0, self.height, bitmap, cells[0][2]) # Draw lower-right corner @skin.bitmap.trim(self.width - w, self.height, w, mask(11)) @border.bitmap.blt(self.width - w, self.height, bitmap, cells[3][2]) # Draw left side for i in 2..self.height / h - 1 y = i * h @skin.bitmap.trim(0, y, w, mask(4)) @border.bitmap.blt(0, y, bitmap, cells[0][1]) end # Draw right side x = self.width - w for i in 2..self.height / h - 1 y = i * h @skin.bitmap.trim(x, y, w, mask(7)) @border.bitmap.blt(x, y, bitmap, cells[3][1]) end # Compute where to put the tail for i in 1..self.width / w - 2 x_quote = i if @event.real_x / 4 - $game_map.display_x / 4 < self.x + i * w break end end # Draw lower side y = self.height for i in 1..self.width / w - 2 x = i * w if @event.real_y / 4 - 32 - $game_map.display_y / 4 > self.y if i == x_quote @skin.bitmap.trim(x, y, w, mask(10)) @border.bitmap.blt(x, y, bitmap, cells[2][2]) @skin.bitmap.trim(x, y + h, w, mask(5)) @border.bitmap.blt(x, y + h, bitmap, cells[1][1]) next end end @skin.bitmap.trim(x, y, w, mask(9)) @border.bitmap.blt(x, y, bitmap, cells[1][2]) @skin.bitmap.fill_rect(x, y + h, w, h, Color::TRANSPARENT) end # Draw upper side y = h for i in 1..self.width / w - 2 x = i * w if @event.real_y / 4 - 32 - $game_map.display_y / 4 < self.y if i == x_quote @skin.bitmap.trim(x, y, w, mask(2)) @border.bitmap.blt(x, y, bitmap, cells[2][0]) @skin.bitmap.trim(x, 0, w, mask(6)) @border.bitmap.blt(x, 0, bitmap, cells[2][1]) next end end @skin.bitmap.trim(x, y, w, mask(1)) @border.bitmap.blt(x, y, bitmap, cells[1][0]) @skin.bitmap.fill_rect(x, 0, w, h, Color::TRANSPARENT) end end def mask(n) return Balloonskin.mask(@balloonskin_name, n) end def dispose @skin.bitmap.dispose @skin.dispose @border.bitmap.dispose @border.dispose @sprite_wait.dispose super end def x=(x) @sprite_wait.x = x + self.width - 32 @skin.x = @border.x = super(x) end def y=(y) @sprite_wait.y = y + self.height - 32 @skin.y = @border.y = super(y) end def z=(z) @skin.z = @border.z = @sprite_wait.z = super(z) end def opacity=(opacity) @skin.opacity = @border.opacity = super(opacity) end def back_opacity=(opacity) @skin.opacity = super(opacity) end end class Window_Balloon < Window_Message include Balloonskin attr_accessor :message_proc attr_reader :terminated def initialize balloonskin_initialize super self.windowskin = nil self.opacity = OPACITY_BALLOON end def update super update_position if @sprite_wait.visible = $game_temp.message_window_showing if @wait_count == 0 @wait_rect_index += 1 @wait_rect_index %= 4 @sprite_wait.src_rect = @wait_rect[@wait_rect_index] @wait_count = FRAMES_BALLOON_WAIT end @wait_count -= 1 end if f = FRAMES_BALLOON_BLINK[@balloonskin_name] if @blink_count == 0 @blink_count = f end @border.color.alpha = (f - (2 * @blink_count - f).abs) * 128 / f @blink_count -= 1 end end def update_position down = @event.real_y / 4 - 32 - $game_map.display_y / 4 <= self.y self.y = @event.real_y / 4 + 32 - $game_map.display_y / 4 if @event.real_y / 4 - 32 - $game_map.display_y / 4 > self.height self.y -= self.height + 64 self.y -= 50 if down render_balloonskin end else unless down render_balloonskin end end self.x = [ [@event.real_x / 4 - self.width / 2 + 16 - $game_map.display_x / 4, 0].max, 640 - self.width].min #@skin.x = @border.x = self.x #@skin.y = @border.y = self.y end def set_message(text) if $game_variables[VAR_EVENT_ID_ANCHOR] == 0 @event = $game_player else @event = $game_map.events[$game_variables[VAR_EVENT_ID_ANCHOR]] end #$game_temp.choice_max text = parse_text(text) lines = text.split("\n") if CUT_LINES_IN_TWO old_lines = lines lines = [] for line in old_lines if line.size <= MAX_CHARACTERS_PER_LINE lines << line else n = line[0, MAX_CHARACTERS_PER_LINE].reverse.index(" ") n = MAX_CHARACTERS_PER_LINE - (n.nil? ? 0 : n) p = line[MAX_CHARACTERS_PER_LINE, line.size - MAX_CHARACTERS_PER_LINE].index(" ") p = line.size - n if p == nil if MAX_CHARACTERS_PER_LINE - n > p n = MAX_CHARACTERS_PER_LINE + p end lines << line[0, n] lines << line[n, line.size - n].lstrip end end text = lines.join("\n") end bitmap = Balloon_Bitmap.new(640, 480) size = 0 lines.each do |str| size = [size, bitmap.text_size(str).width + PADDING_RIGHT].max # * FONT_BALLOON_TEXT.size / Font.default_size end bitmap.dispose self.width = 32 + size self.height = 32 + (Font.default_size - FONT_BALLOON_TEXT.size) * 2 + SPACING_BALLOON_TEXT * lines.size self.contents = Balloon_Bitmap.new(size, height - 32) self.balloonskin_name = sprintf("%03d", $game_variables[VAR_BALLOONSKIN]) bitmap = RPG::Cache.balloonskin(@balloonskin_name) w = bitmap.width >> 3 h = bitmap.height / 3 # Round up width and height to avoid gaps in balloonskin if self.width % w != 0 self.width = (self.width / w + 1) * w end if self.height % h != 0 self.height = (self.height / h + 1) * h end # Displace content self.ox = (-self.width + 32 + self.contents.width) / 2 self.oy = (-self.height + 32 + self.contents.height) / 2 #self.balloonskin = RPG::Cache.balloonskin(@balloonskin_name) update_position render_balloonskin $game_temp.message_text = text @contents_showing = true $game_temp.message_window_showing = true #reset_window refresh Graphics.frame_reset self.visible = true self.contents_opacity = 0 #if @input_number_window != nil # @input_number_window.contents_opacity = 0 #end @fade_in = true $game_temp.message_text = nil end def parse_text(text) # Control text processing begin last_text = text.clone text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] } end until text == last_text text.gsub!(/\\[Nn]\[([0-9]+)\]/) do $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : "" end #-------------------------------------------------------------------------- text.gsub!(/\\[Ff]\[([ \w\=\+\-\*\/\$\(\)\!\.\,\'\:\%\@]+)\]/) { eval $1 } #-------------------------------------------------------------------------- # Change "\\\\" to "\000" for convenience text.gsub!(/\\\\/) { "\000" } # Change "\\C" to "\001" and "\\G" to "\002" text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" } text.gsub!(/\\[Gg]/) { "\002" } return text end def terminate_message $game_temp.message_proc = self.message_proc super @terminated = true # self.dispose $game_temp.message_proc = nil end def normal_color return Color.new(0, 0, 0) end #-------------------------------------------------------------------------- # * Get Text Color # n : text color number (0-7) #-------------------------------------------------------------------------- def text_color(n) case n when 0 return Color.new(0, 0, 0, 255) when 1 return Color.new(64, 64, 128, 255) when 2 return Color.new(128, 64, 64, 255) when 3 return Color.new(64, 128, 64, 255) when 4 return Color.new(64, 128, 128, 255) when 5 return Color.new(128, 64, 128, 255) when 6 return Color.new(128, 128, 64, 255) when 7 return Color.new(96, 96, 96, 255) else normal_color end end end[/code][/spoiler] Tiens, c'est le script que tu as modifié. Je l'ai remodifié et normalement c'est bon. Enfin ça devrait afficher tout le texte 50 pixels plus haut


Delta

Star
Delta
  • Messages : 2420

Modification script balloon pour RPG MAKER XP. (Résolu)


mer. 02 juil. 2014 - 16h36

Merci je te dirai ça ce soir, je peux pas le tester actuellement.


[size=15] Mon site perso et la démo http://deltaproduction.free-h.net/index.html Téléchargez Yggdrasil la quête du dragon de sang: (05/08/2016) 28 Heures de jeu[/size] [center][url=http://www.alexdor.info/?p=jeu&id=878][img]http://delta.comics.pagesperso-orange.fr/barre.gif[/img][/url][/center] [size=15]Nouvelle démo Sentinelles du (20/07/2016) Environ 6H de jeu[/size] [center][url=http://www.alexdor.info/?p=jeu&id=876][img]http://delta.comics.pagesperso-orange.fr/sentinelles.png[/img][/url][/center] [size=15]Nouvelle démo La Chute d'Atalanta du (18/06/2016) Environ 1H30 de jeu[/size] [center][url=http://www.alexdor.info/?p=jeu&id=874][img]http://delta.comics.pagesperso-orange.fr/Atalanta.png[/img][/url][/center]

Delta

Star
Delta
  • Messages : 2420

Modification script balloon pour RPG MAKER XP. (Résolu)


mer. 02 juil. 2014 - 19h53

Impeccable, merci !


[size=15] Mon site perso et la démo http://deltaproduction.free-h.net/index.html Téléchargez Yggdrasil la quête du dragon de sang: (05/08/2016) 28 Heures de jeu[/size] [center][url=http://www.alexdor.info/?p=jeu&id=878][img]http://delta.comics.pagesperso-orange.fr/barre.gif[/img][/url][/center] [size=15]Nouvelle démo Sentinelles du (20/07/2016) Environ 6H de jeu[/size] [center][url=http://www.alexdor.info/?p=jeu&id=876][img]http://delta.comics.pagesperso-orange.fr/sentinelles.png[/img][/url][/center] [size=15]Nouvelle démo La Chute d'Atalanta du (18/06/2016) Environ 1H30 de jeu[/size] [center][url=http://www.alexdor.info/?p=jeu&id=874][img]http://delta.comics.pagesperso-orange.fr/Atalanta.png[/img][/url][/center]

Ssozi

Expert
Ssozi
  • Messages : 1166

Modification script balloon pour RPG MAKER XP. (Résolu)


mer. 02 juil. 2014 - 20h05

De rien, je déplace