예제 #1
0
    def create_gui(self):
        """create gui

        :return:
        """
        self.remove_all_widgets()
        bg = Image(self.images['inventory'], (0, 0))
        self.addwidget(bg)

        # close button
        closebutton = Button("X", (380, 3),
                             labelsize=15,
                             color=(255, 255, 255))
        closebutton.connect("clicked", lambda x: self.hide())
        self.addwidget(closebutton)

        # create items
        counterx = 0
        countery = 0
        for item in self.player.inventory:
            px = counterx * 64 + self.inventoryoffset[0] + 25
            py = countery * 32 + self.inventoryoffset[1] + 30
            # make grid
            px += counterx * 30
            py += countery * 15

            # grid image
            gridimage = Image(self.images['grid2'], (px, py))
            self.addwidget(gridimage)

            # item button
            img = self.images['object' + str(item)]
            itembutton = Button("", (px, py), img)
            itembutton.connect("clicked", self.on_item_select, itemid=item)
            itembutton.connect("onenter", self.on_item_enter, itemid=item)
            itembutton.connect("onleave", self.on_item_leave, itemid=item)
            self.addwidget(itembutton)

            # item count
            text = str(self.player.itemscounter[str(item)])
            itemcount = Label(text, (px + 40, py + 16), align="center")
            self.addwidget(itemcount)

            # limit
            counterx += 1
            if counterx == self.inventorysize[0]:
                counterx = 0
                countery += 1
            if countery == self.inventorysize[1]:
                break
예제 #2
0
    def __init__(self):
        self.parent = None
        Container.__init__(self, (800, 600), (0, 0))
        self.running = True

        self.menupos = 0
        self.maxmenupos = 1

        # background
        imgpath = os.path.join("images", "gui", "mainmenubg.png")
        bgimage = pygame.image.load(imgpath).convert_alpha()
        bg = Image(bgimage, (0, 0))
        self.addwidget(bg)

        # start button
        self.menucursor = Label("-> ", (230, 200),
                                color=(255, 255, 0), size=20)
        self.addwidget(self.menucursor)

        # start button
        self.startbutton = Button("Start game / Continue", (270, 200),
                                  color=(255, 255, 200), labelsize=20)
        self.startbutton.connect("clicked", self.on_startgame)
        self.addwidget(self.startbutton)

        # Quit button
        self.quitbutton = Button("Quit", (270, 240),
                                 color=(255, 0, 0),
                                 labelsize=20)
        self.quitbutton.connect("clicked", self.on_quit)
        self.addwidget(self.quitbutton)

        # Show window
        self.show()
예제 #3
0
    def create_gui(self):
        # Add images for seeds in market
        posx, posy = [0, 0]
        columns = (self.width / 64) - 1
        #rows = (self.height / 32) - 1
        # Background
        bgimage = self.imgloader["marketbg"]
        bgimage = Image(bgimage, (0, 0))
        self.addwidget(bgimage)

        # close button
        closebutton = Button("X", (380, 3),
                             labelsize=15,
                             color=(255, 255, 255))
        closebutton.connect("clicked", lambda x: self.hide())
        closebutton.connect("onshow", self.on_market_show)
        self.addwidget(closebutton)

        # refill watercan
        waterbuybutton = Button("Refill water ($%s)" % WATERREFILLCOST,
                                (10, 30),
                                color=(128, 128, 255))
        waterbuybutton.connect("clicked", self.on_water_buy)
        self.addwidget(waterbuybutton)

        # Buy farm
        farmcost = self.gamemanager.getnextfarmcost()
        self.buyfarm = Button("Buy new farm ($%s)" % farmcost, (150, 30),
                              color=(255, 0, 0))
        self.buyfarm.connect("clicked", self.on_farm_buy)
        self.addwidget(self.buyfarm)

        # Add items
        gridimg = self.imgloader['grid2']
        for seeddef in objects:
            if seeddef["id"] in OBJECTSNOTINMARKET:
                continue
            itemid = seeddef['id']
            # add seed image widget
            img = self.imgloader['object' + str(itemid)]
            px = 64 * posx + self.itemsoffset[0]
            py = 32 * posy + self.itemsoffset[1] + 30
            # add grid
            grid = Image(gridimg, (px, py))
            self.addwidget(grid)
            # Add image button
            imagebutton = Button("", (px, py), bgimage=img)
            self.addwidget(imagebutton)
            imagebutton.connect("clicked", self.on_item_select, itemid=itemid)
            imagebutton.connect("onenter",
                                self.on_mouse_item_enter,
                                itemid=itemid)
            imagebutton.connect("onleave",
                                self.on_mouse_item_leave,
                                itemid=itemid)
            # limit
            posx += 1
            if posx >= columns:
                posx = 0
                posy += 1

        # Costlabel
        costlabel = Label("Cost:", (80, 340),
                          size=12,
                          color=(255, 255, 255),
                          align="center")
        self.addwidget(costlabel)
        # Cost value
        self.costvalue = Label("", (110, 340),
                               size=12,
                               color=(200, 200, 50),
                               align="center")
        self.addwidget(self.costvalue)

        # Selllabel
        selllabel = Label("Sell value:", (280, 340),
                          size=12,
                          color=(255, 255, 255),
                          align="center")
        self.addwidget(selllabel)
        # Sell value
        self.sellvalue = Label("", (330, 340),
                               size=12,
                               color=(200, 200, 50),
                               align="center")
        self.addwidget(self.sellvalue)

        # Message
        self.message = Label("", (10, 360),
                             size=12,
                             color=(250, 0, 250),
                             align="left")
        self.addwidget(self.message)
        # Selected item icon
        self.selectedicon = Image(None, (160, 332))
        self.addwidget(self.selectedicon)

        # add buttons
        self.buybutton = Button("BUY", (60, 375),
                                color=(0, 255, 0),
                                labelsize=13)
        self.sellbutton = Button("SELL", (300, 375),
                                 color=(0, 255, 0),
                                 labelsize=13)
        self.addwidget(self.buybutton)
        self.addwidget(self.sellbutton)
        self.buybutton.connect("clicked", self.on_buy_clicked)
        self.sellbutton.connect("clicked", self.on_sell_clicked)
예제 #4
0
    def __init__(self):
        Window.__init__(self, (800, 600), (0, 0))

        self.lazyscreen = None

        # Create gamemanager
        self.gamemanager = GameManager()
        # timers
        self.eventstimer = Timer()
        self.updatetimer = Timer()

        self.images = ImageLoader(imagesdata)
        self.notifyfont = pygame.font.Font("dejavusansmono.ttf", 12)
        self.font2 = pygame.font.Font("dejavusansmono.ttf", 18)

        # Install plugins
        self.coreplugin = PluginSystem.installPlugin(CorePlugin)
        self.coreplugin.gamewindow = self

        # background image
        bgimg = Image(self.images['background'], (0, 0))
        self.addwidget(bgimg)

        # Create inventory window
        player = self.gamemanager.getplayer()
        self.inventorywindow = InventoryWindow(self.images, player)
        self.inventorywindow.hide()

        # create market window
        self.sellwindow = MarketWindow((400, 400), self.images, player,
                                       self.gamemanager)
        self.sellwindow.gamewindow = self

        # Market button
        marketbutton = Button("", (800 - 42, 10),
                              bgimage=self.images['marketbutton'])
        marketbutton.connect("clicked", self.toggle_market)
        self.addwidget(marketbutton)

        # Inventory button
        inventorybutton = Button("", (800 - 42, 52),
                                 bgimage=self.images['inventorybutton'])
        inventorybutton.connect("clicked", self.toggle_inventory)
        self.addwidget(inventorybutton)

        # Create help window
        self.helpwindow = HelpWindow((500, 300))

        # Create expbar
        self.expbar = ExpBar(player)
        self.addwidget(self.expbar)

        # labels
        self.moneylabel = Label("", (400, 5), align="center")
        self.addwidget(self.moneylabel)

        # Label for version
        versionlabel = Label("v. " + __VERSION__ + " (H for help)", (5, 580))
        self.addwidget(versionlabel)

        # Is game running?
        self.running = False

        # Farm position offset (to center map)
        self.farmoffset = (212, 50)

        # Temp image for farmfield redraw if not modified
        self.tempfarmimage = None