77 lines
2.0 KiB
Python
77 lines
2.0 KiB
Python
import pygame
|
|
import sys
|
|
|
|
class Button:
|
|
def __init__(self, x, y, w, h, text, callback):
|
|
self.rect = pygame.Rect(x, y, w, h)
|
|
self.text = text
|
|
self.callback = callback
|
|
|
|
def handle_event(self, event):
|
|
if event.type == pygame.MOUSEBUTTONDOWN:
|
|
if self.rect.collidepoint(event.pos):
|
|
self.callback()
|
|
|
|
def draw(self, screen):
|
|
pygame.draw.rect(screen, (255, 255, 255), self.rect)
|
|
font = pygame.font.Font(None, 36)
|
|
text_surf = font.render(self.text, True, (0, 0, 0))
|
|
screen.blit(text_surf, (self.rect.x + 10, self.rect.y + 10))
|
|
|
|
class Screen:
|
|
def __init__(self):
|
|
self.buttons = []
|
|
|
|
def handle_event(self, event):
|
|
for button in self.buttons:
|
|
button.handle_event(event)
|
|
|
|
def draw(self, screen):
|
|
for button in self.buttons:
|
|
button.draw(screen)
|
|
|
|
class Screen0(Screen):
|
|
def __init__(self, screens):
|
|
super().__init__()
|
|
self.buttons.append(Button(50, 50, 200, 100, "Create Item", lambda: screens.set_current("Screen1")))
|
|
self.buttons.append(Button(50, 200, 200, 100, "Lookup Item", lambda: screens.set_current("Screen14")))
|
|
|
|
# ... other screens ...
|
|
|
|
class Screens:
|
|
def __init__(self):
|
|
self.screens = {
|
|
"Screen0": Screen0(self),
|
|
# ... other screens ...
|
|
}
|
|
self.current = self.screens["Screen0"]
|
|
|
|
def set_current(self, name):
|
|
self.current = self.screens[name]
|
|
|
|
def handle_event(self, event):
|
|
self.current.handle_event(event)
|
|
|
|
def draw(self, screen):
|
|
self.current.draw(screen)
|
|
|
|
def main():
|
|
pygame.init()
|
|
screen = pygame.display.set_mode((1366, 768))
|
|
screens = Screens()
|
|
|
|
while True:
|
|
for event in pygame.event.get():
|
|
if event.type == pygame.QUIT:
|
|
pygame.quit()
|
|
sys.exit()
|
|
screens.handle_event(event)
|
|
|
|
screen.fill((0, 0, 0))
|
|
screens.draw(screen)
|
|
pygame.display.flip()
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|