Debian Codegraph @

scripts/modules/achievement_screen.py

raw symbols SCIP
1 #
2 # $Id$
3 #
4 # (C) Copyright 2016 Kai Sterker <[email protected]>
5 # Part of the Adonthell Project <http://adonthell.nongnu.org>
6 #
7 # Adonthell is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # Adonthell is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Adonthell. If not, see <http://www.gnu.org/licenses/>.
19 #
20
21 import adonthell
22
23 # -- pygettext support
24 def N_(message): return message
25 def _(message): return adonthell.nls_translate (message)
26
27 # -- GUI for displaying in-game achievements
28 class achievement_screen (adonthell.win_container):
29
30 # -- dictionary of achievements present in the game
31 # with their unique id as key
32 achievements = { \
33 1: (N_("Sommelier"), N_("You know a good drop when you taste it")), \
34 2: (N_("Conversationalist"), N_("None will escape your silver tongue")), \
35 3: (N_("Keeper of secrets"), N_("Embarrassing confessions are safe with you")), \
36 4: (N_("Revealer of truth"), N_("Under your vigilant eye, no wrongdoing stays hidden")), \
37 5: (N_("Trusty servant"), N_("As always, you keep your mistress out of harm's way")), \
38 6: (N_("Yetin acolyte"), N_("You walk the path of the yetin spirit")), \
39 7: (N_("Master detective"), N_("Your inquisitive powers lead you to the right conclusions")), \
40 8: (N_("Gem-bearer"), N_("What is thought to be lost, you already discovered")), \
41 9: (N_("Paragon of virtue"), N_("Neither lie nor deceit parts your lips")), \
42 255: (N_("Leet haxor"), N_("Your hex editing skillz are unparalleled ... or your disk broken")) }
43
44 # -- Constructor
45 def __init__(self):
46 adonthell.win_container.__init__(self)
47
48 self.scroll_direction = -1
49
50 # -- get fonts and theme
51 self.font1 = adonthell.win_manager_get_font ("yellow")
52 self.font2 = adonthell.win_manager_get_font ("original")
53 self.theme = adonthell.win_manager_get_theme ("original")
54
55 self.move (19, 15)
56 self.resize (282, 216)
57
58 # -- list of achievements
59 self.achievement_list = adonthell.win_select()
60 self.achievement_list.move (11, 20)
61 self.achievement_list.resize (260, 186)
62 self.achievement_list.set_border (self.theme)
63 self.achievement_list.set_visible_border (True)
64 self.achievement_list.set_background (self.theme)
65 self.achievement_list.set_visible_background (True)
66 self.achievement_list.set_trans_background (True)
67 self.achievement_list.set_scrollbar (self.theme);
68 self.achievement_list.set_visible_scrollbar (True);
69 self.achievement_list.set_space_between_object(6)
70 self.achievement_list.set_space_with_border(6)
71 self.achievement_list.set_layout (adonthell.win_container_LIST_LAYOUT)
72 self.achievement_list.set_mode (adonthell.win_select_MODE_BORDER)
73 self.achievement_list.py_signal_connect (self.page_up, adonthell.win_event_PREVIOUS)
74 self.achievement_list.py_signal_connect (self.page_down, adonthell.win_event_NEXT)
75 self.achievement_list.thisown = 0
76
77 # -- activate the list
78 self.achievement_list.set_activate (True)
79
80 # -- give focus to the list
81 self.add(self.achievement_list)
82 self.set_focus_object (self.achievement_list)
83
84 # -- add achievements
85 num_achievements = adonthell.achievements.num_achievements()
86 for i in range(num_achievements):
87 id = adonthell.achievements.achievement_id(i)
88 unlocked = adonthell.achievements.is_unlocked(i)
89 self.achievement_list.add(self.make_item(id, unlocked))
90
91 # -- add title
92 title = adonthell.win_label()
93 title.set_form (adonthell.label_AUTO_SIZE)
94 title.set_font (self.font2)
95 title.set_text (_("Achievements") + " [%s / %s]" % (adonthell.achievements.num_unlocked(), num_achievements))
96 title.move ((self.length() - title.length()) // 2, 0)
97 title.pack ()
98 title.thisown = 0
99
100 self.add(title)
101
102 # -- set everything visible
103 self.set_visible_all (True)
104 self.set_activate (True)
105
106 self.py_signal_connect (self.on_update, adonthell.win_event_UPDATE)
107
108 def make_item(self, id, unlocked):
109 # -- get title and text of the given achievement id
110 data = achievement_screen.achievements.get(id)
111 if data == None: return
112
113 iconId = 0
114 if unlocked: iconId = id
115
116 iconpath = adonthell.game.find_file("gfx/achievements/%s.pnm" % (iconId))
117
118 container = adonthell.win_container()
119 container.thisown = 0
120
121 icon = adonthell.win_image ()
122 icon.load_pnm (iconpath);
123 icon.move (8, 3);
124 icon.set_border (self.theme, adonthell.win_border_MINI)
125 icon.set_visible_border (True)
126 icon.pack()
127 icon.thisown = 0
128
129 label1 = adonthell.win_label()
130 label1.resize (176, 18)
131 label1.move (64, 0)
132 if unlocked:
133 label1.set_font (self.font1)
134 else:
135 label1.set_font (self.font2)
136 label1.set_form (adonthell.label_AUTO_SIZE)
137 label1.set_text (adonthell.nls_translate (data[0]))
138 label1.pack ()
139 label1.set_brightness(not unlocked)
140 label1.thisown = 0
141
142 label2 = adonthell.win_label()
143 label2.resize (176, 36)
144 label2.move (64, 17)
145 label2.set_font (self.font2)
146 label2.set_text (adonthell.nls_translate (data[1]))
147 label2.pack ()
148 label2.thisown = 0
149
150 container.add(icon)
151 container.add(label1)
152 container.add(label2)
153 container.resize (250, 54)
154 container.set_visible_all (True)
155
156 return container
157
158 # -- callback for custom updating
159 def on_update (self):
160 # -- pressing ESC will close the dialog
161 if adonthell.input_has_been_pushed (adonthell.SDLK_ESCAPE):
162 adonthell.gamedata_engine ().main_quit ()
163
164 def page_up (self):
165 # -- do a page-wise scrolling of the achievment list
166 pos = self.achievement_list.get_selected_position()
167 if self.scroll_direction == 1:
168 self.achievement_list.set_default_position(pos - 3)
169 self.scroll_direction = -1
170
171 def page_down (self):
172 # -- do a page-wise scrolling of the achievment list
173 pos = self.achievement_list.get_selected_position()
174 if self.scroll_direction == -1:
175 self.achievement_list.set_default_position(pos + 1)
176 self.scroll_direction = 1
177
178
179 # -- GUI for displaying a popup when an achievement unlocks
180 class achievement_popup (adonthell.win_container):
181
182 # -- position where the popup should appear, in case multiple achievements unlock at once
183 pos_y = [ 5 ]
184
185 # -- Constructor
186 def __init__(self, achievement):
187 adonthell.win_container.__init__(self)
188
189 # -- check that the achievement data exists
190 data = achievement_screen.achievements.get(achievement)
191 if data == None: return
192
193 # -- number of cycles the popup remains open
194 self.time_remaining = 250
195
196 # -- get font and theme
197 self.font = adonthell.win_manager_get_font ("yellow")
198 self.theme = adonthell.win_manager_get_theme ("original")
199
200 pos_y = achievement_popup.pos_y[-1]
201 self.move (190, pos_y)
202 self.resize (125, 28)
203
204 achievement_popup.pos_y.append(pos_y + 34)
205
206 self.set_border (self.theme, adonthell.win_border_MINI)
207 self.set_visible_border (True)
208 self.set_background (self.theme)
209 self.set_visible_background (True)
210 self.set_trans_background (True)
211 self.thisown = 0
212
213 iconpath = adonthell.game.find_file("gfx/achievements/%s.pnm" % (achievement))
214
215 tmp_image = adonthell.image ()
216 tmp_image.load_pnm (iconpath)
217
218 icon = adonthell.win_image ()
219 icon.resize (24, 24)
220 icon.move (3, 2);
221 icon.zoom (tmp_image)
222 icon.pack()
223 icon.thisown = 0
224
225 label = adonthell.win_label()
226 label.resize (90, 24)
227 label.move (30, 2)
228 label.set_font (self.font)
229 label.set_text (adonthell.nls_translate(data[0]))
230 label.pack ()
231 label.thisown = 0
232
233 self.add (icon)
234 self.add (label)
235
236 self.set_visible_all (True)
237
238 self.py_signal_connect (self.on_update, adonthell.win_event_UPDATE)
239 self.py_signal_connect (self.on_destroy, adonthell.win_event_DESTROY)
240
241 def on_update(self):
242 # -- count down how long the popup remains open
243 self.time_remaining = self.time_remaining - 1
244
245 def on_destroy(self):
246 # -- close the popup when the time arrives
247 if self.time_remaining == 0:
248 achievement_popup.pos_y.pop(1)
249 return False
250
251 return True