551 lines
18 KiB
Python
551 lines
18 KiB
Python
import pygame
|
|
import pygame_gui
|
|
from project_constants import SCREEN_WIDTH, SCREEN_HEIGHT, V_NAME_OF_WINDOW
|
|
from assets.asset_constants import ASSET_CONCRETE
|
|
|
|
|
|
# =========== #
|
|
# == const == #
|
|
# =========== #
|
|
|
|
# main heights and lengths
|
|
gap_main = 20
|
|
gap_elem = 10
|
|
height_label = 24
|
|
height_cable_double_label = 2 * height_label + gap_elem
|
|
length_param_desc = 120
|
|
length_param_values = 250
|
|
length_cables = 250
|
|
# main heights and lengths
|
|
|
|
# frame, image and image labels
|
|
length_frame = length_param_desc + gap_elem + length_param_values + 3 * gap_main + length_cables
|
|
length_image = int((length_frame - 3 * gap_main) / 2)
|
|
height_image = length_image
|
|
height_frame = 6 * height_label + 5 * gap_elem + height_image + 2 * height_label + 2 * gap_elem + 3 * gap_main
|
|
screen_size = (int(length_frame), int(height_frame))
|
|
length_label_image = int((length_image - gap_elem) / 2)
|
|
# frame, image and image labels
|
|
|
|
# sizes
|
|
size_label_param_desc = (length_param_desc, height_label)
|
|
size_label_param_values = (length_param_values, height_label)
|
|
size_cable_label = (length_cables, height_label)
|
|
size_cable = (length_cables, height_cable_double_label)
|
|
size_image = (length_image, height_image)
|
|
size_light = (height_label, height_label)
|
|
size_label_image = (length_label_image, height_label)
|
|
# sizes
|
|
|
|
# y's
|
|
y_params1 = y_cables_label1 \
|
|
= gap_main
|
|
y_params2 = y_cable1 \
|
|
= y_params1 + gap_elem + height_label
|
|
y_params3 = y_params2 + gap_elem + height_label
|
|
y_params4 = y_cables_label2 \
|
|
= y_params3 + gap_elem + height_label
|
|
y_params5 = y_cable2 \
|
|
= y_params4 + gap_elem + height_label
|
|
y_params6 = y_params5 + gap_elem + height_label
|
|
y_image = y_params6 + gap_main + height_label
|
|
y_image_label1 = y_image + height_image + gap_elem
|
|
y_image_label2 = y_image_label1 + height_label + gap_elem
|
|
# y's
|
|
|
|
# x's
|
|
x_param_desc = x_image1 = x_image1_label1 \
|
|
= gap_main
|
|
x_image1_label2 = x_image1_label1 + length_label_image + gap_elem
|
|
x_param_values = x_param_desc + length_param_desc + gap_elem
|
|
x_param_values_after_light = x_param_values + gap_elem
|
|
x_cables = x_param_values + length_param_values + gap_main
|
|
x_image2 = x_image2_label1\
|
|
= x_image1 + length_image + gap_main
|
|
x_image2_label2 = x_image2_label1 + length_label_image + gap_elem
|
|
# x's
|
|
|
|
|
|
# =========== #
|
|
# == class == #
|
|
# =========== #
|
|
|
|
class SampleWindow:
|
|
|
|
def __init__(self):
|
|
|
|
# main attributes
|
|
self.running = True
|
|
self.clock = pygame.time.Clock()
|
|
self.manager = pygame_gui.UIManager(screen_size, 'theme.json') # TODO : change theme path
|
|
# main attributes
|
|
|
|
def gui():
|
|
|
|
def params_desc():
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_param_desc, y_params1),
|
|
size_label_param_desc
|
|
),
|
|
text="TYPE",
|
|
manager=self.manager,
|
|
object_id="description"
|
|
)
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_param_desc, y_params2),
|
|
size_label_param_desc
|
|
),
|
|
text="DANGER CLASS",
|
|
manager=self.manager,
|
|
object_id="description"
|
|
)
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_param_desc, y_params3),
|
|
size_label_param_desc
|
|
),
|
|
text="INDICATOR",
|
|
manager=self.manager,
|
|
object_id="description"
|
|
)
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_param_desc, y_params4),
|
|
size_label_param_desc
|
|
),
|
|
text="WEIGHT",
|
|
manager=self.manager,
|
|
object_id="description"
|
|
)
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_param_desc, y_params5),
|
|
size_label_param_desc
|
|
),
|
|
text="SERIES",
|
|
manager=self.manager,
|
|
object_id="description"
|
|
)
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_param_desc, y_params6),
|
|
size_label_param_desc
|
|
),
|
|
text="SPECIFICITY",
|
|
manager=self.manager,
|
|
object_id="description"
|
|
)
|
|
|
|
def params_values():
|
|
# type value
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_param_values, y_params1),
|
|
size_label_param_values
|
|
),
|
|
text="...",
|
|
manager=self.manager,
|
|
object_id="empty_field"
|
|
)
|
|
# danger class value
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_param_values, y_params2),
|
|
size_label_param_values
|
|
),
|
|
text="...",
|
|
manager=self.manager,
|
|
object_id="empty_field"
|
|
)
|
|
# indicator value
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_param_values, y_params3),
|
|
size_label_param_values
|
|
),
|
|
text="...",
|
|
manager=self.manager,
|
|
object_id="empty_field"
|
|
)
|
|
# weight value
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_param_values, y_params4),
|
|
size_label_param_values
|
|
),
|
|
text="...",
|
|
manager=self.manager,
|
|
object_id="empty_field"
|
|
)
|
|
# series value
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_param_values, y_params5),
|
|
size_label_param_values
|
|
),
|
|
text="...",
|
|
manager=self.manager,
|
|
object_id="empty_field"
|
|
)
|
|
# spec value
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_param_values, y_params6),
|
|
size_label_param_values
|
|
),
|
|
text="...",
|
|
manager=self.manager,
|
|
object_id="empty_field"
|
|
)
|
|
|
|
def cables():
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_cables, y_cables_label1),
|
|
size_cable_label
|
|
),
|
|
text="CORRECT CABLE",
|
|
manager=self.manager,
|
|
object_id="description"
|
|
)
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_cables, y_cables_label2),
|
|
size_cable_label
|
|
),
|
|
text="CHOSEN CABLE",
|
|
manager=self.manager,
|
|
object_id="description"
|
|
)
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_cables, y_cable1),
|
|
size_cable
|
|
),
|
|
text="...",
|
|
manager=self.manager,
|
|
object_id="empty_field"
|
|
)
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_cables, y_cable2),
|
|
size_cable
|
|
),
|
|
text="...",
|
|
manager=self.manager,
|
|
object_id="empty_field"
|
|
)
|
|
|
|
def image1():
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_image1_label1, y_image_label1),
|
|
size_label_image
|
|
),
|
|
text="CORRECT SERIES",
|
|
manager=self.manager,
|
|
object_id="description"
|
|
)
|
|
# correct series value
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_image1_label1, y_image_label2),
|
|
size_label_image
|
|
),
|
|
text="...",
|
|
manager=self.manager,
|
|
object_id="empty_field"
|
|
)
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_image1_label2, y_image_label1),
|
|
size_label_image
|
|
),
|
|
text="RECOGNISED SERIES",
|
|
manager=self.manager,
|
|
object_id="description"
|
|
)
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_image1_label2, y_image_label2),
|
|
size_label_image
|
|
),
|
|
text="...",
|
|
manager=self.manager,
|
|
object_id="empty_field"
|
|
)
|
|
|
|
def image2():
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_image2_label1, y_image_label1),
|
|
size_label_image
|
|
),
|
|
text="CORRECT SPEC",
|
|
manager=self.manager,
|
|
object_id="description"
|
|
)
|
|
# correct spec value
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_image2_label1, y_image_label2),
|
|
size_label_image
|
|
),
|
|
text="...",
|
|
manager=self.manager,
|
|
object_id="empty_field"
|
|
)
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_image2_label2, y_image_label1),
|
|
size_label_image
|
|
),
|
|
text="RECOGNISED SPEC",
|
|
manager=self.manager,
|
|
object_id="description"
|
|
)
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_image2_label2, y_image_label2),
|
|
size_label_image
|
|
),
|
|
text="...",
|
|
manager=self.manager,
|
|
object_id="empty_field"
|
|
)
|
|
|
|
params_desc()
|
|
params_values()
|
|
cables()
|
|
image1()
|
|
image2()
|
|
|
|
# frame basics
|
|
pygame.display.set_caption("disarming...")
|
|
self.window_surface = pygame.display.set_mode(screen_size)
|
|
self.background = pygame.Surface(screen_size)
|
|
self.background.fill(pygame.Color('#000000'))
|
|
|
|
# loading the gui
|
|
gui()
|
|
|
|
# ============= #
|
|
# == showing == #
|
|
# ============= #
|
|
|
|
def show_params(self, mine_type: str, weight: str, danger: str, indicator: str, series: str, spec: str):
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_param_values, y_params1),
|
|
size_label_param_values
|
|
),
|
|
text=mine_type,
|
|
manager=self.manager,
|
|
object_id="field"
|
|
)
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_param_values, y_params4),
|
|
size_label_param_values
|
|
),
|
|
text=weight,
|
|
manager=self.manager,
|
|
object_id="field"
|
|
)
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_param_values, y_params2),
|
|
size_label_param_values
|
|
),
|
|
text=danger,
|
|
manager=self.manager,
|
|
object_id="field"
|
|
)
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_param_values, y_params3),
|
|
size_label_param_values
|
|
),
|
|
text=indicator,
|
|
manager=self.manager,
|
|
object_id="field"
|
|
)
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_image1_label1, y_image_label2),
|
|
size_label_image
|
|
),
|
|
text=series,
|
|
manager=self.manager,
|
|
object_id="field"
|
|
)
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_image2_label1, y_image_label2),
|
|
size_label_image
|
|
),
|
|
text=spec,
|
|
manager=self.manager,
|
|
object_id="field"
|
|
)
|
|
|
|
def show_pic_series(self, pic: pygame.Surface):
|
|
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
|
|
)
|
|
|
|
def show_pic_spec(self, pic: pygame.Surface):
|
|
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_image2, y_image),
|
|
size_image
|
|
),
|
|
manager=self.manager
|
|
)
|
|
|
|
def show_series(self, series: str, correct: bool):
|
|
colour = "param_values_correct" if correct else "param_values_wrong"
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_param_values, y_params5),
|
|
size_label_param_values
|
|
),
|
|
text=series,
|
|
manager=self.manager,
|
|
object_id="field"
|
|
)
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_param_values, y_params5),
|
|
size_light
|
|
),
|
|
text="",
|
|
manager=self.manager,
|
|
object_id=colour
|
|
)
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_image1_label2, y_image_label2),
|
|
size_label_image
|
|
),
|
|
text=series,
|
|
manager=self.manager,
|
|
object_id=colour
|
|
)
|
|
|
|
def show_spec(self, spec: str, correct: bool):
|
|
colour = "param_values_correct" if correct else "param_values_wrong"
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_param_values, y_params6),
|
|
size_label_param_values
|
|
),
|
|
text=spec,
|
|
manager=self.manager,
|
|
object_id="field"
|
|
)
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_param_values, y_params6),
|
|
size_light
|
|
),
|
|
text="",
|
|
manager=self.manager,
|
|
object_id=colour
|
|
)
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_image2_label2, y_image_label2),
|
|
size_label_image
|
|
),
|
|
text=spec,
|
|
manager=self.manager,
|
|
object_id=colour
|
|
)
|
|
|
|
def show_cable_calculated(self, colour: str):
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_cables, y_cable1),
|
|
size_cable
|
|
),
|
|
text=colour,
|
|
manager=self.manager,
|
|
object_id=colour
|
|
)
|
|
|
|
def show_cable_chosen(self, colour: str):
|
|
pygame_gui.elements.UILabel(
|
|
relative_rect=pygame.Rect(
|
|
(x_cables, y_cable2),
|
|
size_cable
|
|
),
|
|
text=colour,
|
|
manager=self.manager,
|
|
object_id=colour
|
|
)
|
|
|
|
# ========= #
|
|
# == run == #
|
|
# ========= #
|
|
|
|
def run(self):
|
|
|
|
while self.running:
|
|
|
|
time_delta = self.clock.tick(60) / 1000.0
|
|
|
|
keystate = pygame.key.get_pressed()
|
|
|
|
# all events except QUIT are for testing
|
|
for event in pygame.event.get():
|
|
if event.type == pygame.QUIT:
|
|
self.running = False
|
|
if keystate[pygame.K_a]:
|
|
self.show_params("hello", "yello", "gel", "jello", "yum", "hello")
|
|
if keystate[pygame.K_s]:
|
|
self.show_series("workhorse 3200wx", True)
|
|
if keystate[pygame.K_d]:
|
|
self.show_spec("anti aircraft", False)
|
|
if keystate[pygame.K_f]:
|
|
self.show_cable_calculated("red")
|
|
if keystate[pygame.K_g]:
|
|
self.show_cable_chosen("blue")
|
|
if keystate[pygame.K_q]:
|
|
self.show_pic_series(ASSET_CONCRETE)
|
|
if keystate[pygame.K_w]:
|
|
self.show_pic_spec(ASSET_CONCRETE)
|
|
|
|
self.manager.update(time_delta)
|
|
self.window_surface.blit(self.background, (0, 0))
|
|
self.manager.draw_ui(self.window_surface)
|
|
|
|
pygame.display.update()
|
|
|
|
|
|
def disarming_popup():
|
|
# run the pop-up
|
|
app = SampleWindow()
|
|
app.run()
|
|
|
|
# bring display back to normal
|
|
pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
|
|
pygame.display.set_caption(V_NAME_OF_WINDOW)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
pygame.init()
|
|
disarming_popup()
|