Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # RM2k/2k3 Graphics (320x240) v. 1.5
- # XP version
- # by mikb89
- # 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. Characters come from the Font.png image
- # inside Graphics, in the subfolder you can choose next. 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 Graphics the 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?
- FONT_FOLDER = "Windowskins/"
- # Where are the fonts IF method is 1? (Fonts in this case are the four images
- # Font, FontB, FontI and FontBI). Write "Fonts/" if you want to use the same
- # folder as the other method.
- # 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.
- end
- #Codename: rm2k
- ($imported ||= {})[:mikb89_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.
- # Codice per codifica accentate
- class String
- #class String#def conv()
- def conv # convert to a byte array
- ns = []
- add_n = false
- self.each_byte {|b|
- if add_n
- ns.push(b+64)
- add_n = false
- elsif b < 128
- ns.push(b)
- add_n = false
- else
- add_n = true
- end
- }
- ns
- end
- end
- class Fixnum
- #class Fixnum#def conv()
- def conv # convert to a byte array
- ns = []
- self.to_s.each_byte {|b| ns << b}
- ns
- end
- end
- # Codice vecchio
- 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 color ind(ex) in Window_Base/cache
- c = Color.new(0,0,0)
- p = text_color(ind)
- for x in 0...width
- for y in 0...height
- set_pixel(x,y,p) if get_pixel(x,y) == c
- end
- end
- 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...8
- 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 8+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 7+@@xtra_col.size
- end
- #class Bitmap#def text_color(n)
- def text_color(n) # get color from palette or from cache
- if n < 8
- w = Window_Base.new(-33,-33,33,33)
- p = w.text_color(n)
- w.dispose
- return p
- end
- return Color.new(0,0,0) if (@@xtra_col ||= []).size <= n-8
- return @@xtra_col[n-8]
- 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 == 1) ? "" : "s/")
- f += "B" if font.bold
- f += "I" if font.italic
- f += "/" if m==3 && (font.bold || font.italic)
- fh = (font.size*16)/RM2K::STANDARD_FONT_SIZE
- e = ((font.respond_to?(:shadow) && font.shadow) ? 1 : 0)
- for b in str.conv
- b = "f" + b.to_s if m==3
- img = RPG::Cache.font(f, b)
- e += img.width+2
- end
- 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
- 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
- for b in s.conv
- x_b = x+plus+e
- y_b = y + h/2 - ts.height/2
- #if font.shadow
- # img = RPG::Cache.font(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 = RPG::Cache.font(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
- end
- 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/"
- f += "B" if font.bold
- f += "I" if font.italic
- f += "/" if font.bold || 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
- for b in s.conv
- x_b = x+plus+e
- y_b = y + h/2 - ts.height/2
- #if font.shadow
- # img = RPG::Cache.font(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 = RPG::Cache.font(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
- end
- module RPG::Cache
- #module RPG::Cache#def self.font(filename, ind, col)
- def self.font(filename, ind = "", col = "")
- fold = "Graphics/"
- fold += RM2K::FONT_FOLDER if ind.is_a?(Numeric)
- load_bitmap(fold, filename, 0, ind, col)
- end
- #module RPG::Cache#def self.load_bitmap(folder_name, filename, hue, ind, col) <- rewritten
- def self.load_bitmap(folder_name, filename, hue = 0, ind = "", col = "")
- plus = $DEBUG ? "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"[0]
- 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
- @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
- @cache[key]
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement