tweaked disarm popup, mainly fixed picture blitting
This commit is contained in:
parent
70fb44f69e
commit
2daf6a2f6b
@ -1,8 +1,8 @@
|
||||
|
||||
import pygame
|
||||
import pygame_gui
|
||||
|
||||
from project_constants import SCREEN_WIDTH, SCREEN_HEIGHT, V_NAME_OF_WINDOW
|
||||
from assets.asset_constants import ASSET_CONCRETE
|
||||
from objects.mine_models.mine import Mine
|
||||
from disarming.disarming_handler import DisarmingHandler
|
||||
|
||||
@ -278,6 +278,16 @@ class SampleWindow:
|
||||
manager=self.manager,
|
||||
object_id="empty_field"
|
||||
)
|
||||
surf = pygame.Surface(size_image)
|
||||
surf.fill((20, 20, 20))
|
||||
pygame_gui.elements.UIImage(
|
||||
image_surface=surf,
|
||||
relative_rect=pygame.Rect(
|
||||
(x_image1, y_image),
|
||||
size_image
|
||||
),
|
||||
manager=self.manager
|
||||
)
|
||||
|
||||
def image2():
|
||||
pygame_gui.elements.UILabel(
|
||||
@ -317,6 +327,16 @@ class SampleWindow:
|
||||
manager=self.manager,
|
||||
object_id="empty_field"
|
||||
)
|
||||
surf = pygame.Surface(size_image)
|
||||
surf.fill((20, 20, 20))
|
||||
pygame_gui.elements.UIImage(
|
||||
image_surface=surf,
|
||||
relative_rect=pygame.Rect(
|
||||
(x_image2, y_image),
|
||||
size_image
|
||||
),
|
||||
manager=self.manager
|
||||
)
|
||||
|
||||
params_desc()
|
||||
params_values()
|
||||
@ -393,25 +413,32 @@ class SampleWindow:
|
||||
object_id="field"
|
||||
)
|
||||
|
||||
def show_pic_series(self, pic: pygame.Surface):
|
||||
def blit_pic(self, x_image, pic):
|
||||
|
||||
# initializing surface with background
|
||||
surf = pygame.Surface(size_image)
|
||||
surf.blit(pygame.transform.scale(pic, size_image), (0, 0))
|
||||
pygame_gui.elements.UIImage(
|
||||
image_surface=surf,
|
||||
relative_rect=pygame.Rect(
|
||||
(x_image1, y_image),
|
||||
size_image
|
||||
),
|
||||
manager=self.manager
|
||||
surf.fill((20, 20, 20))
|
||||
|
||||
# scaling size & coords
|
||||
bigger = max(pic.get_size()[0], pic.get_size()[1])
|
||||
scaling_factor = (height_image - 10) / bigger
|
||||
|
||||
length_pic = int(pic.get_size()[0]*scaling_factor)
|
||||
height_pic = int(pic.get_size()[1]*scaling_factor)
|
||||
size_pic = (length_pic, height_pic)
|
||||
|
||||
coords_pic = (
|
||||
int((length_image-length_pic) / 2),
|
||||
int((height_image-height_pic) / 2)
|
||||
)
|
||||
|
||||
def show_pic_spec(self, pic: pygame.Surface):
|
||||
surf = pygame.Surface(size_image)
|
||||
surf.blit(pygame.transform.scale(pic, size_image), (0, 0))
|
||||
# blitting the image onto background
|
||||
surf.blit(pygame.transform.scale(pic, size_pic), coords_pic)
|
||||
|
||||
pygame_gui.elements.UIImage(
|
||||
image_surface=surf,
|
||||
relative_rect=pygame.Rect(
|
||||
(x_image2, y_image),
|
||||
(x_image, y_image),
|
||||
size_image
|
||||
),
|
||||
manager=self.manager
|
||||
@ -505,7 +532,7 @@ class SampleWindow:
|
||||
|
||||
def run(self, mine: Mine):
|
||||
timed_event = pygame.USEREVENT + 1
|
||||
pygame.time.set_timer(timed_event, 5000)
|
||||
pygame.time.set_timer(timed_event, 1500)
|
||||
|
||||
step = 0
|
||||
handler = DisarmingHandler(mine)
|
||||
@ -515,39 +542,29 @@ class SampleWindow:
|
||||
time_delta = self.clock.tick(60) / 1000.0
|
||||
|
||||
for event in pygame.event.get():
|
||||
|
||||
if event.type == pygame.QUIT:
|
||||
self.running = False
|
||||
|
||||
if event.type == timed_event:
|
||||
if step == 0:
|
||||
if step == 0: # just the params
|
||||
params = handler.get_mine_params()
|
||||
self.show_params(params[0], params[1], params[2], params[3], params[4], params[5])
|
||||
elif step == 1:
|
||||
elif step == 1: # correct cable
|
||||
self.show_cable_calculated(handler.correct_wire)
|
||||
elif step == 2:
|
||||
|
||||
# TODO:
|
||||
img = pygame.transform.scale(
|
||||
pygame.image.load(handler.pick_series_image()),
|
||||
(1080, 1080)
|
||||
)
|
||||
|
||||
self.show_pic_series(img)
|
||||
elif step == 3:
|
||||
|
||||
# TODO:
|
||||
img = pygame.transform.scale(
|
||||
pygame.image.load(handler.pick_specificity_image()),
|
||||
(60, 60)
|
||||
)
|
||||
|
||||
self.show_pic_spec(img)
|
||||
elif step == 4:
|
||||
elif step == 2: # loading the letter image
|
||||
img = pygame.image.load(handler.pick_series_image())
|
||||
self.blit_pic(x_image1, img)
|
||||
elif step == 3: # recognising the letter
|
||||
answer, is_correct = handler.recognize_series()
|
||||
self.show_series(answer, is_correct)
|
||||
elif step == 5:
|
||||
elif step == 4: # loading spec image
|
||||
img = pygame.image.load(handler.pick_specificity_image())
|
||||
self.blit_pic(x_image2, img)
|
||||
elif step == 5: # recognising spec image
|
||||
answer, is_correct = handler.recognize_specificity()
|
||||
self.show_spec(answer, is_correct)
|
||||
elif step == 6:
|
||||
elif step == 6: # showing the chosen cable
|
||||
self.show_cable_chosen(handler.choose_wire())
|
||||
else:
|
||||
self.running = False
|
||||
|
Loading…
Reference in New Issue
Block a user