Advertisement
rpgmakergraphics

[VX Ace] RM2k/2k3 Graphics (320x240) v. 1.4

Apr 12th, 2012
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 16.70 KB | None | 0 0
  1. # RM2k/2k3 Graphics (320x240) v. 1.4
  2. # Ace version
  3. # by mikb89 & 255
  4.  
  5. # Scriverò un po' italiano e un po' inglese, spero di non urtarvi ^^
  6. # I'll write both in italian & english, I hope this won't get you angry ^^
  7.  
  8. # Guida italiano
  9.  
  10.   # Questo script permette di utilizzare grafica nello stile 2k/2k3 in quanto
  11.   # ogni immagine visualizzata viene ingrandita del 2x, come avveniva nei vecchi
  12.   # RPG Maker.
  13.  
  14.   # Per importare DIRETTAMENTE i charset del 2k/2k3 inserite
  15.   # il simbolo # davanti al nome del file. Esempio: '#Chara1'.
  16.   # Così facendo lo script mostrerà correttamente le direzioni dei
  17.   # charset (i charset del 2k/2k3 hanno infatti posizioni diverse).
  18.   # Ovviamente nell'importarli dovrete settare il colore trasparente.
  19.  
  20.   # La cartella MidGraphics contiene le immagini ridimensionate, mentre la
  21.   # Graphics serve per vedere le immagini nel programma.
  22.   # Il problema è che, anche se dagli script le immagini vengono raddoppiate, il
  23.   # vx ace non lo fa, perciò vi serve una copia delle immagini in dimensioni
  24.   # doppie.
  25.   # Se importate immagini vostre o ne modificate, mettetele in MidGraphics.
  26.   # Dopodiché, fatene una copia a dimensioni raddoppiate e mettetela in Graphics.
  27.   # Non importa la qualità, serve solo momentaneamente per gestirla correttamente
  28.   # nel progetto.
  29.   # Una volta che rilasciate il gioco, togliete (magari temporaneamente) la
  30.   # cartella Graphics, rinominate MidGraphics in Graphics e distribuite.
  31.   # Durante il test infatti le immagini vengono prese da MidGraphics, altrimenti
  32.   # da Graphics. Inoltre se distribuite tramite il comando del menu File in questo
  33.   # modo le immagini verranno normalmente criptate, se settate l'opzione.
  34.  
  35. # English guide
  36.  
  37.   # With this script you can use graphic files with a lower resolution, similar
  38.   # to the older RPG Maker. The size of the graphic will be doubled once drawn.
  39.  
  40.   # Old RPG Maker charsets can be used DIRECTLY by inserting a '#' in the file
  41.   # name. Ex: '#Chara1'.
  42.   # This way the script will correctly show the directions of the charsets
  43.   # (indeed charsets from the 2k/2k3 have different positions).
  44.   # You have to set the transparent colour when importing though.
  45.  
  46.   # MidGraphics folder contains resized images, while Graphics is used by the
  47.   # application, as usually.
  48.   # The problem is that vx ace CAN'T double images WHILE making your project, so
  49.   # we have to carry a double-copy of images, to use them in the project.
  50.   # If you use other images or modify those existing, insert them in MidGraphics.
  51.   # Next, do a copy of them which is double-sized and insert in Graphics at the
  52.   # same location. No matter quality, it's just for pratical purpuose.
  53.   # Once you release the game, get rid (but not permanently!) of Graphics
  54.   # let MidGraphics take his place by renaming in Graphics and you're ready.
  55.   # During test, in fact, images are taken from MidGraphics, but in normal playing
  56.   # (by opening Game.exe) they came from Graphics. In this way you can release the
  57.   # project as usual also by menu File option and everything will work, included
  58.   # criptation for ones who care about image copyright.
  59.  
  60. # Impostazioni // Settings
  61.  
  62. module RM2K
  63.   FONT_TYPE = 1
  64.   # Puoi scegliere fra:  //  You can choose between:
  65.  
  66.   # 0: Niente da dire, testo normale.
  67.  
  68.   # 0: Nothing to say, just tipical text.
  69.  
  70.   # 1: Metodo tipico RPG Maker 2k/2k3. Il colore dipende da OGNI pixel del
  71.   #     quadratino colore nella windowskin e il testo viene preso da una
  72.   #     palette bitmap chiamata Font.png dentro System. Ogni carattere ha
  73.   #     dimensioni max 8x8 ma non preoccupatevi per le i: se il carattere ha
  74.   #     spazi vuoti vengono riconosciuti ed eliminati.
  75.   #     Per corsivo e grassetto l'immagine è FontBI, per grassetto è FontB e
  76.   #     per corsivo è FontI.
  77.  
  78.   # 1: Tipical of RPG Maker 2k/2k3. Color depends by EACH pixel in windowskin
  79.   #     color and characters come from the Font.png image inside System.
  80.   #     Characters max size is 8x8 but don't worry about i: if there are empty
  81.   #     spaces before or after the character, they'll be (brutally) trimmed.
  82.   #     For bold and italic the image is FontBI, for just bold it's FontB and
  83.   #     for italic, FontI.
  84.  
  85.   # 2: Font normale. L'unica cosa è che viene prima dimezzato e poi raddoppiato,
  86.   #     con ovvia perdità di qualità. Potevo non fare questo giro ma il testo
  87.   #     normale mi pare che stoni.
  88.  
  89.   # 2: Usual font. The only thing to know is that the text is stretched and
  90.   #     enlarged to obtain a vintage (see also: awful) effect. That because the
  91.   #     normal font (in my opinion) doesn't fit with the doubled images style.
  92.  
  93.   # 3: Caratteri in immagini separate. Create dentro System la cartella Font;
  94.   #     dentro questa mettete i caratteri come f0, f1, f2 con il numero che
  95.   #     rappresenta il codice ASCII del carattere (es. f49 sarà lo zero).
  96.   #     Per il grassetto bisogna creare la cartella B, I per il corsivo e BI per
  97.   #     la combinazione delle due. B, I, BI stanno dentro Font.
  98.   #     In questa modalità la larghezza dei caratteri è decisa dall'immagine.
  99.  
  100.   # 3: Characters in separated image files. Create inside System the Font folder;
  101.   #     inside this, insert the characters as f0, f1, f2 with the number part
  102.   #     representing the ASCII code (f49 is the zero, for example).
  103.   #     For bold characters folder name will be B, I for italic, BI for both.
  104.   #     B, I, BI must be placed inside Font.
  105.   #     In this drawing type, characters width depend on image width.
  106.  
  107.   # Numero a casaccio: Non vi scriverà niente.
  108.  
  109.   # Random number: Won't see anything, somebody may like it...
  110.  
  111.   RESIZE_SCREEN = true
  112.   # Lasciando true, la dimensione dello schermo verrà impostata a 640x480.
  113.  
  114.   # With true, screen size will be 640x480.
  115.  
  116.   CHANGE_SKIN_TONE = true
  117.   # La tonalità della window viene cambiata dal database. Tuttavia, se non si
  118.   # vuole usufruire di questa funzione è possibile impostare false.
  119.  
  120.   # Window tone is usually changed by database. To deactivate this functionality
  121.   # and use the image as is, you can set this to false.
  122.  
  123.   BLUR_SCREEN_ON_MENU = false
  124.   # Quando si accede in un menu l'immagine della mappa viene sfocata. Con false
  125.   # questo effetto viene rimosso.
  126.  
  127.   # Background map bitmap is commonly blurred when accessing menus. Setting false
  128.   # will remove this effect.
  129.  
  130.   # Opzioni avanzate. Non toccare se non sai quello che fai.
  131.  
  132.   # Advanced settings. Don't touch unless you know what you're doing.
  133.  
  134.   STANDARD_FONT_SIZE = Font.default_size
  135.   # Questo serve come metro di paragone per ridimensionare i caratteri da immagine.
  136.  
  137.   # Needed for measuring the amount of resizing for character in images.
  138.  
  139.   TABLE_ENCODING = "iso-8859-1"
  140.   # Cambia la codifica dei caratteri.
  141.  
  142.   # Change characters encoding.
  143.  
  144. # Da qui in avanti è tutto script.  //  From now on it's just script.
  145.  
  146. end
  147.  
  148. #Codename: rm2k
  149.  
  150. ($imported ||= {})[:mikb89_255_rm2k] = true
  151.  
  152. # Ace mods
  153. Graphics.resize_screen(640,480) if RM2K::RESIZE_SCREEN
  154. (class Window_Base; def update_tone; end; end) unless RM2K::CHANGE_SKIN_TONE
  155.  
  156. # Old VX script
  157. class Font
  158.   attr_writer :font_type
  159.   def self.default_font_type
  160.     @default_font_type = RM2K::FONT_TYPE if @default_font_type == nil
  161.     return @default_font_type
  162.   end
  163.   def font_type
  164.     @font_type = Font.default_font_type if @font_type == nil
  165.     return @font_type
  166.   end
  167.   def self.default_font_type=(dm)
  168.     @default_font_type = dm
  169.   end
  170. end
  171.  
  172. class Bitmap
  173.   def double
  174.     b = Bitmap.new(width*2, height*2)
  175.     b.stretch_blt(b.rect, self, rect)
  176.     return b
  177.   end
  178.  
  179.   def tru_img
  180.     sx, fx = width-1, 0
  181.     c = Color.new(0,0,0)
  182.     for x in 0...width
  183.       e = false
  184.       for y in 0...height
  185.         if get_pixel(x,y) == c
  186.           e = true
  187.           break
  188.         end
  189.       end
  190.       if e == true
  191.         sx = x
  192.         break
  193.       end
  194.     end
  195.     for x in 1...width
  196.       e = false
  197.       for y in 0...height
  198.         if get_pixel(width-x,y) == c
  199.           e = true
  200.           break
  201.         end
  202.       end
  203.       if e == true
  204.         fx = width-x
  205.         break
  206.       end
  207.     end
  208.     if fx+1 > sx
  209.       bit = Bitmap.new(fx-sx+1,height)
  210.       bit.blt(0,0,self,Rect.new(sx,0,fx-sx+1,height))
  211.       return bit
  212.     else
  213.       return Bitmap.new(width/2,height)
  214.     end
  215.   end
  216.  
  217.   def recolour(ind)
  218.     c = Color.new(0,0,0)
  219.     dum = Bitmap.new(8,8)
  220.     if ind < 32
  221.       dum.blt(0,0,Cache.system("Window"),Rect.new(64+(ind%8)*8,96+(ind/8)*8,8,8))
  222.     else
  223.       dum.fill_rect(dum.rect, text_color(ind))
  224.     end
  225.     for x in 0...width
  226.       for y in 0...height
  227.         set_pixel(x,y,dum.get_pixel(x,y)) if get_pixel(x,y) == c
  228.       end
  229.     end
  230.     dum.dispose
  231.   end
  232.  
  233.   def color_ind(col)
  234.     for i in 0...32
  235.       return i if text_color(i).red == col.red &&
  236.                   text_color(i).green == col.green &&
  237.                   text_color(i).blue == col.blue
  238.     end
  239.     @@xtra_col ||= []
  240.     for c in 0...@@xtra_col.size
  241.       return 32+c if @@xtra_col[c].red == col.red &&
  242.                      @@xtra_col[c].green == col.green &&
  243.                      @@xtra_col[c].blue == col.blue
  244.     end
  245.     @@xtra_col.push(col)
  246.     return 31+@@xtra_col.size
  247.   end
  248.  
  249.   def text_color(n)
  250.     if n < 32
  251.       x = 64 + (n % 8) * 8
  252.       y = 96 + (n / 8) * 8
  253.       return Cache.system("Window").get_pixel(x, y)
  254.     end
  255.     return Color.new(0,0,0) if (@@xtra_col ||= []).size <= n-32
  256.     return @@xtra_col[n-32]
  257.   end
  258.  
  259.   alias_method :text_size_b4_rm2k, :text_size unless method_defined?(:text_size_b4_rm2k)
  260.   def text_size(str)
  261.     m = font.font_type
  262.     case m
  263.     when 1,3
  264.       f = "Font"
  265.       f += "/" if m==3 && font.bold || font.italic
  266.       f += "B" if font.bold
  267.       f += "I" if font.italic
  268.       fh = (font.size*16)/RM2K::STANDARD_FONT_SIZE
  269.       e = font.shadow ? 1 : 0
  270.       st = str.to_s.encode(RM2K::TABLE_ENCODING) rescue str.to_s
  271.       st.each_byte {|b|
  272.         b = "f" + b.to_s if m==3
  273.         img = Cache.system(f, b)
  274.         e += img.width+2
  275.       }
  276.       return Rect.new(0,4-(fh-16)/2,e,fh)
  277.     when 0,2
  278.       return text_size_b4_rm2k(str)
  279.     end
  280.     return Rect.new(0,0,1,1)
  281.   end
  282.  
  283.   alias_method :draw_text_b4_rm2k, :draw_text unless method_defined?(:draw_text_b4_rm2k)
  284.   def draw_text(*t)
  285.     case t.size
  286.     when 2,3
  287.       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
  288.     when 5,6
  289.       x,y,w,h,s,a = t[0],t[1],t[2],t[3],t[4], t.size==6? t[5] : 0
  290.     end
  291.     if [1,3].include?(RM2K::FONT_TYPE)
  292.       s = case s
  293.       when "→"; ">"
  294.       when "×"; "x"
  295.       when "←"; "<"
  296.       else; s; end
  297.     end
  298.     m = font.font_type
  299.     case m
  300.     when 0 # nessun cambiamento
  301.       draw_text_b4_rm2k(x,y,w,h,s,a)
  302.     when 1 # usa una tavolozza font 8x8
  303.       f = "Font"
  304.       f += "B" if font.bold
  305.       f += "I" if font.italic
  306.       plus = 0
  307.       ts = text_size(s)
  308.       plus = w/2 - ts.width/2 - 1 if a == 1
  309.       plus = w - ts.width if a == 2
  310.       fh = (font.size*16)/RM2K::STANDARD_FONT_SIZE
  311.       e = 0
  312.       st = s.to_s.encode(RM2K::TABLE_ENCODING) rescue s.to_s
  313.       st.each_byte {|b|
  314.         x_b = x+plus+e
  315.         y_b = y + h/2 - ts.height/2
  316.         if font.outline
  317.           img = Cache.system(f, b, color_ind(font.out_color))
  318.           iw = img.width
  319.           stretch_blt(Rect.new(x_b+2,y_b+2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
  320.           stretch_blt(Rect.new(x_b+2,y_b,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
  321.           stretch_blt(Rect.new(x_b+2,y_b-2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
  322.           stretch_blt(Rect.new(x_b,y_b+2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
  323.           stretch_blt(Rect.new(x_b,y_b-2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
  324.           stretch_blt(Rect.new(x_b-2,y_b+2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
  325.           stretch_blt(Rect.new(x_b-2,y_b,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
  326.           stretch_blt(Rect.new(x_b-2,y_b-2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
  327.         end
  328.         if font.shadow# && !font.outline
  329.           img = Cache.system(f, b)
  330.           iw = img.width
  331.           stretch_blt(Rect.new(x_b+2,y_b+2,iw,fh),img,Rect.new(0,0,iw,16))
  332.         end
  333.         img = Cache.system(f, b, color_ind(font.color))
  334.         iw = img.width
  335.         stretch_blt(Rect.new(x_b,y_b,iw,fh),img,Rect.new(0,0,iw,16), font.color.alpha)
  336.         e += iw+2
  337.       }
  338.     when 2 # usa font normale
  339.       b = Bitmap.new(w/2,h/2)
  340.       b.font = font.clone
  341.       b.font.size = font.size/2
  342.       b.draw_text_b4_rm2k(0,0,w/2,h/2,s,a)
  343.       stretch_blt(Rect.new(x,y,w,h), b, b.rect)
  344.       b.dispose
  345.     when 3 # usa file immagine Wx8 in cartelle (dove W è variabile)
  346.       f = "Font"
  347.       if font.bold
  348.         f += "/B"
  349.         f += "I" if font.italic
  350.       elsif font.italic
  351.         f += "/I"
  352.       end
  353.       plus = 0
  354.       ts = text_size(s)
  355.       plus = w/2 - ts.width/2 - 1 if a == 1
  356.       plus = w - ts.width if a == 2
  357.       fh = (font.size*16)/RM2K::STANDARD_FONT_SIZE
  358.       e = 0
  359.       st = s.to_s.encode(RM2K::TABLE_ENCODING) rescue s.to_s
  360.       st.each_byte {|b|
  361.         x_b = x+plus+e
  362.         y_b = y + h/2 - ts.height/2
  363.         if font.outline
  364.           img = Cache.system(f, "f"+b.to_s, color_ind(font.out_color))
  365.           iw = img.width
  366.           stretch_blt(Rect.new(x_b+2,y_b+2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
  367.           stretch_blt(Rect.new(x_b+2,y_b,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
  368.           stretch_blt(Rect.new(x_b+2,y_b-2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
  369.           stretch_blt(Rect.new(x_b,y_b+2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
  370.           stretch_blt(Rect.new(x_b,y_b-2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
  371.           stretch_blt(Rect.new(x_b-2,y_b+2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
  372.           stretch_blt(Rect.new(x_b-2,y_b,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
  373.           stretch_blt(Rect.new(x_b-2,y_b-2,iw,fh),img,Rect.new(0,0,iw,16),font.out_color.alpha)
  374.         end
  375.         if font.shadow# && !font.outline
  376.           img = Cache.system(f, "f"+b.to_s)
  377.           iw = img.width
  378.           stretch_blt(Rect.new(x_b+2,y_b+2,iw,fh),img,Rect.new(0,0,iw,16))
  379.         end
  380.         img = Cache.system(f, "f"+b.to_s, color_ind(font.color))
  381.         iw = img.width
  382.         stretch_blt(Rect.new(x_b,y_b,iw,fh),img,Rect.new(0,0,iw,16), font.color.alpha)
  383.         e += iw+2
  384.       }
  385.     end
  386.   end
  387. end
  388.  
  389. module Cache
  390.   def self.system(filename, ind = "", col = "")
  391.     load_bitmap("Graphics/System/", filename, 0, ind, col)
  392.   end
  393.  
  394.   def self.load_bitmap(folder_name, filename, hue = 0, ind = "", col = "")
  395.     @cache ||= {}
  396.     plus = $TEST? "Mid" : ""
  397.     path = trupath = plus + folder_name + filename
  398.     path += ":" + ind.to_s + ":" + col.to_s if (ind != "" || col != "")
  399.     if not @cache.include?(path) or @cache[path].disposed?
  400.       if filename.empty?
  401.         @cache[path] = Bitmap.new(32, 32)
  402.       else
  403.         if ind != ""
  404.           if ind[0] != "f"
  405.             bit = Bitmap.new(trupath)
  406.             buf = Bitmap.new(8,8)
  407.             px = (ind%16)*8
  408.             py = (ind/16)*8
  409.             buf.blt(0,0,bit,Rect.new(px,py,8,8))
  410.             bit = buf.tru_img
  411.             buf.dispose
  412.           else
  413.             if FileTest.exist?(trupath+"/"+ind+".png")
  414.               bit = Bitmap.new(trupath+"/"+ind)
  415.             else
  416.               bit = Bitmap.new(1,16)
  417.             end
  418.           end
  419.           bit.recolour(col) if col != ""
  420.         else
  421.           bit = Bitmap.new(trupath)
  422.         end
  423.         @cache[path] = bit.double
  424.       end
  425.     end
  426.     if hue == 0
  427.       return @cache[path]
  428.     else
  429.       key = [path, hue]
  430.       if not @cache.include?(key) or @cache[key].disposed?
  431.         @cache[key] = @cache[path].clone
  432.         @cache[key].hue_change(hue)
  433.       end
  434.       return @cache[key]
  435.     end
  436.   end
  437. end
  438.  
  439. class Sprite_Character < Sprite_Base
  440.   def update_src_rect
  441.     if @tile_id == 0
  442.       index = @character.character_index
  443.       pattern = @character.pattern < 3 ? @character.pattern : 1
  444.       sx = (index % 4 * 3 + pattern) * @cw
  445.       dir = 0
  446.       if @character_name.include?("#")
  447.         case @character.direction
  448.         when 2; dir = 2
  449.         when 4; dir = 3
  450.         when 6; dir = 1
  451.         when 8; dir = 0
  452.         end
  453.       else
  454.         dir = (@character.direction - 2) / 2
  455.       end
  456.       sy = (index / 4 * 4 + dir) * @ch
  457.       self.src_rect.set(sx, sy, @cw, @ch)
  458.     end
  459.   end
  460. end
  461.  
  462. module SceneManager
  463.   def self.snapshot_for_background
  464.     @background_bitmap.dispose if @background_bitmap
  465.     @background_bitmap = Graphics.snap_to_bitmap
  466.     @background_bitmap.blur if RM2K::BLUR_SCREEN_ON_MENU
  467.   end
  468. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement