| 1 |  |  | # | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | #  Copyright 2001 - 2016 Ludek Smid [http://www.ospace.net/] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | # | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | #  This file is part of Outer Space. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | # | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | #  Outer Space is free software; you can redistribute it and/or modify | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | #  it under the terms of the GNU General Public License as published by | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | #  the Free Software Foundation; either version 2 of the License, or | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | #  (at your option) any later version. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | # | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | #  Outer Space is distributed in the hope that it will be useful, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | #  but WITHOUT ANY WARRANTY; without even the implied warranty of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | #  GNU General Public License for more details. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | # | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | #  You should have received a copy of the GNU General Public License | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | #  along with Outer Space; if not, write to the Free Software | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | #  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | # | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | import pygameui as ui, string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | from osci import client, gdata | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | import ige.ospace.Const as Const | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | class ShowBuoyDlg: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     def __init__(self, app): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         self.app = app | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         self.createUI() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     def display(self, objID): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         player = client.getPlayer() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         text = [] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         if hasattr(player, "buoys") and objID in player.buoys: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             label = _("Private buoy text") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |             if player.buoys[objID][1] == Const.BUOY_TO_ALLY: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |                 label = u"%s%s:" % (label, _(" (visible to allies)")) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             else: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |                 label = u"%s:" % label | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |             text.append(label) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |             text.extend(player.buoys[objID][0].split("\n")) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |             text.append("") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         if hasattr(player, "alliedBuoys") and objID in player.alliedBuoys: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |             text.append(_("Buoy texts from allies:")) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             for buoy in player.alliedBuoys[objID]: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |                 text.extend(buoy[0].split("\n")) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |                 text.append(_('(Author: %s)') % buoy[2]) #owner's name | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |                 text.append("") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         self.win.vText.text = text | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         self.win.show() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         # register for updates | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         if self not in gdata.updateDlgs: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             gdata.updateDlgs.append(self) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     def hide(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         self.win.setStatus(_("Ready.")) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         self.win.hide() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         # unregister updates | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         if self in gdata.updateDlgs: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |             gdata.updateDlgs.remove(self) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     def update(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         self.win.show() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     def onOK(self, widget, action, data): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         self.hide() | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 70 |  |  |     def createUI(self): | 
            
                                                        
            
                                    
            
            
                | 71 |  |  |         w, h = gdata.scrnSize | 
            
                                                        
            
                                    
            
            
                | 72 |  |  |         cols = 20 | 
            
                                                        
            
                                    
            
            
                | 73 |  |  |         rows = 13 | 
            
                                                        
            
                                    
            
            
                | 74 |  |  |         width = cols * 20 + 4 | 
            
                                                        
            
                                    
            
            
                | 75 |  |  |         height = rows * 20 + 24 | 
            
                                                        
            
                                    
            
            
                | 76 |  |  |         self.win = ui.Window(self.app, | 
            
                                                        
            
                                    
            
            
                | 77 |  |  |             modal = 1, | 
            
                                                        
            
                                    
            
            
                | 78 |  |  |             escKeyClose = 1, | 
            
                                                        
            
                                    
            
            
                | 79 |  |  |             movable = 0, | 
            
                                                        
            
                                    
            
            
                | 80 |  |  |             title = _("Show buoy text"), | 
            
                                                        
            
                                    
            
            
                | 81 |  |  |             rect = ui.Rect((w - width) / 2, (h - height) / 2, width, height), | 
            
                                                        
            
                                    
            
            
                | 82 |  |  |             layoutManager = ui.SimpleGridLM(), | 
            
                                                        
            
                                    
            
            
                | 83 |  |  |         ) | 
            
                                                        
            
                                    
            
            
                | 84 |  |  |         # creating dialog window | 
            
                                                        
            
                                    
            
            
                | 85 |  |  |         self.win.subscribeAction('*', self) | 
            
                                                        
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 87 |  |  |         s = ui.Scrollbar(self.win, layout = (cols - 1, 0, 1, rows - 1)) | 
            
                                                        
            
                                    
            
            
                | 88 |  |  |         t = ui.Text(self.win, id = 'vText', | 
            
                                                        
            
                                    
            
            
                | 89 |  |  |             align = ui.ALIGN_W, | 
            
                                                        
            
                                    
            
            
                | 90 |  |  |             layout = (0, 0, cols - 1, rows - 1), | 
            
                                                        
            
                                    
            
            
                | 91 |  |  |             editable = 0 | 
            
                                                        
            
                                    
            
            
                | 92 |  |  |         ) | 
            
                                                        
            
                                    
            
            
                | 93 |  |  |         t.attachVScrollbar(s) | 
            
                                                        
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 95 |  |  |         ui.Title(self.win, layout = (0, rows - 1, cols - 5, 1)) | 
            
                                                        
            
                                    
            
            
                | 96 |  |  |         okBtn = ui.TitleButton(self.win, layout = (cols - 5, rows - 1, 5, 1), text = _("OK"), action = 'onOK') | 
            
                                                        
            
                                    
            
            
                | 97 |  |  |  |