Python Forum
[pygame] Equiping inventory slots with invisible buttons
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[pygame] Equiping inventory slots with invisible buttons
#1
I have an inventory class with 3 functions. __init__, draw, and equipChange
The job of each function -
__init__ - to define x, y, slots, and a few more predefined variables
draw - draw inventory based on the amount of slots and x and y. Also checks if a slot is pressed on and turns it red if so (I currently have not added the unequip feature. I am working on the equip feature first)
equipChange - the function for changing the tuple of equip which in turn changes what is drawn.

I'm sorry if I made a simple mistake - that would be embarrassing - TIA for your help.

inventory class - the full code is here - https://github.com/Sheepposu/Destination - on github
class inventoryGUI():
    def __init__(self, x, y, slots):
        self.x = x
        self.y = y
        self.i = 0
        self.n = 0
        self.slots = slots
        self.equips = None

    def draw(self, equips):
        SD.message_display(gD, 'Inventory', 50, black, self.x + 100, self.y - 50)
        self.equips = equips
        for n in range(1, self.slots + 1):
            p = equips
            self.n += 1
            if n in p:
                SlotBtn = IBT((self.x + self.i, self.y, self.x + self.i + 20, self.y + 20))
                if self.equips == None:
                    SlotBtn.optClick(partial(self.equipChange, (False, n)))
                else:
                    self.equips += (n,)
                    SlotBtn.optClick(partial(self.equipChange, (False, self.equips)))
                pygame.draw.line(gD, red, (self.x + self.i, self.y), (self.x + self.i + 20, self.y)) #Top
                pygame.draw.line(gD, red, (self.x + self.i + 20, self.y), (self.x + 20 + self.i, self.y + 20)) # Right
                pygame.draw.line(gD, red, (self.x + self.i, self.y), (self.x + self.i, self.y + 20)) #Left
                pygame.draw.line(gD, red, (self.x + self.i, self.y + 20), (self.x + self.i + 20, self.y + 20)) #Bottom
            else:
                SlotBtn = IBT((self.x + self.i, self.y, self.x + self.i + 20, self.y + 20))
                if self.equips == None:
                    SlotBtn.optClick(partial(self.equipChange, (False, n)))
                else:
                    self.equips += (n,)
                    SlotBtn.optClick(partial(self.equipChange, (False, self.equips)))
                pygame.draw.line(gD, black, (self.x + self.i, self.y), (self.x + self.i + 20, self.y)) #Top
                pygame.draw.line(gD, black, (self.x + self.i + 20, self.y), (self.x + 20 + self.i, self.y + 20)) # Right
                pygame.draw.line(gD, black, (self.x + self.i, self.y), (self.x + self.i, self.y + 20)) #Left
                pygame.draw.line(gD, black, (self.x + self.i, self.y + 20), (self.x + self.i + 20, self.y + 20)) #Bottom
            if self.n < 6:
                self.i += 30
            else:
                self.n = 0
                self.i = 0
                self.y += 30

    def equipChange(self, receive, equips=None):
        if receive:
            return self.equips
        elif not receive:
            self.equips = equips
            print('self.equip now equals ' + self.equips)
Reply


Messages In This Thread
[pygame] Equiping inventory slots with invisible buttons - by SheeppOSU - Apr-25-2019, 09:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyGame] pygame-manu : using controller buttons to move around menu mlw19mlw91 2 1,709 Mar-12-2023, 01:55 PM
Last Post: deanhystad
  Pygame - Images As Buttons vman44 3 13,174 Mar-20-2020, 08:13 PM
Last Post: vman44
  Adding an inventory and a combat system to a text based adventure game detkitten 2 6,975 Dec-17-2019, 03:40 AM
Last Post: detkitten
  [pygame] Inventory items not working SheeppOSU 14 6,970 May-27-2019, 09:44 PM
Last Post: metulburr
  [pygame] Inventory problems. Weapons equipped to wrong slot SheeppOSU 6 4,112 May-07-2019, 02:46 AM
Last Post: SheeppOSU
  [pygame] Blitting armor and weapons with inventory SheeppOSU 3 2,950 Apr-29-2019, 02:31 AM
Last Post: SheeppOSU
  Problems with loading buttons (pygame) SheeppOSU 2 3,181 Apr-12-2019, 08:04 PM
Last Post: SheeppOSU
  Buttons in PyGame mzmingle 4 13,155 Oct-09-2018, 05:19 PM
Last Post: Mekire
  Menus, buttons and other widgets for Pygame Olleus 4 11,573 Apr-17-2017, 11:08 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020