예제 #1
0
    def crete_widgets(self):
        rowid = 0
        fontsize = 13
        spaceing = 4
        marginleft = 5
        for data in self.data:
            if len(data) < 2:
                continue

            # Label
            labelwidth = marginleft
            labelheight = rowid * (fontsize + 2)
            label = Label(data[0], (labelwidth, labelheight), size=fontsize)
            self.addwidget(label)

            # Value
            valuewidth = marginleft + label.size[0] + spaceing
            valueheight = rowid * (fontsize + 2)
            value = Label(data[1], (valuewidth, valueheight),
                          color=(255, 255, 150),
                          size=fontsize
                          )
            self.addwidget(value)
            # total width
            totalwidth = label.size[0] + value.size[0]
            if self.width < totalwidth:
                self.width = totalwidth + 5
            # increase row
            rowid += 1
        # update height
        totalheight = len(self.data) * (fontsize + 2)
        if self.height < totalheight:
            self.height = totalheight + 5
        # update window size
        self.size = [self.width, self.height]
예제 #2
0
    def create_gui(self):
        """create gui

        :return:
        """
        messages = [
            "TIPS:", "* Plant seeds and harvest to get money",
            "* There is a chance to lost plant when its ready",
            "* You can DESTROY plant using shovel.",
            "* You can `pickup` pond using shovel.", "", "KEYS:",
            "S - Open/Close market  I - Open/Close inventory",
            "Z/X - Go to previous/next farm", "M - Mute/Unmute sounds",
            "A - Screenshot"
        ]

        label = Label("GAME HELP", (250, 5),
                      size=18,
                      color=(255, 255, 0),
                      align="center")
        self.addwidget(label)

        fontsize = 12
        index = 0
        for msg in messages:
            label = Label(msg, (10, 25 + (fontsize + 2) * index),
                          size=fontsize,
                          color=(255, 240, 240),
                          align="left")
            self.addwidget(label)
            index += 1
예제 #3
0
    def create_gui(self):
        messages = []

        currpath = os.path.join(os.path.dirname(__file__))
        with open(os.path.join(currpath, '../data/help.txt'),
                  'r') as help_file:
            lines = help_file.readlines()
            for l in lines:
                messages.append(l.strip())

        label = Label("GAME HELP", (250, 5),
                      size=18,
                      color=(255, 255, 0),
                      align="center")
        self.addwidget(label)

        fontsize = 12
        index = 0
        for msg in messages:
            label = Label(msg, (10, 25 + (fontsize + 2) * index),
                          size=fontsize,
                          color=(255, 240, 240),
                          align="left")
            self.addwidget(label)
            index += 1
예제 #4
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()
예제 #5
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
예제 #6
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)
예제 #7
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
예제 #8
0
    def redraw(self, screen):
        """Redraw screen"""
        Window.draw(self, screen)

        # Draw gamewindow
        self.draw(screen)

        farm = self.gamemanager.getfarm()
        player = self.gamemanager.getplayer()

        # avoid temp farm image to be None
        if not self.tempfarmimage or farm.ismodified():
            # Draw farmfield
            self.tempfarmimage = render_field(screen, self.images, farm,
                                              self.farmoffset)
        # Blit farmfield
        screen.blit(self.tempfarmimage, (0, 0))

        # draw rain
        if farm.raining and self.updatetimer.tickpassed(2):
            render_rain(screen)
            x = random.randint(0, 12)
            y = random.randint(0, 12)
            farm.water(x, y)

        drawnearcursor = not self.sellwindow.visible
        # Draw tools and selected tool rectangle
        draw_tools(screen,
                   player.selectedtool,
                   player.selecteditem,
                   self.images,
                   drawnearcursor=drawnearcursor)

        # draw watercanuses
        uses = Label("", (110 + 2, 10 + 2), color=(255, 240, 240))
        uses.settext(str(player.watercanuses))
        uses.repaint()
        uses.draw(screen)

        if not self.sellwindow.visible and \
                not self.inventorywindow.visible:

            mx, my = pygame.mouse.get_pos()

            # Draw help window
            self.helpwindow.draw(screen)

            # draw notify window if mouse under seed
            pos = self.get_farmtile_pos_under_mouse()
            if pos:
                farmtile = farm.get_farmtile(pos[0], pos[1])
                farmobject = farmtile['object']
                render_seed_notify(screen, self.notifyfont, mx + 5, my + 5,
                                   farmobject, farmtile, self.images)
        # draw selected seed
        if player.selecteditem != None:
            draw_selected_seed(screen, player.selecteditem, self.images)

        # draw inventory
        self.inventorywindow.draw(screen)
        # redraw sell window
        self.sellwindow.draw(screen)