Apr-25-2019, 09:20 PM
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
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)