tiptop gui
This commit is contained in:
parent
9d37e2464c
commit
183be3d5b3
3 changed files with 79 additions and 35 deletions
Binary file not shown.
14
button.py
14
button.py
|
@ -1,8 +1,8 @@
|
||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
class Button():
|
class Button():
|
||||||
def __init__(self, screen, color, x, y, width, height, text) -> None:
|
def __init__(self, screen, color, pos, width, height, text) -> None:
|
||||||
self.pos = x,y
|
self.pos = pos
|
||||||
self.größe = width,height
|
self.größe = width,height
|
||||||
self.color = color
|
self.color = color
|
||||||
self.screen = screen
|
self.screen = screen
|
||||||
|
@ -15,8 +15,16 @@ class Button():
|
||||||
self.größe[0],
|
self.größe[0],
|
||||||
self.größe[1])
|
self.größe[1])
|
||||||
)
|
)
|
||||||
|
pygame.draw.rect(self.screen,
|
||||||
|
(0,150,0),
|
||||||
|
(self.pos[0]-self.größe[0]//2,
|
||||||
|
self.pos[1]-self.größe[1]//2,
|
||||||
|
self.größe[0],
|
||||||
|
self.größe[1]),
|
||||||
|
2
|
||||||
|
)
|
||||||
|
|
||||||
font = pygame.font.Font(None, 36)
|
font = pygame.font.Font(None, 30)
|
||||||
text_surface = font.render(self.text, True, (0,0,0))
|
text_surface = font.render(self.text, True, (0,0,0))
|
||||||
text_rect = text_surface.get_rect()
|
text_rect = text_surface.get_rect()
|
||||||
text_rect.center = (self.pos[0],
|
text_rect.center = (self.pos[0],
|
||||||
|
|
100
main.py
100
main.py
|
@ -35,8 +35,9 @@ def draw_feld(feld, color_key, block_size):
|
||||||
(a * block_size, b * block_size, block_size, block_size),
|
(a * block_size, b * block_size, block_size, block_size),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def verarbeite_feld(feld):
|
def verarbeite_feld(feld):
|
||||||
feldx,feldy = len(feld[0]),len(feld)
|
feldx, feldy = len(feld[0]), len(feld)
|
||||||
feld2 = copy.deepcopy(feld)
|
feld2 = copy.deepcopy(feld)
|
||||||
for y in range(len(feld)):
|
for y in range(len(feld)):
|
||||||
for x in range(len(feld[0])):
|
for x in range(len(feld[0])):
|
||||||
|
@ -84,12 +85,26 @@ default_font = pygame.font.SysFont("sans", 14)
|
||||||
display_mode = "border"
|
display_mode = "border"
|
||||||
feld, feldx, feldy = make_feld(20, display_mode)
|
feld, feldx, feldy = make_feld(20, display_mode)
|
||||||
|
|
||||||
acolor = (255, 0, 0)
|
|
||||||
wechselfarbe = "r"
|
|
||||||
using_element = "a"
|
using_element = "a"
|
||||||
pixelsize = 20
|
pixelsize = 20
|
||||||
|
button_abstandy = 30
|
||||||
|
|
||||||
buttons = [Button(screen,(200,200,200),100,100,30,30,"*")]
|
buttons = [
|
||||||
|
Button(screen, (200, 200, 200), (screensize[0] - 70, 50), 25, 25, "\/"),
|
||||||
|
Button(screen, (200, 200, 200), (screensize[0] - 70, 50), 100, 25, "Debug"),
|
||||||
|
Button(screen, (200, 200, 200), (screensize[0] - 70, 50), 100, 25, "Reset"),
|
||||||
|
Button(screen, (200, 200, 200), (screensize[0] - 70, 50), 100, 25, "Element"),
|
||||||
|
Button(screen, (200, 200, 200), (screensize[0] - 70, 50), 100, 25, "Zoom +"),
|
||||||
|
Button(screen, (200, 200, 200), (screensize[0] - 70, 50), 100, 25, "Zoom -"),
|
||||||
|
]
|
||||||
|
buttona = {"dropdown": 0, "debug": 1, "reset": 2, "element": 3, "plus": 4, "minus": 5}
|
||||||
|
for i, button in enumerate(buttons):
|
||||||
|
i += 1
|
||||||
|
button.pos = (screensize[0] - 70, button_abstandy * i)
|
||||||
|
buttonhovered = [False, False, False, False, False, False]
|
||||||
|
buttons_to_render = 6
|
||||||
|
dropdown = True
|
||||||
|
preview_buttonhovered = False
|
||||||
show_debug = False
|
show_debug = False
|
||||||
running = True
|
running = True
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
@ -118,6 +133,9 @@ if __name__ == "__main__":
|
||||||
else:
|
else:
|
||||||
display_mode = "border"
|
display_mode = "border"
|
||||||
feld, feldx, feldy = make_feld(pixelsize, display_mode)
|
feld, feldx, feldy = make_feld(pixelsize, display_mode)
|
||||||
|
for i, button in enumerate(buttons):
|
||||||
|
i += 1
|
||||||
|
button.pos = (screensize[0] - 70, button_abstandy * i)
|
||||||
|
|
||||||
preview_pressed_keys = pressed_keys
|
preview_pressed_keys = pressed_keys
|
||||||
## event managment
|
## event managment
|
||||||
|
@ -127,43 +145,61 @@ if __name__ == "__main__":
|
||||||
if event.type == pygame.WINDOWRESIZED:
|
if event.type == pygame.WINDOWRESIZED:
|
||||||
screensize = pygame.display.get_window_size()
|
screensize = pygame.display.get_window_size()
|
||||||
feld, feldx, feldy = make_feld(pixelsize, display_mode)
|
feld, feldx, feldy = make_feld(pixelsize, display_mode)
|
||||||
r, g, b = acolor
|
for i, button in enumerate(buttons):
|
||||||
if wechselfarbe == "r":
|
i += 1
|
||||||
r -= 1
|
button.pos = (screensize[0] - 70, button_abstandy * i)
|
||||||
g += 1
|
color_key = {"#": (100, 100, 100), "a": (200,200,80)}
|
||||||
if r == 0:
|
|
||||||
wechselfarbe = "g"
|
|
||||||
if wechselfarbe == "g":
|
|
||||||
g -= 1
|
|
||||||
b += 1
|
|
||||||
if g == 0:
|
|
||||||
wechselfarbe = "b"
|
|
||||||
if wechselfarbe == "b":
|
|
||||||
b -= 1
|
|
||||||
r += 1
|
|
||||||
if b == 0:
|
|
||||||
wechselfarbe = "r"
|
|
||||||
acolor = r, g, b
|
|
||||||
color_key = {"#": (100, 100, 100), "a": acolor}
|
|
||||||
draw_feld(feld, color_key, pixelsize)
|
draw_feld(feld, color_key, pixelsize)
|
||||||
|
|
||||||
mx, my = pygame.mouse.get_pos()
|
mx, my = pygame.mouse.get_pos()
|
||||||
mousepressed = pygame.mouse.get_pressed()[0]
|
mousepressed = pygame.mouse.get_pressed()[0]
|
||||||
for button in buttons:
|
|
||||||
button.draw()
|
|
||||||
|
|
||||||
if mousepressed:
|
|
||||||
for button in buttons:
|
|
||||||
if button.check_press((mx,my)):
|
|
||||||
show_debug = not show_debug
|
|
||||||
else:
|
|
||||||
feld[my // pixelsize][mx // pixelsize] = using_element
|
|
||||||
|
|
||||||
|
for button in buttons[:buttons_to_render]:
|
||||||
|
button.draw()
|
||||||
|
|
||||||
|
if mousepressed:
|
||||||
|
for i, button in enumerate(buttons[:buttons_to_render]):
|
||||||
|
if button.check_press((mx, my)):
|
||||||
|
buttonhovered[i] = True
|
||||||
|
else:
|
||||||
|
buttonhovered[i] = False
|
||||||
|
if not True in buttonhovered:
|
||||||
|
feld[my // pixelsize][mx // pixelsize] = using_element
|
||||||
|
|
||||||
|
if mousepressed and not preview_mousepressed:
|
||||||
|
if buttonhovered[buttona["dropdown"]]:
|
||||||
|
dropdown = not dropdown
|
||||||
|
if dropdown:
|
||||||
|
buttons_to_render = len(buttons)
|
||||||
|
buttons[buttona["dropdown"]].text = "\/"
|
||||||
|
else:
|
||||||
|
buttons_to_render = 1
|
||||||
|
buttons[buttona["dropdown"]].text = "/\\"
|
||||||
|
if buttonhovered[buttona["debug"]]:
|
||||||
|
show_debug = not show_debug
|
||||||
|
if buttonhovered[buttona["reset"]]:
|
||||||
|
if display_mode == "border":
|
||||||
|
display_mode = "loop"
|
||||||
|
else:
|
||||||
|
display_mode = "border"
|
||||||
|
feld, feldx, feldy = make_feld(pixelsize, display_mode)
|
||||||
|
if buttonhovered[buttona["plus"]]:
|
||||||
|
pixelsize += 2
|
||||||
|
feld, feldx, feldy = make_feld(pixelsize, display_mode)
|
||||||
|
if buttonhovered[buttona["minus"]]:
|
||||||
|
pixelsize -= 2
|
||||||
|
feld, feldx, feldy = make_feld(pixelsize, display_mode)
|
||||||
|
if buttonhovered[buttona["element"]]:
|
||||||
|
if using_element == "a":
|
||||||
|
using_element = "#"
|
||||||
|
else:
|
||||||
|
using_element = "a"
|
||||||
|
preview_buttonhovered = buttonhovered
|
||||||
preview_mousepressed = pygame.mouse.get_pressed()[0]
|
preview_mousepressed = pygame.mouse.get_pressed()[0]
|
||||||
feld = verarbeite_feld(feld)
|
feld = verarbeite_feld(feld)
|
||||||
if show_debug:
|
if show_debug:
|
||||||
get_debug_text()
|
get_debug_text()
|
||||||
## bildschirm aktuallisierung
|
## bildschirm aktuallisierung
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
clock.tick(30)
|
clock.tick(60)
|
||||||
screen.fill((0, 0, 0))
|
screen.fill((0, 0, 0))
|
||||||
|
|
Loading…
Reference in a new issue