Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Saludame.activity/events_windows.py
blob: 9432767cbc9c84e9dd558c2b29a4e3b7f62f5c8f (plain)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# -*- coding: utf-8 -*-

# Copyright (C) 2011 ceibalJAM! - ceibaljam.org
# This file is part of Saludame.
#
# Saludame is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Saludame is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Saludame. If not, see <http://www.gnu.org/licenses/>.

import gui
import pygame
import game
import animation

TEXT_COLOR = (0,0,0)

class PersonalWindow(gui.Window):
    def __init__(self, container, rect, frame_rate, windows_controller):
        
        gui.Window.__init__(self, container, rect, frame_rate, windows_controller, "personal_window")

        self.active_personal_events = [] # tuple (event, animation)
        self.index_personal_event = 0
        
        self.personal_next = gui.ImageButton(self.rect, pygame.Rect(120, 95, 30, 30), 1, "assets/events/go-next.png", self._cb_button_click_personal_next)
        self.personal_back = gui.ImageButton(self.rect, pygame.Rect(5, 95, 30, 30), 1, "assets/events/go-back.png", self._cb_button_click_personal_back)
        
        self.add_button(self.personal_next)
        self.add_button(self.personal_back)
        
        self.personal_next.visible = False
        self.personal_back.visible = False
        
        self.count_personal_events = gui.Text(self.rect, 60, 100, 1, "", 22, TEXT_COLOR, gui.Text.ALIGN_CENTER, True, False)
        self.add_child(self.count_personal_events)
        
        self.current_animation = None # Visible event at panel
    
    # Add/remove personal events    
    def add_personal_event(self, event):
        
        if not event in self.active_personal_events:
                       
            event_info = "%s \n" % (event.description)            
            if event.effect:
                for eff in event.effect.effect_status_list:
                    bar_label = event.effect.bars_controller.get_bar_label(eff[0])
                    if eff[1] > 0:
                        event_info += "+ %s \n" % (bar_label)
                    else:
                        event_info += "- %s \n" % (bar_label)
            
            ## Animation
            animation_rect = pygame.Rect((0, 0), self.rect.size)
            temp_animation = animation.ActionAnimation(self.rect, animation_rect, 3, event.directory_path)            
            temp_animation.set_on_mouse_click(self._cb_button_click_personal)
            temp_animation.highlight = False
            temp_animation.set_super_tooltip(event_info)
            
            self.active_personal_events.append((event, temp_animation))
            
            if self.current_animation:
                self.remove_button(self.current_animation)
                
            self.current_animation = temp_animation
            self.add_button(self.current_animation, 0)
            
            self.current_animation.set_dirty()
            self.index_personal_event = len(self.active_personal_events) - 1
            
            self.refresh_count_personal_events()       
        
    def remove_personal_event(self, event):        
        for e in self.active_personal_events:
            if e[0] == event:
                self.active_personal_events.remove(e)             
                
        if self.current_animation:
            self.remove_button(self.current_animation)
                
        if self.active_personal_events:
            self.index_personal_event = 0
            self.current_animation = self.active_personal_events[0][1]
            self.add_button(self.current_animation, 0)
        
        self.windows_controller.hide_active_tooltip()
        
        self.parent.set_dirty_background()       
        self.refresh_count_personal_events()        
        
    def refresh_count_personal_events(self):
        if len(self.active_personal_events) > 1:
            self.count_personal_events.text = "%s/%s" % (self.index_personal_event + 1, len(self.active_personal_events))
            self.count_personal_events.refresh()
            
            self.personal_next.visible = True
            self.personal_back.visible = True
        else:
            self.count_personal_events.text = ""
            self.count_personal_events.refresh()
            
            self.personal_next.visible = False
            self.personal_back.visible = False
    
    def get_current_event(self):
        if self.index_personal_event < len(self.active_personal_events):
            return self.active_personal_events[self.index_personal_event][0]

    # Buttons Callbacks
    def _cb_button_click_personal(self, button):
        event = self.get_current_event()
        if event and event.library_link:
            game.set_library_event(event.library_link)
        
    def _cb_button_click_personal_next(self, button):
        if self.index_personal_event < len (self.active_personal_events) - 1:
            self.remove_button(self.current_animation)
            self.index_personal_event += 1
            self.refresh_count_personal_events()
            self.current_animation = self.active_personal_events[self.index_personal_event][1]
            self.add_button(self.current_animation, 0)
            
    def _cb_button_click_personal_back(self, button):
        if self.index_personal_event > 0:
            self.remove_button(self.current_animation)
            self.index_personal_event -= 1
            self.refresh_count_personal_events()
            self.current_animation = self.active_personal_events[self.index_personal_event][1]
            self.add_button(self.current_animation, 0)

class SocialWindow(gui.Window):
    def __init__(self, container, rect, frame_rate, windows_controller):
        
        gui.Window.__init__(self, container, rect, frame_rate, windows_controller, "social_window")   
        
        self.active_social_events = [] # tuple (event, animation)
        self.index_social_event = 0
        
        self.social_next = gui.ImageButton(self.rect, pygame.Rect(120, 95, 30, 30), 1, "assets/events/go-next.png", self._cb_button_click_social_next)
        self.social_back = gui.ImageButton(self.rect, pygame.Rect(5, 95, 30, 30), 1, "assets/events/go-back.png", self._cb_button_click_social_back)
        
        self.add_button(self.social_next)
        self.add_button(self.social_back)
        self.social_next.visible = False
        self.social_back.visible = False
        
        self.count_social_events = gui.Text(self.rect, 60, 100, 1, "", 22, TEXT_COLOR, gui.Text.ALIGN_CENTER, True, False)
        self.add_child(self.count_social_events)
        
        self.current_animation = None # Visible event at panel
        
    # Add/Remove social events    
    def add_social_event(self, event):
        
        if not event in self.active_social_events:
                       
            event_info = "%s \n" % (event.description)            
            if event.effect:
                for eff in event.effect.effect_status_list:
                    bar_label = event.effect.bars_controller.get_bar_label(eff[0])
                    if eff[1] > 0:
                        event_info += "+ %s \n" % (bar_label)
                    else:
                        event_info += "- %s \n" % (bar_label)
            
            animation_rect = pygame.Rect((0, 0), self.rect.size)
            temp_animation = animation.ActionAnimation(self.rect, animation_rect, 3, event.directory_path)
            temp_animation.set_on_mouse_click(self._cb_button_click_social)
            temp_animation.highlight = False
            temp_animation.set_super_tooltip(event_info)
            
            self.active_social_events.append((event, temp_animation))
            
            if self.current_animation:
                self.remove_button(self.current_animation)
            self.current_animation = temp_animation
            self.add_button(self.current_animation, 0)
            
            self.current_animation.set_dirty()
            self.index_social_event = len(self.active_social_events) - 1
            
            self.refresh_count_social_events()
    
    def remove_social_event(self, event):
        
        for e in self.active_social_events:
            if e[0] == event:
                self.active_social_events.remove(e)
                
        if self.current_animation:
            self.remove_button(self.current_animation)
                
        if self.active_social_events:
            self.index_social_event = 0
            self.current_animation = self.active_social_events[0][1]
            self.add_button(self.current_animation, 0)
            
        self.windows_controller.hide_active_tooltip()
        
        self.parent.set_dirty_background()          
        self.refresh_count_social_events()
            
    def refresh_count_social_events(self):
        if len(self.active_social_events) > 1:
            self.count_social_events.text = "%s/%s" % (self.index_social_event + 1, len(self.active_social_events))
            self.count_social_events.refresh()
            
            self.social_next.visible = True
            self.social_back.visible = True
        else:
            self.count_social_events.text = ""
            self.count_social_events.refresh()
            
            self.social_next.visible = False
            self.social_back.visible = False

    def get_current_event(self):
        if self.index_social_event < len(self.active_social_events):
            return self.active_social_events[self.index_social_event][0]
    
    ## Buttons callbacks
    def _cb_button_click_social(self, button):
        event = self.get_current_event()
        if event and event.library_link:
            game.set_library_event(event.library_link)
    
    def _cb_button_click_social_next(self, button):
        if self.index_social_event < len (self.active_social_events) - 1:
            self.remove_button(self.current_animation)
            self.index_social_event += 1
            self.refresh_count_social_events()
            self.current_animation = self.active_social_events[self.index_social_event][1]
            self.add_button(self.current_animation, 0)

    def _cb_button_click_social_back(self, button):
        if self.index_social_event > 0:
            self.remove_button(self.current_animation)
            self.index_social_event -= 1
            self.refresh_count_social_events()
            self.current_animation = self.active_social_events[self.index_social_event][1]
            self.add_button(self.current_animation, 0)