Advertisement
mikb89

[Ace] RM2k/2k3 Graphics (320x240) v1.5

Jun 17th, 2012
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 13.66 KB | None | 0 0
  1. # RM2k/2k3 Graphics (320x240) v. 1.5
  2. # VX Ace version
  3. # by mikb89 & 255
  4.  
  5. # Details:
  6. #  With this script you can use graphic files with a lower resolution, similar
  7. #   to the older RPG Maker. The size of the graphic will be doubled once drawn.
  8. #
  9. #  MidGraphics folder contains resized images, while Graphics is used by the
  10. #   application, as usually.
  11. #  The problem is that the tool CAN'T double images WHILE making your project,
  12. #   so we have to carry a double-copy of images, to use them in the project.
  13. #  If you use other images or modify those existing, insert them in MidGraphics.
  14. #  Next, do a copy of them which is double-sized and insert in Graphics at the
  15. #   same location. No matter quality, it's just for pratical purpuose.
  16. #  Once you release the game, get rid (but not permanently!) of Graphics
  17. #   let MidGraphics take his place by renaming in Graphics and you're ready.
  18. #  During test, in fact, images are taken from MidGraphics, but in normal
  19. #   playing (by opening Game.exe) they came from Graphics. This way you can
  20. #   release the project as usual also by menu File option and everything will
  21. #   work, included criptation for ones who care about image copyright.
  22.  
  23. # Configurations:
  24. module RM2K
  25.   FONT_TYPE = 1
  26.    # You can choose between:
  27.     # 0: Nothing to say, just tipical text.
  28.     # 1: Tipical of RPG Maker 2k/2k3. Color depends by EACH pixel in windowskin
  29.     #     color and characters come from the Font.png image inside System.
  30.     #     Characters max size is 8x8 but don't worry about the i: if there are
  31.     #     empty spaces before or after the character, they'll be trimmed.
  32.     #    For bold and italic the image is FontBI, for just bold it's FontB and
  33.     #     for italic, FontI.
  34.     # 2: Usual font. The only thing to know is that the text is stretched then
  35.     #     enlarged. That because the normal font (in my opinion) doesn't fit
  36.     #     with the doubled images style.
  37.     # 3: Characters in separated image files. Create inside System a Fonts
  38.     #     folder; inside this, insert the characters as f0, f1, f2 with the
  39.     #     number part representing the ASCII code (e.g. f49 is the zero).
  40.     #    For bold characters folder name will be B, I for italic, BI for both.
  41.     #     B, I, BI must be placed inside Fonts.
  42.     #    In this drawing type, characters width depend on image width.
  43.    # Other numbers: won't see anything... may somebody like it?
  44.  
  45.   RESIZE_SCREEN = true
  46.    # With true, screen size will be 640x480.
  47.  
  48.   CHANGE_SKIN_TONE = true
  49.    # Window tone is usually changed by database. To deactivate this
  50.    #  functionality and use the image as is, you can set this to false.
  51.  
  52.   BLUR_SCREEN_ON_MENU = false
  53.    # Background map bitmap is commonly blurred when accessing menus. Setting
  54.    #  false will remove this effect.
  55.  
  56.  
  57.   # Advanced settings. Don't touch unless you know what you're doing.
  58.  
  59.   STANDARD_FONT_SIZE = Font.default_size
  60.    # Needed for measuring the amount of resizing for character in images.
  61.  
  62.   TABLE_ENCODING = "iso-8859-1"
  63.    # Change characters encoding.
  64. end
  65.  
  66. #Codename: rm2k
  67.  
  68. ($imported ||= {})[:mikb89_255_rm2k] = true
  69.  
  70. # License:
  71. # - You can ask me to include support for other scripts as long as these scripts
  72. #   use the $imported[script] = true;
  73. # - You can modify and even repost my scripts, after having received a response
  74. #   by me. For reposting it, anyway, you must have done heavy edit or porting,
  75. #   you can't do a post with the script as is;
  76. # - You can use my scripts for whatever you want, from free to open to
  77. #   commercial games. I'd appreciate by the way if you let me know about what
  78. #   you're doing;
  79. # - You must credit me, if you use this script or part of it.
  80.  
  81. # Ace version mods
  82. Graphics.resize_screen(640,480) if RM2K::RESIZE_SCREEN
  83. #class Window_Base#def update_tone() <- rewritten
  84. (class Window_Base; def update_tone; end; end) unless RM2K::CHANGE_SKIN_TONE
  85.  
  86. # Old script from VX version
  87.  
  88. module SceneManager; unless RM2K::BLUR_SCREEN_ON_MENU
  89. #module SceneManager#def self.snapshot_for_background() <- rewritten
  90.   def self.snapshot_for_background
  91.     @background_bitmap.dispose if @background_bitmap
  92.     @background_bitmap = Graphics.snap_to_bitmap
  93.   end
  94. end; end
  95.  
  96. class Font
  97.   attr_writer :font_type
  98. #class Font#def self.default_font_type()
  99.   def self.default_font_type
  100.     @default_font_type = RM2K::FONT_TYPE if @default_font_type == nil
  101.     @default_font_type
  102.   end
  103. #class Font#def self.default_font_type=(dm)
  104.   def self.default_font_type=(dm)
  105.     @default_font_type = dm
  106.   end
  107. #class Font#def font_type()
  108.   def font_type
  109.     @font_type = Font.default_font_type if @font_type == nil
  110.     @font_type
  111.   end
  112. end
  113.  
  114. class Bitmap
  115. #class Bitmap#def double()
  116.   def double
  117.     b = Bitmap.new(width*2, height*2)
  118.     b.stretch_blt(b.rect, self, rect)
  119.     b
  120.   end
  121. #class Bitmap#def tru_img()
  122.   def tru_img # get the image without trasparent left and right borders
  123.     sx, fx = width-1, 0
  124.     c = Color.new(0,0,0)
  125.     for x in 0...width
  126.       e = false
  127.       for y in 0...height
  128.         if get_pixel(x,y) == c
  129.           e = true
  130.           break
  131.         end
  132.       end
  133.       if e == true
  134.         sx = x
  135.         break
  136.       end
  137.     end
  138.     for x in 1...width
  139.       e = false
  140.       for y in 0...height
  141.         if get_pixel(width-x,y) == c
  142.           e = true
  143.           break
  144.         end
  145.       end
  146.       if e == true
  147.         fx = width-x
  148.         break
  149.       end
  150.     end
  151.     if fx+1 > sx
  152.       bit = Bitmap.new(fx-sx+1,height)
  153.       bit.blt(0,0,self,Rect.new(sx,0,fx-sx+1,height))
  154.       return bit
  155.     else
  156.       return Bitmap.new(width/2,height)
  157.     end
  158.   end
  159. #class Bitmap#def recolour(ind)
  160.   def recolour(ind) # color change from c to ind(ex) in Window.png
  161.     c = Color.new(0,0,0)
  162.     dum = Bitmap.new(8,8)
  163.     if ind < 32
  164.       dum.blt(0,0,Cache.system("Window"),Rect.new(64+(ind%8)*8,96+(ind/8)*8,8,8))
  165.     else
  166.       dum.fill_rect(dum.rect, text_color(ind))
  167.     end
  168.     for x in 0...width
  169.       for y in 0...height
  170.         set_pixel(x,y,dum.get_pixel(x,y)) if get_pixel(x,y) == c
  171.       end
  172.     end
  173.     dum.dispose
  174.   end
  175. #class Bitmap#def color_ind(col)
  176.   def color_ind(col) # get the index of color if found in palette or cache
  177.     for i in 0...32
  178.       return i if text_color(i).red == col.red &&
  179.                   text_color(i).green == col.green &&
  180.                   text_color(i).blue == col.blue
  181.     end
  182.     @@xtra_col ||= []
  183.     for c in 0...@@xtra_col.size
  184.       return 32+c if @@xtra_col[c].red == col.red &&
  185.                      @@xtra_col[c].green == col.green &&
  186.                      @@xtra_col[c].blue == col.blue
  187.     end
  188.     @@xtra_col.push(col)
  189.     return 31+@@xtra_col.size
  190.   end
  191. #class Bitmap#def text_color(n)
  192.   def text_color(n) # get color from palette or from cache
  193.     if n < 32
  194.       x = 64 + (n % 8) * 8
  195.       y = 96 + (n / 8) * 8
  196.       return Cache.system("Window").get_pixel(x, y)
  197.     end
  198.     return Color.new(0,0,0) if (@@xtra_col ||= []).size <= n-32
  199.     return @@xtra_col[n-32]
  200.   end
  201.   alias_method(:text_size_b4_rm2k, :text_size) unless method_defined?(:text_size_b4_rm2k)
  202. #class Bitmap#def text_size(str) <- aliased
  203.   def text_size(str)
  204.     m = font.font_type
  205.     case m
  206.     when 1,3
  207.       f = "Font" + ((m == 3) ? "s" : "")
  208.       f += "/" if m==3 && font.bold || font.italic
  209.       f += "B" if font.bold
  210.       f += "I" if font.italic
  211.       fh = (font.size*16)/RM2K::STANDARD_FONT_SIZE
  212.       e = font.shadow ? 1 : 0
  213.       st = str.to_s.encode(RM2K::TABLE_ENCODING) rescue str.to_s
  214.       st.each_byte {|b|
  215.         b = "f" + b.to_s if m==3
  216.         img = Cache.system(f, b)
  217.         e += img.width+2
  218.       }
  219.       return Rect.new(0,4-(fh-16)/2,e,fh)
  220.     when 0,2
  221.       return text_size_b4_rm2k(str)
  222.     end
  223.     return Rect.new(0,0,1,1)
  224.   end
  225.  
  226.   alias_method(:draw_text_b4_rm2k, :draw_text) unless method_defined?(:draw_text_b4_rm2k)
  227. #class Bitmap#def draw_text(*t) <- aliased
  228.   def draw_text(*t)
  229.     case t.size
  230.     when 2,3
  231.       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
  232.     when 5,6
  233.       x,y,w,h,s,a = t[0],t[1],t[2],t[3],t[4],t.size==6 ? t[5] : 0
  234.     end
  235.     m = font.font_type
  236.     if [1,3].include?(m)
  237.       s = case s
  238.        when "โ†’"; ">"
  239.        when "ร—"; "x"
  240.        when "โ†"; "<"
  241.       else; s; end
  242.     end
  243.     case m
  244.     when 0 # nessun cambiamento
  245.       draw_text_b4_rm2k(x,y,w,h,s,a)
  246.     when 1 # usa una tavolozza font 8x8
  247.       f = "Font"
  248.       f += "B" if font.bold
  249.       f += "I" if font.italic
  250.       plus = 0
  251.       ts = text_size(s)
  252.       plus = w/2 - ts.width/2 - 1 if a == 1
  253.       plus = w - ts.width if a == 2
  254.       fh = (font.size*16)/RM2K::STANDARD_FONT_SIZE
  255.       e = 0
  256.       st = s.to_s.encode(RM2K::TABLE_ENCODING) rescue s.to_s
  257.       st.each_byte {|b|
  258.         x_b = x+plus+e
  259.         y_b = y + h/2 - ts.height/2
  260.         if font.outline
  261.           img = Cache.system(f, b, color_ind(font.out_color))
  262.           iw = img.width
  263.           stretch_blt(Rect.new(x_b+2,y_b+2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
  264.           stretch_blt(Rect.new(x_b+2,y_b,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
  265.           stretch_blt(Rect.new(x_b+2,y_b-2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
  266.           stretch_blt(Rect.new(x_b,y_b+2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
  267.           stretch_blt(Rect.new(x_b,y_b-2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
  268.           stretch_blt(Rect.new(x_b-2,y_b+2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
  269.           stretch_blt(Rect.new(x_b-2,y_b,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
  270.           stretch_blt(Rect.new(x_b-2,y_b-2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
  271.         end
  272.         if font.shadow# && !font.outline
  273.           img = Cache.system(f, b)
  274.           iw = img.width
  275.           stretch_blt(Rect.new(x_b+2,y_b+2,iw,fh),img,Rect.new(0,0,iw,16))
  276.         end
  277.         img = Cache.system(f, b, color_ind(font.color))
  278.         iw = img.width
  279.         stretch_blt(Rect.new(x_b,y_b,iw,fh),img,Rect.new(0,0,iw,16), font.color.alpha)
  280.         e += iw+2
  281.       }
  282.     when 2 # usa font normale
  283.       b = Bitmap.new(w/2,h/2)
  284.       b.font = font.clone
  285.       b.font.size = font.size/2
  286.       b.draw_text_b4_rm2k(0,0,w/2,h/2,s,a)
  287.       stretch_blt(Rect.new(x,y,w,h), b, b.rect)
  288.       b.dispose
  289.     when 3 # usa file immagine Wx8 in cartelle (dove W รจ variabile)
  290.       f = "Fonts"
  291.       if font.bold
  292.         f += "/B"
  293.         f += "I" if font.italic
  294.       elsif font.italic
  295.         f += "/I"
  296.       end
  297.       plus = 0
  298.       ts = text_size(s)
  299.       plus = w/2 - ts.width/2 - 1 if a == 1
  300.       plus = w - ts.width if a == 2
  301.       fh = (font.size*16)/RM2K::STANDARD_FONT_SIZE
  302.       e = 0
  303.       st = s.to_s.encode(RM2K::TABLE_ENCODING) rescue s.to_s
  304.       st.each_byte {|b|
  305.         x_b = x+plus+e
  306.         y_b = y + h/2 - ts.height/2
  307.         if font.outline
  308.           img = Cache.system(f, "f"+b.to_s, color_ind(font.out_color))
  309.           iw = img.width
  310.           stretch_blt(Rect.new(x_b+2,y_b+2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
  311.           stretch_blt(Rect.new(x_b+2,y_b,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
  312.           stretch_blt(Rect.new(x_b+2,y_b-2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
  313.           stretch_blt(Rect.new(x_b,y_b+2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
  314.           stretch_blt(Rect.new(x_b,y_b-2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
  315.           stretch_blt(Rect.new(x_b-2,y_b+2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
  316.           stretch_blt(Rect.new(x_b-2,y_b,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
  317.           stretch_blt(Rect.new(x_b-2,y_b-2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
  318.         end
  319.         if font.shadow# && !font.outline
  320.           img = Cache.system(f, "f"+b.to_s)
  321.           iw = img.width
  322.           stretch_blt(Rect.new(x_b+2,y_b+2,iw,fh),img,Rect.new(0,0,iw,16))
  323.         end
  324.         img = Cache.system(f, "f"+b.to_s, color_ind(font.color))
  325.         iw = img.width
  326.         stretch_blt(Rect.new(x_b,y_b,iw,fh),img,Rect.new(0,0,iw,16), font.color.alpha)
  327.         e += iw+2
  328.       }
  329.     end
  330.   end
  331. end
  332.  
  333. module Cache
  334. #module Cache#def self.system(filename, ind, col) <- rewritten
  335.   def self.system(filename, ind = "", col = "")
  336.     load_bitmap("Graphics/System/", filename, 0, ind, col)
  337.   end
  338. #module Cache#def self.load_bitmap(folder_name, filename, hue, ind, col) <- rewritten
  339.   def self.load_bitmap(folder_name, filename, hue = 0, ind = "", col = "")
  340.     @cache ||= {}
  341.     plus = $TEST ? "Mid" : ""
  342.     path = trupath = plus + folder_name + filename
  343.     path += ":" + ind.to_s + ":" + col.to_s if (ind != "" || col != "")
  344.     if not @cache.include?(path) or @cache[path].disposed?
  345.       if filename.empty?
  346.         @cache[path] = Bitmap.new(32, 32)
  347.       else
  348.         if ind != ""
  349.           if ind[0] != "f"
  350.             bit = Bitmap.new(trupath)
  351.             buf = Bitmap.new(8,8)
  352.             px = (ind%16)*8
  353.             py = (ind/16)*8
  354.             buf.blt(0,0,bit,Rect.new(px,py,8,8))
  355.             bit = buf.tru_img
  356.             buf.dispose
  357.           else
  358.             if FileTest.exist?(trupath+"/"+ind+".png")
  359.               bit = Bitmap.new(trupath+"/"+ind)
  360.             else
  361.               bit = Bitmap.new(1,16)
  362.             end
  363.           end
  364.           bit.recolour(col) if col != ""
  365.         else
  366.           bit = Bitmap.new(trupath)
  367.         end
  368.         @cache[path] = bit.double
  369.       end
  370.     end
  371.     if hue == 0
  372.       return @cache[path]
  373.     else
  374.       key = [path, hue]
  375.       if not @cache.include?(key) or @cache[key].disposed?
  376.         @cache[key] = @cache[path].clone
  377.         @cache[key].hue_change(hue)
  378.       end
  379.       return @cache[key]
  380.     end
  381.   end
  382. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement