-
Notifications
You must be signed in to change notification settings - Fork 0
/
EscMenu.py
74 lines (58 loc) · 2.4 KB
/
EscMenu.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
74
import util
import Camera
import pygame
import os
class EscMenu(Camera.Drawable):
closeRect = pygame.Rect(30,30,245,33)
leaveRect = pygame.Rect(30,85,245,33)
changeRect = pygame.Rect(30,135,245,77)
quitRect = pygame.Rect(30,227,245,33)
CLICK_CLOSE = 0
CLICK_LEAVE = 1
CLICK_CHANGE = 2
CLICK_QUIT = 3
onClick = None
leaveGame = False
changeChar = False
highlight = -1
x = 0
y = 0
def __init__(self):
image = util.IMAGECACHE[os.path.join(util.IMAGES['BUTTONS'], 'escmenu.png')]
self.x = (util.INTERNAL_WIDTH >> 1) - (image.get_width() >> 1)
self.y = (util.INTERNAL_HEIGHT >> 1) - (image.get_height() >> 1)
def draw(self, surface, offset):
if self.highlight == -1:
image = util.IMAGECACHE[os.path.join(util.IMAGES['BUTTONS'], 'escmenu.png')]
else:
image = util.IMAGECACHE[os.path.join(util.IMAGES['BUTTONS'], 'escmenu_%d.png' % self.highlight)]
surface.blit(image, (self.x,self.y))
def canLeaveGame(self, value):
self.leaveGame = value
def canChangeChar(self, value):
self.changeChar = value
def getPoints(self, rect):
return (rect.topleft, rect.topright, rect.bottomright, rect.bottomleft)
def processEvents(self, events):
for event in events:
if event.type == pygame.MOUSEMOTION:
self.mouseMove((event.pos[0], event.pos[1]))
if event.type == pygame.MOUSEBUTTONDOWN:
self.mouseClick((event.pos[0], event.pos[1]), event.button)
def setHandler(self, func):
self.onClick = func
def mouseClick(self, mousePoint, mouseButton):
if mouseButton == 1 and self.onClick != None and self.highlight != -1:
self.onClick(self.highlight)
def mouseMove(self, mousePoint):
mousePoint = mousePoint[0]-self.x, mousePoint[1]-self.y
if util.pointInside(mousePoint, self.getPoints(self.closeRect)):
self.highlight = 0
elif util.pointInside(mousePoint, self.getPoints(self.leaveRect)) and self.leaveGame:
self.highlight = 1
elif util.pointInside(mousePoint, self.getPoints(self.changeRect)) and self.changeChar:
self.highlight = 2
elif util.pointInside(mousePoint, self.getPoints(self.quitRect)):
self.highlight = 3
else:
self.highlight = -1