Resolution Fix
#1
Resolution Fix

This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.


Features:

First - This script is no where near finished, well kinda :P
Second - There are a few small bugs because of some short cuts I used in scripting this...
Third - This script auto sizes to your max screen Resolution this can be good and bad...
Fourth - The autotiles animation is incomplete...
Fifth - I am working on a function that will change your screen Resolution to a standard size and then back to normal on exit like professional games do...
Sixth - Remember that when you change the screen Resolution things like title graphic, menus, fog, and panorama will not work or will need to be resized... Iam still working on the fog, and panoramas...

Script:

Code:
#================================
#   ■ Resolution Fix
#  By: Near Fantastica
#   Date: 16.09.05
#   Version: 1
#
#   NOTE :: Add the following in the Main after begin
#   Resolution.Maximize
#
#================================

class Resolution
  #--------------------------------------------------------------------------
  # ● define constant
  #--------------------------------------------------------------------------
  GAME_INI_FILE = ".\\Game.ini"         # define "Game.ini" file
  HWND_TOPMOST = 0                      # window always active
  HWND_TOP = -1                         # window active when used only
  SWP_NOMOVE   = 0                      # window pos and sizes can be changed
  SW_MAXIMIZE = 3
  #--------------------------------------------------------------------------
  # ● Win32API.GetPrivateProfileString // check your game title in Game.ini
  #--------------------------------------------------------------------------
  def Resolution.GetPrivateProfileString(section, key)
    val = "\0"*256
    gps = Win32API.new('kernel32', 'GetPrivateProfileString',%w(p p p p l p), 'l')
    gps.call(section, key, "", val, 256, GAME_INI_FILE)
    val.delete!("\0")
    return val
  end
  #--------------------------------------------------------------------------
  # ● Win32API.client_size // check the window width and height
  #--------------------------------------------------------------------------
  def Resolution.client_size
    title =  Resolution.GetPrivateProfileString("Game", "Title")
    findwindow = Win32API.new('user32', 'FindWindow', %w(p p), 'l')
    hwnd = findwindow.call("RGSS Player", title)
    rect = [0, 0, 0, 0].pack('l4')
    Win32API.new('user32', 'GetClientRect', %w(l p), 'i').call(hwnd, rect)
    width, height = rect.unpack('l4')[2..3]
    return width, height
  end
  #--------------------------------------------------------------------------
  # ● Win32API.Maximize // Maximize Window
  #--------------------------------------------------------------------------
  def Resolution.Maximize
    # Setup
    findwindow = Win32API.new('user32', 'FindWindow', %w(p p), 'l')
    max = Win32API.new('user32', 'ShowWindow', 'LL', 'L')
    title =  Resolution.GetPrivateProfileString("Game", "Title")
    hwnd = findwindow.call("RGSS Player", title)
    max.call(hwnd, SW_MAXIMIZE)
  end
end

#======================================
# ■ Game_Map
#======================================

class Game_Map
  #--------------------------------------------------------------------------
  def scroll_down(distance)
    width, height = Resolution.client_size
    height /= 32
    @display_y = [@display_y + distance, (self.height - height) * 128].min
  end
  #--------------------------------------------------------------------------
  def scroll_right(distance)
    width, height = Resolution.client_size
    width /= 32
    @display_x = [@display_x + distance, (self.width - width) * 128].min
  end
end

class Game_Player
  #--------------------------------------------------------------------------
  def center(x, y)
    width, height = Resolution.client_size
    width /= 32
    height /= 32
    max_x = ($game_map.width - width) * 128
    max_y = ($game_map.height - height) * 128
    $game_map.display_x = [0, [x * 128 - CENTER_X, max_x].min].max
    $game_map.display_y = [0, [y * 128 - CENTER_Y, max_y].min].max
  end
end

#======================================
# ■ Tilemap
#======================================

class Tilemap
  #--------------------------------------------------------------------------
  attr_accessor :tileset
  attr_accessor :tileset
  attr_accessor :autotiles
  attr_accessor :map_data
  attr_accessor :flash_data
  attr_accessor :priorities
  attr_accessor :visible
  attr_accessor :ox
  attr_accessor :oy
  #--------------------------------------------------------------------------
  def initialize(viewport)
    @map = []
    width, height = $game_map.width * 32, $game_map.height * 32
    for p in 0..2
      @map[p] = Sprite.new(viewport)
      @map[p].bitmap = Bitmap.new(width, height )
    end
    @map[0].z = 0
    @map[1].z = 150
    @map[2].z = 300
    @tileset_tile_width = 32
    @tileset_tile_height = 32
    @tileset = nil
    @autotiles = []
    @autotiles2 = []
    @map_data = nil
    @data = nil
    @flash_data = nil
    @priorities = nil
    @visible = true
    @ox = 0
    @oy = 0
  end
  #--------------------------------------------------------------------------
  def update
    for p in 0..2
      @map[p].ox = @ox
      @map[p].oy = @oy
    end
    if @data != @map_data
      refresh
    end
  end
  #--------------------------------------------------------------------------
  def refresh
    @data = @map_data
    generate_autotiles2
    for p in 0..5
      for z in 0...@map_data.zsize
        for x in 0...@map_data.xsize
          for y in 0...@map_data.ysize
            id = @map_data[x,y,z]
            next if @priorities[id] != p
            refresh_autotiles(x,y,p,id) if id < 384
            refresh_tileset(x,y,p,id) if id >= 384
          end
        end
      end
    end
  end
  #--------------------------------------------------------------------------
  def refresh_autotiles(x,y,p,id)
    p = 2 if p > 2
    if id >= 48 and id <= 95
      sy = id - 48
      sy /= 8
      sx = id - 48
      sx = sx - (8 * sy)
      src_rect = Rect.new(sx*32, sy*32, 32, 32)
      @map[p].bitmap.blt(x*32, y*32, @autotiles2[0], src_rect)
    end
  end
  #--------------------------------------------------------------------------
  def refresh_tileset(x,y,p,id)
    p = 2 if p > 2
    sy = id - 384
    sy /= 8
    sx = id - 384
    sx = sx - (8 * sy)
    src_rect = Rect.new(sx*32, sy*32, 32, 32)
    @map[p].bitmap.blt(x*32, y*32, @tileset, src_rect)
  end
  #--------------------------------------------------------------------------
  def dispose
    for p in 0..2
      @map[p].bitmap.dispose
    end
  end
  #======================================
  #   ■ Generates Autotiles
  #   By: Fuso
  #   Generates the tiles used by the game (can be seen in the editor by
  #   doubleclicking an autotile field), from the images given as
  #   resources.
  #======================================
  def generate_autotiles2(ats = @autotiles, frame_id = 0)
    h = 32
    w = 32
    for at in 0..6
      @autotiles2[at] = Bitmap.new(@tileset_tile_width * 8, @tileset_tile_height * 6) if @autotiles2[at].nil?
      break if at >= @autotiles.size
      # Generate the 16 tiles containing water and a number of corners.
      # Each bit in i will represent whether or not a certain corner will be filled in.
      for i in 0...16
        @autotiles2[at].blt(i % 8 * w,             i / 8 * h,            ats[at], Rect.new(frame_id * 3 * w + w,           2 * h, w,      h)) if i < 15
        @autotiles2[at].blt(i % 8 * w,             i / 8 * h,            ats[at], Rect.new(frame_id * 3 * w + 2 * w,      0,      w / 2, h / 2)) if i & 0x1 == 0x1
        @autotiles2[at].blt(i % 8 * w + w / 2, i / 8 * h,            ats[at], Rect.new(frame_id * 3 * w + 5 * w / 2, 0,      w / 2, h / 2)) if i & 0x2 == 0x2
        @autotiles2[at].blt(i % 8 * w + w / 2, i / 8 * h + h / 2, ats[at], Rect.new(frame_id * 3 * w + 5 * w / 2, h / 2, w / 2, h / 2)) if i & 0x4 == 0x4
        @autotiles2[at].blt(i % 8 * w,             i / 8 * h + h / 2, ats[at], Rect.new(frame_id * 3 * w + 2 * w,      h / 2, w / 2, h / 2)) if i & 0x8 == 0x8
      end
      # Generate the 16 tiles containing a certain whole strip + up to 2 corners.
      # The two most signifant bits will hold the direction of the strip and the other
      # two bits whether or not the remaining 2 corners will be filled in.
      for i in 0...16
        d = i / 4
        # The strip.
        #@autotiles2[at].blt(i % 8 * w + (d==3 ? w / 2 : 0), 2 * h + i / 8 * h + (d==4 ? h / 2 : 0), ats[at],
        #  Rect.new(d == 0 ? 0 : d == 2 ? 5 * d / 4 : d, d == 1 ? h : d == 3 ? 7 * h / 4 : 2 * h,
        #               (d&3 + 1) * w / 2, (4 - d&3) * h / 2))
        @autotiles2[at].blt(i % 8 * w, (2 + i / 8) * h, ats[at], Rect.new(frame_id * 3 * w + d == 0 ? 0 : d == 2 ? 2 * w : w, d == 1 ? h : d == 3 ? 3 * h : 2 * h, w, h))
        l1 = (d + 1)%4
        l2 = (d + 2)%4
        x1 = (l1 == 1 or l1 == 2) ? w / 2 : 0
        x2 = (l2 == 1 or l2 == 2) ? w / 2 : 0
        y1 = l1/2 * h / 2
        y2 = l2/2 * h / 2
        @autotiles2[at].blt(i % 8 * w + x1, (2 + i / 8) * h + y1, ats[at], Rect.new(frame_id * 3 * w + 2 * w + x1, y1, w / 2,  h / 2)) if i & 0x1 == 0x1
        @autotiles2[at].blt(i % 8 * w + x2, (2 + i / 8) * h + y2, ats[at], Rect.new(frame_id * 3 * w + 2 * w + x2, y2, w / 2,  h / 2)) if i & 0x2 == 0x2
      end
      # The "double-strip" tiles.
      @autotiles2[at].blt(0,       4 * h,           ats[at], Rect.new(frame_id * 3 * w + 0,            2 * h,             w,      h))
      @autotiles2[at].blt(w / 2, 4 * h,           ats[at], Rect.new(frame_id * 3 * w + 5 * w / 2, 2 * h,             w / 2, h))
      @autotiles2[at].blt(w,      4 * h,           ats[at], Rect.new(frame_id * 3 * w + w,            h,                  w,      h))
      @autotiles2[at].blt(w,      4 * h + h /2, ats[at], Rect.new(frame_id * 3 * w + w,            3 * h + h / 2, w, h / 2))
      for i in 0...4
        @autotiles2[at].blt((2 + 2 * i)%8 * w, (4 + i/3) * h, ats[at], Rect.new(frame_id * 3 * w + ((i == 1 or i == 2) ? 2 * w : 0), ((i&2) + 1) * h, w, h))
        @autotiles2[at].blt((3 + 2 * i)%8 * w, (4 + i/3) * h, ats[at], Rect.new(frame_id * 3 * w + ((i == 1 or i == 2) ? 2 * w : 0), ((i&2) + 1) * h, w, h))
        l = (i + 2)%4
        x = (l == 1 or l == 2) ? w / 2 : 0
        y = l/2 * h / 2
        @autotiles2[at].blt((3 + 2 * i)%8 * w + x, (4 + i/3) * h + y, ats[at], Rect.new(frame_id * 3 * w + 2 * w + x, y, w / 2,  h / 2))
      end
      for i in 0...4
        @autotiles2[at].blt((i + 2) * w, 5 * h, ats[at], Rect.new(frame_id * 3 * w + i/2 * 2 * w, (i == 1 or i == 2) ? 3 * h : h, w, h))
        l = (i + 3) % 4
        dx = (l == 3 ? w / 2 : 0)
        dy = (l == 2 ? h / 2 : 0)
        tx = (l < 2 ? 0 : 2 * w)
        ty = (l == 0 ? 0 : l == 3 ? 0 : 2 * h)
        @autotiles2[at].blt((i + 2) * w + dx, 5 * h + dy, ats[at], Rect.new(frame_id * 3 * w + tx + dx, h + ty + dy, w - l%2 * w / 2, h / 2 + l%2 * h / 2))
      end
      # The final two squares which is simply the upper left one and possiby a merge of the
      # inner corners, we'll make them both the first tile for now.
      @autotiles2[at].blt(6 * w, 5 * h, ats[at], Rect.new(0, 0, w, h))
      @autotiles2[at].blt(7 * w, 5 * h, ats[at], Rect.new(0, 0, w, h))
    end
  end
end

#======================================
# ■ Spriteset_Map
#======================================

class Spriteset_Map
  #--------------------------------------------------------------------------
  def initialize
    width, height = Resolution.client_size
    @viewport1 = Viewport.new(0, 0, width, height)
    @viewport2 = Viewport.new(0, 0, width, height)
    @viewport3 = Viewport.new(0, 0, width, height)
    @viewport2.z = 200
    @viewport3.z = 5000
    @tilemap = Tilemap.new(@viewport1)
    @tilemap.tileset = RPG::Cache.tileset($game_map.tileset_name)
    for i in 0..6
      autotile_name = $game_map.autotile_names[i]
      @tilemap.autotiles[i] = RPG::Cache.autotile(autotile_name)
    end
    @tilemap.map_data = $game_map.data
    @tilemap.priorities = $game_map.priorities
    @panorama = Plane.new(@viewport1)
    @panorama.z = -1000
    @fog = Plane.new(@viewport1)
    @fog.z = 3000
    @character_sprites = []
    for i in $game_map.events.keys.sort
      sprite = Sprite_Character.new(@viewport1, $game_map.events[i])
      @character_sprites.push(sprite)
    end
    @character_sprites.push(Sprite_Character.new(@viewport1, $game_player))
    @weather = RPG::Weather.new(@viewport1)
    @picture_sprites = []
    for i in 1..50
      @picture_sprites.push(Sprite_Picture.new(@viewport2,
        $game_screen.pictures[i]))
    end
    @timer_sprite = Sprite_Timer.new
    update
  end
end

Take Care,
Near
}




Users browsing this thread: 1 Guest(s)