Commit 6a1dc4b2 authored by Tošner, Jan's avatar Tošner, Jan
Browse files

v1.2

- doladěny všechny mouchy se změnou rozlišení
parent cf649e4c
......@@ -7,8 +7,9 @@ from tkinter.filedialog import askopenfilename, asksaveasfilename
# Size of the screen
SCREEN_TITLE = "Map Maker"
SCREEN_WIDTH = 1920
SCREEN_HEIGHT = 1080
SCREEN_WIDTH = 1920 #Change this
SCREEN_HEIGHT = 1080 #Change this
RATIO = (1920/SCREEN_WIDTH,1080/SCREEN_HEIGHT)
os.environ['SDL_VIDEO_WINDOW_POS'] = "0,0"
# Colors according to RGB codes
WHITE_COLOR = (255, 255, 255)
......@@ -18,10 +19,13 @@ MAXIMAL_ZOOM = 3.5
clock = pygame.time.Clock()
pygame.font.init()
font = pygame.font.SysFont("Sans", 75)
level_font = pygame.font.SysFont("Sans", 25)
ctypes.windll.user32.SetProcessDPIAware()
def scale(surf):
return pygame.transform.scale(surf, (SCREEN_WIDTH, SCREEN_HEIGHT))
class Game:
# Typical rate of 60, equivalent to FPS
TICK_RATE = 60
......@@ -49,6 +53,7 @@ class Game:
picture = Picture()
moving = False
selected = -1
changed = True
while running:
......@@ -56,27 +61,36 @@ class Game:
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
in_menu = not in_menu
changed = True
if event.key == pygame.K_TAB and not in_menu:
in_book = not in_book
changed = True
elif event.type == pygame.MOUSEBUTTONDOWN:
x, y = pygame.mouse.get_pos()
l, m, r = pygame.mouse.get_pressed()
x *= RATIO[0]
y *= RATIO[1]
if in_menu and l == 1:
# Cross
if 1165 < x < 1165 + 75 and 160 < y < 160 + 75:
in_menu = False
changed = True
# Save
if 789 < x < 789 + 342 and 311 < y < 311 + 135:
in_menu = False
Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
path = asksaveasfilename(title = "Select file",defaultextension=".png", filetypes=(("PNG (*.png)", "*.png"),("All Files", "*.*") )) # show an "Open" dialog box and return the path to the selected file
picture.save(path)
if path:
in_menu = False
changed = True
picture.save(path)
# Load
if 789 < x < 789 + 342 and 473 < y < 473 + 135:
in_menu = False
Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
path = askopenfilename(title = "Select file",defaultextension=".png", filetypes=(("PNG (*.png)", "*.png"),("All Files", "*.*") )) # show an "Open" dialog box and return the path to the selected file
picture.load(path)
if path:
in_menu = False
changed = True
picture.load(path)
# Vypnout program
if 789 < x < 789 + 342 and 635 < y < 635 + 135:
running = False
......@@ -85,29 +99,33 @@ class Game:
if 330 < x < 330 + 42 and 890 < y < 890 + 63:
if book.page != 0:
book.page += -2
changed = True
#Doprava
elif 1530 < x < 1530 + 42 and 890 < y < 890 + 63:
if book.page + 2 < (len(book.blocks)+14)//15:
book.page += 2
changed = True
#Reload
elif 287 < x < 287 + 75 and 38 < y < 38 +75:
book.load()
changed = True
else:
selected = book.select(x, y)
elif not in_menu and not in_book:
if event.button == 4:
if picture.extend <= MAXIMAL_ZOOM:
if picture.extend != MAXIMAL_ZOOM:
picture.extend += 0.5
picture.moveext(x, y, True)
changed = True
elif event.button == 5:
if picture.extend <= 1:
picture.extend = 1
else:
if picture.extend != 1:
picture.extend -= 0.5
picture.moveext(x, y, False)
changed = True
elif l == 1:
if selected >= 0:
picture.put(book.blocks[selected], (x, y))
picture.put(book.blocks[selected], (x * (1/RATIO[0]), y * (1/RATIO[1])))
changed = True
if m == 1:
pygame.mouse.get_rel()
moving = True
......@@ -117,20 +135,24 @@ class Game:
moving = False
if moving and not in_menu and not in_book:
picture.move(pygame.mouse.get_rel())
picture.print(self.screen)
#self.screen.blit(self.image, (0, 0)) #Přidání rámečku
changed = True
if selected != -1 and not in_book and not in_menu:
picture.preview(book.blocks[selected], pygame.mouse.get_pos())
if picture.preview(book.blocks[selected], pygame.mouse.get_pos(), changed):
changed = True
else:
picture.stop_preview()
if in_book:
book.draw(self.screen)
if changed:
changed = False
picture.print(self.screen)
#self.screen.blit(self.image, (0, 0)) #Přidání rámečku
if in_book:
book.draw(self.screen)
if in_menu:
menu.draw(self.screen)
if in_menu:
menu.draw(self.screen)
# Update all game graphics
pygame.display.update()
......@@ -147,9 +169,10 @@ class Picture:
self.ratio = ((SCREEN_WIDTH/self.pic.get_width()), (SCREEN_HEIGHT/self.pic.get_height()))
self.pic.fill(WHITE_COLOR)
self.shown = self.pic.copy()
self.last_cord = (-1, -1)
def scale(self):
return pygame.transform.scale(self.shown, (int(SCREEN_WIDTH * self.extend), int(SCREEN_HEIGHT * self.extend)))
def scale(self, pic):
return pygame.transform.scale(pic, (int(SCREEN_WIDTH * self.extend), int(SCREEN_HEIGHT * self.extend)))
def load(self, path):
self.pic = pygame.image.load(path)
......@@ -178,7 +201,7 @@ class Picture:
self.pos = (0, 0)
def print(self, screen):
self.surf.blit(self.scale(), self.pos)
self.surf.blit(self.shown, self.pos)
screen.blit(self.surf, (0, 0))
def moveext(self, x, y, zoom): #zoom = true -> making bigger; false -> making smaller
......@@ -194,22 +217,29 @@ class Picture:
pygame.image.save(self.pic, path)
def put(self, img, cord):
x, y = cord
xp, yp = self.pos
cord = (((x - xp)//(16 * self.ratio[0] * self.extend))*16, ((y - yp)//(16 * self.ratio[0] * self.extend))*16)
img.draw(self.pic, cord)
self.shown = self.pic.copy()
def preview(self, img, cord):
self.shown = self.pic.copy()
x, y = cord
xp, yp = self.pos
cord = (((x - xp)//(16 * self.ratio[0] * self.extend))*16, ((y - yp)//(16 * self.ratio[1] * self.extend))*16)
img.draw(self.shown, cord)
img.draw(self.pic, cord)
self.shown = self.scale(self.pic)
def preview(self, img, cord, changed):
if self.last_cord != (cord[0]//16*self.extend, cord[1]//16*self.extend):
self.last_cord = cord
x, y = cord
xp, yp = self.pos
cord = (((x - xp)//(16 * self.ratio[0] * self.extend))*16, ((y - yp)//(16 * self.ratio[1] * self.extend))*16)
#if self.last_cord != cord or changed:
self.shown = self.pic.copy()
img.draw(self.shown, cord)
self.shown = self.scale(self.shown)
ret = True
else:
ret = False
return ret
def stop_preview(self):
self.shown = self.pic.copy()
self.shown = self.scale(self.pic)
class Menu:
......@@ -221,19 +251,22 @@ class Menu:
self.button3 = pygame.image.load("images/GUI/plank_15.png")
self.cross = pygame.image.load("images/GUI/cross.png")
self.cross = pygame.transform.scale(self.cross, (75,75))
self.surf = pygame.Surface((1920, 1080), pygame.SRCALPHA, 32)
self.surf = self.surf.convert_alpha()
def draw(self, screen):
screen.blit(self.background, (704, 184))
screen.blit(self.button1, (789, 311))
screen.blit(self.cross, (1165, 160))
self.surf.blit(self.background, (704, 184))
self.surf.blit(self.button1, (789, 311))
self.surf.blit(self.cross, (1165, 160))
text = font.render("Uložit", True, BLACK_COLOR)
screen.blit(text, (880, 336))
screen.blit(self.button2, (789, 473))
self.surf.blit(text, (880, 336))
self.surf.blit(self.button2, (789, 473))
text = font.render("Načíst", True, BLACK_COLOR)
screen.blit(text, (872, 498))
screen.blit(self.button3, (789, 635))
self.surf.blit(text, (872, 498))
self.surf.blit(self.button3, (789, 635))
text = font.render("Vypnout", True, BLACK_COLOR)
screen.blit(text, (847, 660))
self.surf.blit(text, (847, 660))
screen.blit(scale(self.surf), (0, 0))
class Book:
......@@ -251,14 +284,17 @@ class Book:
self.cords = [(300,100)]
self.blocks = []
self.load()
self.surf = pygame.Surface((1920, 1080), pygame.SRCALPHA, 32)
self.surf = self.surf.convert_alpha()
def draw(self, screen):
screen.blit(self.book, (278, 27))
self.draw_icons(screen, self.page)
self.draw_icons(screen, self.page+1)
screen.blit(self.left, (330, 890))
screen.blit(self.right, (1530, 890))
screen.blit(self.reload, (287, 38))
self.surf.blit(self.book, (278, 27))
self.draw_icons(self.surf, self.page)
self.draw_icons(self.surf, self.page+1)
self.surf.blit(self.left, (330, 890))
self.surf.blit(self.right, (1530, 890))
self.surf.blit(self.reload, (287, 38))
screen.blit(scale(self.surf), (0, 0))
def draw_icons(self, screen, page):
for i in range(5):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment