赞 | 0 |
VIP | 0 |
好人卡 | 0 |
积分 | 1 |
经验 | 1000 |
最后登录 | 2016-12-10 |
在线时间 | 5 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 50
- 在线时间
- 5 小时
- 注册时间
- 2015-7-6
- 帖子
- 6
|
6楼
楼主 |
发表于 2015-7-6 13:31:17
|
只看该作者
紫英晓狼1130 发表于 2015-7-6 12:12
现在还没有完美的分辨率更改方法
这是在下的帖子
https://rpg.blue/forum.php?mod=viewthread&tid=36255 ...
我改成了这样:
★Game_Resolution
#==============================================================================
# ■ 真·RMXP分辨率拓展 By 紫英晓狼工作室
#------------------------------------------------------------------------------
# 用于更改游戏分辨率,紫英晓狼工作室修改
# 脚本主要来源于癫狂侠客的DKRM,自己稍作修改
# 全局搜索“修改”可以看到修改的地方
# 所有的窗口类没有改动,使用前请注意
# 使用需复制带★的脚本,以及START.dll
#==============================================================================
module GAME_WINDOW
INT_WIDTH = 300 # 窗口宽度
INT_HEIGHT = 225 # 窗口高度
end
ini=".\\Game.ini"
val = "\0"*256
gps = Win32API.new('kernel32', 'GetPrivateProfileString','pppplp', 'l')
gps.call("Game", "Title", "", val, 256, ini)
val.delete!("\0")
title = val
fw = Win32API.new('user32', 'FindWindow', 'pp', 'i')
hWnd = fw.call("RGSS Player", title)
swp = Win32API.new('user32', 'SetWindowPos', 'lliiiii', 'i')
pointwds = [0,0,0,0].pack('llll')
pointcet = [0, 0].pack('ll')
wdsrect = Win32API.new('user32.dll', 'GetWindowRect', 'lp', 'l')
client_screen = Win32API.new("user32", "ClientToScreen", 'ip', 'i')
wdsrect.call(hWnd,pointwds)
client_screen.call(hWnd, pointcet)
wds = pointwds.unpack('llll')
cet = pointcet.unpack('ll')
addw = wds[2] - wds[0] - 640
addh = wds[3] - wds[1] - 480
x = wds[0] - (GAME_WINDOW::INT_WIDTH - 640) / 2
y = wds[1] - (GAME_WINDOW::INT_HEIGHT - 480) / 2
swp.call(hWnd, 0, x, y, GAME_WINDOW::INT_WIDTH + addw, GAME_WINDOW::INT_HEIGHT+addh,0x20)
#============================================================================
# ■ Plane
#============================================================================
class Plane
#--------------------------------------------------------------------------
# ● 初始化定义
#--------------------------------------------------------------------------
def initialize(v = Viewport.new(0, 0, 640, 480))
@x = 0
@y = 0
@z = 0
@ox = 0
@oy = 0
@ox2 = 0
@oy2 = 0
@rect = v.rect
@zoom_x = 1.0
@zoom_y = 1.0
@bitmap = nil
@contents = Sprite.new
@n_w = 1
@n_h = 1
@visible = true
@tone = Tone.new(0, 0, 0, 0)
@color = Color.new(255,255,255,0)
@blend_type = 0
@opacity = 255
@dispose = false
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def update
@contents.x = @x
@contents.y = @y
@contents.ox = @ox2
@contents.oy = @oy2
@contents.opacity = @opacity
@contents.visible = @visible
@contents.tone = @tone
@contents.blend_type = @blend_type
@contents.z = @z
end
#--------------------------------------------------------------------------
# ● 装载图形(bitmap)
#--------------------------------------------------------------------------
def bitmap=(bitmap)
if @disposed
raise(RGSSError,"disposed window")
else
@bitmap = bitmap
count_wh
update
end
end
#--------------------------------------------------------------------------
# ● 图形
#--------------------------------------------------------------------------
def bitmap
return if @bitmap != nil
end
#--------------------------------------------------------------------------
# ● X 坐标(x)
#--------------------------------------------------------------------------
def x=(x)
if @disposed
raise(RGSSError,"disposed window")
else
@x = x
update
end
end
def x
return @x
end
#--------------------------------------------------------------------------
# ● Y 坐标(y)
#--------------------------------------------------------------------------
def y=(y)
if @disposed
raise(RGSSError,"disposed window")
else
@y = y
update
end
end
def y
return @y
end
#--------------------------------------------------------------------------
# ● Z 坐标(z)
#--------------------------------------------------------------------------
def z=(z)
if @disposed
raise(RGSSError,"disposed window")
else
@z = z
update
end
end
def z
return @z
end
#--------------------------------------------------------------------------
# ● X 漂移量(ox)
#--------------------------------------------------------------------------
def ox=(ox)
if @disposed
raise(RGSSError,"disposed window")
else
if @bitmap != nil
@ox = ox
@ox2 = ox % (@bitmap.width * @zoom_x).to_i
update
end
end
end
def ox
return @ox
end
#--------------------------------------------------------------------------
# ● Y 漂移量(oy)
#--------------------------------------------------------------------------
def oy=(oy)
if @disposed
raise(RGSSError,"disposed window")
else
if @bitmap != nil
@oy = oy
@oy2 = oy % (@bitmap.height * @zoom_y).to_i
update
end
end
end
def oy
return @oy
end
#--------------------------------------------------------------------------
# ● X 方向缩放(zoom_x)
#--------------------------------------------------------------------------
def zoom_x=(zx)
if @disposed
raise(RGSSError,"disposed window")
else
if @zoom_x != zx
@zoom_x = zx
count_wh
end
update
end
end
def zoom_x
return @zoom_x
end
#--------------------------------------------------------------------------
# ● Y 方向缩放(zoom_y)
#--------------------------------------------------------------------------
def zoom_y=(zy)
if @disposed
raise(RGSSError,"disposed window")
else
if @zoom_y != zy
@zoom_y = zy
count_wh
end
update
end
end
def zoom_y
return @zoom_y
end
#--------------------------------------------------------------------------
# ● 不透明度(opacity)
#--------------------------------------------------------------------------
def opacity=(op)
if @disposed
raise(RGSSError,"disposed window")
else
@opacity = op
update
end
end
def opacity
return @opacity
end
#--------------------------------------------------------------------------
# ● 颜色叠加(color)
#--------------------------------------------------------------------------
def color=(c)
if @disposed
raise(RGSSError,"disposed window")
else
@color = c
update
end
end
def color
return @color
end
#--------------------------------------------------------------------------
# ● 色调(tone)
#--------------------------------------------------------------------------
def tone=(tone)
if @disposed
raise(RGSSError,"disposed window")
else
@tone = tone
update
end
end
def tone
return @tone
end
#--------------------------------------------------------------------------
# ● 是否可见(visible)
#--------------------------------------------------------------------------
def visible=(v)
if @disposed
raise(RGSSError,"disposed window")
else
@visible = v
update
end
end
def visible
return @visible
end
#--------------------------------------------------------------------------
# ● 叠加模式(blend_type)
#--------------------------------------------------------------------------
def blend_type=(bt)
if @disposed
raise(RGSSError,"disposed window")
else
@blend_type = bt
update
end
end
def blend_type
return @blend_type
end
#--------------------------------------------------------------------------
# ● 释放内存(dispose)
#--------------------------------------------------------------------------
def dispose
return if @dispose
@dispose = true
@contents.bitmap.dispose if @contents.bitmap != nil
@contents.bitmap = nil
@contents.dispose if @contents != nil
@contents = nil
@bitmap.dispose if @bitmap != nil
@bitmap = nil
end
#--------------------------------------------------------------------------
# ● 检测释放(dispose?)
#--------------------------------------------------------------------------
def dispose?
@dispose
end
#--------------------------------------------------------------------------
# ● 计算Plane的长宽与精灵排布(count_wh)
#--------------------------------------------------------------------------
def count_wh
if @bitmap != nil
@n_w = @rect.width / (@bitmap.width * @zoom_x).to_i + 3
@n_h = @rect.height / (@bitmap.height * @zoom_y).to_i + 3
h = @n_h * (@bitmap.height * @zoom_y).to_i
w = @n_w * (@bitmap.width * @zoom_x).to_i
if @contents.bitmap == nil
@contents.bitmap = Bitmap.new(w, h)
end
@contents.bitmap.clear
for x in 0..@n_w
for y in 0..@n_h
rect = Rect.new(0,0,@bitmap.width,@bitmap.height)
dest_rect = Rect.new(x * @bitmap.width * @zoom_x,\
y * @bitmap.height * @zoom_y,@bitmap.width * @zoom_x,\
@bitmap.height * @zoom_y)
@contents.bitmap.stretch_blt(dest_rect, @bitmap, rect)
end
end
end
end
end
#===================================================
# ■ Tilemap
#===================================================
class CustomTilemapAutotiles
attr_accessor :changed
def initialize
@changed=true
@tiles=[nil,nil,nil,nil,nil,nil,nil]
end
def []=(i,value)
@tiles=value
@changed=true
end
def [](i)
return @tiles
end
end
class Tilemap
Animated_Autotiles_Frames = 15
Autotiles = [
[ [27, 28, 33, 34], [ 5, 28, 33, 34], [27, 6, 33, 34], [ 5, 6, 33, 34],
[27, 28, 33, 12], [ 5, 28, 33, 12], [27, 6, 33, 12], [ 5, 6, 33, 12] ],
[ [27, 28, 11, 34], [ 5, 28, 11, 34], [27, 6, 11, 34], [ 5, 6, 11, 34],
[27, 28, 11, 12], [ 5, 28, 11, 12], [27, 6, 11, 12], [ 5, 6, 11, 12] ],
[ [25, 26, 31, 32], [25, 6, 31, 32], [25, 26, 31, 12], [25, 6, 31, 12],
[15, 16, 21, 22], [15, 16, 21, 12], [15, 16, 11, 22], [15, 16, 11, 12] ],
[ [29, 30, 35, 36], [29, 30, 11, 36], [ 5, 30, 35, 36], [ 5, 30, 11, 36],
[39, 40, 45, 46], [ 5, 40, 45, 46], [39, 6, 45, 46], [ 5, 6, 45, 46] ],
[ [25, 30, 31, 36], [15, 16, 45, 46], [13, 14, 19, 20], [13, 14, 19, 12],
[17, 18, 23, 24], [17, 18, 11, 24], [41, 42, 47, 48], [ 5, 42, 47, 48] ],
[ [37, 38, 43, 44], [37, 6, 43, 44], [13, 18, 19, 24], [13, 14, 43, 44],
[37, 42, 43, 48], [17, 18, 47, 48], [13, 18, 43, 48], [ 1, 2, 7, 8] ]
]
FlashOpacity=[100,90,80,70,80,90]
attr_reader :tileset
attr_reader :autotiles
attr_reader :map_data
attr_accessor :flash_data
attr_accessor :priorities
attr_reader :visible
attr_accessor :ox
attr_accessor :oy
attr_reader :viewport
def initialize(viewport=Viewport.new(0,0,640,480))
@tileset = nil # Refers to Map Tileset Name
@autotiles = CustomTilemapAutotiles.new
@map_data = nil # Refers to 3D Array Of Tile Settings
@flash_data = nil # Refers to 3D Array of Tile Flashdata
@priorities = nil # Refers to Tileset Priorities
@visible = true # Refers to Tileset Visibleness
@ox = 0 # Bitmap Offsets
@oy = 0 # bitmap Offsets
@plane = false
@viewport=viewport
@tiles=[]
@autotileInfo=[]
@regularTileInfo=[]
@oldOx=0
@oldOy=0
@layer0=Sprite.new(viewport)
@layer0.visible=true
@nowshown=false
@layer0.bitmap=Bitmap.new(@viewport.rect.width*2,@viewport.rect.height*2)
@flash=nil
@layer0.ox=0
@layer0.oy=0
@oxLayer0=0
@oyLayer0=0
@oxFlash=0
@oyFlash=0
@layer0.z=0
@priotiles=[]
@prioautotiles=[]
@autosprites=[]
@framecount=[]
@tilesetChanged=true
@flashChanged=false
@firsttime=true
@disposed=false
@usedsprites=false
@layer0clip=true
@firsttimeflash=true
@fullyrefreshed=false
@fullyrefreshedautos=false
end
def disposed?
return @disposed
end
def flash_data=(value)
@flash_data=value
@flashChanged=true
end
def update
if @autotiles.changed
refresh_autotiles
repaintAutotiles
end
if @flashChanged
refresh_flash
end
if @tilesetChanged
refresh_tileset
end
if @flash
@flash.opacity=FlashOpacity[(Graphics.frame_count/2) % 6]
end
if !(@oldOx==@ox&&@oldOy==@oy&&
!@tilesetChanged&&
[email protected])
refresh
end
if (Graphics.frame_count % Animated_Autotiles_Frames == 0) || @nowshown
repaintAutotiles
refresh(true)
end
@nowshown=false
@autotiles.changed=false
@tilesetChanged=false
end
def priorities=(value)
@priorities=value
@tilesetChanged=true
end
def tileset=(value)
@tileset=value
@tilesetChanged=true
end
def shown?
return false if !@visible
ysize=@map_data.ysize
xsize=@map_data.xsize
xStart=(@ox/32)-1
xEnd=((@[email protected])/32)+1
yStart=(@oy/32)-1
yEnd=((@[email protected])/32)+1
xStart=0 if xStart<0
xStart=xsize-1 if xStart>=xsize
xEnd=0 if xEnd<0
xEnd=xsize-1 if xEnd>=xsize
yStart=0 if yStart<0
yStart=ysize-1 if yStart>=ysize
yEnd=0 if yEnd<0
yEnd=ysize-1 if yEnd>=ysize
return (xStart<xEnd&&yStart<yEnd)
end
def dispose
return if disposed?
@help.dispose if @help
@help=nil
i=0;[email protected];while i<len
if @autotileInfo
@autotileInfo.dispose
@autotileInfo=nil
end
i+=1
end
i=0;[email protected];while i<len
if @regularTileInfo
@regularTileInfo.dispose
@regularTileInfo=nil
end
i+=1
end
i=0;[email protected];while i<len
@tiles.dispose
@tiles=nil
i+=2
end
i=0;[email protected];while i<len
@autosprites.dispose
@autosprites=nil
i+=2
end
if @layer0
@layer0.bitmap.dispose if [email protected]?
@layer0.bitmap=nil if [email protected]?
@layer0.dispose
@layer0=nil
end
if @flash
@flash.bitmap.dispose if [email protected]?
@flash.bitmap=nil if [email protected]?
@flash.dispose
@flash=nil
end
for i in 0...7
self.autotiles=nil
end
@tiles.clear
@autosprites.clear
@autotileInfo.clear
@regularTileInfo.clear
@tilemap=nil
@tileset=nil
@priorities=nil
@disposed=true
end
def bltAutotile(bitmap,x,y,id,frame)
return if frame<0
autotile=@autotiles[id/48-1]
return if !autotile
if autotile.height==32
anim=frame*32
src_rect=Rect.new(anim,0,32,32)
bitmap.blt(x,y,autotile,src_rect)
else
anim=frame*96
id%=48
tiles = Autotiles[id>>3][id&7]
src=Rect.new(0,0,0,0)
for i in 0...4
tile_position = tiles - 1
src.set(tile_position % 6 * 16 + anim,
tile_position / 6 * 16, 16, 16)
bitmap.blt(i%2*16+x,i/2*16+y, autotile, src)
end
end
end
def autotileNumFrames(id)
autotile=@autotiles[id/48-1]
return 0 if !autotile || autotile.disposed?
frames=1
if autotile.height==32
frames=autotile.width/32
else
frames=autotile.width/96
end
return frames
end
def autotileFrame(id)
autotile=@autotiles[id/48-1]
return -1 if !autotile || autotile.disposed?
frames=1
if autotile.height==32
frames=autotile.width/32
else
frames=autotile.width/96
end
return (Graphics.frame_count/Animated_Autotiles_Frames)%frames
end
def repaintAutotiles
for i in [email protected]
next if !@autotileInfo
frame=autotileFrame(i)
bltAutotile(@autotileInfo,0,0,i,frame)
end
end
def getAutotile(sprite,id)
anim=autotileFrame(id)
return if anim<0
bitmap=@autotileInfo[id]
if !bitmap
bitmap=Bitmap.new(32,32)
bltAutotile(bitmap,0,0,id,anim)
@autotileInfo[id]=bitmap
end
sprite.bitmap=bitmap if !sprite.equal?(bitmap) || sprite.bitmap!=bitmap
end
def getRegularTile(sprite,id)
if false
sprite.bitmap=@tileset if !sprite.equal?(@tileset) || sprite.bitmap!=@tileset
sprite.src_rect.set((id - 384) % 8 * 32, (id - 384) / 8 * 32,32,32)
else
bitmap=@regularTileInfo[id]
if !bitmap
bitmap=Bitmap.new(32,32)
rect=Rect.new((id - 384) % 8 * 32, (id - 384) / 8 * 32,32,32)
bitmap.blt(0,0,@tileset,rect)
@regularTileInfo[id]=bitmap
end
sprite.bitmap=bitmap if !sprite.equal?(bitmap) || sprite.bitmap!=bitmap
end
end
def addTile(tiles,count,xpos,ypos,id)
if id>=384
if count>=tiles.length
sprite=Sprite.new(@viewport)
tiles.push(sprite,0)
else
sprite=tiles[count]
tiles[count+1]=0
end
sprite.visible=@visible
sprite.x=xpos
sprite.y=ypos
getRegularTile(sprite,id)
spriteZ=(@priorities[id]==0||!@priorities[id]) ? 0 : ypos+@priorities[id]*32+32
sprite.z=spriteZ
count+=2
else
if count>=tiles.length
sprite=Sprite.new(@viewport)
tiles.push(sprite,1)
else
sprite=tiles[count]
tiles[count+1]=1
end
sprite.visible=@visible
sprite.x=xpos
sprite.y=ypos
getAutotile(sprite,id)
spriteZ=(@priorities[id]==0||!@priorities[id]) ? 0 : ypos+@priorities[id]*32+32
sprite.z=spriteZ
count+=2
end
return count
end
def refresh_tileset
i=0;[email protected];while i<len
if @regularTileInfo
@regularTileInfo.dispose
@regularTileInfo=nil
end
i+=1
end
@regularTileInfo.clear
@priotiles.clear
ysize=@map_data.ysize
xsize=@map_data.xsize
zsize=@map_data.zsize
if xsize>100 || ysize>100
@fullyrefreshed=false
else
for z in 0...zsize
for y in 0...ysize
for x in 0...xsize
id = @map_data[x, y, z]
next if id==0 || !@priorities[id]
next if @priorities[id]==0
@priotiles.push([x,y,z,id])
end
end
end
@fullyrefreshed=true
end
end
def refresh_flash
if @flash_data&&!@flash
@flash=Sprite.new(viewport)
@flash.visible=true
@flash.z=1
@flash.blend_type=1
@flash.bitmap=Bitmap.new(@viewport.rect.width*2,@viewport.rect.height*2)
@firsttimeflash=true
elsif !@flash_data&&@flash
@flash.bitmap.dispose if @flash.bitmap
@flash.dispose
@flash=nil
@firsttimeflash=false
end
end
def refresh_autotiles
i=0;[email protected];while i<len
if @autotileInfo
@autotileInfo.dispose
@autotileInfo=nil
end
i+=1
end
i=0;[email protected];while i<len
if @autosprites
@autosprites.dispose
@autosprites=nil
end
i+=2
end
@autosprites.clear
@autotileInfo.clear
@prioautotiles.clear
hasanimated=false
for i in 0...7
numframes=autotileNumFrames(48*(i+1))
hasanimated=true if numframes>=2
@framecount=numframes
end
if hasanimated
ysize=@map_data.ysize
xsize=@map_data.xsize
zsize=@map_data.zsize
if xsize>100 || ysize>100
@fullyrefreshedautos=false
else
for y in 0...ysize
for x in 0...xsize
haveautotile=false
for z in 0...zsize
id = @map_data[x, y, z]
next if id==0 || id>=384 || @priorities[id]!=0 || !@priorities[id]
next if @framecount[id/48-1]<2
haveautotile=true
break
end
@prioautotiles.push([x,y]) if haveautotile
end
end
@fullyrefreshedautos=true
end
else
@fullyrefreshedautos=true
end
end
def map_data=(value)
@map_data=value
@tilesetChanged=true
end
def refreshFlashSprite
return if !@Flash || @flash_data.nil?
ptX=@ox-@oxFlash
ptY=@oy-@oyFlash
if !@firsttimeflash&&!@usedsprites&&
ptX>=0&&[email protected]<[email protected]&&
ptY>=0&&[email protected]<[email protected]
@flash.ox=0
@flash.oy=0
@flash.src_rect.set(ptX.round,ptY.round,
@viewport.rect.width,@viewport.rect.height)
return
end
[email protected]
[email protected]
[email protected]
ysize=@map_data.ysize
xsize=@map_data.xsize
zsize=@map_data.zsize
@firsttimeflash=false
@oxFlash=@ox-(width>>2)
@oyFlash=@oy-(height>>2)
@flash.ox=0
@flash.oy=0
@flash.src_rect.set(width>>2,
height>>2,
@viewport.rect.width,@viewport.rect.height)
@flash.bitmap.clear
@[email protected]
@[email protected]
xStart=(@oxFlash>>5)
xStart=0 if xStart<0
yStart=(@oyFlash>>5)
yStart=0 if yStart<0
xEnd=xStart+(width>>5)+1
yEnd=yStart+(height>>5)+1
xEnd=xsize if xEnd>=xsize
yEnd=ysize if yEnd>=ysize
if xStart<xEnd&&yStart<yEnd
yrange=yStart...yEnd
xrange=xStart...xEnd
tmpcolor=Color.new(0,0,0,0)
for y in yrange
ypos=(y<<5)-@oyFlash
for x in xrange
xpos=(x<<5)-@oxFlash
id = @flash_data[x, y, 0]
r=(id>>8)&15
g=(id>>4)&15
b=(id)&15
tmpcolor.set(r*16,g*16,b*16)
bitmap.fill_rect(xpos,ypos,32,32,tmpcolor)
end
end
end
end
def refreshLayer0(autotiles=false)
ptX=@ox-@oxLayer0
ptY=@oy-@oyLayer0
if !autotiles&&!@firsttime&&!@usedsprites&&
ptX>=0&&[email protected]<[email protected]&&
ptY>=0&&[email protected]<[email protected]
if @layer0clip
@layer0.ox=0
@layer0.oy=0
@layer0.src_rect.set(ptX.round,ptY.round,
@viewport.rect.width,@viewport.rect.height)
else
@layer0.ox=ptX.round
@layer0.oy=ptY.round
@layer0.src_rect.set(0,0,@layer0.bitmap.width,@layer0.bitmap.height)
end
return true
end
[email protected]
[email protected]
[email protected]
ysize=@map_data.ysize
xsize=@map_data.xsize
zsize=@map_data.zsize
if autotiles
return true if @fullyrefreshedautos&&@prioautotiles.length==0
return true if !shown?
xStart=(@oxLayer0>>5)
xStart=0 if xStart<0
yStart=(@oyLayer0>>5)
yStart=0 if yStart<0
xEnd=xStart+(width>>5)+1
yEnd=yStart+(height>>5)+1
xEnd=xsize if xEnd>xsize
yEnd=ysize if yEnd>ysize
return true if xStart>=xEnd || yStart>=yEnd
trans=Color.new(0,0,0,0)
temprect=Rect.new(0,0,0,0)
tilerect=Rect.new(0,0,32,32)
range=0...zsize
overallcount=0
count=0
if !@fullyrefreshedautos
for y in yStart..yEnd
for x in xStart..xEnd
haveautotile=false
for z in range
id = @map_data[x, y, z]
next if id<48 || id>=384 || @priorities[id]!=0 || !@priorities[id]
next if @framecount[id/48-1]<2
haveautotile=true
break
end
next if !haveautotile
overallcount+=1
xpos=(x<<5)-@oxLayer0
ypos=(y<<5)-@oyLayer0
bitmap.fill_rect(xpos,ypos,0,0,trans) if overallcount<=2000
for z in range
id = @map_data[x,y,z]
next if id<48 || @priorities[id]!=0 || !@priorities[id]
if overallcount>2000
count=addTile(@autosprites,count,xpos,ypos,id)
next
elsif id>=384
temprect.set((id - 384) % 8 * 32, (id - 384) / 8 * 32,32,32)
bitmap.blt(xpos,ypos,@tileset,temprect)
else
tilebitmap=@autotileInfo[id]
if !tilebitmap
anim=autotileFrame(id)
next if anim<0
tilebitmap=Bitmap.new(32,32)
bltAutotile(tilebitmap,0,0,id,anim)
@autotileInfo[id]=tilebitmap
end
bitmap.blt(xpos,ypos,tilebitmap,tilerect)
end
end
end
end
else
for tile in @prioautotiles
x=tile[0]
y=tile[1]
next if x<xStart||x>xEnd
next if y<yStart||y>yEnd
overallcount+=1
xpos=(x<<5)-@oxLayer0
ypos=(y<<5)-@oyLayer0
bitmap.fill_rect(xpos,ypos,0,0,trans) if overallcount<=2000
for z in range
id = @map_data[x,y,z]
next if id<48 || @priorities[id]!=0 || !@priorities[id]
if overallcount>2000
count=addTile(@autosprites,count,xpos,ypos,id)
next
elsif id>=384
temprect.set((id - 384) % 8 * 32, (id - 384) / 8 * 32,32,32)
bitmap.blt(xpos,ypos,@tileset,temprect)
else
tilebitmap=@autotileInfo[id]
if !tilebitmap
anim=autotileFrame(id)
next if anim<0
tilebitmap=Bitmap.new(32,32)
bltAutotile(tilebitmap,0,0,id,anim)
@autotileInfo[id]=tilebitmap
end
bitmap.blt(xpos,ypos,tilebitmap,tilerect)
end
end
end
end
Graphics.frame_reset if overallcount>2000
@usedsprites=false
return true
end
return false if @usedsprites
@firsttime=false
@oxLayer0=@ox-(width>>2)
@oyLayer0=@oy-(height>>2)
if @layer0clip
@layer0.ox=0
@layer0.oy=0
@layer0.src_rect.set(width>>2,height>>2,
@viewport.rect.width,@viewport.rect.height)
else
@layer0.ox=(width>>2)
@layer0.oy=(height>>2)
end
@layer0.bitmap.clear
@[email protected]
@[email protected]
xStart=(@oxLayer0>>5)
xStart=0 if xStart<0
yStart=(@oyLayer0>>5)
yStart=0 if yStart<0
xEnd=xStart+(width>>5)+1
yEnd=yStart+(height>>5)+1
xEnd=xsize if xEnd>=xsize
yEnd=ysize if yEnd>=ysize
if xStart<xEnd&&yStart<yEnd
tmprect=Rect.new(0,0,0,0)
yrange=yStart...yEnd
xrange=xStart...xEnd
for z in 0...zsize
for y in yrange
ypos=(y<<5)-@oyLayer0
for x in xrange
xpos=(x<<5)-@oxLayer0
id = @map_data[x, y, z]
next if id==0 || @priorities[id]!=0 || !@priorities[id]
if id>=384
tmprect.set((id - 384) % 8 * 32, (id - 384) / 8 * 32,32,32)
bitmap.blt(xpos,ypos,@tileset,tmprect)
else
frame=autotileFrame(id)
bltAutotile(bitmap,xpos,ypos,id,frame)
end
end
end
end
Graphics.frame_reset
end
return true
end
def getResizeFactor
return $ResizeFactor ? $ResizeFactor : 1.0
end
def ox=(val)
val=(val*getResizeFactor).to_i
val=(val/getResizeFactor).to_i
wasshown=self.shown?
@ox=val.floor
@nowshown=(!wasshown&&self.shown?)
end
def oy=(val)
val=(val*getResizeFactor).to_i
val=(val/getResizeFactor).to_i
wasshown=self.shown?
@oy=val.floor
@nowshown=(!wasshown&&self.shown?)
end
def visible=(val)
wasshown=@visible
@visible=val
@nowshown=(!wasshown&&val)
end
def refresh(autotiles=false)
@oldOx=@ox
@oldOy=@oy
usesprites=false
if @layer0
@layer0.visible=@visible
usesprites=!refreshLayer0(autotiles)
if autotiles&&!usesprites
return
end
else
usesprites=true
end
refreshFlashSprite
[email protected]
[email protected]
[email protected]+vpx
[email protected]+vpy
xsize=@map_data.xsize
ysize=@map_data.ysize
minX=(@ox/32)-1
maxX=((@[email protected])/32)+1
minY=(@oy/32)-1
maxY=((@[email protected])/32)+1
minX=0 if minX<0
minX=xsize-1 if minX>=xsize
maxX=0 if maxX<0
maxX=xsize-1 if maxX>=xsize
minY=0 if minY<0
minY=ysize-1 if minY>=ysize
maxY=0 if maxY<0
maxY=ysize-1 if maxY>=ysize
count=0
if minX<maxX&&minY<maxY
@usedsprites=usesprites || @usedsprites
if @layer0
@layer0.visible=false if usesprites
end
if @fullyrefreshed
for prio in @priotiles
next if prio[0]<minX||prio[0]>maxX
next if prio[1]<minY||prio[1]>maxY
id=prio[3]
xpos=(prio[0]<<5)-@ox
ypos=(prio[1]<<5)-@oy
count=addTile(@tiles,count,xpos,ypos,id)
end
else
for z in 0...@map_data.zsize
for y in minY..maxY
for x in minX..maxX
id = @map_data[x, y, z]
next if id==0 || !@priorities[id]
next if @priorities[id]==0
xpos=(x<<5)-@ox
ypos=(y<<5)-@oy
count=addTile(@tiles,count,xpos,ypos,id)
end
end
end
end
end
if count<@tiles.length
bigchange=(count<=(@tiles.length*2/3))&&(@tiles.length*2/3)>25
j=count;[email protected];while j<len
sprite=@tiles[j]
@tiles[j+1]=-1
if bigchange
sprite.dispose
@tiles[j]=nil
@tiles[j+1]=nil
elsif !@tiles[j].disposed?
sprite.visible=false if sprite.visible
end
j+=2
end
@tiles.compact! if bigchange
end
end
end
=begin
脚本:【完美输入法修正】
功能:输入法。
说明: 直接用Type_Field创建输入域即可进行输入,在此可根据Type_Field域对象
的活动标记active来自定义刷新等,在Type_Field中需要自己处理特殊按键
的处理方法。具体不明白之处请参考范例工程。
作者:灼眼的夏娜
补充: 至于以前那个版本也许很多人都注意到那个烦人的问题了吧,按Enter和Tab那
些会出现不爽的声音,这个版本解决了那个问题,并简化添加了Type_Field类
来方便创建输入域。
=end
#==============================================================================
# ■ RInput
#------------------------------------------------------------------------------
# 全键盘处理的模块。
#==============================================================================
module RInput
#--------------------------------------------------------------------------
# ● 常量定义
#--------------------------------------------------------------------------
ENTER = 0x0D
SPACE = 0x20
UP = 0x26
DOWN = 0x28
LEFT = 0x25
RIGHT = 0x27
LCTRL = 0xA2
LALT = 0xA4
#--------------------------------------------------------------------------
# ● 临时Hash
#--------------------------------------------------------------------------
@R_Key_Hash = {}
@R_Key_Repeat = {}
#--------------------------------------------------------------------------
# ● 唯一API
#--------------------------------------------------------------------------
GetKeyState = Win32API.new("user32","GetAsyncKeyState",['I'],'I')
#--------------------------------------------------------------------------
# ● 单键处理
#--------------------------------------------------------------------------
def self.trigger?(rkey)
result = GetKeyState.call(rkey)
if @R_Key_Hash[rkey] == 1 and result != 0
return false
end
if result != 0
@R_Key_Hash[rkey] = 1
return true
else
@R_Key_Hash[rkey] = 0
return false
end
end
end
#==============================================================================
# ■ EasyConv
#------------------------------------------------------------------------------
# 转码模块。
#==============================================================================
module EasyConv
#--------------------------------------------------------------------------
# ● 常量定义
#--------------------------------------------------------------------------
CP_ACP = 0
CP_UTF8 = 65001
#--------------------------------------------------------------------------
# ● 模块函数
#--------------------------------------------------------------------------
module_function
#--------------------------------------------------------------------------
# ● 转码
#--------------------------------------------------------------------------
def s2u(text)
m2w = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
w2m = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')
len = m2w.call(CP_ACP, 0, text, -1, nil, 0)
buf = "\0" * (len*2)
m2w.call(CP_ACP, 0, text, -1, buf, buf.size/2)
len = w2m.call(CP_UTF8, 0, buf, -1, nil, 0, nil, nil)
ret = "\0" * len
w2m.call(CP_UTF8, 0, buf, -1, ret, ret.size, nil, nil)
ret[-1] = ""
return ret
end
#--------------------------------------------------------------------------
# ● 转码
#--------------------------------------------------------------------------
def u2s(text)
m2w = Win32API.new('kernel32', 'MultiByteToWideChar', 'ilpipi', 'i')
w2m = Win32API.new('kernel32', 'WideCharToMultiByte', 'ilpipipp', 'i')
len = m2w.call(CP_UTF8, 0, text, -1, nil, 0)
buf = "\0" * (len*2)
m2w.call(CP_UTF8, 0, text, -1, buf, buf.size/2)
len = w2m.call(CP_ACP, 0, buf, -1, nil, 0, nil, nil)
ret = "\0" * len
w2m.call(CP_ACP, 0, buf, -1, ret, ret.size, nil, nil)
return ret
end
end
#==============================================================================
# ■ TypeAPI
#------------------------------------------------------------------------------
# 输入法相关API模块。
#==============================================================================
module TypeAPI
#--------------------------------------------------------------------------
# ● API定义
#--------------------------------------------------------------------------
GPPS = Win32API.new("kernel32","GetPrivateProfileString",'pppplp','l')
FindWindow = Win32API.new("user32", "FindWindow", 'pp', 'i')
CreateWindow = Win32API.new("NetGame","CreatWnd",'l','l')
SetHK = Win32API.new("NetGame","SetHK",'v','v')
GetText = Win32API.new("NetGame","GetWndText",'l','p')
SetFocus = Win32API.new("user32","SetFocus",'l','l')
IfBack = Win32API.new("NetGame","If_Back",'v','i')
StartType = Win32API.new("NetGame","StartType",'v','v')
EndType = Win32API.new("NetGame","EndType",'v','v')
GetKeyInfos = Win32API.new("NetGame","GetKeyInfo",'v','i')
#--------------------------------------------------------------------------
# ● 模块函数
#--------------------------------------------------------------------------
module_function
#--------------------------------------------------------------------------
# ● 获取参数
#--------------------------------------------------------------------------
def getParam
val = "\0" * 256
GPPS.call("Game","Title","",val,256,"./Game.ini")
val.delete!("\0")
return val
end
#--------------------------------------------------------------------------
# ● 获取窗口
#--------------------------------------------------------------------------
def findWindow
return FindWindow.call("RGSS Player",self.getParam)
end
#--------------------------------------------------------------------------
# ● 创建窗口
#--------------------------------------------------------------------------
def createWindow(hwnd)
return CreateWindow.call(hwnd)
end
#--------------------------------------------------------------------------
# ● 设置HK
#--------------------------------------------------------------------------
def setHK
SetHK.call
end
#--------------------------------------------------------------------------
# ● 获取文字
#--------------------------------------------------------------------------
def getText
return EasyConv.s2u(GetText.call(@subhwnd))
end
#--------------------------------------------------------------------------
# ● 设置焦点
#--------------------------------------------------------------------------
def setFocus
SetFocus.call(@subhwnd)
end
#--------------------------------------------------------------------------
# ● 转换焦点
#--------------------------------------------------------------------------
def lostFocus
SetFocus.call(@hwnd)
end
#--------------------------------------------------------------------------
# ● 退格判定
#--------------------------------------------------------------------------
def ifBack
return IfBack.call
end
#--------------------------------------------------------------------------
# ● 开始输入
#--------------------------------------------------------------------------
def startType
StartType.call
end
#--------------------------------------------------------------------------
# ● 结束输入
#--------------------------------------------------------------------------
def endType
EndType.call
end
#--------------------------------------------------------------------------
# ● 输入中特殊按键处理
#--------------------------------------------------------------------------
def getKeyInfos
return GetKeyInfos.call
end
#--------------------------------------------------------------------------
# ● 获取句柄
#--------------------------------------------------------------------------
@hwnd = self.findWindow
@subhwnd = self.createWindow(@hwnd)
#--------------------------------------------------------------------------
# ● 设置HK应用
#--------------------------------------------------------------------------
self.setHK
end
#==============================================================================
# ■ Type_Field
#------------------------------------------------------------------------------
# 处理输入域的类。
#==============================================================================
class Type_Field
#--------------------------------------------------------------------------
# ● 定义实例变量
#--------------------------------------------------------------------------
attr(:active)
#--------------------------------------------------------------------------
# ● 初始化
#--------------------------------------------------------------------------
def initialize(v,default_text = "",default_careth = nil,default_fonts = 16,\
default_fontc = Color.new(0,0,0))
# active
@active = true
# 视口
rect = v.rect
@v = Viewport.new(rect.x,rect.y,rect.width,rect.height)
@w = rect.width
@h = rect.height
# 属性
@caret_h = default_careth.nil? ? @h : [@h,default_careth].min
@caret_y = rect.y + (@h - @caret_h) / 2
@font_size = [default_fonts,@h].min
# 描绘contents
@cts = Sprite.new(@v)
@cts.bitmap = Bitmap.new(@w - 3,@h)
@cts.bitmap.font.size = @font_size
@cts.bitmap.font.color = default_fontc
# 辅助属性
@bk_count = 0
@text = default_text.scan(/./)
@max_width = @w - 3
@caret_pos = @text.size
@save_pos = @caret_pos
# 光标Caret
@v1 = Viewport.new(rect.x,@caret_y,@w + 3,@caret_h)
@caret_sp = Sprite.new(@v1)
@caret_bitmap = Bitmap.new(3,@caret_h)
@caret_bitmap.fill_rect(0,0,1,@caret_h,Color.new(0,0,0,180))
@caret_bitmap.fill_rect(1,0,1,@caret_h,Color.new(0,0,0))
@caret_bitmap.fill_rect(2,0,1,@caret_h,Color.new(120,120,120))
@caret_sp.bitmap = @caret_bitmap
@caret_sp.x = self.get_width(@text[0,@caret_pos].to_s)
@caret_sp.y = 0
@caret_sp.visible = false
@caret_flash_count = 0
# 刷新
refresh
# 设置焦点
TypeAPI.setFocus
# 开始输入
TypeAPI.startType
end
#--------------------------------------------------------------------------
# ● 设置活动标记
#--------------------------------------------------------------------------
def active=(value)
if value != true and value != false
return
end
@active = value
@caret_sp.visible = @active
end
#--------------------------------------------------------------------------
# ● 释放
#--------------------------------------------------------------------------
def dispose
@caret_bitmap.dispose
@caret_sp.bitmap.dispose
@caret_sp.dispose
@cts.bitmap.dispose
@cts.dispose
@v.dispose
@v1.dispose
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
@cts.bitmap.clear
@cts.bitmap.draw_text(0,0,@w,@h,@text.to_s)
end
#--------------------------------------------------------------------------
# ● 获取文字
#--------------------------------------------------------------------------
def get_text
return @text.to_s
end
#--------------------------------------------------------------------------
# ● 取得字符宽度
#--------------------------------------------------------------------------
def get_width(str)
return @cts.bitmap.text_size(str).width
end
#--------------------------------------------------------------------------
# ● 更新
#--------------------------------------------------------------------------
def update
# 非激活状态则返回
unless @active
return
end
# 获取按键信息
key_info = TypeAPI.getKeyInfos
case key_info
when 0x09 # Tab
# 按下 Tab 键的情况自己定义怎么处理
return
when 0x0d # Enter
# 按下 Enter 键的情况自己定义怎么处理
return
when 0x1B # Esc
# 按下 Esc 键的情况自己定义怎么处理
return
end
self.update_text
self.update_lrb
self.update_back
self.update_caret
end
#--------------------------------------------------------------------------
# ● 更新文字
#--------------------------------------------------------------------------
def update_text
# 文字刷新
TypeAPI.setFocus
text = TypeAPI.getText
if text != ""
for char in text.scan(/./)
if self.get_width(@text.to_s + char) <= @max_width
@text[@caret_pos,0] = char
@caret_pos += 1
else
break
end
end
refresh
end
end
#--------------------------------------------------------------------------
# ● 更新左右按键
#--------------------------------------------------------------------------
def update_lrb
if RInput.trigger?(RInput::LEFT) and @caret_pos > 0
@caret_pos -= 1
return
end
if RInput.trigger?(RInput::RIGHT) and @caret_pos < @text.size
@caret_pos += 1
return
end
end
#--------------------------------------------------------------------------
# ● 更新退格
#--------------------------------------------------------------------------
def update_back
# 前退格处理
@bk_count += TypeAPI.ifBack
if @bk_count > 0
@bk_count -= 1
if @caret_pos > 0
@text.delete_at(@caret_pos - 1);@caret_pos -= 1;refresh
end
end
end
#--------------------------------------------------------------------------
# ● 更新光标闪烁
#--------------------------------------------------------------------------
def update_caret
# 闪烁计时
@caret_flash_count += 1
if @caret_flash_count == 20
@caret_sp.visible = !@caret_sp.visible
@caret_flash_count = 0
end
# Caret位置刷新
if @save_pos != @caret_pos
@save_pos = @caret_pos
@caret_sp.x = self.get_width(@text[0,@save_pos].to_s)
end
end
end
其他没改..
|
|