Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # RM2k/2k3 Graphics (320x240) v. 1.5
- # VX Ace version
- # by mikb89 & 255
- # Details:
- # 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.
- #
- # MidGraphics folder contains resized images, while Graphics is used by the
- # application, as usually.
- # The problem is that the tool 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. 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.
- # Configurations:
- module RM2K
- FONT_TYPE = 1
- # You can choose between:
- # 0: Nothing to say, just tipical text.
- # 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 the i: if there are
- # empty spaces before or after the character, they'll be trimmed.
- # For bold and italic the image is FontBI, for just bold it's FontB and
- # for italic, FontI.
- # 2: Usual font. The only thing to know is that the text is stretched then
- # enlarged. That because the normal font (in my opinion) doesn't fit
- # with the doubled images style.
- # 3: Characters in separated image files. Create inside System a Fonts
- # folder; inside this, insert the characters as f0, f1, f2 with the
- # number part representing the ASCII code (e.g. f49 is the zero).
- # For bold characters folder name will be B, I for italic, BI for both.
- # B, I, BI must be placed inside Fonts.
- # In this drawing type, characters width depend on image width.
- # Other numbers: won't see anything... may somebody like it?
- RESIZE_SCREEN = true
- # With true, screen size will be 640x480.
- CHANGE_SKIN_TONE = true
- # 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
- # Background map bitmap is commonly blurred when accessing menus. Setting
- # false will remove this effect.
- # Advanced settings. Don't touch unless you know what you're doing.
- STANDARD_FONT_SIZE = Font.default_size
- # Needed for measuring the amount of resizing for character in images.
- TABLE_ENCODING = "iso-8859-1"
- # Change characters encoding.
- end
- #Codename: rm2k
- ($imported ||= {})[:mikb89_255_rm2k] = true
- # License:
- # - You can ask me to include support for other scripts as long as these scripts
- # use the $imported[script] = true;
- # - You can modify and even repost my scripts, after having received a response
- # by me. For reposting it, anyway, you must have done heavy edit or porting,
- # you can't do a post with the script as is;
- # - You can use my scripts for whatever you want, from free to open to
- # commercial games. I'd appreciate by the way if you let me know about what
- # you're doing;
- # - You must credit me, if you use this script or part of it.
- # Ace version mods
- Graphics.resize_screen(640,480) if RM2K::RESIZE_SCREEN
- #class Window_Base#def update_tone() <- rewritten
- (class Window_Base; def update_tone; end; end) unless RM2K::CHANGE_SKIN_TONE
- # Old script from VX version
- module SceneManager; unless RM2K::BLUR_SCREEN_ON_MENU
- #module SceneManager#def self.snapshot_for_background() <- rewritten
- def self.snapshot_for_background
- @background_bitmap.dispose if @background_bitmap
- @background_bitmap = Graphics.snap_to_bitmap
- end
- end; end
- class Font
- attr_writer :font_type
- #class Font#def self.default_font_type()
- def self.default_font_type
- @default_font_type = RM2K::FONT_TYPE if @default_font_type == nil
- @default_font_type
- end
- #class Font#def self.default_font_type=(dm)
- def self.default_font_type=(dm)
- @default_font_type = dm
- end
- #class Font#def font_type()
- def font_type
- @font_type = Font.default_font_type if @font_type == nil
- @font_type
- end
- end
- class Bitmap
- #class Bitmap#def double()
- def double
- b = Bitmap.new(width*2, height*2)
- b.stretch_blt(b.rect, self, rect)
- b
- end
- #class Bitmap#def tru_img()
- def tru_img # get the image without trasparent left and right borders
- 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
- #class Bitmap#def recolour(ind)
- def recolour(ind) # color change from c to ind(ex) in Window.png
- 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
- #class Bitmap#def color_ind(col)
- def color_ind(col) # get the index of color if found in palette or cache
- 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
- #class Bitmap#def text_color(n)
- def text_color(n) # get color from palette or from cache
- 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)
- #class Bitmap#def text_size(str) <- aliased
- def text_size(str)
- m = font.font_type
- case m
- when 1,3
- f = "Font" + ((m == 3) ? "s" : "")
- 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)
- #class Bitmap#def draw_text(*t) <- aliased
- 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
- m = font.font_type
- if [1,3].include?(m)
- s = case s
- when "โ"; ">"
- when "ร"; "x"
- when "โ"; "<"
- else; s; end
- end
- 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 = "Fonts"
- 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
- #module Cache#def self.system(filename, ind, col) <- rewritten
- def self.system(filename, ind = "", col = "")
- load_bitmap("Graphics/System/", filename, 0, ind, col)
- end
- #module Cache#def self.load_bitmap(folder_name, filename, hue, ind, col) <- rewritten
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement