import
pygame as py
class
Screen():
def
__init__(
self
, title, width
=
440
, height
=
445
,
fill
=
(
0
,
0
,
255
)):
self
.height
=
height
self
.title
=
title
self
.width
=
width
self
.fill
=
fill
self
.CurrentState
=
False
def
makeCurrentScreen(
self
):
py.display.set_caption(
self
.title)
self
.CurrentState
=
True
self
.screen
=
py.display.set_mode((
self
.width,
self
.height))
def
endCurrentScreen(
self
):
self
.CurrentState
=
False
def
checkUpdate(
self
, fill):
self
.fill
=
fill
return
self
.CurrentState
def
screenUpdate(
self
):
if
self
.CurrentState:
self
.screen.fill(
self
.fill)
def
returnTitle(
self
):
return
self
.screen
class
Button():
def
__init__(
self
, x, y, sx, sy, bcolour,
fbcolour, font, fcolour, text):
self
.x
=
x
self
.y
=
y
self
.sx
=
sx
self
.sy
=
sy
self
.fontsize
=
25
self
.bcolour
=
bcolour
self
.fbcolour
=
fbcolour
self
.fcolour
=
fcolour
self
.text
=
text
self
.CurrentState
=
False
self
.buttonf
=
py.font.SysFont(font,
self
.fontsize)
def
showButton(
self
, display):
if
(
self
.CurrentState):
py.draw.rect(display,
self
.fbcolour,
(
self
.x,
self
.y,
self
.sx,
self
.sy))
else
:
py.draw.rect(display,
self
.fbcolour,
(
self
.x,
self
.y,
self
.sx,
self
.sy))
textsurface
=
self
.buttonf.render(
self
.text,
False
,
self
.fcolour)
display.blit(textsurface,
((
self
.x
+
(
self
.sx
/
2
)
-
(
self
.fontsize
/
2
)
*
(
len
(
self
.text)
/
2
)
-
5
, (
self
.y
+
(
self
.sy
/
2
)
-
(
self
.fontsize
/
2
)
-
4
))))
def
focusCheck(
self
, mousepos, mouseclick):
if
(mousepos[
0
] >
=
self
.x
and
mousepos[
0
] <
=
self
.x
+
self
.sx
and
mousepos[
1
] >
=
self
.y
and
mousepos[
1
]
<
=
self
.y
+
self
.sy):
self
.CurrentState
=
True
return
mouseclick[
0
]
else
:
self
.CurrentState
=
False
return
False
py.init()
py.font.init()
menuScreen
=
Screen(
"Menu Screen"
)
control_bar
=
Screen(
"Control Screen"
)
win
=
menuScreen.makeCurrentScreen()
MENU_BUTTON
=
Button(
150
,
150
,
150
,
50
, (
255
,
250
,
250
),
(
255
,
0
,
0
),
"TimesNewRoman"
,
(
255
,
255
,
255
),
"Main Menu"
)
CONTROL_BUTTON
=
Button(
150
,
150
,
150
,
50
,
(
0
,
0
,
0
), (
0
,
0
,
255
),
"TimesNewRoman"
,
(
255
,
255
,
255
),
"Back"
)
done
=
False
toggle
=
False
while
not
done:
menuScreen.screenUpdate()
control_bar.screenUpdate()
mouse_pos
=
py.mouse.get_pos()
mouse_click
=
py.mouse.get_pressed()
keys
=
py.key.get_pressed()
if
menuScreen.checkUpdate((
25
,
0
,
255
)):
control_barbutton
=
MENU_BUTTON.focusCheck(mouse_pos,
mouse_click)
MENU_BUTTON.showButton(menuScreen.returnTitle())
if
control_barbutton:
win
=
control_bar.makeCurrentScreen()
menuScreen.endCurrentScreen()
elif
control_bar.checkUpdate((
255
,
0
,
255
)):
return_back
=
CONTROL_BUTTON.focusCheck(mouse_pos,
mouse_click)
CONTROL_BUTTON.showButton(control_bar.returnTitle())
if
return_back:
control_bar.endCurrentScreen()
win
=
menuScreen.makeCurrentScreen()
for
event
in
py.event.get():
if
(event.
type
=
=
py.QUIT):
done
=
True
py.display.update()
py.quit()