Commit 6c2ce309 authored by captnfab's avatar captnfab 🦃
Browse files

Cleaning + stat display bugfix

parent c241578d
......@@ -554,33 +554,29 @@ class GuiCredits:
class GuiSelection:
def __init__(self, rnd):
bg = pygame.Surface((WIDTH, HEIGHT))
bg.fill(DARKGRAY)
pygame.draw.line(
bg,
WHITE,
(bg.get_width()//2, int(HEIGHT*0.05)),
(bg.get_width()//2, int(HEIGHT*0.80)),
)
self.rnd = rnd
skullhead_center = (
WIDTH//4,
HEIGHT//4,
)
skullhead_size = int(bg.get_width()*0.3)
# Precompute background
self.bg = pygame.Surface((WIDTH, HEIGHT))
self.bg.fill(DARKGRAY)
pygame.draw.line(self.bg, WHITE, (WIDTH//2, int(HEIGHT*0.05)), (WIDTH//2, int(HEIGHT*0.80)))
# Some alpha magic needed because convert alpha breaks set_alpha
skullhead_center = (WIDTH//4, HEIGHT//4)
skullhead_size = int(WIDTH*0.3)
skullhead_raw = pygame.image.load("gfx/skullhead.png").convert_alpha()
skullhead_raw = pygame.transform.smoothscale(skullhead_raw, (skullhead_size, skullhead_size))
skullhead = pygame.Surface(skullhead_raw.get_size()).convert()
skullhead.fill(DARKGRAY)
skullhead.blit(skullhead_raw, (0, 0))
skullhead.set_alpha(80)
skullhead_rect = skullhead.get_rect()
skullhead_rect.center = skullhead_center
bg.blit(skullhead, skullhead_rect)
self.bg = bg
self.bg.blit(skullhead, skullhead_rect)
# Precompute menu
self.menu_next = pygame.image.load("gfx/button_next.png").convert_alpha()
self.menu_next = pygame.transform.smoothscale(self.menu_next, (50, 50))
self.menu_next_hover = pygame.image.load("gfx/button_next_hover.png").convert_alpha()
......@@ -618,14 +614,8 @@ class GuiSelection:
#("Damien Monbars", "bill-wright", "Damien Monbars, dit Monbars l'exterminateur, est un pirate Français du XVIIe siècle qui attaquait les bateaux espagnols afin de venger le peuple indien et les esclaves noirs."),
]
charmenu_center = (
int(WIDTH * 0.25),
int(HEIGHT * 0.65),
)
portrait_center = (
int(WIDTH * 0.75),
int(HEIGHT * 0.5),
)
charmenu_center = (int(WIDTH * 0.25), int(HEIGHT * 0.65))
portrait_center = (int(WIDTH * 0.75), int(HEIGHT * 0.5))
portrait_size = int(WIDTH * 0.5)
charname_font = pygame.font.Font(FONT, 40)
......@@ -633,7 +623,8 @@ class GuiSelection:
descr_width = 50
self.charmenu_items = []
maxwidth,maxheight=0,0
cmaxwidth,cmaxheight=0,0
dmaxwidth,dmaxheight=0,0
for (n,(name, slug, descr)) in enumerate(characters):
charname = charname_font.render(name, 1, WHITE)
crect = charname.get_rect()
......@@ -646,39 +637,50 @@ class GuiSelection:
prect = portrait.get_rect()
prect.center = portrait_center
self.charmenu_items.append((n, charname, crect, portrait, prect, chardescr))
if crect.width > maxwidth:
maxwidth=crect.width
if crect.height > maxheight:
maxheight=crect.height
self.charmenu_rect = pygame.Rect(0, 0, maxwidth, maxheight)
if crect.width > cmaxwidth:
caxwidth=crect.width
if crect.height > cmaxheight:
cmaxheight=crect.height
s = sum([line.get_height() for line in chardescr])
if s > dmaxheight:
dmaxheight=s
m = max([line.get_width() for line in chardescr])
if m > dmaxwidth:
dmaxwidth=m
self.charmenu_rect = pygame.Rect(0, 0, cmaxwidth, cmaxheight)
self.charmenu_rect.center = charmenu_center
self.charmenu_drect = pygame.Rect(0, 0, dmaxwidth, dmaxheight)
self.charmenu_drect.midtop = self.charmenu_rect.midbottom
self.charmenu_drect.top += 15
self.reset()
def reset(self):
self.charmenu_index = 0
def update(self, rnd, params):
pass
def draw(self, s):
update_rects = []
# Draw background
s.blit(self.bg, (0, 0))
update_rects.append(s.get_rect())
for (n, charname, crect, portrait, prect, chardescr) in self.charmenu_items:
if self.charmenu_index == n:
s.blit(charname, crect)
update_rects.append(self.charmenu_rect)
x,y = crect.midbottom
midbottom = x,y+15
midbottom = self.charmenu_drect.midtop
for line in chardescr:
rect = line.get_rect()
rect.midtop = midbottom
midbottom = rect.midbottom
s.blit(line, rect)
s.blit(portrait, prect)
update_rects.append(portrait.get_rect())
update_rects.append(prect)
update_rects.append(self.charmenu_rect)
update_rects.append(self.charmenu_drect)
s.blit(self.menu_label, self.menu_label_rect)
......@@ -699,9 +701,6 @@ class GuiSelection:
return update_rects
def update(self, rnd, params):
pass
def input(self, event, rnd):
if event.type == pygame.MOUSEBUTTONDOWN:
if self.menu_next_rect.collidepoint(event.pos):
......@@ -1405,7 +1404,7 @@ class GuiBattleShips:
else:
x,y = WIDTH-20,HEIGHT-20
counts = [len(other.miss) + len(other.hits), len(other.miss), len(other.hits), len(other.sunk)]
counts = [len(other.sunk), len(other.hits), len(other.miss), len(other.miss) + len(other.hits)]
labels_counts = [self.font_stats.render(str(c), 1, BLACK) for c in counts]
counts_width = self.font_stats.render("100", 1, BLACK).get_width()
......
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