def createButtons(self, itemWidth, marginWidth, spacingWidth, items,
                      itemMatrix):

        self.buttons = []
        for row in range(itemMatrix[1]):
            for col in range(itemMatrix[0]):
                itemIndex = (itemMatrix[0] * row) + col
                if (itemIndex >= len(items)):
                    return

                item = items[itemIndex]

                xPos = (itemWidth * col) + (spacingWidth * (col)) + marginWidth
                yPos = (itemWidth * row) + (spacingWidth * (row)) + marginWidth

                rect = Rect((xPos, yPos), (itemWidth, itemWidth))

                if (isinstance(item, mapchar.MapChar)):
                    images = []
                    icons = [item.images[0][0], item.images[1][0]]
                    for i in range(len(icons)):
                        icon = icons[i]
                        iconRect = Rect((0, 0), icon.get_size())
                        iconRect.centerx = (rect.width / 2)
                        iconRect.centery = (rect.height / 2)
                        surface = pygame.Surface(rect.size)
                        surface.fill(CHARACTER_SELECTION_DIALOG_BUTTON_COLOR)
                        surface.blit(icon, iconRect.topleft)
                        images.append(surface)

                self.buttons.append(
                    DetailDialogButton(rect, images[0], images[1], item))
 def createButtons(self, itemWidth, marginWidth, spacingWidth, items, itemMatrix):
     
     self.buttons = []
     for row in range(itemMatrix[1]):
         for col in range(itemMatrix[0]):
             itemIndex = (itemMatrix[0] * row) + col
             if (itemIndex >= len(items)):
                 return
             
             item = items[itemIndex]
             
             xPos = (itemWidth * col) + (spacingWidth * (col)) + marginWidth
             yPos = (itemWidth * row) + (spacingWidth * (row)) + marginWidth
             
             rect = Rect((xPos, yPos), (itemWidth, itemWidth))
             
             if (isinstance(item, mapchar.MapChar)):
                 images = []
                 icons = [item.images[0][0], item.images[1][0]]
                 for i in range(len(icons)):
                     icon = icons[i]
                     iconRect = Rect((0, 0), icon.get_size())
                     iconRect.centerx = (rect.width / 2)
                     iconRect.centery = (rect.height / 2)
                     surface = pygame.Surface(rect.size)
                     surface.fill(CHARACTER_SELECTION_DIALOG_BUTTON_COLOR)
                     surface.blit(icon, iconRect.topleft)
                     images.append(surface)
             
             self.buttons.append(DetailDialogButton(rect, images[0], images[1], item))
    def selectMap(self, map, wasRandom):

        self.mapPanel.setData(MapData(map, wasRandom))

        numOfCharacterSlots = 0
        if not map is None:
            numOfCharacterSlots = len(map.startingPoints[0])

        self.characterPanels = []

        for i in range(2):
            xMid = (SCREEN_SIZE[0] / 4) * (1 + (i * 2))

            yMid = SCREEN_SIZE[1] / 2
            if (numOfCharacterSlots % 2 == 0):
                numToDisplaceFromCenter = (numOfCharacterSlots / 2) - 1
                yMid -= (CHARACTER_SELECTION_PANEL_SPACING /
                         2) + (CHARACTER_SELECTION_PANEL_SIZE[1] / 2)
            else:
                numToDisplaceFromCenter = int(numOfCharacterSlots / 2)

            yMid -= (
                CHARACTER_SELECTION_PANEL_SPACING +
                CHARACTER_SELECTION_PANEL_SIZE[1]) * numToDisplaceFromCenter

            for j in range(numOfCharacterSlots):
                rect = Rect((0, 0), CHARACTER_SELECTION_PANEL_SIZE)
                rect.centerx = xMid
                rect.centery = yMid + ((CHARACTER_SELECTION_PANEL_SPACING +
                                        CHARACTER_SELECTION_PANEL_SIZE[1]) * j)
                self.characterPanels.append(
                    Panel(i, (self.playerNum == i), rect))

            rect = rect = Rect((0, 0), READY_PANEL_SIZE)
            rect.centerx = xMid
            rect.bottom = SCREEN_SIZE[1] - CHARACTER_SELECTION_PANEL_SPACING
            readyPanel = Panel(i, (self.playerNum == i), rect)
            readyPanel.faceUp = True
            readyPanel.setData(ReadyData(False))
            self.readyPanels[i] = readyPanel

        self.subScreen = 0
 def selectMap(self, map, wasRandom):
     
     self.mapPanel.setData(MapData(map, wasRandom))
     
     numOfCharacterSlots = 0
     if not map is None:
         numOfCharacterSlots = len(map.startingPoints[0])
         
     self.characterPanels = []
     
     for i in range(2):
         xMid = (SCREEN_SIZE[0] / 4) * (1 + (i * 2))
         
         yMid = SCREEN_SIZE[1] / 2
         if (numOfCharacterSlots % 2 == 0):
             numToDisplaceFromCenter = (numOfCharacterSlots / 2) - 1
             yMid -= (CHARACTER_SELECTION_PANEL_SPACING / 2) + (CHARACTER_SELECTION_PANEL_SIZE[1] / 2)
         else:
             numToDisplaceFromCenter = int(numOfCharacterSlots / 2)
             
         yMid -= (CHARACTER_SELECTION_PANEL_SPACING + CHARACTER_SELECTION_PANEL_SIZE[1]) * numToDisplaceFromCenter
             
         
         for j in range(numOfCharacterSlots):
             rect = Rect((0,0), CHARACTER_SELECTION_PANEL_SIZE)
             rect.centerx = xMid
             rect.centery = yMid + ((CHARACTER_SELECTION_PANEL_SPACING + CHARACTER_SELECTION_PANEL_SIZE[1]) * j)
             self.characterPanels.append(Panel(i, (self.playerNum == i), rect))
             
         rect = rect = Rect((0,0), READY_PANEL_SIZE)
         rect.centerx = xMid
         rect.bottom = SCREEN_SIZE[1] - CHARACTER_SELECTION_PANEL_SPACING
         readyPanel = Panel(i, (self.playerNum == i), rect)
         readyPanel.faceUp = True
         readyPanel.setData(ReadyData(False))
         self.readyPanels[i] = readyPanel
         
     self.subScreen = 0
    def update(self):
        if (self.redraw):

            #Draw Panel Surface
            if (self.data is None or (isinstance(self.data, ReadyData)
                                      and self.data.value == False)):
                paletteBase = CHARACTER_SELECT_PANEL_BASE_COLORS_OFF
                paletteDecor = CHARACTER_SELECT_PANEL_DECOR_COLORS_OFF
            else:
                paletteBase = CHARACTER_SELECT_PANEL_BASE_COLORS_ON
                paletteDecor = CHARACTER_SELECT_PANEL_DECOR_COLORS_ON

            colorBase = paletteBase[self.team]
            colorDecor = paletteDecor[self.team]

            self.image = pygame.Surface(self.rect.size)
            self.image.fill(colorBase)

            showFront = self.faceUp or self.isOwner

            if (showFront):
                decorMargin = CHARACTER_SELECT_PANEL_FACE_DECOR_MARGIN
                decorWidth = CHARACTER_SELECT_PANEL_FACE_DECOR_WIDTH
            else:
                decorMargin = CHARACTER_SELECT_PANEL_BACK_DECOR_MARGIN
                decorWidth = CHARACTER_SELECT_PANEL_BACK_DECOR_WIDTH

            decorOuter = pygame.Surface((self.rect.width - (decorMargin * 2),
                                         self.rect.height - (decorMargin * 2)))
            decorOuter.fill(colorDecor)

            decorInner = pygame.Surface(
                (decorOuter.get_size()[0] - (decorWidth * 2),
                 decorOuter.get_size()[1] - (decorWidth * 2)))
            decorInner.fill(colorBase)

            if (not showFront):
                margins = CHARACTER_SELECT_PANEL_BACK_CIRCLE_MARGINS
                ovalRect = Rect((margins[0], margins[1]),
                                (decorInner.get_size()[0] - (margins[0] * 2),
                                 decorInner.get_size()[1] - (margins[1] * 2)))
                pygame.draw.ellipse(decorInner, colorDecor, ovalRect)

            decorOuter.blit(decorInner, (decorWidth, decorWidth))
            self.image.blit(decorOuter, (decorMargin, decorMargin))

            #Fill Data
            fillRect = Rect(
                ((decorWidth + decorMargin), (decorWidth + decorMargin)),
                decorInner.get_size())
            if isinstance(self.data, mapchar.MapChar):

                font = CHARACTER_SELECTION_CAPTION_FONT
                textHeight = font.get_linesize() + 2
                tRect = Rect((0, 0), (fillRect.width - 10, textHeight))
                tRect.centerx = fillRect.centerx
                tRect.centery = fillRect.centery
                text = textrect.render_textrect(
                    self.data.name, font, tRect,
                    CHARACTER_SELECTION_FONT_COLOR, ALMOST_BLACK, 0, True)
                self.image.blit(text, tRect.topleft)

                speciesImage = self.data.getSmallImage()
                speciesRect = Rect((0, 0), speciesImage.get_size())
                speciesRect.right = tRect.right
                speciesRect.centery = self.rect.height / 2

                self.image.blit(speciesImage, speciesRect.topleft)

            elif isinstance(self.data, MapData):

                font = CHARACTER_SELECTION_CAPTION_FONT
                textHeight = font.get_linesize() + 2
                tRect = Rect((0, 0), (fillRect.width - 10, textHeight))
                tRect.centerx = fillRect.centerx
                tRect.centery = fillRect.centery
                text = textrect.render_textrect(
                    self.data.map.name, font, tRect,
                    CHARACTER_SELECTION_FONT_COLOR, ALMOST_BLACK, 0, True)
                self.image.blit(text, tRect.topleft)

                if self.data.wasRandom:
                    image = RANDOM_ICON
                    rect = Rect((0, 0), image.get_size())
                    rect.right = fillRect.right
                    rect.centery = fillRect.centery
                    self.image.blit(image, rect.topleft)

            elif isinstance(self.data, ReadyData):

                font = CHARACTER_SELECTION_CAPTION_FONT
                font = CHARACTER_SELECTION_CAPTION_FONT
                textHeight = font.get_linesize() + 2
                tRect = Rect((0, 0), (fillRect.width - 10, textHeight))
                tRect.centerx = fillRect.centerx
                tRect.centery = fillRect.centery
                if self.data.value:
                    color = READY_PANEL_FONT_COLOR_TRUE
                    text = "READY"
                else:
                    color = READY_PANEL_FONT_COLOR_FALSE
                    text = "PREPARING..."
                text = textrect.render_textrect(text, font, tRect, color,
                                                ALMOST_BLACK, 1, True)
                self.image.blit(text, tRect.topleft)

            if isinstance(self.data, GoData):

                font = CHARACTER_SELECTION_CAPTION_FONT
                font = CHARACTER_SELECTION_CAPTION_FONT
                textHeight = font.get_linesize() + 2
                tRect = Rect((0, 0), (fillRect.width - 10, textHeight))
                tRect.centerx = fillRect.centerx
                tRect.centery = fillRect.centery
                color = READY_PANEL_FONT_COLOR_TRUE
                text = "GO!"
                text = textrect.render_textrect(text, font, tRect, color,
                                                ALMOST_BLACK, 1, True)
                self.image.blit(text, tRect.topleft)

            self.redraw = False
 def update(self):
     if (self.redraw):
         
         #Draw Panel Surface
         if (self.data is None or (isinstance(self.data, ReadyData) and self.data.value == False)):
             paletteBase = CHARACTER_SELECT_PANEL_BASE_COLORS_OFF
             paletteDecor = CHARACTER_SELECT_PANEL_DECOR_COLORS_OFF
         else:
             paletteBase = CHARACTER_SELECT_PANEL_BASE_COLORS_ON
             paletteDecor = CHARACTER_SELECT_PANEL_DECOR_COLORS_ON
             
         colorBase = paletteBase[self.team]
         colorDecor = paletteDecor[self.team]
         
         self.image = pygame.Surface(self.rect.size)
         self.image.fill(colorBase)
         
         showFront = self.faceUp or self.isOwner
         
         if (showFront):
             decorMargin = CHARACTER_SELECT_PANEL_FACE_DECOR_MARGIN
             decorWidth = CHARACTER_SELECT_PANEL_FACE_DECOR_WIDTH
         else:
             decorMargin = CHARACTER_SELECT_PANEL_BACK_DECOR_MARGIN
             decorWidth = CHARACTER_SELECT_PANEL_BACK_DECOR_WIDTH
             
         decorOuter = pygame.Surface((self.rect.width - (decorMargin * 2), self.rect.height - (decorMargin * 2)))
         decorOuter.fill(colorDecor)
             
         decorInner = pygame.Surface((decorOuter.get_size()[0] - (decorWidth * 2),
                                      decorOuter.get_size()[1] - (decorWidth * 2)))
         decorInner.fill(colorBase)
         
         if (not showFront):
             margins = CHARACTER_SELECT_PANEL_BACK_CIRCLE_MARGINS
             ovalRect = Rect((margins[0], margins[1]),
                             (decorInner.get_size()[0] - (margins[0] * 2),
                              decorInner.get_size()[1] - (margins[1] * 2)))
             pygame.draw.ellipse(decorInner, colorDecor, ovalRect)
         
         decorOuter.blit(decorInner, (decorWidth, decorWidth))
         self.image.blit(decorOuter, (decorMargin, decorMargin))
         
         
         #Fill Data
         fillRect = Rect(((decorWidth + decorMargin), (decorWidth + decorMargin)), decorInner.get_size())
         if isinstance(self.data, mapchar.MapChar):
             
             font = CHARACTER_SELECTION_CAPTION_FONT
             textHeight = font.get_linesize() + 2
             tRect = Rect((0,0), (fillRect.width - 10, textHeight))
             tRect.centerx = fillRect.centerx
             tRect.centery = fillRect.centery
             text = textrect.render_textrect(self.data.name, font, tRect,
                                             CHARACTER_SELECTION_FONT_COLOR,
                                             ALMOST_BLACK, 0, True)
             self.image.blit(text, tRect.topleft)
             
             speciesImage = self.data.getSmallImage()
             speciesRect = Rect((0, 0), speciesImage.get_size())
             speciesRect.right = tRect.right
             speciesRect.centery = self.rect.height / 2
             
             self.image.blit(speciesImage, speciesRect.topleft)
             
             
         elif isinstance(self.data, MapData):
             
             font = CHARACTER_SELECTION_CAPTION_FONT
             textHeight = font.get_linesize() + 2
             tRect = Rect((0,0), (fillRect.width - 10, textHeight))
             tRect.centerx = fillRect.centerx
             tRect.centery = fillRect.centery
             text = textrect.render_textrect(self.data.map.name, font, tRect,
                                             CHARACTER_SELECTION_FONT_COLOR,
                                             ALMOST_BLACK, 0, True)
             self.image.blit(text, tRect.topleft)
             
             if self.data.wasRandom:
                 image = RANDOM_ICON
                 rect = Rect((0,0), image.get_size())
                 rect.right = fillRect.right
                 rect.centery = fillRect.centery
                 self.image.blit(image, rect.topleft)
                 
         elif isinstance(self.data, ReadyData):
             
             font = CHARACTER_SELECTION_CAPTION_FONT
             font = CHARACTER_SELECTION_CAPTION_FONT
             textHeight = font.get_linesize() + 2
             tRect = Rect((0,0), (fillRect.width - 10, textHeight))
             tRect.centerx = fillRect.centerx
             tRect.centery = fillRect.centery
             if self.data.value:
                 color = READY_PANEL_FONT_COLOR_TRUE
                 text = "READY"
             else:
                 color = READY_PANEL_FONT_COLOR_FALSE
                 text = "PREPARING..."
             text = textrect.render_textrect(text, font, tRect,
                                             color, ALMOST_BLACK, 1, True)
             self.image.blit(text, tRect.topleft)
             
         if isinstance(self.data, GoData):
             
             font = CHARACTER_SELECTION_CAPTION_FONT
             font = CHARACTER_SELECTION_CAPTION_FONT
             textHeight = font.get_linesize() + 2
             tRect = Rect((0,0), (fillRect.width - 10, textHeight))
             tRect.centerx = fillRect.centerx
             tRect.centery = fillRect.centery
             color = READY_PANEL_FONT_COLOR_TRUE
             text = "GO!"
             text = textrect.render_textrect(text, font, tRect,
                                             color, ALMOST_BLACK, 1, True)
             self.image.blit(text, tRect.topleft)
         
         
         self.redraw = False