Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # RM2k/2k3 Graphics (320x240) v. 1.4
- # Ace version
- # by mikb89 & 255
- # Scriverò un po' italiano e un po' inglese, spero di non urtarvi ^^
- # I'll write both in italian & english, I hope this won't get you angry ^^
- # Guida italiano
- # Questo script permette di utilizzare grafica nello stile 2k/2k3 in quanto
- # ogni immagine visualizzata viene ingrandita del 2x, come avveniva nei vecchi
- # RPG Maker.
- # Per importare DIRETTAMENTE i charset del 2k/2k3 inserite
- # il simbolo # davanti al nome del file. Esempio: '#Chara1'.
- # Così facendo lo script mostrerà correttamente le direzioni dei
- # charset (i charset del 2k/2k3 hanno infatti posizioni diverse).
- # Ovviamente nell'importarli dovrete settare il colore trasparente.
- # La cartella MidGraphics contiene le immagini ridimensionate, mentre la
- # Graphics serve per vedere le immagini nel programma.
- # Il problema è che, anche se dagli script le immagini vengono raddoppiate, il
- # vx ace non lo fa, perciò vi serve una copia delle immagini in dimensioni
- # doppie.
- # Se importate immagini vostre o ne modificate, mettetele in MidGraphics.
- # Dopodiché, fatene una copia a dimensioni raddoppiate e mettetela in Graphics.
- # Non importa la qualità, serve solo momentaneamente per gestirla correttamente
- # nel progetto.
- # Una volta che rilasciate il gioco, togliete (magari temporaneamente) la
- # cartella Graphics, rinominate MidGraphics in Graphics e distribuite.
- # Durante il test infatti le immagini vengono prese da MidGraphics, altrimenti
- # da Graphics. Inoltre se distribuite tramite il comando del menu File in questo
- # modo le immagini verranno normalmente criptate, se settate l'opzione.
- # English guide
- # With this script you can use graphic files with a lower resolution, similar
- # to the older RPG Maker. The size of the graphic will be doubled once drawn.
- # Old RPG Maker charsets can be used DIRECTLY by inserting a '#' in the file
- # name. Ex: '#Chara1'.
- # This way the script will correctly show the directions of the charsets
- # (indeed charsets from the 2k/2k3 have different positions).
- # You have to set the transparent colour when importing though.
- # MidGraphics folder contains resized images, while Graphics is used by the
- # application, as usually.
- # The problem is that vx ace CAN'T double images WHILE making your project, so
- # we have to carry a double-copy of images, to use them in the project.
- # If you use other images or modify those existing, insert them in MidGraphics.
- # Next, do a copy of them which is double-sized and insert in Graphics at the
- # same location. No matter quality, it's just for pratical purpuose.
- # Once you release the game, get rid (but not permanently!) of Graphics
- # let MidGraphics take his place by renaming in Graphics and you're ready.
- # During test, in fact, images are taken from MidGraphics, but in normal playing
- # (by opening Game.exe) they came from Graphics. In this way you can release the
- # project as usual also by menu File option and everything will work, included
- # criptation for ones who care about image copyright.
- # Impostazioni // Settings
- module RM2K
- FONT_TYPE = 1
- # Puoi scegliere fra: // You can choose between:
- # 0: Niente da dire, testo normale.
- # 0: Nothing to say, just tipical text.
- # 1: Metodo tipico RPG Maker 2k/2k3. Il colore dipende da OGNI pixel del
- # quadratino colore nella windowskin e il testo viene preso da una
- # palette bitmap chiamata Font.png dentro System. Ogni carattere ha
- # dimensioni max 8x8 ma non preoccupatevi per le i: se il carattere ha
- # spazi vuoti vengono riconosciuti ed eliminati.
- # Per corsivo e grassetto l'immagine è FontBI, per grassetto è FontB e
- # per corsivo è FontI.
- # 1: Tipical of RPG Maker 2k/2k3. Color depends by EACH pixel in windowskin
- # color and characters come from the Font.png image inside System.
- # Characters max size is 8x8 but don't worry about i: if there are empty
- # spaces before or after the character, they'll be (brutally) trimmed.
- # For bold and italic the image is FontBI, for just bold it's FontB and
- # for italic, FontI.
- # 2: Font normale. L'unica cosa è che viene prima dimezzato e poi raddoppiato,
- # con ovvia perdità di qualità. Potevo non fare questo giro ma il testo
- # normale mi pare che stoni.
- # 2: Usual font. The only thing to know is that the text is stretched and
- # enlarged to obtain a vintage (see also: awful) effect. That because the
- # normal font (in my opinion) doesn't fit with the doubled images style.
- # 3: Caratteri in immagini separate. Create dentro System la cartella Font;
- # dentro questa mettete i caratteri come f0, f1, f2 con il numero che
- # rappresenta il codice ASCII del carattere (es. f49 sarà lo zero).
- # Per il grassetto bisogna creare la cartella B, I per il corsivo e BI per
- # la combinazione delle due. B, I, BI stanno dentro Font.
- # In questa modalità la larghezza dei caratteri è decisa dall'immagine.
- # 3: Characters in separated image files. Create inside System the Font folder;
- # inside this, insert the characters as f0, f1, f2 with the number part
- # representing the ASCII code (f49 is the zero, for example).
- # For bold characters folder name will be B, I for italic, BI for both.
- # B, I, BI must be placed inside Font.
- # In this drawing type, characters width depend on image width.
- # Numero a casaccio: Non vi scriverà niente.
- # Random number: Won't see anything, somebody may like it...
- RESIZE_SCREEN = true
- # Lasciando true, la dimensione dello schermo verrà impostata a 640x480.
- # With true, screen size will be 640x480.
- CHANGE_SKIN_TONE = true
- # La tonalità della window viene cambiata dal database. Tuttavia, se non si
- # vuole usufruire di questa funzione è possibile impostare false.
- # Window tone is usually changed by database. To deactivate this functionality
- # and use the image as is, you can set this to false.
- BLUR_SCREEN_ON_MENU = false
- # Quando si accede in un menu l'immagine della mappa viene sfocata. Con false
- # questo effetto viene rimosso.
- # Background map bitmap is commonly blurred when accessing menus. Setting false
- # will remove this effect.
- # Opzioni avanzate. Non toccare se non sai quello che fai.
- # Advanced settings. Don't touch unless you know what you're doing.
- STANDARD_FONT_SIZE = Font.default_size
- # Questo serve come metro di paragone per ridimensionare i caratteri da immagine.
- # Needed for measuring the amount of resizing for character in images.
- TABLE_ENCODING = "iso-8859-1"
- # Cambia la codifica dei caratteri.
- # Change characters encoding.
- # Da qui in avanti è tutto script. // From now on it's just script.
- end
- #Codename: rm2k
- ($imported ||= {})[:mikb89_255_rm2k] = true
- # Ace mods
- Graphics.resize_screen(640,480) if RM2K::RESIZE_SCREEN
- (class Window_Base; def update_tone; end; end) unless RM2K::CHANGE_SKIN_TONE
- # Old VX script
- class Font
- attr_writer :font_type
- def self.default_font_type
- @default_font_type = RM2K::FONT_TYPE if @default_font_type == nil
- return @default_font_type
- end
- def font_type
- @font_type = Font.default_font_type if @font_type == nil
- return @font_type
- end
- def self.default_font_type=(dm)
- @default_font_type = dm
- end
- end
- class Bitmap
- def double
- b = Bitmap.new(width*2, height*2)
- b.stretch_blt(b.rect, self, rect)
- return b
- end
- def tru_img
- sx, fx = width-1, 0
- c = Color.new(0,0,0)
- for x in 0...width
- e = false
- for y in 0...height
- if get_pixel(x,y) == c
- e = true
- break
- end
- end
- if e == true
- sx = x
- break
- end
- end
- for x in 1...width
- e = false
- for y in 0...height
- if get_pixel(width-x,y) == c
- e = true
- break
- end
- end
- if e == true
- fx = width-x
- break
- end
- end
- if fx+1 > sx
- bit = Bitmap.new(fx-sx+1,height)
- bit.blt(0,0,self,Rect.new(sx,0,fx-sx+1,height))
- return bit
- else
- return Bitmap.new(width/2,height)
- end
- end
- def recolour(ind)
- c = Color.new(0,0,0)
- dum = Bitmap.new(8,8)
- if ind < 32
- dum.blt(0,0,Cache.system("Window"),Rect.new(64+(ind%8)*8,96+(ind/8)*8,8,8))
- else
- dum.fill_rect(dum.rect, text_color(ind))
- end
- for x in 0...width
- for y in 0...height
- set_pixel(x,y,dum.get_pixel(x,y)) if get_pixel(x,y) == c
- end
- end
- dum.dispose
- end
- def color_ind(col)
- for i in 0...32
- return i if text_color(i).red == col.red &&
- text_color(i).green == col.green &&
- text_color(i).blue == col.blue
- end
- @@xtra_col ||= []
- for c in 0...@@xtra_col.size
- return 32+c if @@xtra_col[c].red == col.red &&
- @@xtra_col[c].green == col.green &&
- @@xtra_col[c].blue == col.blue
- end
- @@xtra_col.push(col)
- return 31+@@xtra_col.size
- end
- def text_color(n)
- if n < 32
- x = 64 + (n % 8) * 8
- y = 96 + (n / 8) * 8
- return Cache.system("Window").get_pixel(x, y)
- end
- return Color.new(0,0,0) if (@@xtra_col ||= []).size <= n-32
- return @@xtra_col[n-32]
- end
- alias_method :text_size_b4_rm2k, :text_size unless method_defined?(:text_size_b4_rm2k)
- def text_size(str)
- m = font.font_type
- case m
- when 1,3
- f = "Font"
- f += "/" if m==3 && font.bold || font.italic
- f += "B" if font.bold
- f += "I" if font.italic
- fh = (font.size*16)/RM2K::STANDARD_FONT_SIZE
- e = font.shadow ? 1 : 0
- st = str.to_s.encode(RM2K::TABLE_ENCODING) rescue str.to_s
- st.each_byte {|b|
- b = "f" + b.to_s if m==3
- img = Cache.system(f, b)
- e += img.width+2
- }
- return Rect.new(0,4-(fh-16)/2,e,fh)
- when 0,2
- return text_size_b4_rm2k(str)
- end
- return Rect.new(0,0,1,1)
- end
- alias_method :draw_text_b4_rm2k, :draw_text unless method_defined?(:draw_text_b4_rm2k)
- def draw_text(*t)
- case t.size
- when 2,3
- x,y,w,h,s,a = t[0].x,t[0].y,t[0].width,t[0].height,t[1], t.size==3? t[2] : 0
- when 5,6
- x,y,w,h,s,a = t[0],t[1],t[2],t[3],t[4], t.size==6? t[5] : 0
- end
- if [1,3].include?(RM2K::FONT_TYPE)
- s = case s
- when "→"; ">"
- when "×"; "x"
- when "←"; "<"
- else; s; end
- end
- m = font.font_type
- case m
- when 0 # nessun cambiamento
- draw_text_b4_rm2k(x,y,w,h,s,a)
- when 1 # usa una tavolozza font 8x8
- f = "Font"
- f += "B" if font.bold
- f += "I" if font.italic
- plus = 0
- ts = text_size(s)
- plus = w/2 - ts.width/2 - 1 if a == 1
- plus = w - ts.width if a == 2
- fh = (font.size*16)/RM2K::STANDARD_FONT_SIZE
- e = 0
- st = s.to_s.encode(RM2K::TABLE_ENCODING) rescue s.to_s
- st.each_byte {|b|
- x_b = x+plus+e
- y_b = y + h/2 - ts.height/2
- if font.outline
- img = Cache.system(f, b, color_ind(font.out_color))
- iw = img.width
- stretch_blt(Rect.new(x_b+2,y_b+2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
- stretch_blt(Rect.new(x_b+2,y_b,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
- stretch_blt(Rect.new(x_b+2,y_b-2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
- stretch_blt(Rect.new(x_b,y_b+2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
- stretch_blt(Rect.new(x_b,y_b-2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
- stretch_blt(Rect.new(x_b-2,y_b+2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
- stretch_blt(Rect.new(x_b-2,y_b,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
- stretch_blt(Rect.new(x_b-2,y_b-2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
- end
- if font.shadow# && !font.outline
- img = Cache.system(f, b)
- iw = img.width
- stretch_blt(Rect.new(x_b+2,y_b+2,iw,fh),img,Rect.new(0,0,iw,16))
- end
- img = Cache.system(f, b, color_ind(font.color))
- iw = img.width
- stretch_blt(Rect.new(x_b,y_b,iw,fh),img,Rect.new(0,0,iw,16), font.color.alpha)
- e += iw+2
- }
- when 2 # usa font normale
- b = Bitmap.new(w/2,h/2)
- b.font = font.clone
- b.font.size = font.size/2
- b.draw_text_b4_rm2k(0,0,w/2,h/2,s,a)
- stretch_blt(Rect.new(x,y,w,h), b, b.rect)
- b.dispose
- when 3 # usa file immagine Wx8 in cartelle (dove W è variabile)
- f = "Font"
- if font.bold
- f += "/B"
- f += "I" if font.italic
- elsif font.italic
- f += "/I"
- end
- plus = 0
- ts = text_size(s)
- plus = w/2 - ts.width/2 - 1 if a == 1
- plus = w - ts.width if a == 2
- fh = (font.size*16)/RM2K::STANDARD_FONT_SIZE
- e = 0
- st = s.to_s.encode(RM2K::TABLE_ENCODING) rescue s.to_s
- st.each_byte {|b|
- x_b = x+plus+e
- y_b = y + h/2 - ts.height/2
- if font.outline
- img = Cache.system(f, "f"+b.to_s, color_ind(font.out_color))
- iw = img.width
- stretch_blt(Rect.new(x_b+2,y_b+2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
- stretch_blt(Rect.new(x_b+2,y_b,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
- stretch_blt(Rect.new(x_b+2,y_b-2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
- stretch_blt(Rect.new(x_b,y_b+2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
- stretch_blt(Rect.new(x_b,y_b-2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
- stretch_blt(Rect.new(x_b-2,y_b+2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
- stretch_blt(Rect.new(x_b-2,y_b,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
- stretch_blt(Rect.new(x_b-2,y_b-2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
- end
- if font.shadow# && !font.outline
- img = Cache.system(f, "f"+b.to_s)
- iw = img.width
- stretch_blt(Rect.new(x_b+2,y_b+2,iw,fh),img,Rect.new(0,0,iw,16))
- end
- img = Cache.system(f, "f"+b.to_s, color_ind(font.color))
- iw = img.width
- stretch_blt(Rect.new(x_b,y_b,iw,fh),img,Rect.new(0,0,iw,16), font.color.alpha)
- e += iw+2
- }
- end
- end
- end
- module Cache
- def self.system(filename, ind = "", col = "")
- load_bitmap("Graphics/System/", filename, 0, ind, col)
- end
- def self.load_bitmap(folder_name, filename, hue = 0, ind = "", col = "")
- @cache ||= {}
- plus = $TEST? "Mid" : ""
- path = trupath = plus + folder_name + filename
- path += ":" + ind.to_s + ":" + col.to_s if (ind != "" || col != "")
- if not @cache.include?(path) or @cache[path].disposed?
- if filename.empty?
- @cache[path] = Bitmap.new(32, 32)
- else
- if ind != ""
- if ind[0] != "f"
- bit = Bitmap.new(trupath)
- buf = Bitmap.new(8,8)
- px = (ind%16)*8
- py = (ind/16)*8
- buf.blt(0,0,bit,Rect.new(px,py,8,8))
- bit = buf.tru_img
- buf.dispose
- else
- if FileTest.exist?(trupath+"/"+ind+".png")
- bit = Bitmap.new(trupath+"/"+ind)
- else
- bit = Bitmap.new(1,16)
- end
- end
- bit.recolour(col) if col != ""
- else
- bit = Bitmap.new(trupath)
- end
- @cache[path] = bit.double
- end
- end
- if hue == 0
- return @cache[path]
- else
- key = [path, hue]
- if not @cache.include?(key) or @cache[key].disposed?
- @cache[key] = @cache[path].clone
- @cache[key].hue_change(hue)
- end
- return @cache[key]
- end
- end
- end
- class Sprite_Character < Sprite_Base
- def update_src_rect
- if @tile_id == 0
- index = @character.character_index
- pattern = @character.pattern < 3 ? @character.pattern : 1
- sx = (index % 4 * 3 + pattern) * @cw
- dir = 0
- if @character_name.include?("#")
- case @character.direction
- when 2; dir = 2
- when 4; dir = 3
- when 6; dir = 1
- when 8; dir = 0
- end
- else
- dir = (@character.direction - 2) / 2
- end
- sy = (index / 4 * 4 + dir) * @ch
- self.src_rect.set(sx, sy, @cw, @ch)
- end
- end
- end
- module SceneManager
- def self.snapshot_for_background
- @background_bitmap.dispose if @background_bitmap
- @background_bitmap = Graphics.snap_to_bitmap
- @background_bitmap.blur if RM2K::BLUR_SCREEN_ON_MENU
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement