[Resolved] Game Window Size Changer

Started by This Side Backwards, May 24, 2010, 07:10:06 pm

Previous topic - Next topic

This Side Backwards

May 24, 2010, 07:10:06 pm Last Edit: May 25, 2010, 09:12:02 pm by This Side Backwards
I was wondering if someone could write a script much like Blizz's "Switch to Fullscreen" from TOA only have it make the game window smaller (320x240). Another way to put it would be the way you could change the screen size back in RM2K3. The tricky part would be having it be compatible with BABS.

I've already tried a few that I've found through google but none of them are compatible with BABS.

nathmatt

there is no way through a script to change the screen size that requires altering the program itself
Join Dead Frontier
Sorry, I will no longer be scripting for RMXP. I may or may not give support for my scripts. I don't have the will to script in RGSS anymore.
My script


Jragyn

This uhh, sorta works for resizing stuff, but erm, you'd have to do some edits to it:


# Written by Squall (squall@loeher.znn.com)
# 할 일: 1. GetSystemMetrics 함수
#        2. ??
WINDOW_WIDTH = 1020
WINDOW_HEIGHT = 740
class Win32API
  GAME_INI_FILE = ".\\Game.ini"
  HWND_TOPMOST = 0
  HWND_TOP = -1
  SWP_NOMOVE = 0
  def Win32API.GetPrivateProfileString(section, key)
    val = "\0" * 256
    gps = Win32API.new("kernel32", "GetPrivateProfileString", ['P', 'P', 'P', 'P', 'L', 'P'], 'L')
    gps.call(section, key, '', val, 256, GAME_INI_FILE)
    val.delete!("\0")
    return val
  end
  def Win32API.FindWindow(class_name, title)
    fw = Win32API.new("user32", "FindWindow", ['P', 'P'], 'I')
    hwnd = fw.call(class_name, title)
    return hwnd
  end
  def Win32API.SetWindowPos(w, h)
    title = Win32API.GetPrivateProfileString("Game", "Title")
    hwnd = Win32API.FindWindow("RGSS Player", title)
    swp = Win32API.new("user32", "SetWindowPos", ['L', 'L', 'I', 'I', 'I', 'I', 'I'], 'I')
    win = swp.call(hwnd, HWND_TOP, 0, 0, w + 6, h + 32, 0)
#    win = swp.call(hwnd, HWND_TOPMOST, 0, 0, w + 6, h + 32, SWP_NOMOVE)
    return win
  end
end
$window_width = WINDOW_WIDTH
$window_height = WINDOW_HEIGHT
class Game_Map
  def scroll_down(distance)
    if $window_height / 32.0 < self.height - 1
      @display_y = [@display_y + distance, (self.height - ($window_height / 32.0)) * 128].min
    else
      @display_y = [@display_y + distance, (self.height - 15) * 128].min
    end
  end
  def scroll_left(distance)
    @display_x = [@display_x - distance, 0].max
  end
  def scroll_right(distance)
    if $window_width / 32.0 < self.width - 1
      @display_x = [@display_x + distance, (self.width - ($window_width / 32.0)) * 128].min
    else
      @display_x = [@display_x + distance, (self.width - 20) * 128].min
    end
  end
  def scroll_up(distance)
    @display_y = [@display_y - distance, 0].max
  end
end
class Game_Player < Game_Character
  CENTER_X = ($window_width / 2 - 16) * 4
  CENTER_Y = ($window_height / 2 - 16) * 4
end
class Spriteset_Map
  def initialize
    if $game_map.width >= 25 and $game_map.height >= 19
      $window_width2 = $window_width
      $window_height2 = $window_height
    elsif $game_map.width >= 25 and $game_map.height < 19
      $window_width2 = $window_width
      $window_height2 = 480
    elsif $game_map.width < 25 and $game_map.height >= 19
      $window_width2 = 640
      $window_height2 = $window_height
    elsif $game_map.width < 25 and $game_map.height < 19
      $window_width2 = 640
      $window_height2 = 480
    else
      $window_width2 = $window_width
      $window_height2 = $window_height
    end
    @viewport1 = Viewport.new(0, 0, $window_width2, $window_height2)
    @viewport2 = Viewport.new(0, 0, $window_width2, $window_height2)
    @viewport3 = Viewport.new(0, 0, $window_width2, $window_height2)
    @viewport4 = Viewport.new(640, 0, $window_width2 - 640, 480)
    @viewport5 = Viewport.new(0, 480, 640, $window_height2 - 480)
    @viewport6 = Viewport.new(640, 480, $window_width2 - 640, $window_height2 - 480)
    @viewport2.z = 200
    @viewport3.z = 5000
    @tilemap = Tilemap.new(@viewport2)
    @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(@viewport2)
    @panorama.z = -1000
    @fog = Plane.new(@viewport2)
    @fog.z = 3000
    @character_sprites = []
    for i in $game_map.events.keys.sort
      sprite = Sprite_Character.new(@viewport2, $game_map.events[i])
      @character_sprites.push(sprite)
    end
    @character_sprites.push(Sprite_Character.new(@viewport2, $game_player))
    @weather = RPG::Weather.new(@viewport2)
    @picture_sprites = []
    for i in 1..50
      @picture_sprites.push(Sprite_Picture.new(@viewport2, $game_screen.pictures[i]))
    end
    @timer_sprite = Sprite_Timer.new
    @tilemap2 = Tilemap.new(@viewport4)
    @tilemap2.tileset = RPG::Cache.tileset($game_map.tileset_name)
    @tilemap3 = Tilemap.new(@viewport5)
    @tilemap3.tileset = RPG::Cache.tileset($game_map.tileset_name)
    @tilemap4 = Tilemap.new(@viewport6)
    @tilemap4.tileset = RPG::Cache.tileset($game_map.tileset_name)
    for i in 0..6
      autotile_name = $game_map.autotile_names[i]
      @tilemap2.autotiles[i] = RPG::Cache.autotile(autotile_name)
      @tilemap3.autotiles[i] = RPG::Cache.autotile(autotile_name)
      @tilemap4.autotiles[i] = RPG::Cache.autotile(autotile_name)
    end
    @tilemap2.map_data = $game_map.data
    @tilemap3.map_data = $game_map.data
    @tilemap4.map_data = $game_map.data
    update
  end
  def dispose
    @tilemap.tileset.dispose
    @tilemap2.tileset.dispose
    @tilemap3.tileset.dispose
    @tilemap4.tileset.dispose
    for i in 0..6
      @tilemap.autotiles[i].dispose
      @tilemap2.autotiles[i].dispose
      @tilemap3.autotiles[i].dispose
      @tilemap4.autotiles[i].dispose
    end
    @tilemap.dispose
    @tilemap2.dispose
    @tilemap3.dispose
    @tilemap4.dispose
    @panorama.dispose
    @fog.dispose
    for sprite in @character_sprites
      sprite.dispose
    end
    @weather.dispose
    for sprite in @picture_sprites
      sprite.dispose
    end
    @timer_sprite.dispose
    @viewport1.dispose
    @viewport2.dispose
    @viewport3.dispose
    @viewport4.dispose
    @viewport5.dispose
    @viewport6.dispose
  end
  def update
    if @panorama_name != $game_map.panorama_name or
       @panorama_hue != $game_map.panorama_hue
      @panorama_name = $game_map.panorama_name
      @panorama_hue = $game_map.panorama_hue
      if @panorama.bitmap != nil
        @panorama.bitmap.dispose
        @panorama.bitmap = nil
      end
      if @panorama_name != ""
        @panorama.bitmap = RPG::Cache.panorama(@panorama_name, @panorama_hue)
      end
      Graphics.frame_reset
    end
    if @fog_name != $game_map.fog_name or @fog_hue != $game_map.fog_hue
      @fog_name = $game_map.fog_name
      @fog_hue = $game_map.fog_hue
      if @fog.bitmap != nil
        @fog.bitmap.dispose
        @fog.bitmap = nil
      end
      if @fog_name != ""
        @fog.bitmap = RPG::Cache.fog(@fog_name, @fog_hue)
      end
      Graphics.frame_reset
    end
    @tilemap.ox = $game_map.display_x / 4
    @tilemap.oy = $game_map.display_y / 4
    @tilemap.update
    @tilemap2.ox = @tilemap.ox + 640
    @tilemap2.oy = @tilemap.oy
    @tilemap2.update
    @tilemap3.ox = @tilemap.ox
    @tilemap3.oy = @tilemap.oy + 480
    @tilemap3.update
    @tilemap4.ox = @tilemap.ox + 640
    @tilemap4.oy = @tilemap.oy + 480
    @tilemap4.update
    @panorama.ox = $game_map.display_x / 8
    @panorama.oy = $game_map.display_y / 8
    @fog.zoom_x = $game_map.fog_zoom / 100.0
    @fog.zoom_y = $game_map.fog_zoom / 100.0
    @fog.opacity = $game_map.fog_opacity
    @fog.blend_type = $game_map.fog_blend_type
    @fog.ox = $game_map.display_x / 4 + $game_map.fog_ox
    @fog.oy = $game_map.display_y / 4 + $game_map.fog_oy
    @fog.tone = $game_map.fog_tone
    for sprite in @character_sprites
      sprite.update
    end
    @weather.type = $game_screen.weather_type
    @weather.max = $game_screen.weather_max
    @weather.ox = $game_map.display_x / 4
    @weather.oy = $game_map.display_y / 4
    @weather.update
    for sprite in @picture_sprites
      sprite.update
    end
    @timer_sprite.update
    @viewport3.tone = $game_screen.tone
    @viewport1.ox = $game_screen.shake
    @viewport3.color = $game_screen.flash_color
    @viewport1.update
    @viewport3.update
   
    win = Win32API.SetWindowPos($window_width, $window_height)
    if win == 0
      print("창 크기 변경에 실패하였습니다.")
      exit
    end
  end
end
#ㅇ이거 ㅗ좀 쩔드라 ㅋㅋㅋㅋㅋ뻉바밥ㅏㅂ뺴

A bright light can either illuminate or blind, but how will you know which until you open your eyes?

Spaceman McConaughey

Quote from: nathmatt on May 24, 2010, 08:04:58 pm
there is no way through a script to change the screen size that requires altering the program itself


Uh-huh.. another person who didn't search for something(like many on the web) before speaking. :P

Blizzard

Quote from: nathmatt on May 24, 2010, 08:04:58 pm
there is no way through a script to change the screen size that requires altering the program itself


Lol. When you use an API call, it is. :P
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

nathmatt

May 25, 2010, 09:09:09 am #5 Last Edit: May 25, 2010, 09:12:15 am by nathmatt
i thougt for sure Blizzard told someone it was impossible a while back guess i was wrong
Join Dead Frontier
Sorry, I will no longer be scripting for RMXP. I may or may not give support for my scripts. I don't have the will to script in RGSS anymore.
My script


Blizzard

Quote from: Blizzard on January 07, 2008, 08:54:15 pm
Changed Resolution (6/10)

- Reason:
The problem on itself is not a big one and several scripts already exist. The problem is RMXP itself. Since the map does not work with bigger resolutions, RMXP's "Tilemap class" would need to be rewritten to support it. Eventually many other scripts would need to be edited. Also, this would cause problems with various menu systems from custom scripts as well as CMSes themselves. The last problem would be lag. Bigger screen means bigger sprites and more stuff to be updated.
- What is needed to create this:
Understanding of WinAPI.
Understanding of all RTP scripts. Ability to improve RTP scripts in a way of lowering the lag by decreasing algorithm complexity (NOT SIMPLE OPTIMIZATION!).
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

nathmatt

May 25, 2010, 11:07:46 am #7 Last Edit: May 25, 2010, 12:03:20 pm by nathmatt
thats a nice script but to make it work on the title add in main before
$scene = Scene_Title


add

win = Win32API.SetWindowPos($window_width, $window_height)
exit if win == 0


edit: how about an add on this will center all the windows to the screen size

class Window_Base < Window
 
 alias new_x x=
 def x=(x)
   news_x = x +($window_width - 640) / 2
   new_x(news_x)
 end
 
 alias new_y y=
 def y=(y)
   news_y = y +($window_height - 480) / 2
   new_y(news_y)
 end
 
end


edit: and this will allow you to change the screen size in game
just use  $screen.size(width,height)

class Screen
 
  def size(width,height)
    $window_width = width
    $window_height = height
    win = Win32API.SetWindowPos($window_width, $window_height)
  end
 
end

$screen = Screen.new
Join Dead Frontier
Sorry, I will no longer be scripting for RMXP. I may or may not give support for my scripts. I don't have the will to script in RGSS anymore.
My script


This Side Backwards

Thanks guys!
It still causes problems with BABS but that's OK.

I'll more than likely use this on another smaller project then.
+ to all three of you for the help!

I'll mark as resolved.