def __init__(self,gotoBackController): super(BattleFieldController,self).__init__() self.lspacer = ImageSprite(images["lspacer"]) self.lspacer.setpos(0,gamectrlbuttony) self.add(self.lspacer) self.credits = ImageSprite(images["credits"]) self.credits.setpos(creditx,credity) self.add(self.credits) self.paneltop = ImageSprite(images["top"]) self.paneltop.setpos(topx,self.credits.bottom()) self.add(self.paneltop) self.bttnbkgd = ImageSprite(images["bttnbkgd"]) self.bttnbkgd.setpos(bttnbkgdx,bttnbkgdy) self.add(self.bttnbkgd) self.map = None self.mousedrag = False self.mouseMinimapDown = False self.animations = pygame.sprite.Group() self.lendcap = SimpleAnimation(\ images["lendcap"],0,0,28,32,3,1,lendcapx,lendcapy) self.lendcap.setIndex(0) self.animations.add(self.lendcap) self.rendcap = SimpleAnimation(\ images["rendcap"],0,0,28,32,1,1,rendcapx,rendcapy) self.rendcap.setIndex(0) self.animations.add(self.rendcap) self.buttons = pygame.sprite.Group() self.diplobtn = GamePanelButton("diplobtn") self.addSprite(self.diplobtn,diplobtnx,diplobtny) self.buttons.add(self.diplobtn) self.optbtn = GamePanelButton("optbtn") self.optbtn.setMouseListener(gotoBackController) self.addSprite(self.optbtn,self.diplobtn.right(),diplobtny) self.buttons.add(self.optbtn) self.radar = SimpleAnimation(\ images["radar"],0,0,168,110,33,1,radarx,self.paneltop.bottom()) self.radar.setIndex(0) self.animations.add(self.radar) self.tabtop = ImageSprite(images["tabtop"]) self.tabtop.setpos(tabx,self.radar.bottom()) self.add(self.tabtop) self.side0 = ImageSprite(images["sideb"]) self.side0.setpos(createbtnboxx,self.tabtop.bottom()) self.add(self.side0) self.side1 = ImageSprite(images["sideb"]) self.side1.setpos(createbtnboxx,self.side0.bottom()) self.add(self.side1) self.side2 = ImageSprite(images["sideb"]) self.side2.setpos(createbtnboxx,self.side1.bottom()) self.add(self.side2) self.side3 = ImageSprite(images["sideb"]) self.side3.setpos(createbtnboxx,self.side2.bottom()) self.add(self.side3) self.side4 = ImageSprite(images["sideb"]) self.side4.setpos(createbtnboxx,self.side3.bottom()) self.add(self.side4) self.side5 = ImageSprite(images["sideb"]) self.side5.setpos(createbtnboxx,self.side4.bottom()) self.add(self.side5) self.side6 = ImageSprite(images["sideb"]) self.side6.setpos(createbtnboxx,self.side5.bottom()) self.add(self.side6) self.tabbtm = ImageSprite(images["tabbtm"]) self.tabbtm.setpos(tabx,self.side6.bottom()) self.add(self.tabbtm) self.repairbtn = GamePanelPressedButton("repairbtn") self.addSprite(self.repairbtn,repairbtnx,self.radar.bottom()+7) self.buttons.add(self.repairbtn) self.sellbtn = GamePanelPressedButton("sellbtn") self.addSprite(self.sellbtn,self.repairbtn.right(),self.repairbtn.top()) self.buttons.add(self.sellbtn) self.tab = Set() self.tabbtn = [] for i in range(4): self.tabbtn.append(TabButton(i,self.tab,ButtonSet())) self.tab.add(self.tabbtn[i]) self.buttons.add(self.tabbtn[i]) self.addSprite(self.tabbtn[0],tabbtnx,self.repairbtn.bottom()) for i in range(1,4): self.addSprite(self.tabbtn[i],self.tabbtn[i-1].right(),\ self.repairbtn.bottom()) self.tabbtn[0].under()
class BattleFieldController(SpriteContainer): def __init__(self,gotoBackController): super(BattleFieldController,self).__init__() self.lspacer = ImageSprite(images["lspacer"]) self.lspacer.setpos(0,gamectrlbuttony) self.add(self.lspacer) self.credits = ImageSprite(images["credits"]) self.credits.setpos(creditx,credity) self.add(self.credits) self.paneltop = ImageSprite(images["top"]) self.paneltop.setpos(topx,self.credits.bottom()) self.add(self.paneltop) self.bttnbkgd = ImageSprite(images["bttnbkgd"]) self.bttnbkgd.setpos(bttnbkgdx,bttnbkgdy) self.add(self.bttnbkgd) self.map = None self.mousedrag = False self.mouseMinimapDown = False self.animations = pygame.sprite.Group() self.lendcap = SimpleAnimation(\ images["lendcap"],0,0,28,32,3,1,lendcapx,lendcapy) self.lendcap.setIndex(0) self.animations.add(self.lendcap) self.rendcap = SimpleAnimation(\ images["rendcap"],0,0,28,32,1,1,rendcapx,rendcapy) self.rendcap.setIndex(0) self.animations.add(self.rendcap) self.buttons = pygame.sprite.Group() self.diplobtn = GamePanelButton("diplobtn") self.addSprite(self.diplobtn,diplobtnx,diplobtny) self.buttons.add(self.diplobtn) self.optbtn = GamePanelButton("optbtn") self.optbtn.setMouseListener(gotoBackController) self.addSprite(self.optbtn,self.diplobtn.right(),diplobtny) self.buttons.add(self.optbtn) self.radar = SimpleAnimation(\ images["radar"],0,0,168,110,33,1,radarx,self.paneltop.bottom()) self.radar.setIndex(0) self.animations.add(self.radar) self.tabtop = ImageSprite(images["tabtop"]) self.tabtop.setpos(tabx,self.radar.bottom()) self.add(self.tabtop) self.side0 = ImageSprite(images["sideb"]) self.side0.setpos(createbtnboxx,self.tabtop.bottom()) self.add(self.side0) self.side1 = ImageSprite(images["sideb"]) self.side1.setpos(createbtnboxx,self.side0.bottom()) self.add(self.side1) self.side2 = ImageSprite(images["sideb"]) self.side2.setpos(createbtnboxx,self.side1.bottom()) self.add(self.side2) self.side3 = ImageSprite(images["sideb"]) self.side3.setpos(createbtnboxx,self.side2.bottom()) self.add(self.side3) self.side4 = ImageSprite(images["sideb"]) self.side4.setpos(createbtnboxx,self.side3.bottom()) self.add(self.side4) self.side5 = ImageSprite(images["sideb"]) self.side5.setpos(createbtnboxx,self.side4.bottom()) self.add(self.side5) self.side6 = ImageSprite(images["sideb"]) self.side6.setpos(createbtnboxx,self.side5.bottom()) self.add(self.side6) self.tabbtm = ImageSprite(images["tabbtm"]) self.tabbtm.setpos(tabx,self.side6.bottom()) self.add(self.tabbtm) self.repairbtn = GamePanelPressedButton("repairbtn") self.addSprite(self.repairbtn,repairbtnx,self.radar.bottom()+7) self.buttons.add(self.repairbtn) self.sellbtn = GamePanelPressedButton("sellbtn") self.addSprite(self.sellbtn,self.repairbtn.right(),self.repairbtn.top()) self.buttons.add(self.sellbtn) self.tab = Set() self.tabbtn = [] for i in range(4): self.tabbtn.append(TabButton(i,self.tab,ButtonSet())) self.tab.add(self.tabbtn[i]) self.buttons.add(self.tabbtn[i]) self.addSprite(self.tabbtn[0],tabbtnx,self.repairbtn.bottom()) for i in range(1,4): self.addSprite(self.tabbtn[i],self.tabbtn[i-1].right(),\ self.repairbtn.bottom()) self.tabbtn[0].under() def save(self): pass def get_battle_rect(self): return pygame.Rect(0,0,battlewidth,battleheight) def goodToPutBuilding(self,name,col,row): return self.characters.isEmpty(col,row) and\ ((self.map.islandGrid(col,row) and canland[name]) or (self.map.iswaterGrid(col,row) and canwater[name])) def draw(self,screen): super(BattleFieldController,self).draw(screen) self.buttons.draw(screen) self.animations.draw(screen) self.drawMinimap(screen) self.drawCreateButtons(screen) def drawCreateButtons(self,screen): for i in range(4): if self.tabbtn[i].children.visible: self.drawCreateButtonSet(self.tabbtn[i].children,screen) def drawCreateButtonSet(self,buttonSet,screen): if not buttonSet.visible: return for button in buttonSet: ix = button.index % 2 iy = button.index / 2 + buttonSet.scroll button.setpos(ix*createbtnw+createbtnx,iy*createbtnh+self.side0.top()) buttonSet.group.draw(screen) def drawMinimap(self,screen): screen.blit(self.minimap,(minimapx,minimapy)) x,y = self.map.transformMini(-self.map.x,-self.map.y) view = pygame.Rect(x,y,self.map.minimapvieww,self.map.minimapviewh) pygame.draw.rect(screen,RED,view,1) def updateMinimapView(self,x,y): if x >= minimapx and x <= minimapx + minimapw and\ y >= minimapy and y <= minimapy + minimaph: x,y = self.map.transformFromMini(\ x-self.map.minimapvieww/2,y-self.map.minimapviewh/2) self.map.x,self.map.y = -x,-y self.map.fitOffset() self.mouseMinimapDown = True def clickButtonSet(self,buttonSet,x,y,button): for b in buttonSet: if button == 1 or button == 3: if not b.disabled and b.contains(x,y): if button == 1: b.mouseListener(b.name) elif button == 3: b.rightMouseListener(b.name) def onMouseMove(self,x,y,button1=None,button2=None,button3=None): super(BattleFieldController,self).onMouseMove(x,y,button1,button2,button3) if self.map != None: self.map.updateScrollV(x,y,button3==True) if self.mouseMinimapDown: self.updateMinimapView(x,y) def onMouseDown(self,x,y,button): super(BattleFieldController,self).onMouseDown(x,y,button) for i in range(4): if self.tabbtn[i].children.visible: self.clickButtonSet(self.tabbtn[i].children,x,y,button) self.updateMinimapView(x,y) def onMouseUp(self,x,y,button): super(BattleFieldController,self).onMouseUp(x,y,button) self.mouseMinimapDown = False def onKeyDown(self,keyCode,mod): if keyCode == pygame.K_LEFT: self.map.scrollv[0] = 1 elif keyCode == pygame.K_RIGHT: self.map.scrollv[1] = 1 elif keyCode == pygame.K_UP: self.map.scrollv[2] = 1 elif keyCode == pygame.K_DOWN: self.map.scrollv[3] = 1 def onKeyUp(self,keyCode,mod): if keyCode == pygame.K_LEFT: self.map.scrollv[0] = 0 elif keyCode == pygame.K_RIGHT: self.map.scrollv[1] = 0 elif keyCode == pygame.K_UP: self.map.scrollv[2] = 0 elif keyCode == pygame.K_DOWN: self.map.scrollv[3] = 0