Ejemplo n.º 1
0
    def buildingTypeCell( self, board, buildingType, available, x = None, y = None, width = 1, height = 1 ):
        color = ( 0, 0, 0 )
        if not available:
            color = ( 0.5, 0.5, 0.5 )
        if x is not None: self.x = x
        if y is not None: self.y = y

        menu = gtk.Menu()    # Don't need to show menus
        unavailable = gtk.MenuItem( _( "Mark as unavailable" ) )
        available = gtk.MenuItem( _( "Mark as available" ) )
        menu.append( unavailable )
        menu.append( available )
        unavailable.connect( "activate", lambda widget, buildingType: board.setUnavailable( buildingType ), buildingType )
        available.connect( "activate", lambda widget, buildingType: board.setAvailable( buildingType ), buildingType )
        unavailable.show()
        available.show()

        self.addCell(
            ContextMenuCell(
                CairoTable.TextCell( _( buildingType ), color = color ),
                menu
            ),
            self.x,
            self.y,
            width,
            height
        )
        self.x += width
Ejemplo n.º 2
0
 def drawObjectNeeds( self, o ):
     self.ctx.save()
     self.ctx.set_font_size( 15 )
     maxWidth = 0
     
     self.ctx.save()
     self.ctx.identity_matrix()
     texts = dict()
     for surface, ( needs, interaction, check ) in o.needs.iteritems():
         if needs == check:
             color = ( 0, 0, 0 )
         elif needs:
             color = ( 0.6, 0, 0 )
         else:
             color = ( 0, 0.5, 0 )
         if needs:
             needsLikes = "Needs"
         else:
             needsLikes = "Likes"
         text = _( needsLikes + "." + surface + "." + str( interaction ) )
         x_bearing, y_bearing, width, height, x_advance, y_advance = self.ctx.text_extents( text )
         maxWidth = max( maxWidth, width )
         texts[ text ] = color
     self.ctx.restore()
     
     x, y = o.polygon.center
     
     self.ctx.save()
     self.ctx.translate( x, y )
     self.ctx.scale( 1. / self.__scale, 1. / self.__scale )
     self.ctx.set_source_rgb( 1, 1, 0.6 )
     self.ctx.rectangle( -5, -2, maxWidth + 10, len( texts ) * 15 + 10 )
     self.ctx.identity_matrix()
     self.ctx.fill_preserve()
     self.ctx.set_source_rgba( 0, 0, 0, 1 )
     self.ctx.stroke()
     self.ctx.restore()
     
     i = 0
     for text in sorted( texts.keys() ):
         i += 15
         color = texts[ text ]
         self.ctx.set_source_rgb( *color )
         self.ctx.move_to( x, y )
         self.ctx.save()
         self.ctx.identity_matrix()
         self.ctx.rel_move_to( 0, i )
         self.ctx.show_text( text )
         self.ctx.restore()
     self.ctx.restore()
Ejemplo n.º 3
0
    def __init__( self, board, primaryObjectFamilies, secondaryObjectFamilies, primarySurfaceFamilies, secondarySurfaceFamilies ):
        gtk.HBox.__init__( self, False, 0 )

        self.board = board
        self.board.registerView( self )
        self.selection = Selection( self )
        self.mouseManager = MouseManager.MouseManager( self )
        for family in primaryObjectFamilies:
            self.selection.addObjects( family )
        for family in primarySurfaceFamilies:
            self.selection.addSurfaces( family )
        self.__scale = MapView.__pixelPerUnit * 4
        self.__translateX = 0
        self.__translateY = 0
        self.__sisterViews = list()

        self.drawingArea = gtk.DrawingArea()
        self.drawingArea.connect( "expose-event", self.__onExposeEvent )
        self.drawingArea.set_events(
            gtk.gdk.EXPOSURE_MASK |
            gtk.gdk.LEAVE_NOTIFY_MASK |
            gtk.gdk.BUTTON_PRESS_MASK |
            gtk.gdk.BUTTON_RELEASE_MASK |
            gtk.gdk.POINTER_MOTION_MASK |
            gtk.gdk.POINTER_MOTION_HINT_MASK
        )
        self.drawingArea.show()

        toolBar = gtk.Toolbar()
        toolBar.set_orientation( gtk.ORIENTATION_VERTICAL )

        self.__objectFamilies = primaryObjectFamilies + secondaryObjectFamilies
        self.__surfaces = list()
        for family in secondarySurfaceFamilies + primarySurfaceFamilies:
            for surface in GameItemTypes.surfaces[ family ]:
                self.__surfaces.append( surface )

        toolBar.append_item( _( "Select/Move" ), "", "", None, lambda widget: self.resetMouseManager() )

        for family in primarySurfaceFamilies:
            for surface in GameItemTypes.surfaces[ family ]:
                if GameItemTypes.attributes[ surface ][ "BuiltByLengths" ]:
                    menu = gtk.Menu()
                    item = gtk.MenuItem( _( "Length" ) )
                    menu.append( item )
                    item.connect( "activate", lambda widget, surfaceType: self.mouseManager.setState( MouseManager.StartInsertSurface, surfaceType, MouseManager.SurfaceLength() ), surface )
                    item.show()
                    item = gtk.MenuItem( _( "Rectangle" ) )
                    menu.append( item )
                    item.connect( "activate", lambda widget, surfaceType: self.mouseManager.setState( MouseManager.StartInsertSurface, surfaceType, MouseManager.SurfaceRectangle() ), surface )
                    item.show()
                    toolBar.append_item( _( surface ), "", "", None, lambda widget, menu: menu.popup( None, None, None, 3, 0 ), menu )
                else:
                    toolBar.append_item( _( surface ), "", "", None, lambda widget, surfaceType: self.mouseManager.setState( MouseManager.StartInsertSurface, surfaceType, MouseManager.SurfaceRectangle() ), surface )

        for family in primaryObjectFamilies:
            for category, subCategories in GameItemTypes.objects[ family ].iteritems():
                menu = gtk.Menu()
                for subCategory, buildingTypes in subCategories.iteritems():
                    for buildingType in buildingTypes:
                        item = gtk.MenuItem( _( buildingType ) )
                        menu.append( item )
                        item.connect( "activate", lambda widget, buildingType: self.mouseManager.setState( MouseManager.InsertingObject, buildingType ), buildingType )
                        if not self.board.isAvailable( buildingType ):
                            item.set_sensitive( False )
                        item.show()
                toolBar.append_item( _( category ), "", "", None, lambda widget, menu: menu.popup( None, None, None, 3, 0 ), menu )
        toolBar.show()

        self.pack_end( toolBar, False, False, 2 )
        self.pack_start( self.drawingArea, True, True, 2 )
Ejemplo n.º 4
0
 def textCell( self, text, x = None, y = None, width = 1, height = 1 ):
     self.untranslatedTextCell( _( text ), x, y, width, height )
Ejemplo n.º 5
0
 def titleCell( self, text, x = None, y = None, width = 1, height = 1 ):
     if x is not None: self.x = x
     if y is not None: self.y = y
     self.addCell( CairoTable.TextCell( _( text ), fontSize = 18, bold = True ), self.x, self.y, width, height )
     self.x += width
Ejemplo n.º 6
0
 def balanceCell( self, value, ok = None, x = None, y = None, width = 1, height = 1 ):
     self.untranslatedBalanceCell( _( value ), ok, x, y, width, height )