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