Advertisement
Guest User

Untitled

a guest
Dec 23rd, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.88 KB | None | 0 0
  1. class Window_CommandPokemonModern < Window_DrawableCommand
  2.   attr_reader :commands
  3.  
  4.   def initialize(commands,width=nil)
  5.     @starting=true
  6.     @commands=[]
  7.     dims=[]
  8.     @command=AnimatedBitmap.new("Graphics/Pictures/command")
  9.     super(0,0,32,32)
  10.     self.rowHeight=@command.bitmap.height/2
  11.     getAutoDims(commands,dims,width)
  12.     self.width=dims[0]
  13.     self.height=dims[1]
  14.     @commands=commands
  15.     self.active=true
  16.     self.baseColor=Color.new(255,255,255)
  17.     self.shadowColor=Color.new(140,140,140)
  18.     self.windowskin=nil
  19.     refresh
  20.     @starting=false
  21.   end
  22.  
  23.   def self.newWithSize(commands,x,y,width,height,viewport=nil)
  24.     ret=self.new(commands,width)
  25.     ret.x=x
  26.     ret.y=y
  27.     ret.width=width
  28.     ret.height=height
  29.     ret.viewport=viewport
  30.     return ret
  31.   end
  32.  
  33.   def self.newEmpty(x,y,width,height,viewport=nil)
  34.     ret=self.new([],width)
  35.     ret.x=x
  36.     ret.y=y
  37.     ret.width=width
  38.     ret.height=height
  39.     ret.viewport=viewport
  40.     return ret
  41.   end
  42.  
  43.   def index=(value)
  44.     super
  45.     refresh if !@starting
  46.   end
  47.  
  48.   def commands=(value)
  49.     @commands=value
  50.     @item_max=commands.length  
  51.     self.update_cursor_rect
  52.     self.refresh
  53.   end
  54.  
  55.   def width=(value)
  56.     value=value+(value/2)
  57.     super
  58.     if !@starting
  59.       self.index=self.index
  60.       self.update_cursor_rect
  61.     end
  62.   end
  63.  
  64.   def height=(value)
  65.     super
  66.     if !@starting
  67.       self.index=self.index
  68.       self.update_cursor_rect
  69.     end
  70.   end
  71.  
  72.   def resizeToFit(commands,width=nil)
  73.     dims=[]
  74.     getAutoDims(commands,dims,width)
  75.     self.width=dims[0]
  76.     self.height=dims[1]
  77.   end
  78.  
  79.   def itemCount
  80.     return @commands ? @commands.length : 0
  81.   end
  82.  
  83.   def drawCursor(index,rect)
  84.     return Rect.new(rect.x,rect.y,rect.width,rect.height)
  85.   end
  86.  
  87.   def getCommandBitmap(widthp,sel=false)
  88.     w=@command.bitmap.width/3
  89.     h=@command.bitmap.height/2
  90.     xp=sel ? h : 0
  91.    
  92.     bitmap=Bitmap.new(widthp,h)
  93.     bitmap.clear
  94.     # Draw first part
  95.     bitmap.blt(0,0,@command.bitmap,Rect.new(0,xp,w,h))
  96.     # Draw middle
  97.     bitmap.stretch_blt(Rect.new(w,0,bitmap.width-w*2,h),@command.bitmap,
  98.     Rect.new(w,xp,w,h))
  99.     # Draw last part
  100.     bitmap.blt(bitmap.width-w-2,0,@command.bitmap,Rect.new(w*2,xp,w,h))
  101.     return bitmap
  102.   end
  103.  
  104.   def drawItem(index,count,rect)
  105.     pbSetSystemFont(self.contents) if @starting
  106.     rect=drawCursor(index,rect)
  107.    
  108.     @unselc=getCommandBitmap(rect.width) if !@unsel
  109.     @selc=getCommandBitmap(rect.width,true) if !@selc
  110.    
  111.     pbCopyBitmap(self.contents,self.index==index ? @selc : @unselc,rect.x,rect.y)
  112.    
  113.     pbDrawShadowText(self.contents,rect.x+18,rect.y+2,rect.width,rect.height,
  114.        @commands[index],self.baseColor,self.shadowColor)
  115.   end
  116.      
  117.   def dispose
  118.     @selc.dispose if @selc
  119.     @command.dispose
  120.     @unselc.dispose if @unselc
  121.     super
  122.   end
  123.  
  124.   def update
  125.     super
  126.    
  127.     if @unselc
  128.       wmo=@unselc.width
  129.       hmo=@unselc.height*@commands.length
  130.       if $mouse.inArea?(self.x+14,self.y+14,wmo,hmo) && !$mouse.isStatic?
  131.        ny=$mouse.y-(self.y+14)
  132.        ny-=self.viewport.rect.y if self.viewport
  133.        nindex=ny/@row_height
  134.        self.index=nindex if nindex!=self.index
  135.       end
  136.     end
  137.    
  138.   end
  139.  
  140.   def refresh
  141.     @item_max=itemCount()
  142.     dwidth=self.width-self.borderX
  143.     dheight=self.height-self.borderY
  144.     self.contents=pbDoEnsureBitmap(self.contents,dwidth,dheight)
  145.     self.contents.clear
  146.     for i in 0...@item_max
  147.       if i<self.top_item || i>self.top_item+self.page_item_max
  148.         next
  149.       end
  150.       drawItem(i,@item_max,itemRect(i))
  151.     end
  152.   end
  153.  
  154. end
  155. #-----------
  156. def Kernel.pbShowCommandsSystemModern(pos,msgwindow,commands=nil,cmdIfCancel=0,defaultCmd=0)
  157.   ret=0
  158.   if commands
  159.     cmdwindow=Window_CommandPokemonModern.new(commands)
  160.     cmdwindow.z=99999
  161.     cmdwindow.visible=true
  162.     cmdwindow.resizeToFit(cmdwindow.commands)
  163.     pbPositionNearMsgWindowSystemModern(pos,cmdwindow,msgwindow,:right)
  164.     cmdwindow.index=defaultCmd
  165.     command=0
  166.     loop do
  167.       Graphics.update
  168.       Input.update
  169.       inarea=$mouse.inArea?(cmdwindow.x,cmdwindow.y,cmdwindow.width,cmdwindow.height)
  170.       pbUpdateSpriteHash($sprites) if $sprites
  171.    
  172.       cmdwindow.update
  173.       msgwindow.update if msgwindow
  174.       yield if block_given?
  175.       if Input.trigger?(Input::B)
  176.         if cmdIfCancel>0
  177.           command=cmdIfCancel-1
  178.           break
  179.         elsif cmdIfCancel<0
  180.           command=cmdIfCancel
  181.           break
  182.         end
  183.       end
  184.       if Input.trigger?(Input::C) || (inarea and Input.triggerex?(Input::Mouse_Left))
  185.         command=cmdwindow.index
  186.         break
  187.       end
  188.     end
  189.     ret=command
  190.     cmdwindow.dispose
  191.     Input.update
  192.   end
  193.   return ret
  194. end
  195.  
  196. #-------------------------------------------------
  197. def pbPositionNearMsgWindowSystemModern(pos,cmdwindow,msgwindow,side)
  198.   return if !cmdwindow
  199.  
  200.   if msgwindow
  201.     height=[cmdwindow.height,msgwindow.height].min #384-
  202.     if cmdwindow.height!=height
  203.       cmdwindow.height=height
  204.     end
  205.     cmdwindow.y=msgwindow.y+cmdwindow.height
  206.     if cmdwindow.y<0
  207.       cmdwindow.y=msgwindow.y+msgwindow.height
  208.       if cmdwindow.y+cmdwindow.height>0 #0
  209.         cmdwindow.y=msgwindow.y-cmdwindow.height
  210.       end
  211.     end
  212.    
  213.     case pos
  214.     when 0
  215.     cmdwindow.y=msgwindow.y+msgwindow.height-14
  216.     when 1
  217.     cmdwindow.y=msgwindow.y-msgwindow.height+14
  218.     when 2
  219.     cmdwindow.y=msgwindow.y-cmdwindow.height+14
  220.     end
  221.  
  222.     case side
  223.       when :left
  224.         cmdwindow.x=msgwindow.x-14
  225.       when :right
  226.         cmdwindow.x=msgwindow.x+msgwindow.width-cmdwindow.width+14
  227.       else
  228.         cmdwindow.x=msgwindow.x+msgwindow.width-cmdwindow.width+14
  229.       end
  230.      
  231.   else
  232.     cmdwindow.height=384 if cmdwindow.height>384
  233.     cmdwindow.x=0
  234.     cmdwindow.y=0
  235.   end
  236. end
  237. #-----------------------------------------------------------
  238. def Kernel.pbMessageSystemModern(pos,black,message,commands=nil,cmdIfCancel=0,skin=nil,defaultCmd=0,&block)
  239.   ret=0
  240.   msgwindowsave=Kernel.pbCreateMessageWindowSystem(black,nil,skin)
  241.  
  242.   if commands
  243.     ret=Kernel.pbMessageDisplaySystem(pos,msgwindowsave,message,true,
  244.        proc {|msgwindow|
  245.        next Kernel.pbShowCommandsSystemModern(pos,msgwindowsave,commands,cmdIfCancel,defaultCmd,&block)
  246.     },&block)
  247.    
  248.   else
  249.     Kernel.pbMessageDisplaySystem(pos,msgwindowsave,message,&block)
  250.   end
  251.   Kernel.pbDisposeMessageWindow(msgwindowsave)
  252.   Input.update
  253.   return ret
  254. end
  255. #---------------------------------------------------------------
  256. def Kernel.pbConfirmMessageSystemModern(pos,black,message,&block)
  257.   return (Kernel.pbMessageSystemModern(pos,black,message,[_INTL("YES"),_INTL("NO")],2,&block)==0)
  258. end
  259. #---------------------------------------------------------------
  260. def pbBottomRightModern(window)
  261.   window.x=Graphics.width-window.width+14
  262.   window.y=Graphics.height-window.height+14
  263. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement