1 | #!/usr/bin/env python |
---|
2 | # -*- coding: utf-8 -*- |
---|
3 | # |
---|
4 | # Puzzlebox - Brainstorms - Client Interface - Button |
---|
5 | # |
---|
6 | # Copyright Puzzlebox Productions, LLC (2010) |
---|
7 | # |
---|
8 | # Portions of this code have been previously |
---|
9 | # released under the GNU Pulic License (GPL) version 2 |
---|
10 | # and is Copyright Steven M. Castellotti (2010) |
---|
11 | # For more information please refer to http://www.gnu.org/copyleft/gpl.htm |
---|
12 | # |
---|
13 | # Last Update: 2010.02.04 |
---|
14 | # |
---|
15 | ##################################################################### |
---|
16 | |
---|
17 | import puzzlebox_brainstorms_client_interface_component as component |
---|
18 | |
---|
19 | ##################################################################### |
---|
20 | # Classes |
---|
21 | ##################################################################### |
---|
22 | |
---|
23 | class puzzlebox_brainstorms_client_interface_button( \ |
---|
24 | component.puzzlebox_brainstorms_client_interface_component): |
---|
25 | |
---|
26 | def __init__(self, pygame, screen, \ |
---|
27 | button_image, \ |
---|
28 | activated_image, \ |
---|
29 | x, \ |
---|
30 | y, \ |
---|
31 | command, \ |
---|
32 | match_keys, \ |
---|
33 | DEBUG = 0): |
---|
34 | |
---|
35 | self.pygame = pygame |
---|
36 | self.screen = screen |
---|
37 | self.button_image = button_image |
---|
38 | self.DEBUG = DEBUG |
---|
39 | |
---|
40 | self.button_image = self.load_image(button_image) |
---|
41 | self.activated_image = self.load_image(activated_image) |
---|
42 | |
---|
43 | self.position = (x, y) |
---|
44 | |
---|
45 | self.x = self.button_image.get_rect()[2] |
---|
46 | self.y = self.button_image.get_rect()[3] |
---|
47 | |
---|
48 | self.display_position = self.position |
---|
49 | |
---|
50 | # display the button graphic centered over the |
---|
51 | # coordinates instead of to the lower-right |
---|
52 | #self.display_position = (self.position[0] - (self.x / 2), \ |
---|
53 | #self.position[1] - (self.y / 2)) |
---|
54 | |
---|
55 | self.rect = self.button_image.get_rect() |
---|
56 | self.rect[0] = self.position[0] |
---|
57 | self.rect[1] = self.position[1] |
---|
58 | |
---|
59 | |
---|
60 | self.command = command |
---|
61 | self.match_keys = match_keys |
---|
62 | |
---|
63 | self.hits = 0 |
---|
64 | |
---|
65 | self.activated = False |
---|
66 | |
---|
67 | self.display() |
---|
68 | |
---|
69 | |
---|
70 | ##################################################################### |
---|
71 | |
---|
72 | def display(self): |
---|
73 | |
---|
74 | if not self.activated: |
---|
75 | self.draw_image(self.button_image, self.display_position) |
---|
76 | |
---|
77 | else: |
---|
78 | self.draw_image(self.activated_image, self.display_position) |
---|
79 | |
---|
80 | |
---|
81 | ##################################################################### |
---|
82 | |
---|
83 | def check_collision(self, target_rect): |
---|
84 | |
---|
85 | collision = self.rect.colliderect(target_rect) |
---|
86 | |
---|
87 | if collision: |
---|
88 | self.hits = self.hits + 1 |
---|
89 | |
---|
90 | |
---|
91 | return(collision) |
---|
92 | |
---|
93 | |
---|
94 | ##################################################################### |
---|
95 | # Functions |
---|
96 | ##################################################################### |
---|
97 | |
---|
98 | ##################################################################### |
---|
99 | # Main |
---|
100 | ##################################################################### |
---|
101 | |
---|
102 | if __name__ == '__main__': |
---|
103 | |
---|
104 | pass |
---|
105 | |
---|