-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathConfirmOverlay.py
73 lines (56 loc) · 2.92 KB
/
ConfirmOverlay.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import RenderObject, Configuration, Common
import os, Keys, RenderControl
import pygame, sys
import Theme
class ConfirmOverlay(RenderObject.RenderObject):
background = None
backgroundShadow = None
config = Configuration.getConfiguration()
theme = Configuration.getTheme()
entryFont = pygame.font.Font('theme/NotoSans-Regular.ttf', 16)
footerHeight = 24
spacing = 6
width = 160
height = 60
def render(self, screen):
screen.blit(self.backgroundShadow, (self.xOffset + 4,self.yOffset + 4))
screen.blit(self.background, (self.xOffset,self.yOffset))
def initBackground(self):
self.background = pygame.Surface((self.width, self.height))
self.background.fill(Theme.getColor("selectionMenu/backgroundColor", (137,137,137)))
self.backgroundShadow = pygame.Surface((self.width, self.height),pygame.SRCALPHA)
self.backgroundShadow.fill((0,0,0, 128))
text = self.entryFont.render(self.text, True, self.textColor)
xText = ( self.background.get_width() - text.get_width()) / 2
yText = (self.background.get_height() - self.footerHeight - text.get_height()) / 2
self.background.blit(text, (xText,yText))
self.xOffset = (self.config["screenWidth"] - self.background.get_width()) / 2
self.yOffset = (self.config["screenHeight"] - self.background.get_height()) / 2
footerOffset = self.background.get_height() - self.footerHeight
rightOffset = self.background.get_width() - 2
for entry in self.buttons:
if(entry[1] != None):
text = self.entryFont.render(entry[1], True, self.textColor)
self.background.blit(text, (rightOffset - text.get_width(),((self.footerHeight - text.get_height()) / 2) + footerOffset))
rightOffset = rightOffset - text.get_width() - self.spacing
if(entry[0] != None):
icon = Common.loadImage(entry[0])
icon= icon.convert_alpha().copy()
icon.fill(self.textColor, None, pygame.BLEND_RGBA_MULT)
self.background.blit(icon, (rightOffset - icon.get_width() , ((self.footerHeight - icon.get_height()) / 2) + footerOffset ))
rightOffset = rightOffset - icon.get_width() - self.spacing
def handleEvents(self, events):
for event in events:
if event.type == pygame.KEYDOWN:
if event.key == Keys.DINGOO_BUTTON_B:
self.callback(-1)
RenderControl.setDirty()
if event.key == Keys.DINGOO_BUTTON_A:
self.callback(1)
RenderControl.setDirty()
def __init__(self, text ,buttons, callback):
self.callback = callback
self.text = text
self.textColor = Theme.getColor("selectionMenu/fontColor", (55,55,55))
self.buttons = buttons
self.initBackground()