def add_alien_fleet(self, fleet): ft = fleet['turn'] max_t = store.max_turn() label = '' if ft < max_t: label = '[-%d] '%(max_t - ft,) if max_t - ft > 100: # fleet info is too old return cp = wx.CollapsiblePane(self, label=label+'%s'%fleet['name'], style=wx.CP_DEFAULT_STYLE|wx.CP_NO_TLW_RESIZE) self.sizer.Add(cp) pane = cp.GetPane() u = store.get_user(fleet['user_id']) if u: owner_name = u['name'] else: owner_name = '<unknown>' sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(wx.StaticText(pane, label='owner: %s'%(owner_name,)), 1, wx.EXPAND) for unit in store.iter_objects_list('alien_unit', {'fleet_id':fleet['fleet_id']}): hbox = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(hbox, 1, wx.EXPAND) carp = unit['carapace'] if carp == 0: img = image.getBcImage(unit['class']) else: img = image.getCarapaceImage(carp, unit['color'] ) if img: bitmap = wx.StaticBitmap(pane) bitmap.SetBitmap(img) hbox.Add(bitmap, 1, wx.EXPAND) else: print 'image not found for unit %s, carp %s, color %s'%(unit['unit_id'], int(unit['carapace']), int(unit['color']) ) name = get_unit_name(int(unit['carapace'])) hbox.Add(wx.StaticText(pane, label=name), 1, wx.EXPAND) border = wx.BoxSizer() border.Add(sizer, 1, wx.EXPAND|wx.ALL) pane.SetSizer(border) self.sizer.Layout() self.Bind(wx.EVT_COLLAPSIBLEPANE_CHANGED, self.OnPaneChanged, cp) cp.Expand() cp.Bind(wx.EVT_LEFT_DOWN, self.onFleetSelect) self.fleets[cp] = fleet
def add_fleet(self, fleet): nm = '' if 'arrival_turn' in fleet: nm = '[%d] '%(fleet['arrival_turn'] - store.max_turn(),) nm += fleet['name'] cp = wx.CollapsiblePane(self, label=nm, style=wx.CP_DEFAULT_STYLE|wx.CP_NO_TLW_RESIZE) self.sizer.Add(cp) pane = cp.GetPane() u = store.get_user(fleet['user_id']) if u: owner_name = u['name'] else: owner_name = '<unknown>' sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(wx.StaticText(pane, label='owner: %s'%(owner_name,)), 1, wx.EXPAND) speed, rng = store.get_fleet_speed_range(fleet['fleet_id']) if speed and rng: sizer.Add(wx.StaticText(pane, label='%0.2f / %0.2f'%(speed, rng)), 1, wx.EXPAND) #can we contrl the fleet? is_controlled = 'login' in u and u['login'] in config.users if is_controlled and rng >= 1 and (not 'in_transit' in fleet or fleet['in_transit']==0): jump_button = wx.ToggleButton(pane, label='jump') jump_button.fleet_id = fleet['fleet_id'] sizer.Add(jump_button, 1, wx.EXPAND) self.Bind(wx.EVT_TOGGLEBUTTON, self.on_jump, jump_button) #else: # print 'user %s not controllable'%(u,) for unit in store.get_fleet_units(fleet['fleet_id']): hbox = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(hbox, 1, wx.EXPAND) proto = store.get_object('proto', {'proto_id':unit['proto_id']}) if not proto: print 'Prototype not found for %s'%(unit,) continue obj_carp = int(unit['proto_id']), int(proto['carapace']), int(proto['color']) if is_controlled: planet = store.get_object('planet', {'x':self.coord[0], 'y':self.coord[1]}) inhabited = False if planet and planet['user_id'] and int(planet['user_id']) > 0: inhabited = True # get unit actions ( colony, kill-people ) if not inhabited: for action_type in [action.Action.COLONY_COLONISE, action.Action.ARC_COLONISE, action.Action.OUTPOST_COLONISE]: action_colonize = store.get_object('proto_action', {'proto_id':proto['proto_id'], 'proto_action_id':action_type}) if action_colonize: c_action = store.get_object('action', {'unit_id':unit['unit_id']}) if c_action: # already colonizing cancel_button = wx.Button(pane, label='Cancel colonize %s'%(action.get_colony_population(action_type))) cancel_button.cancel_action = u['user_id'], unit['unit_id'], c_action['cancel_id'] self.Bind(wx.EVT_BUTTON, self.on_cancel_action, cancel_button) sizer.Add( cancel_button , 1, wx.EXPAND ) else: colonize_button = wx.Button(pane, label='Colonize %s'%(action.get_colony_population(action_type))) colonize_button.action = action_type, unit['unit_id'], fleet['fleet_id'], self.coord, u['user_id'] self.Bind(wx.EVT_BUTTON, self.on_store_action, colonize_button) sizer.Add( colonize_button , 1, wx.EXPAND ) if inhabited and planet['user_id'] != u['user_id']: #TODO: check if our mult, or ally, and notify user about it action_kill_people = store.get_object('proto_action', {'proto_id':proto['proto_id'], 'proto_action_id':action.Action.KILL_PEOPLE}) if action_kill_people: c_action = store.get_object('action', {'unit_id':unit['unit_id']}) if c_action: # already colonizing cancel_button = wx.Button(pane, label='Cancel kill people') cancel_button.cancel_action = u['user_id'], unit['unit_id'], c_action['cancel_id'] self.Bind(wx.EVT_BUTTON, self.on_cancel_action, cancel_button) sizer.Add( cancel_button , 1, wx.EXPAND ) else: colonize_button = wx.Button(pane, label='Kill people') colonize_button.action = action.Action.KILL_PEOPLE, unit['unit_id'], fleet['fleet_id'], self.coord, u['user_id'] self.Bind(wx.EVT_BUTTON, self.on_store_action, colonize_button) sizer.Add( colonize_button , 1, wx.EXPAND ) img = image.get_image( int(unit['proto_id']), int(proto['carapace']), int(proto['color']) ) if img: bitmap = wx.StaticBitmap(pane) bitmap.SetBitmap(img) hbox.Add(bitmap, 1, wx.EXPAND) #else: # print 'image not found for unit %s, bc %s, carp %s, color %s'%(unit['unit_id'], int(unit['proto_id']), int(proto['carapace']), int(proto['color']) ) name = proto['name'] if not name: name = get_unit_name(int(proto['carapace'])) hbox.Add(wx.StaticText(pane, label=name), 1, wx.EXPAND) border = wx.BoxSizer() border.Add(sizer, 1, wx.EXPAND|wx.ALL) pane.SetSizer(border) self.sizer.Layout() self.Bind(wx.EVT_COLLAPSIBLEPANE_CHANGED, self.OnPaneChanged, cp) cp.Expand() cp.Bind(wx.EVT_LEFT_DOWN, self.onFleetSelect) self.fleets[cp] = fleet