Yet more script rearranging

This commit is contained in:
Maruno17
2021-04-17 23:45:42 +01:00
parent 96c68e79a3
commit 2ca8a42949
236 changed files with 923 additions and 928 deletions

View File

@@ -887,6 +887,64 @@ end
#===============================================================================
# Draw text and images on a bitmap
#===============================================================================
def getLineBrokenText(bitmap,value,width,dims)
x=0
y=0
textheight=0
ret=[]
if dims
dims[0]=0
dims[1]=0
end
line=0
position=0
column=0
return ret if !bitmap || bitmap.disposed? || width<=0
textmsg=value.clone
ret.push(["",0,0,0,bitmap.text_size("X").height,0,0,0,0])
while ((c = textmsg.slice!(/\n|(\S*([ \r\t\f]?))/)) != nil)
break if c==""
length=c.scan(/./m).length
ccheck=c
if ccheck=="\n"
ret.push(["\n",x,y,0,textheight,line,position,column,0])
x=0
y+=(textheight==0) ? bitmap.text_size("X").height : textheight
line+=1
textheight=0
column=0
position+=length
ret.push(["",x,y,0,textheight,line,position,column,0])
next
end
words=[ccheck]
for i in 0...words.length
word=words[i]
if word && word!=""
textSize=bitmap.text_size(word)
textwidth=textSize.width
if x>0 && x+textwidth>=width-2
# Zero-length word break
ret.push(["",x,y,0,textheight,line,position,column,0])
x=0
column=0
y+=(textheight==0) ? bitmap.text_size("X").height : textheight
line+=1
textheight=0
end
textheight=[textheight,textSize.height].max
ret.push([word,x,y,textwidth,textheight,line,position,column,length])
x+=textwidth
dims[0]=x if dims && dims[0]<x
end
end
position+=length
column+=length
end
dims[1]=y+textheight if dims
return ret
end
def getLineBrokenChunks(bitmap,value,width,dims,plain=false)
x=0
y=4

View File

@@ -921,3 +921,43 @@ def pbMessageWaitForInput(msgwindow,frames,showPause=false)
end
msgwindow.stopPause if msgwindow && showPause
end
def pbFreeText(msgwindow,currenttext,passwordbox,maxlength,width=240)
window=Window_TextEntry_Keyboard.new(currenttext,0,0,width,64)
ret=""
window.maxlength=maxlength
window.visible=true
window.z=99999
pbPositionNearMsgWindow(window,msgwindow,:right)
window.text=currenttext
window.passwordChar="*" if passwordbox
Input.text_input = true
loop do
Graphics.update
Input.update
if Input.triggerex?(:ESCAPE)
ret=currenttext
break
elsif Input.triggerex?(:RETURN)
ret=window.text
break
end
window.update
msgwindow.update if msgwindow
yield if block_given?
end
Input.text_input = false
window.dispose
Input.update
return ret
end
def pbMessageFreeText(message,currenttext,passwordbox,maxlength,width=240,&block)
msgwindow=pbCreateMessageWindow
retval=pbMessageDisplay(msgwindow,message,true,
proc { |msgwindow|
next pbFreeText(msgwindow,currenttext,passwordbox,maxlength,width,&block)
},&block)
pbDisposeMessageWindow(msgwindow)
return retval
end

View File

@@ -1,71 +1,3 @@
#===============================================================================
#
#===============================================================================
class Window_CharacterEntry < Window_DrawableCommand
XSIZE=13
YSIZE=4
def initialize(charset,viewport=nil)
@viewport=viewport
@charset=charset
@othercharset=""
super(0,96,480,192)
colors=getDefaultTextColors(self.windowskin)
self.baseColor=colors[0]
self.shadowColor=colors[1]
self.columns=XSIZE
refresh
end
def setOtherCharset(value)
@othercharset=value.clone
refresh
end
def setCharset(value)
@charset=value.clone
refresh
end
def character
if self.index<0 || self.index>=@charset.length
return "";
else
return @charset[self.index]
end
end
def command
return -1 if self.index==@charset.length
return -2 if self.index==@charset.length+1
return -3 if self.index==@charset.length+2
return self.index
end
def itemCount
return @charset.length+3
end
def drawItem(index,_count,rect)
rect=drawCursor(index,rect)
if index==@charset.length # -1
pbDrawShadowText(self.contents,rect.x,rect.y,rect.width,rect.height,"[ ]",
self.baseColor,self.shadowColor)
elsif index==@charset.length+1 # -2
pbDrawShadowText(self.contents,rect.x,rect.y,rect.width,rect.height,@othercharset,
self.baseColor,self.shadowColor)
elsif index==@charset.length+2 # -3
pbDrawShadowText(self.contents,rect.x,rect.y,rect.width,rect.height,_INTL("OK"),
self.baseColor,self.shadowColor)
else
pbDrawShadowText(self.contents,rect.x,rect.y,rect.width,rect.height,@charset[index],
self.baseColor,self.shadowColor)
end
end
end
#===============================================================================
#
#===============================================================================
@@ -294,62 +226,35 @@ end
#===============================================================================
#
#===============================================================================
def getLineBrokenText(bitmap,value,width,dims)
x=0
y=0
textheight=0
ret=[]
if dims
dims[0]=0
dims[1]=0
end
line=0
position=0
column=0
return ret if !bitmap || bitmap.disposed? || width<=0
textmsg=value.clone
ret.push(["",0,0,0,bitmap.text_size("X").height,0,0,0,0])
while ((c = textmsg.slice!(/\n|(\S*([ \r\t\f]?))/)) != nil)
break if c==""
length=c.scan(/./m).length
ccheck=c
if ccheck=="\n"
ret.push(["\n",x,y,0,textheight,line,position,column,0])
x=0
y+=(textheight==0) ? bitmap.text_size("X").height : textheight
line+=1
textheight=0
column=0
position+=length
ret.push(["",x,y,0,textheight,line,position,column,0])
next
end
words=[ccheck]
for i in 0...words.length
word=words[i]
if word && word!=""
textSize=bitmap.text_size(word)
textwidth=textSize.width
if x>0 && x+textwidth>=width-2
# Zero-length word break
ret.push(["",x,y,0,textheight,line,position,column,0])
x=0
column=0
y+=(textheight==0) ? bitmap.text_size("X").height : textheight
line+=1
textheight=0
end
textheight=[textheight,textSize.height].max
ret.push([word,x,y,textwidth,textheight,line,position,column,length])
x+=textwidth
dims[0]=x if dims && dims[0]<x
class Window_TextEntry_Keyboard < Window_TextEntry
def update
@frame+=1
@frame%=20
self.refresh if ((@frame%10)==0)
return if !self.active
# Moving cursor
if Input.triggerex?(:LEFT) || Input.repeatex?(:LEFT)
if @helper.cursor > 0
@helper.cursor-=1
@frame=0
self.refresh
end
return
elsif Input.triggerex?(:LEFT) || Input.repeatex?(:RIGHT)
if @helper.cursor < self.text.scan(/./m).length
@helper.cursor+=1
@frame=0
self.refresh
end
return
elsif Input.triggerex?(:BACKSPACE) || Input.repeatex?(:BACKSPACE)
self.delete if @helper.cursor>0
return
elsif Input.triggerex?(:RETURN) || Input.triggerex?(:ESCAPE)
return
end
position+=length
column+=length
Input.gets.each_char { |c| insert(c) }
end
dims[1]=y+textheight if dims
return ret
end
@@ -657,810 +562,3 @@ class Window_MultilineTextEntry < SpriteWindow_Base
end
end
end
#===============================================================================
#
#===============================================================================
class Window_TextEntry_Keyboard < Window_TextEntry
def update
@frame+=1
@frame%=20
self.refresh if ((@frame%10)==0)
return if !self.active
# Moving cursor
if Input.triggerex?(:LEFT) || Input.repeatex?(:LEFT)
if @helper.cursor > 0
@helper.cursor-=1
@frame=0
self.refresh
end
return
elsif Input.triggerex?(:LEFT) || Input.repeatex?(:RIGHT)
if @helper.cursor < self.text.scan(/./m).length
@helper.cursor+=1
@frame=0
self.refresh
end
return
elsif Input.triggerex?(:BACKSPACE) || Input.repeatex?(:BACKSPACE)
self.delete if @helper.cursor>0
return
elsif Input.triggerex?(:RETURN) || Input.triggerex?(:ESCAPE)
return
end
Input.gets.each_char{|c|insert(c)}
end
end
#===============================================================================
# Text entry screen - free typing.
#===============================================================================
class PokemonEntryScene
@@Characters=[
[("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz").scan(/./),"[*]"],
[("0123456789 !@\#$%^&*() ~`-_+={}[] :;'\"<>,.?/ ").scan(/./),"[A]"],
]
USEKEYBOARD=true
def pbStartScene(helptext,minlength,maxlength,initialText,subject=0,pokemon=nil)
@sprites={}
@viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
@viewport.z=99999
if USEKEYBOARD
@sprites["entry"]=Window_TextEntry_Keyboard.new(initialText,
0,0,400-112,96,helptext,true)
Input.text_input = true
else
@sprites["entry"]=Window_TextEntry.new(initialText,0,0,400,96,helptext,true)
end
@sprites["entry"].x=(Graphics.width/2)-(@sprites["entry"].width/2)+32
@sprites["entry"].viewport=@viewport
@sprites["entry"].visible=true
@minlength=minlength
@maxlength=maxlength
@symtype=0
@sprites["entry"].maxlength=maxlength
if !USEKEYBOARD
@sprites["entry2"]=Window_CharacterEntry.new(@@Characters[@symtype][0])
@sprites["entry2"].setOtherCharset(@@Characters[@symtype][1])
@sprites["entry2"].viewport=@viewport
@sprites["entry2"].visible=true
@sprites["entry2"].x=(Graphics.width/2)-(@sprites["entry2"].width/2)
end
if minlength==0
@sprites["helpwindow"]=Window_UnformattedTextPokemon.newWithSize(
_INTL("Enter text using the keyboard. Press\nEnter to confirm, or Esc to cancel."),
32,Graphics.height-96,Graphics.width-64,96,@viewport
)
else
@sprites["helpwindow"]=Window_UnformattedTextPokemon.newWithSize(
_INTL("Enter text using the keyboard.\nPress Enter to confirm."),
32,Graphics.height-96,Graphics.width-64,96,@viewport
)
end
@sprites["helpwindow"].letterbyletter=false
@sprites["helpwindow"].viewport=@viewport
@sprites["helpwindow"].visible=USEKEYBOARD
@sprites["helpwindow"].baseColor=Color.new(16,24,32)
@sprites["helpwindow"].shadowColor=Color.new(168,184,184)
addBackgroundPlane(@sprites,"background","Naming/bg_2",@viewport)
case subject
when 1 # Player
meta=GameData::Metadata.get_player($Trainer.character_ID)
if meta
@sprites["shadow"]=IconSprite.new(0,0,@viewport)
@sprites["shadow"].setBitmap("Graphics/Pictures/Naming/icon_shadow")
@sprites["shadow"].x=33*2
@sprites["shadow"].y=32*2
filename=pbGetPlayerCharset(meta,1,nil,true)
@sprites["subject"]=TrainerWalkingCharSprite.new(filename,@viewport)
charwidth=@sprites["subject"].bitmap.width
charheight=@sprites["subject"].bitmap.height
@sprites["subject"].x = 44*2 - charwidth/8
@sprites["subject"].y = 38*2 - charheight/4
end
when 2 # Pokémon
if pokemon
@sprites["shadow"]=IconSprite.new(0,0,@viewport)
@sprites["shadow"].setBitmap("Graphics/Pictures/Naming/icon_shadow")
@sprites["shadow"].x=33*2
@sprites["shadow"].y=32*2
@sprites["subject"]=PokemonIconSprite.new(pokemon,@viewport)
@sprites["subject"].setOffset(PictureOrigin::Center)
@sprites["subject"].x=88
@sprites["subject"].y=54
@sprites["gender"]=BitmapSprite.new(32,32,@viewport)
@sprites["gender"].x=430
@sprites["gender"].y=54
@sprites["gender"].bitmap.clear
pbSetSystemFont(@sprites["gender"].bitmap)
textpos=[]
if pokemon.male?
textpos.push([_INTL(""),0,-6,false,Color.new(0,128,248),Color.new(168,184,184)])
elsif pokemon.female?
textpos.push([_INTL(""),0,-6,false,Color.new(248,24,24),Color.new(168,184,184)])
end
pbDrawTextPositions(@sprites["gender"].bitmap,textpos)
end
when 3 # NPC
@sprites["shadow"]=IconSprite.new(0,0,@viewport)
@sprites["shadow"].setBitmap("Graphics/Pictures/Naming/icon_shadow")
@sprites["shadow"].x=33*2
@sprites["shadow"].y=32*2
@sprites["subject"]=TrainerWalkingCharSprite.new(pokemon.to_s,@viewport)
charwidth=@sprites["subject"].bitmap.width
charheight=@sprites["subject"].bitmap.height
@sprites["subject"].x = 44*2 - charwidth/8
@sprites["subject"].y = 38*2 - charheight/4
when 4 # Storage box
@sprites["subject"]=TrainerWalkingCharSprite.new(nil,@viewport)
@sprites["subject"].altcharset="Graphics/Pictures/Naming/icon_storage"
@sprites["subject"].animspeed=4
charwidth=@sprites["subject"].bitmap.width
charheight=@sprites["subject"].bitmap.height
@sprites["subject"].x = 44*2 - charwidth/8
@sprites["subject"].y = 26*2 - charheight/2
end
pbFadeInAndShow(@sprites)
end
def pbEntry1
ret=""
loop do
Graphics.update
Input.update
if Input.triggerex?(:ESCAPE) && @minlength==0
ret=""
break
elsif Input.triggerex?(:RETURN) && @sprites["entry"].text.length>=@minlength
ret=@sprites["entry"].text
break
end
@sprites["helpwindow"].update
@sprites["entry"].update
@sprites["subject"].update if @sprites["subject"]
end
Input.update
return ret
end
def pbEntry2
ret=""
loop do
Graphics.update
Input.update
@sprites["helpwindow"].update
@sprites["entry"].update
@sprites["entry2"].update
@sprites["subject"].update if @sprites["subject"]
if Input.trigger?(Input::USE)
index=@sprites["entry2"].command
if index==-3 # Confirm text
ret=@sprites["entry"].text
if ret.length<@minlength || ret.length>@maxlength
pbPlayBuzzerSE()
else
pbPlayDecisionSE()
break
end
elsif index==-1 # Insert a space
if @sprites["entry"].insert(" ")
pbPlayDecisionSE()
else
pbPlayBuzzerSE()
end
elsif index==-2 # Change character set
pbPlayDecisionSE()
@symtype+=1
@symtype=0 if @symtype>=@@Characters.length
@sprites["entry2"].setCharset(@@Characters[@symtype][0])
@sprites["entry2"].setOtherCharset(@@Characters[@symtype][1])
else # Insert given character
if @sprites["entry"].insert(@sprites["entry2"].character)
pbPlayDecisionSE()
else
pbPlayBuzzerSE()
end
end
next
end
end
Input.update
return ret
end
def pbEntry
return USEKEYBOARD ? pbEntry1 : pbEntry2
end
def pbEndScene
pbFadeOutAndHide(@sprites)
pbDisposeSpriteHash(@sprites)
@viewport.dispose
Input.text_input = false if USEKEYBOARD
end
end
#===============================================================================
# Text entry screen - arrows to select letter.
#===============================================================================
class PokemonEntryScene2
@@Characters = [
[("ABCDEFGHIJ ,."+"KLMNOPQRST '-"+"UVWXYZ ♂♀"+" "+"0123456789 ").scan(/./),_INTL("UPPER")],
[("abcdefghij ,."+"klmnopqrst '-"+"uvwxyz ♂♀"+" "+"0123456789 ").scan(/./),_INTL("lower")],
[(",.:;!? ♂♀ "+"\"'()<>[] "+"~@#%*&$ "+"+-=^_/\\| "+" ").scan(/./),_INTL("other")],
]
ROWS = 13
COLUMNS = 5
MODE1 = -5
MODE2 = -4
MODE3 = -3
BACK = -2
OK = -1
class NameEntryCursor
def initialize(viewport)
@sprite = SpriteWrapper.new(viewport)
@cursortype = 0
@cursor1 = AnimatedBitmap.new("Graphics/Pictures/Naming/cursor_1")
@cursor2 = AnimatedBitmap.new("Graphics/Pictures/Naming/cursor_2")
@cursor3 = AnimatedBitmap.new("Graphics/Pictures/Naming/cursor_3")
@cursorPos = 0
updateInternal
end
def setCursorPos(value)
@cursorPos = value
end
def updateCursorPos
value=@cursorPos
if value==PokemonEntryScene2::MODE1 # Upper case
@sprite.x=48
@sprite.y=120
@cursortype=1
elsif value==PokemonEntryScene2::MODE2 # Lower case
@sprite.x=112
@sprite.y=120
@cursortype=1
elsif value==PokemonEntryScene2::MODE3 # Other symbols
@sprite.x=176
@sprite.y=120
@cursortype=1
elsif value==PokemonEntryScene2::BACK # Back
@sprite.x=312
@sprite.y=120
@cursortype=2
elsif value==PokemonEntryScene2::OK # OK
@sprite.x=392
@sprite.y=120
@cursortype=2
elsif value>=0
@sprite.x=52+32*(value%PokemonEntryScene2::ROWS)
@sprite.y=180+38*(value/PokemonEntryScene2::ROWS)
@cursortype=0
end
end
def visible=(value)
@sprite.visible=value
end
def visible
@sprite.visible
end
def color=(value)
@sprite.color=value
end
def color
@sprite.color
end
def disposed?
@sprite.disposed?
end
def updateInternal
@cursor1.update
@cursor2.update
@cursor3.update
updateCursorPos
case @cursortype
when 0 then @sprite.bitmap=@cursor1.bitmap
when 1 then @sprite.bitmap=@cursor2.bitmap
when 2 then @sprite.bitmap=@cursor3.bitmap
end
end
def update
updateInternal
end
def dispose
@cursor1.dispose
@cursor2.dispose
@cursor3.dispose
@sprite.dispose
end
end
def pbStartScene(helptext,minlength,maxlength,initialText,subject=0,pokemon=nil)
@sprites={}
@viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
@viewport.z=99999
@helptext=helptext
@helper=CharacterEntryHelper.new(initialText)
@bitmaps=[
AnimatedBitmap.new("Graphics/Pictures/Naming/overlay_tab_1"),
AnimatedBitmap.new("Graphics/Pictures/Naming/overlay_tab_2"),
AnimatedBitmap.new("Graphics/Pictures/Naming/overlay_tab_3")
]
@bitmaps[3]=@bitmaps[0].bitmap.clone
@bitmaps[4]=@bitmaps[1].bitmap.clone
@bitmaps[5]=@bitmaps[2].bitmap.clone
for i in 0...3
pos=0
pbSetSystemFont(@bitmaps[i+3])
textPos=[]
for y in 0...COLUMNS
for x in 0...ROWS
textPos.push([@@Characters[i][0][pos],44+x*32,12+y*38,2,
Color.new(16,24,32), Color.new(160,160,160)])
pos+=1
end
end
pbDrawTextPositions(@bitmaps[i+3],textPos)
end
@bitmaps[6]=BitmapWrapper.new(24,6)
@bitmaps[6].fill_rect(2,2,22,4,Color.new(168,184,184))
@bitmaps[6].fill_rect(0,0,22,4,Color.new(16,24,32))
@sprites["bg"]=IconSprite.new(0,0,@viewport)
@sprites["bg"].setBitmap("Graphics/Pictures/Naming/bg")
case subject
when 1 # Player
meta=GameData::Metadata.get_player($Trainer.character_ID)
if meta
@sprites["shadow"]=IconSprite.new(0,0,@viewport)
@sprites["shadow"].setBitmap("Graphics/Pictures/Naming/icon_shadow")
@sprites["shadow"].x=33*2
@sprites["shadow"].y=32*2
filename=pbGetPlayerCharset(meta,1,nil,true)
@sprites["subject"]=TrainerWalkingCharSprite.new(filename,@viewport)
charwidth=@sprites["subject"].bitmap.width
charheight=@sprites["subject"].bitmap.height
@sprites["subject"].x = 44*2 - charwidth/8
@sprites["subject"].y = 38*2 - charheight/4
end
when 2 # Pokémon
if pokemon
@sprites["shadow"]=IconSprite.new(0,0,@viewport)
@sprites["shadow"].setBitmap("Graphics/Pictures/Naming/icon_shadow")
@sprites["shadow"].x=33*2
@sprites["shadow"].y=32*2
@sprites["subject"]=PokemonIconSprite.new(pokemon,@viewport)
@sprites["subject"].setOffset(PictureOrigin::Center)
@sprites["subject"].x=88
@sprites["subject"].y=54
@sprites["gender"]=BitmapSprite.new(32,32,@viewport)
@sprites["gender"].x=430
@sprites["gender"].y=54
@sprites["gender"].bitmap.clear
pbSetSystemFont(@sprites["gender"].bitmap)
textpos=[]
if pokemon.male?
textpos.push([_INTL(""),0,-6,false,Color.new(0,128,248),Color.new(168,184,184)])
elsif pokemon.female?
textpos.push([_INTL(""),0,-6,false,Color.new(248,24,24),Color.new(168,184,184)])
end
pbDrawTextPositions(@sprites["gender"].bitmap,textpos)
end
when 3 # NPC
@sprites["shadow"]=IconSprite.new(0,0,@viewport)
@sprites["shadow"].setBitmap("Graphics/Pictures/Naming/icon_shadow")
@sprites["shadow"].x=33*2
@sprites["shadow"].y=32*2
@sprites["subject"]=TrainerWalkingCharSprite.new(pokemon.to_s,@viewport)
charwidth=@sprites["subject"].bitmap.width
charheight=@sprites["subject"].bitmap.height
@sprites["subject"].x = 44*2 - charwidth/8
@sprites["subject"].y = 38*2 - charheight/4
when 4 # Storage box
@sprites["subject"]=TrainerWalkingCharSprite.new(nil,@viewport)
@sprites["subject"].altcharset="Graphics/Pictures/Naming/icon_storage"
@sprites["subject"].animspeed=4
charwidth=@sprites["subject"].bitmap.width
charheight=@sprites["subject"].bitmap.height
@sprites["subject"].x = 44*2 - charwidth/8
@sprites["subject"].y = 26*2 - charheight/2
end
@sprites["bgoverlay"]=BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
pbDoUpdateOverlay
@blanks=[]
@mode=0
@minlength=minlength
@maxlength=maxlength
@maxlength.times { |i|
@sprites["blank#{i}"]=SpriteWrapper.new(@viewport)
@sprites["blank#{i}"].bitmap=@bitmaps[6]
@sprites["blank#{i}"].x=160+24*i
@blanks[i]=0
}
@sprites["bottomtab"]=SpriteWrapper.new(@viewport) # Current tab
@sprites["bottomtab"].x=22
@sprites["bottomtab"].y=162
@sprites["bottomtab"].bitmap=@bitmaps[0+3]
@sprites["toptab"]=SpriteWrapper.new(@viewport) # Next tab
@sprites["toptab"].x=22-504
@sprites["toptab"].y=162
@sprites["toptab"].bitmap=@bitmaps[1+3]
@sprites["controls"]=IconSprite.new(0,0,@viewport)
@sprites["controls"].setBitmap(_INTL("Graphics/Pictures/Naming/overlay_controls"))
@sprites["controls"].x=16
@sprites["controls"].y=96
@init=true
@sprites["overlay"]=BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
pbDoUpdateOverlay2
@sprites["cursor"]=NameEntryCursor.new(@viewport)
@cursorpos=0
@refreshOverlay=true
@sprites["cursor"].setCursorPos(@cursorpos)
pbFadeInAndShow(@sprites) { pbUpdate }
end
def pbUpdateOverlay
@refreshOverlay=true
end
def pbDoUpdateOverlay2
overlay=@sprites["overlay"].bitmap
overlay.clear
modeIcon=[[_INTL("Graphics/Pictures/Naming/icon_mode"),48+@mode*64,120,@mode*60,0,60,44]]
pbDrawImagePositions(overlay,modeIcon)
end
def pbDoUpdateOverlay
return if !@refreshOverlay
@refreshOverlay=false
bgoverlay=@sprites["bgoverlay"].bitmap
bgoverlay.clear
pbSetSystemFont(bgoverlay)
textPositions=[
[@helptext,160,6,false,Color.new(16,24,32),Color.new(168,184,184)]
]
chars=@helper.textChars
x=166
for ch in chars
textPositions.push([ch,x,42,false,Color.new(16,24,32),Color.new(168,184,184)])
x+=24
end
pbDrawTextPositions(bgoverlay,textPositions)
end
def pbChangeTab(newtab=@mode+1)
pbSEPlay("GUI naming tab swap start")
@sprites["cursor"].visible = false
@sprites["toptab"].bitmap = @bitmaps[(newtab%3)+3]
# Move bottom (old) tab down off the screen, and move top (new) tab right
# onto the screen
deltaX = 48*20/Graphics.frame_rate
deltaY = 24*20/Graphics.frame_rate
loop do
if @sprites["bottomtab"].y<414
@sprites["bottomtab"].y += deltaY
@sprites["bottomtab"].y = 414 if @sprites["bottomtab"].y>414
end
if @sprites["toptab"].x<22
@sprites["toptab"].x += deltaX
@sprites["toptab"].x = 22 if @sprites["toptab"].x>22
end
Graphics.update
Input.update
pbUpdate
break if @sprites["toptab"].x>=22 && @sprites["bottomtab"].y>=414
end
# Swap top and bottom tab around
@sprites["toptab"].x, @sprites["bottomtab"].x = @sprites["bottomtab"].x, @sprites["toptab"].x
@sprites["toptab"].y, @sprites["bottomtab"].y = @sprites["bottomtab"].y, @sprites["toptab"].y
@sprites["toptab"].bitmap, @sprites["bottomtab"].bitmap = @sprites["bottomtab"].bitmap, @sprites["toptab"].bitmap
Graphics.update
Input.update
pbUpdate
# Set the current mode
@mode = (newtab)%3
# Set the top tab up to be the next tab
newtab = @bitmaps[((@mode+1)%3)+3]
@sprites["cursor"].visible = true
@sprites["toptab"].bitmap = newtab
@sprites["toptab"].x = 22-504
@sprites["toptab"].y = 162
pbSEPlay("GUI naming tab swap end")
pbDoUpdateOverlay2
end
def pbUpdate
for i in 0...3
@bitmaps[i].update
end
if @init || Graphics.frame_count%5==0
@init = false
cursorpos = @helper.cursor
cursorpos = @maxlength-1 if cursorpos>=@maxlength
cursorpos = 0 if cursorpos<0
@maxlength.times { |i|
@blanks[i] = (i==cursorpos) ? 1 : 0
@sprites["blank#{i}"].y = [78,82][@blanks[i]]
}
end
pbDoUpdateOverlay
pbUpdateSpriteHash(@sprites)
end
def pbColumnEmpty?(m)
return false if m>=ROWS-1
chset=@@Characters[@mode][0]
return (
chset[m]==" " &&
chset[m+((ROWS-1))]==" " &&
chset[m+((ROWS-1)*2)]==" " &&
chset[m+((ROWS-1)*3)]==" "
)
end
def wrapmod(x,y)
result=x%y
result+=y if result<0
return result
end
def pbMoveCursor
oldcursor=@cursorpos
cursordiv=@cursorpos/ROWS
cursormod=@cursorpos%ROWS
cursororigin=@cursorpos-cursormod
if Input.repeat?(Input::LEFT)
if @cursorpos<0 # Controls
@cursorpos-=1
@cursorpos=OK if @cursorpos<MODE1
else
begin
cursormod=wrapmod((cursormod-1),ROWS)
@cursorpos=cursororigin+cursormod
end while pbColumnEmpty?(cursormod)
end
elsif Input.repeat?(Input::RIGHT)
if @cursorpos<0 # Controls
@cursorpos+=1
@cursorpos=MODE1 if @cursorpos>OK
else
begin
cursormod=wrapmod((cursormod+1),ROWS)
@cursorpos=cursororigin+cursormod
end while pbColumnEmpty?(cursormod)
end
elsif Input.repeat?(Input::UP)
if @cursorpos<0 # Controls
case @cursorpos
when MODE1 then @cursorpos = ROWS*(COLUMNS-1)
when MODE2 then @cursorpos = ROWS*(COLUMNS-1)+2
when MODE3 then @cursorpos = ROWS*(COLUMNS-1)+4
when BACK then @cursorpos = ROWS*(COLUMNS-1)+8
when OK then @cursorpos = ROWS*(COLUMNS-1)+11
end
elsif @cursorpos<ROWS # Top row of letters
case @cursorpos
when 0, 1 then @cursorpos = MODE1
when 2, 3 then @cursorpos = MODE2
when 4, 5, 6 then @cursorpos = MODE3
when 7, 8, 9, 10 then @cursorpos = BACK
when 11, 12 then @cursorpos = OK
end
else
cursordiv=wrapmod((cursordiv-1),COLUMNS)
@cursorpos=(cursordiv*ROWS)+cursormod
end
elsif Input.repeat?(Input::DOWN)
if @cursorpos<0 # Controls
case @cursorpos
when MODE1 then @cursorpos = 0
when MODE2 then @cursorpos = 2
when MODE3 then @cursorpos = 4
when BACK then @cursorpos = 8
when OK then @cursorpos = 11
end
elsif @cursorpos>=ROWS*(COLUMNS-1) # Bottom row of letters
case @cursorpos
when ROWS*(COLUMNS-1),ROWS*(COLUMNS-1)+1
@cursorpos = MODE1
when ROWS*(COLUMNS-1)+2,ROWS*(COLUMNS-1)+3
@cursorpos = MODE2
when ROWS*(COLUMNS-1)+4,ROWS*(COLUMNS-1)+5,ROWS*(COLUMNS-1)+6
@cursorpos = MODE3
when ROWS*(COLUMNS-1)+7,ROWS*(COLUMNS-1)+8,ROWS*(COLUMNS-1)+9,ROWS*(COLUMNS-1)+10
@cursorpos = BACK
when ROWS*(COLUMNS-1)+11,ROWS*(COLUMNS-1)+12
@cursorpos = OK
end
else
cursordiv=wrapmod((cursordiv+1),COLUMNS)
@cursorpos=(cursordiv*ROWS)+cursormod
end
end
if @cursorpos!=oldcursor # Cursor position changed
@sprites["cursor"].setCursorPos(@cursorpos)
pbPlayCursorSE()
return true
else
return false
end
end
def pbEntry
ret=""
loop do
Graphics.update
Input.update
pbUpdate
next if pbMoveCursor
if Input.trigger?(Input::SPECIAL)
pbChangeTab
elsif Input.trigger?(Input::ACTION)
@cursorpos = OK
@sprites["cursor"].setCursorPos(@cursorpos)
elsif Input.trigger?(Input::BACK)
@helper.delete
pbPlayCancelSE()
pbUpdateOverlay
elsif Input.trigger?(Input::USE)
case @cursorpos
when BACK # Backspace
@helper.delete
pbPlayCancelSE()
pbUpdateOverlay
when OK # Done
pbSEPlay("GUI naming confirm")
if @helper.length>=@minlength
ret=@helper.text
break
end
when MODE1
pbChangeTab(0) if @mode!=0
when MODE2
pbChangeTab(1) if @mode!=1
when MODE3
pbChangeTab(2) if @mode!=2
else
cursormod=@cursorpos%ROWS
cursordiv=@cursorpos/ROWS
charpos=cursordiv*(ROWS)+cursormod
chset=@@Characters[@mode][0]
if @helper.length>=@maxlength
@helper.delete
end
@helper.insert(chset[charpos])
pbPlayCursorSE()
if @helper.length>=@maxlength
@cursorpos=OK
@sprites["cursor"].setCursorPos(@cursorpos)
end
pbUpdateOverlay
end
end
end
Input.update
return ret
end
def pbEndScene
pbFadeOutAndHide(@sprites) { pbUpdate }
for bitmap in @bitmaps
bitmap.dispose if bitmap
end
@bitmaps.clear
pbDisposeSpriteHash(@sprites)
@viewport.dispose
end
end
class PokemonEntry
def initialize(scene)
@scene=scene
end
def pbStartScreen(helptext,minlength,maxlength,initialText,mode=-1,pokemon=nil)
@scene.pbStartScene(helptext,minlength,maxlength,initialText,mode,pokemon)
ret=@scene.pbEntry
@scene.pbEndScene
return ret
end
end
#===============================================================================
#
#===============================================================================
def pbEnterText(helptext,minlength,maxlength,initialText="",mode=0,pokemon=nil,nofadeout=false)
ret=""
if ($PokemonSystem.textinput==1 rescue false) # Keyboard
pbFadeOutIn(99999,nofadeout) {
sscene=PokemonEntryScene.new
sscreen=PokemonEntry.new(sscene)
ret=sscreen.pbStartScreen(helptext,minlength,maxlength,initialText,mode,pokemon)
}
else # Cursor
pbFadeOutIn(99999,nofadeout) {
sscene=PokemonEntryScene2.new
sscreen=PokemonEntry.new(sscene)
ret=sscreen.pbStartScreen(helptext,minlength,maxlength,initialText,mode,pokemon)
}
end
return ret
end
def pbEnterPlayerName(helptext,minlength,maxlength,initialText="",nofadeout=false)
return pbEnterText(helptext,minlength,maxlength,initialText,1,nil,nofadeout)
end
def pbEnterPokemonName(helptext,minlength,maxlength,initialText="",pokemon=nil,nofadeout=false)
return pbEnterText(helptext,minlength,maxlength,initialText,2,pokemon,nofadeout)
end
def pbEnterNPCName(helptext,minlength,maxlength,initialText="",id=0,nofadeout=false)
return pbEnterText(helptext,minlength,maxlength,initialText,3,id,nofadeout)
end
def pbEnterBoxName(helptext,minlength,maxlength,initialText="",nofadeout=false)
return pbEnterText(helptext,minlength,maxlength,initialText,4,nil,nofadeout)
end
def pbFreeText(msgwindow,currenttext,passwordbox,maxlength,width=240)
window=Window_TextEntry_Keyboard.new(currenttext,0,0,width,64)
ret=""
window.maxlength=maxlength
window.visible=true
window.z=99999
pbPositionNearMsgWindow(window,msgwindow,:right)
window.text=currenttext
window.passwordChar="*" if passwordbox
Input.text_input = true
loop do
Graphics.update
Input.update
if Input.triggerex?(:ESCAPE)
ret=currenttext
break
elsif Input.triggerex?(:RETURN)
ret=window.text
break
end
window.update
msgwindow.update if msgwindow
yield if block_given?
end
Input.text_input = false
window.dispose
Input.update
return ret
end
def pbMessageFreeText(message,currenttext,passwordbox,maxlength,width=240,&block)
msgwindow=pbCreateMessageWindow
retval=pbMessageDisplay(msgwindow,message,true,
proc { |msgwindow|
next pbFreeText(msgwindow,currenttext,passwordbox,maxlength,width,&block)
},&block)
pbDisposeMessageWindow(msgwindow)
return retval
end

View File

@@ -1,519 +0,0 @@
class PictureOrigin
TopLeft = 0
Center = 1
TopRight = 2
BottomLeft = 3
LowerLeft = 3
BottomRight = 4
LowerRight = 4
Top = 5
Bottom = 6
Left = 7
Right = 8
end
class Processes
XY = 0
DeltaXY = 1
Z = 2
Curve = 3
Zoom = 4
Angle = 5
Tone = 6
Color = 7
Hue = 8
Opacity = 9
Visible = 10
BlendType = 11
SE = 12
Name = 13
Origin = 14
Src = 15
SrcSize = 16
CropBottom = 17
end
def getCubicPoint2(src,t)
x0 = src[0]; y0 = src[1]
cx0 = src[2]; cy0 = src[3]
cx1 = src[4]; cy1 = src[5]
x1 = src[6]; y1 = src[7]
x1 = cx1+(x1-cx1)*t
x0 = x0+(cx0-x0)*t
cx0 = cx0+(cx1-cx0)*t
cx1 = cx0+(x1-cx0)*t
cx0 = x0+(cx0-x0)*t
cx = cx0+(cx1-cx0)*t
# a = x1 - 3 * cx1 + 3 * cx0 - x0
# b = 3 * (cx1 - 2 * cx0 + x0)
# c = 3 * (cx0 - x0)
# d = x0
# cx = a*t*t*t + b*t*t + c*t + d
y1 = cy1+(y1-cy1)*t
y0 = y0+(cy0-y0)*t
cy0 = cy0+(cy1-cy0)*t
cy1 = cy0+(y1-cy0)*t
cy0 = y0+(cy0-y0)*t
cy = cy0+(cy1-cy0)*t
# a = y1 - 3 * cy1 + 3 * cy0 - y0
# b = 3 * (cy1 - 2 * cy0 + y0)
# c = 3 * (cy0 - y0)
# d = y0
# cy = a*t*t*t + b*t*t + c*t + d
return [cx,cy]
end
#===============================================================================
# PictureEx
#===============================================================================
class PictureEx
attr_accessor :x # x-coordinate
attr_accessor :y # y-coordinate
attr_accessor :z # z value
attr_accessor :zoom_x # x directional zoom rate
attr_accessor :zoom_y # y directional zoom rate
attr_accessor :angle # rotation angle
attr_accessor :tone # tone
attr_accessor :color # color
attr_accessor :hue # filename hue
attr_accessor :opacity # opacity level
attr_accessor :visible # visibility boolean
attr_accessor :blend_type # blend method
attr_accessor :name # file name
attr_accessor :origin # starting point
attr_reader :src_rect # source rect
attr_reader :cropBottom # crops sprite to above this y-coordinate
attr_reader :frameUpdates # Array of processes updated in a frame
def initialize(z)
# process: [type, delay, total_duration, frame_counter, cb, etc.]
@processes = []
@x = 0.0
@y = 0.0
@z = z
@zoom_x = 100.0
@zoom_y = 100.0
@angle = 0
@rotate_speed = 0
@tone = Tone.new(0, 0, 0, 0)
@tone_duration = 0
@color = Color.new(0, 0, 0, 0)
@hue = 0
@opacity = 255.0
@visible = true
@blend_type = 0
@name = ""
@origin = PictureOrigin::TopLeft
@src_rect = Rect.new(0,0,-1,-1)
@cropBottom = -1
@frameUpdates = []
end
def callback(cb)
if cb.is_a?(Proc); cb.call(self)
elsif cb.is_a?(Array); cb[0].method(cb[1]).call(self)
elsif cb.is_a?(Method); cb.call(self)
end
end
def setCallback(delay, cb=nil)
delay = ensureDelayAndDuration(delay)
@processes.push([nil,delay,0,0,cb])
end
def running?
return @processes.length>0
end
def totalDuration
ret = 0
for process in @processes
dur = process[1]+process[2]
ret = dur if dur>ret
end
ret *= 20.0/Graphics.frame_rate
return ret.to_i
end
def ensureDelayAndDuration(delay, duration=nil)
delay = self.totalDuration if delay<0
delay *= Graphics.frame_rate/20.0
if !duration.nil?
duration *= Graphics.frame_rate/20.0
return delay.to_i, duration.to_i
end
return delay.to_i
end
def ensureDelay(delay)
return ensureDelayAndDuration(delay)
end
# speed is the angle to change by in 1/20 of a second. @rotate_speed is the
# angle to change by per frame.
# NOTE: This is not compatible with manually changing the angle at a certain
# point. If you make a sprite auto-rotate, you should not try to alter
# the angle another way too.
def rotate(speed)
@rotate_speed = speed*20.0/Graphics.frame_rate
while @rotate_speed<0; @rotate_speed += 360; end
@rotate_speed %= 360
end
def erase
self.name = ""
end
def clearProcesses
@processes = []
end
def adjustPosition(xOffset, yOffset)
for process in @processes
next if process[0]!=Processes::XY
process[5] += xOffset
process[6] += yOffset
process[7] += xOffset
process[8] += yOffset
end
end
def move(delay, duration, origin, x, y, zoom_x=100.0, zoom_y=100.0, opacity=255)
setOrigin(delay,duration,origin)
moveXY(delay,duration,x,y)
moveZoomXY(delay,duration,zoom_x,zoom_y)
moveOpacity(delay,duration,opacity)
end
def moveXY(delay, duration, x, y, cb=nil)
delay, duration = ensureDelayAndDuration(delay,duration)
@processes.push([Processes::XY,delay,duration,0,cb,@x,@y,x,y])
end
def setXY(delay, x, y, cb=nil)
moveXY(delay,0,x,y,cb)
end
def moveCurve(delay, duration, x1, y1, x2, y2, x3, y3, cb=nil)
delay, duration = ensureDelayAndDuration(delay,duration)
@processes.push([Processes::Curve,delay,duration,0,cb,[@x,@y,x1,y1,x2,y2,x3,y3]])
end
def moveDelta(delay, duration, x, y, cb=nil)
delay, duration = ensureDelayAndDuration(delay,duration)
@processes.push([Processes::DeltaXY,delay,duration,0,cb,@x,@y,x,y])
end
def setDelta(delay, x, y, cb=nil)
moveDelta(delay,0,x,y,cb)
end
def moveZ(delay, duration, z, cb=nil)
delay, duration = ensureDelayAndDuration(delay,duration)
@processes.push([Processes::Z,delay,duration,0,cb,@z,z])
end
def setZ(delay, z, cb=nil)
moveZ(delay,0,z,cb)
end
def moveZoomXY(delay, duration, zoom_x, zoom_y, cb=nil)
delay, duration = ensureDelayAndDuration(delay,duration)
@processes.push([Processes::Zoom,delay,duration,0,cb,@zoom_x,@zoom_y,zoom_x,zoom_y])
end
def setZoomXY(delay, zoom_x, zoom_y, cb=nil)
moveZoomXY(delay,0,zoom_x,zoom_y,cb)
end
def moveZoom(delay, duration, zoom, cb=nil)
moveZoomXY(delay,duration,zoom,zoom,cb)
end
def setZoom(delay, zoom, cb=nil)
moveZoomXY(delay,0,zoom,zoom,cb)
end
def moveAngle(delay, duration, angle, cb=nil)
delay, duration = ensureDelayAndDuration(delay,duration)
@processes.push([Processes::Angle,delay,duration,0,cb,@angle,angle])
end
def setAngle(delay, angle, cb=nil)
moveAngle(delay,0,angle,cb)
end
def moveTone(delay, duration, tone, cb=nil)
delay, duration = ensureDelayAndDuration(delay,duration)
target = (tone) ? tone.clone : Tone.new(0,0,0,0)
@processes.push([Processes::Tone,delay,duration,0,cb,@tone.clone,target])
end
def setTone(delay, tone, cb=nil)
moveTone(delay,0,tone,cb)
end
def moveColor(delay, duration, color, cb=nil)
delay, duration = ensureDelayAndDuration(delay,duration)
target = (color) ? color.clone : Color.new(0,0,0,0)
@processes.push([Processes::Color,delay,duration,0,cb,@color.clone,target])
end
def setColor(delay, color, cb=nil)
moveColor(delay,0,color,cb)
end
# Hue changes don't actually work.
def moveHue(delay, duration, hue, cb=nil)
delay, duration = ensureDelayAndDuration(delay,duration)
@processes.push([Processes::Hue,delay,duration,0,cb,@hue,hue])
end
# Hue changes don't actually work.
def setHue(delay, hue, cb=nil)
moveHue(delay,0,hue,cb)
end
def moveOpacity(delay, duration, opacity, cb=nil)
delay, duration = ensureDelayAndDuration(delay,duration)
@processes.push([Processes::Opacity,delay,duration,0,cb,@opacity,opacity])
end
def setOpacity(delay, opacity, cb=nil)
moveOpacity(delay,0,opacity,cb)
end
def setVisible(delay, visible, cb=nil)
delay = ensureDelay(delay)
@processes.push([Processes::Visible,delay,0,0,cb,visible])
end
# Only values of 0 (normal), 1 (additive) and 2 (subtractive) are allowed.
def setBlendType(delay, blend, cb=nil)
delay = ensureDelayAndDuration(delay)
@processes.push([Processes::BlendType,delay,0,0,cb,blend])
end
def setSE(delay, seFile, volume=nil, pitch=nil, cb=nil)
delay = ensureDelay(delay)
@processes.push([Processes::SE,delay,0,0,cb,seFile,volume,pitch])
end
def setName(delay, name, cb=nil)
delay = ensureDelay(delay)
@processes.push([Processes::Name,delay,0,0,cb,name])
end
def setOrigin(delay, origin, cb=nil)
delay = ensureDelay(delay)
@processes.push([Processes::Origin,delay,0,0,cb,origin])
end
def setSrc(delay, srcX, srcY, cb=nil)
delay = ensureDelay(delay)
@processes.push([Processes::Src,delay,0,0,cb,srcX,srcY])
end
def setSrcSize(delay, srcWidth, srcHeight, cb=nil)
delay = ensureDelay(delay)
@processes.push([Processes::SrcSize,delay,0,0,cb,srcWidth,srcHeight])
end
# Used to cut Pokémon sprites off when they faint and sink into the ground.
def setCropBottom(delay, y, cb=nil)
delay = ensureDelay(delay)
@processes.push([Processes::CropBottom,delay,0,0,cb,y])
end
def update
procEnded = false
@frameUpdates.clear
for i in 0...@processes.length
process = @processes[i]
# Decrease delay of processes that are scheduled to start later
if process[1]>=0
# Set initial values if the process will start this frame
if process[1]==0
case process[0]
when Processes::XY
process[5] = @x
process[6] = @y
when Processes::DeltaXY
process[5] = @x
process[6] = @y
process[7] += @x
process[8] += @y
when Processes::Curve
process[5][0] = @x
process[5][1] = @y
when Processes::Z
process[5] = @z
when Processes::Zoom
process[5] = @zoom_x
process[6] = @zoom_y
when Processes::Angle
process[5] = @angle
when Processes::Tone
process[5] = @tone.clone
when Processes::Color
process[5] = @color.clone
when Processes::Hue
process[5] = @hue
when Processes::Opacity
process[5] = @opacity
end
end
# Decrease delay counter
process[1] -= 1
# Process hasn't started yet, skip to the next one
next if process[1]>=0
end
# Update process
@frameUpdates.push(process[0]) if !@frameUpdates.include?(process[0])
fra = (process[2]==0) ? 1 : process[3] # Frame counter
dur = (process[2]==0) ? 1 : process[2] # Total duration of process
case process[0]
when Processes::XY, Processes::DeltaXY
@x = process[5] + fra * (process[7] - process[5]) / dur
@y = process[6] + fra * (process[8] - process[6]) / dur
when Processes::Curve
@x, @y = getCubicPoint2(process[5],fra.to_f/dur)
when Processes::Z
@z = process[5] + fra * (process[6] - process[5]) / dur
when Processes::Zoom
@zoom_x = process[5] + fra * (process[7] - process[5]) / dur
@zoom_y = process[6] + fra * (process[8] - process[6]) / dur
when Processes::Angle
@angle = process[5] + fra * (process[6] - process[5]) / dur
when Processes::Tone
@tone.red = process[5].red + fra * (process[6].red - process[5].red) / dur
@tone.green = process[5].green + fra * (process[6].green - process[5].green) / dur
@tone.blue = process[5].blue + fra * (process[6].blue - process[5].blue) / dur
@tone.gray = process[5].gray + fra * (process[6].gray - process[5].gray) / dur
when Processes::Color
@color.red = process[5].red + fra * (process[6].red - process[5].red) / dur
@color.green = process[5].green + fra * (process[6].green - process[5].green) / dur
@color.blue = process[5].blue + fra * (process[6].blue - process[5].blue) / dur
@color.alpha = process[5].alpha + fra * (process[6].alpha - process[5].alpha) / dur
when Processes::Hue
@hue = (process[6] - process[5]).to_f / dur
when Processes::Opacity
@opacity = process[5] + fra * (process[6] - process[5]) / dur
when Processes::Visible
@visible = process[5]
when Processes::BlendType
@blend_type = process[5]
when Processes::SE
pbSEPlay(process[5],process[6],process[7])
when Processes::Name
@name = process[5]
when Processes::Origin
@origin = process[5]
when Processes::Src
@src_rect.x = process[5]
@src_rect.y = process[6]
when Processes::SrcSize
@src_rect.width = process[5]
@src_rect.height = process[6]
when Processes::CropBottom
@cropBottom = process[5]
end
# Increase frame counter
process[3] += 1
if process[3]>process[2]
# Process has ended, erase it
callback(process[4]) if process[4]
@processes[i] = nil
procEnded = true
end
end
# Clear out empty spaces in @processes array caused by finished processes
@processes.compact! if procEnded
# Add the constant rotation speed
if @rotate_speed != 0
@frameUpdates.push(Processes::Angle) if !@frameUpdates.include?(Processes::Angle)
@angle += @rotate_speed
while @angle<0; @angle += 360; end
@angle %= 360
end
end
end
#===============================================================================
#
#===============================================================================
def setPictureSprite(sprite, picture, iconSprite=false)
return if picture.frameUpdates.length==0
for i in 0...picture.frameUpdates.length
case picture.frameUpdates[i]
when Processes::XY, Processes::DeltaXY
sprite.x = picture.x.round
sprite.y = picture.y.round
when Processes::Z
sprite.z = picture.z
when Processes::Zoom
sprite.zoom_x = picture.zoom_x / 100.0
sprite.zoom_y = picture.zoom_y / 100.0
when Processes::Angle
sprite.angle = picture.angle
when Processes::Tone
sprite.tone = picture.tone
when Processes::Color
sprite.color = picture.color
when Processes::Hue
# This doesn't do anything.
when Processes::BlendType
sprite.blend_type = picture.blend_type
when Processes::Opacity
sprite.opacity = picture.opacity
when Processes::Visible
sprite.visible = picture.visible
when Processes::Name
sprite.name = picture.name if iconSprite && sprite.name != picture.name
when Processes::Origin
case picture.origin
when PictureOrigin::TopLeft, PictureOrigin::Left, PictureOrigin::BottomLeft
sprite.ox = 0
when PictureOrigin::Top, PictureOrigin::Center, PictureOrigin::Bottom
sprite.ox = (sprite.bitmap && !sprite.bitmap.disposed?) ? sprite.src_rect.width/2 : 0
when PictureOrigin::TopRight, PictureOrigin::Right, PictureOrigin::BottomRight
sprite.ox = (sprite.bitmap && !sprite.bitmap.disposed?) ? sprite.src_rect.width : 0
end
case picture.origin
when PictureOrigin::TopLeft, PictureOrigin::Top, PictureOrigin::TopRight
sprite.oy = 0
when PictureOrigin::Left, PictureOrigin::Center, PictureOrigin::Right
sprite.oy = (sprite.bitmap && !sprite.bitmap.disposed?) ? sprite.src_rect.height/2 : 0
when PictureOrigin::BottomLeft, PictureOrigin::Bottom, PictureOrigin::BottomRight
sprite.oy = (sprite.bitmap && !sprite.bitmap.disposed?) ? sprite.src_rect.height : 0
end
when Processes::Src
next unless iconSprite && sprite.src_rect
sprite.src_rect.x = picture.src_rect.x
sprite.src_rect.y = picture.src_rect.y
when Processes::SrcSize
next unless iconSprite && sprite.src_rect
sprite.src_rect.width = picture.src_rect.width
sprite.src_rect.height = picture.src_rect.height
end
end
if iconSprite && sprite.src_rect && picture.cropBottom>=0
spriteBottom = sprite.y-sprite.oy+sprite.src_rect.height
if spriteBottom>picture.cropBottom
sprite.src_rect.height = [picture.cropBottom-sprite.y+sprite.oy,0].max
end
end
end
def setPictureIconSprite(sprite, picture)
setPictureSprite(sprite,picture,true)
end

View File

@@ -1,172 +0,0 @@
class Interpolator
ZOOM_X = 1
ZOOM_Y = 2
X = 3
Y = 4
OPACITY = 5
COLOR = 6
WAIT = 7
def initialize
@tweening = false
@tweensteps = []
@sprite = nil
@frames = 0
@step = 0
end
def tweening?
return @tweening
end
def tween(sprite,items,frames)
@tweensteps = []
if sprite && !sprite.disposed? && frames>0
@frames = frames
@step = 0
@sprite = sprite
for item in items
case item[0]
when ZOOM_X
@tweensteps[item[0]] = [sprite.zoom_x,item[1]-sprite.zoom_x]
when ZOOM_Y
@tweensteps[item[0]] = [sprite.zoom_y,item[1]-sprite.zoom_y]
when X
@tweensteps[item[0]] = [sprite.x,item[1]-sprite.x]
when Y
@tweensteps[item[0]] = [sprite.y,item[1]-sprite.y]
when OPACITY
@tweensteps[item[0]] = [sprite.opacity,item[1]-sprite.opacity]
when COLOR
@tweensteps[item[0]] = [sprite.color.clone,Color.new(
item[1].red-sprite.color.red,
item[1].green-sprite.color.green,
item[1].blue-sprite.color.blue,
item[1].alpha-sprite.color.alpha
)]
end
end
@tweening = true
end
end
def update
if @tweening
t = (@step*1.0)/@frames
for i in 0...@tweensteps.length
item = @tweensteps[i]
next if !item
case i
when ZOOM_X
@sprite.zoom_x = item[0]+item[1]*t
when ZOOM_Y
@sprite.zoom_y = item[0]+item[1]*t
when X
@sprite.x = item[0]+item[1]*t
when Y
@sprite.y = item[0]+item[1]*t
when OPACITY
@sprite.opacity = item[0]+item[1]*t
when COLOR
@sprite.color = Color.new(
item[0].red+item[1].red*t,
item[0].green+item[1].green*t,
item[0].blue+item[1].blue*t,
item[0].alpha+item[1].alpha*t
)
end
end
@step += 1
if @step==@frames
@step = 0
@frames = 0
@tweening = false
end
end
end
end
class RectInterpolator
def initialize(oldrect,newrect,frames)
restart(oldrect,newrect,frames)
end
def restart(oldrect,newrect,frames)
@oldrect = oldrect
@newrect = newrect
@frames = [frames,1].max
@curframe = 0
@rect = oldrect.clone
end
def set(rect)
rect.set(@rect.x,@rect.y,@rect.width,@rect.height)
end
def done?
@curframe>@frames
end
def update
return if done?
t = (@curframe*1.0/@frames)
x1 = @oldrect.x
x2 = @newrect.x
x = x1+t*(x2-x1)
y1 = @oldrect.y
y2 = @newrect.y
y = y1+t*(y2-y1)
rx1 = @oldrect.x+@oldrect.width
rx2 = @newrect.x+@newrect.width
rx = rx1+t*(rx2-rx1)
ry1 = @oldrect.y+@oldrect.height
ry2 = @newrect.y+@newrect.height
ry = ry1+t*(ry2-ry1)
minx = x<rx ? x : rx
maxx = x>rx ? x : rx
miny = y<ry ? y : ry
maxy = y>ry ? y : ry
@rect.set(minx,miny,maxx-minx,maxy-miny)
@curframe += 1
end
end
class PointInterpolator
attr_reader :x
attr_reader :y
def initialize(oldx,oldy,newx,newy,frames)
restart(oldx,oldy,newx,newy,frames)
end
def restart(oldx,oldy,newx,newy,frames)
@oldx = oldx
@oldy = oldy
@newx = newx
@newy = newy
@frames = frames
@curframe = 0
@x = oldx
@y = oldy
end
def done?
@curframe>@frames
end
def update
return if done?
t = (@curframe*1.0/@frames)
rx1 = @oldx
rx2 = @newx
@x = rx1+t*(rx2-rx1)
ry1 = @oldy
ry2 = @newy
@y = ry1+t*(ry2-ry1)
@curframe += 1
end
end