Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Window_CommandPokemonModern < Window_DrawableCommand
- attr_reader :commands
- def initialize(commands,width=nil)
- @starting=true
- @commands=[]
- dims=[]
- @command=AnimatedBitmap.new("Graphics/Pictures/command")
- super(0,0,32,32)
- self.rowHeight=@command.bitmap.height/2
- getAutoDims(commands,dims,width)
- self.width=dims[0]
- self.height=dims[1]
- @commands=commands
- self.active=true
- self.baseColor=Color.new(255,255,255)
- self.shadowColor=Color.new(140,140,140)
- self.windowskin=nil
- refresh
- @starting=false
- end
- def self.newWithSize(commands,x,y,width,height,viewport=nil)
- ret=self.new(commands,width)
- ret.x=x
- ret.y=y
- ret.width=width
- ret.height=height
- ret.viewport=viewport
- return ret
- end
- def self.newEmpty(x,y,width,height,viewport=nil)
- ret=self.new([],width)
- ret.x=x
- ret.y=y
- ret.width=width
- ret.height=height
- ret.viewport=viewport
- return ret
- end
- def index=(value)
- super
- refresh if !@starting
- end
- def commands=(value)
- @commands=value
- @item_max=commands.length
- self.update_cursor_rect
- self.refresh
- end
- def width=(value)
- value=value+(value/2)
- super
- if !@starting
- self.index=self.index
- self.update_cursor_rect
- end
- end
- def height=(value)
- super
- if !@starting
- self.index=self.index
- self.update_cursor_rect
- end
- end
- def resizeToFit(commands,width=nil)
- dims=[]
- getAutoDims(commands,dims,width)
- self.width=dims[0]
- self.height=dims[1]
- end
- def itemCount
- return @commands ? @commands.length : 0
- end
- def drawCursor(index,rect)
- return Rect.new(rect.x,rect.y,rect.width,rect.height)
- end
- def getCommandBitmap(widthp,sel=false)
- w=@command.bitmap.width/3
- h=@command.bitmap.height/2
- xp=sel ? h : 0
- bitmap=Bitmap.new(widthp,h)
- bitmap.clear
- # Draw first part
- bitmap.blt(0,0,@command.bitmap,Rect.new(0,xp,w,h))
- # Draw middle
- bitmap.stretch_blt(Rect.new(w,0,bitmap.width-w*2,h),@command.bitmap,
- Rect.new(w,xp,w,h))
- # Draw last part
- bitmap.blt(bitmap.width-w-2,0,@command.bitmap,Rect.new(w*2,xp,w,h))
- return bitmap
- end
- def drawItem(index,count,rect)
- pbSetSystemFont(self.contents) if @starting
- rect=drawCursor(index,rect)
- @unselc=getCommandBitmap(rect.width) if !@unsel
- @selc=getCommandBitmap(rect.width,true) if !@selc
- pbCopyBitmap(self.contents,self.index==index ? @selc : @unselc,rect.x,rect.y)
- pbDrawShadowText(self.contents,rect.x+18,rect.y+2,rect.width,rect.height,
- @commands[index],self.baseColor,self.shadowColor)
- end
- def dispose
- @selc.dispose if @selc
- @command.dispose
- @unselc.dispose if @unselc
- super
- end
- def update
- super
- if @unselc
- wmo=@unselc.width
- hmo=@unselc.height*@commands.length
- if $mouse.inArea?(self.x+14,self.y+14,wmo,hmo) && !$mouse.isStatic?
- ny=$mouse.y-(self.y+14)
- ny-=self.viewport.rect.y if self.viewport
- nindex=ny/@row_height
- self.index=nindex if nindex!=self.index
- end
- end
- end
- def refresh
- @item_max=itemCount()
- dwidth=self.width-self.borderX
- dheight=self.height-self.borderY
- self.contents=pbDoEnsureBitmap(self.contents,dwidth,dheight)
- self.contents.clear
- for i in 0...@item_max
- if i<self.top_item || i>self.top_item+self.page_item_max
- next
- end
- drawItem(i,@item_max,itemRect(i))
- end
- end
- end
- #-----------
- def Kernel.pbShowCommandsSystemModern(pos,msgwindow,commands=nil,cmdIfCancel=0,defaultCmd=0)
- ret=0
- if commands
- cmdwindow=Window_CommandPokemonModern.new(commands)
- cmdwindow.z=99999
- cmdwindow.visible=true
- cmdwindow.resizeToFit(cmdwindow.commands)
- pbPositionNearMsgWindowSystemModern(pos,cmdwindow,msgwindow,:right)
- cmdwindow.index=defaultCmd
- command=0
- loop do
- Graphics.update
- Input.update
- inarea=$mouse.inArea?(cmdwindow.x,cmdwindow.y,cmdwindow.width,cmdwindow.height)
- pbUpdateSpriteHash($sprites) if $sprites
- cmdwindow.update
- msgwindow.update if msgwindow
- yield if block_given?
- if Input.trigger?(Input::B)
- if cmdIfCancel>0
- command=cmdIfCancel-1
- break
- elsif cmdIfCancel<0
- command=cmdIfCancel
- break
- end
- end
- if Input.trigger?(Input::C) || (inarea and Input.triggerex?(Input::Mouse_Left))
- command=cmdwindow.index
- break
- end
- end
- ret=command
- cmdwindow.dispose
- Input.update
- end
- return ret
- end
- #-------------------------------------------------
- def pbPositionNearMsgWindowSystemModern(pos,cmdwindow,msgwindow,side)
- return if !cmdwindow
- if msgwindow
- height=[cmdwindow.height,msgwindow.height].min #384-
- if cmdwindow.height!=height
- cmdwindow.height=height
- end
- cmdwindow.y=msgwindow.y+cmdwindow.height
- if cmdwindow.y<0
- cmdwindow.y=msgwindow.y+msgwindow.height
- if cmdwindow.y+cmdwindow.height>0 #0
- cmdwindow.y=msgwindow.y-cmdwindow.height
- end
- end
- case pos
- when 0
- cmdwindow.y=msgwindow.y+msgwindow.height-14
- when 1
- cmdwindow.y=msgwindow.y-msgwindow.height+14
- when 2
- cmdwindow.y=msgwindow.y-cmdwindow.height+14
- end
- case side
- when :left
- cmdwindow.x=msgwindow.x-14
- when :right
- cmdwindow.x=msgwindow.x+msgwindow.width-cmdwindow.width+14
- else
- cmdwindow.x=msgwindow.x+msgwindow.width-cmdwindow.width+14
- end
- else
- cmdwindow.height=384 if cmdwindow.height>384
- cmdwindow.x=0
- cmdwindow.y=0
- end
- end
- #-----------------------------------------------------------
- def Kernel.pbMessageSystemModern(pos,black,message,commands=nil,cmdIfCancel=0,skin=nil,defaultCmd=0,&block)
- ret=0
- msgwindowsave=Kernel.pbCreateMessageWindowSystem(black,nil,skin)
- if commands
- ret=Kernel.pbMessageDisplaySystem(pos,msgwindowsave,message,true,
- proc {|msgwindow|
- next Kernel.pbShowCommandsSystemModern(pos,msgwindowsave,commands,cmdIfCancel,defaultCmd,&block)
- },&block)
- else
- Kernel.pbMessageDisplaySystem(pos,msgwindowsave,message,&block)
- end
- Kernel.pbDisposeMessageWindow(msgwindowsave)
- Input.update
- return ret
- end
- #---------------------------------------------------------------
- def Kernel.pbConfirmMessageSystemModern(pos,black,message,&block)
- return (Kernel.pbMessageSystemModern(pos,black,message,[_INTL("YES"),_INTL("NO")],2,&block)==0)
- end
- #---------------------------------------------------------------
- def pbBottomRightModern(window)
- window.x=Graphics.width-window.width+14
- window.y=Graphics.height-window.height+14
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement