2021-05-24 13:10:10 +02:00
|
|
|
import pygame.font
|
|
|
|
|
|
|
|
from survival import settings
|
|
|
|
from survival.components.inventory_component import InventoryComponent
|
2021-05-24 17:20:08 +02:00
|
|
|
from survival.generators.resource_type import ResourceType
|
2021-05-24 13:10:10 +02:00
|
|
|
from survival.image import Image
|
|
|
|
|
|
|
|
|
|
|
|
class UserInterface:
|
2021-06-06 19:55:55 +02:00
|
|
|
def __init__(self, window):
|
2021-05-24 13:10:10 +02:00
|
|
|
self.width = settings.SCREEN_WIDTH
|
|
|
|
self.height = settings.SCREEN_HEIGHT
|
|
|
|
self.window = window
|
|
|
|
self.pos = (self.width - 240, 50)
|
|
|
|
self.scale = 2
|
2021-06-06 19:55:55 +02:00
|
|
|
self.inventory: InventoryComponent = None
|
2021-05-24 13:10:10 +02:00
|
|
|
self.images = {
|
|
|
|
ResourceType.FOOD: Image('apple.png', self.pos, self.scale),
|
|
|
|
ResourceType.WATER: Image('water.png', self.pos, self.scale),
|
|
|
|
ResourceType.WOOD: Image('wood.png', self.pos, self.scale)
|
|
|
|
}
|
|
|
|
i = 0
|
|
|
|
for key, value in self.images.items():
|
|
|
|
self.images[key].pos = (self.pos[0] + i * 32 * self.scale + 8 * i, self.pos[1])
|
|
|
|
i += 1
|
|
|
|
self.slot_image = Image('ui.png', self.pos, scale=2)
|
|
|
|
self.font = pygame.font.SysFont('Comic Sans MS', 20)
|
|
|
|
|
2021-06-06 19:55:55 +02:00
|
|
|
def load_inventory(self, inventory: InventoryComponent):
|
|
|
|
self.inventory = inventory
|
|
|
|
|
2021-05-24 13:10:10 +02:00
|
|
|
def update(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def draw(self):
|
|
|
|
for key, image in self.images.items():
|
|
|
|
items_count = self.inventory.items[key] if self.inventory.has_item(key) else 0
|
|
|
|
|
|
|
|
self.slot_image.pos = image.pos
|
|
|
|
self.slot_image.draw_static(self.window)
|
|
|
|
image.draw_static(self.window)
|
|
|
|
|
|
|
|
textsurface = self.font.render(str(items_count), False, (255, 255, 255))
|
|
|
|
self.window.blit(textsurface, (image.pos[0] + 48, image.pos[1] + 36))
|
|
|
|
|