def __init__(self, parent, proto_u): wx.Window.__init__(self, parent, wx.ID_ANY) img = wx.StaticBitmap(self, wx.ID_ANY) proto = proto_u if not 'carapace' in proto_u: for pr in db.prototypes(['id=%d'%(proto['class'],)]): proto = pr break bmp = None if proto['carapace']: bmp = image.getCarapaceImage( proto['carapace'], proto['color'] ) if not bmp: bmp = image.getBcImage( proto['id'], ) if not bmp: log.error('bitmap not found for %s'%(proto,)) return img.SetBitmap( bmp ) sizer = wx.BoxSizer(wx.VERTICAL) self.SetSizer(sizer) usz = wx.BoxSizer(wx.HORIZONTAL) usz.Add(img) usz.Add(wx.StaticText(self, wx.ID_ANY, '[%s]'%(getProtoName(proto),))) sizer.Add(usz) sizer.Layout()
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 __init__(self, parent, uid): wx.Window.__init__(self, parent) sizer = wx.BoxSizer(wx.HORIZONTAL) img = wx.StaticBitmap(self, wx.ID_ANY) img.SetBitmap( image.smaller(image.getBcImage( uid ) ) ) sizer.Add( img ) self.cb = wx.CheckBox(self, label='' ) sizer.Add ( self.cb ) self.cb.Bind(wx.EVT_CHECKBOX, self.building_filter) self.SetSizer(sizer) sizer.Layout()
def draw_build_stack(self, units): if len(units) == 0: return wsizer = wx.BoxSizer(wx.HORIZONTAL) self.sizer.Add(wsizer) proto = store.get_object('proto', {'proto_id':units[0]['proto_id']}) img = image.getBcImage(units[0]['proto_id'], 20) if not img: img = image.getCarapaceImage(proto['carapace'], proto['color'], 20) wnd = wx.StaticBitmap(self, wx.ID_ANY) if img: wnd.SetBitmap(img) wsizer.Add(wnd) name = proto['name'] if not name: name = get_unit_name(int(proto['carapace'])) count_text = '' if len(units)>1: count_text = 'x%s '%(len(units),) txt = wx.StaticText(self, -1, '%s%s'%(count_text, name)) wsizer.Add(txt) if 'max_count' in proto: if int(proto['max_count'])!=1: build_more = wx.Button(self, label="+", size=(20,20)) build_more.proto_id = proto['proto_id'] build_more.Bind(wx.EVT_LEFT_DOWN, self.on_build) wsizer.Add(build_more) build_less = wx.Button(self, label="-", size=(20,20)) build_less.units = units build_less.Bind(wx.EVT_LEFT_DOWN, self.on_cancel_build) wsizer.Add(build_less)
def set_coord(self, coord): self.coord = coord self.button_fleet.Disable() self.selected_units = {} self.units_sizer.DeleteWindows() user_planet = store.get_object('user_planet', {'x':coord[0], 'y':coord[1]}) if not user_planet: self.sizer.Layout() return item_windows = {} dups = {} protos = {} items = {} gu = store.get_garrison_units(coord) for unit in gu: bc = unit['proto_id'] if bc in items: items[bc].append(unit) continue p = store.get_object('proto', {'proto_id':bc}) if int(p['is_building']) == 1: continue items[bc] = [unit] protos[bc] = p for bc, item_list in items.iteritems(): p = protos[bc] wnd = wx.Window(self, style=wx.SUNKEN_BORDER) wnd.proto_id = bc wnd.units = item_list sz = wx.BoxSizer(wx.HORIZONTAL) wnd.SetSizer(sz) self.units_sizer.Add(wnd) if 'carapace' in p and p['carapace']: img = image.getCarapaceImage(int(p['carapace']), int(p['color'])) else: img = image.getBcImage(bc) bmp = wx.StaticBitmap(wnd) if img: bmp.SetBitmap(img) sz.Add(bmp) n_str = '' if len(item_list) > 1: n_str = ' x%s'%(len(item_list),) name = get_unit_name(bc) if not name: name = p['name'] fly='' transport = '' if int(p['is_spaceship'])==1: fly = '%.2f/%.2f'%(p['fly_speed'], p['fly_range']) tc = int(p['transport_capacity']) if tc > 0: transport = '[%s]'%(tc,) text = wx.StaticText(wnd, -1, '%s%s%s %s'%(fly, transport, n_str, name,)) sz.Add(text) sz.Layout() wnd.Bind(wx.EVT_LEFT_DOWN, self.onLeftDown) bmp.Bind(wx.EVT_LEFT_DOWN, self.onLeftDown) text.Bind(wx.EVT_LEFT_DOWN, self.onLeftDown) self.sizer.Layout()
def set_coord(self, coord): self.coord = coord self.sizer.DeleteWindows() dsizer = wx.BoxSizer(wx.HORIZONTAL) self.sizer.Add(dsizer) dups = {} protos = {} up = store.get_object('user_planet', {'x':coord[0], 'y':coord[1]}) if not up: return user_id = up['user_id'] # buildings if ours for building in store.get_garrison_units(coord): bc = building['proto_id'] p = store.get_object('proto', {'proto_id':bc, 'user_id':user_id}) if not p: print 'proto not found for %s'%(building,) continue if int(p['is_building']) != 1: continue if 'max_count' in p and int(p['max_count'])!=1: dups.setdefault(bc, []).append(building) continue img = image.getBcImage(bc, 20) if not img: wnd = wx.StaticText(self, -1, 'Unknown building %s'%(bc,)) else: wnd = wx.StaticBitmap(self, wx.ID_ANY) wnd.SetBitmap(img) dsizer.Add(wnd) for bc, builds in dups.iteritems(): img = image.getBcImage(bc, 20) wsizer = wx.BoxSizer(wx.HORIZONTAL) self.sizer.Add(wsizer) wnd = wx.StaticBitmap(self, wx.ID_ANY) if img: wnd.SetBitmap(img) wsizer.Add(wnd) txt = wx.StaticText(self, -1, 'x %s'%(len(builds),)) build_more = wx.Button(self, label="+", size=(20,20)) build_more.proto_id = bc wsizer.Add(txt) wsizer.Add(build_more) build_more.Bind(wx.EVT_LEFT_DOWN, self.on_build) has_bq = None prev_units = [] for unit in store.get_building_queue(coord): if not has_bq: self.sizer.Add(wx.StaticText(self, label='build queue:')) has_bq = True if unit['done'] > 0: self.draw_build_stack(prev_units) prev_units = [] proto = store.get_object('proto', {'proto_id':unit['proto_id'], 'user_id':user_id}) img = image.getBcImage(unit['proto_id'], 20) if not img: img = image.getCarapaceImage(proto['carapace'], proto['color'], 20) wsizer = wx.BoxSizer(wx.HORIZONTAL) self.sizer.Add(wsizer) wnd = wx.StaticBitmap(self, wx.ID_ANY) if img: wnd.SetBitmap(img) wsizer.Add(wnd) name = proto['name'] if not name: name = get_unit_name(int(proto['carapace'])) race = store.get_object('race', {'user_id':user_id}) build_modifier = 0 #if proto['is_war'] == 1: # build_modifier = race['modifier_build_war'] #else: # build_modifier = race['modifier_build_peace'] total_speed = proto['build_speed'] - proto['build_speed']*build_modifier/100.0 # if we're lucky? if proto['proto_id'] == 13: govs_count = len(store.get_governers(user_id)) total_speed = pow(1.5, govs_count) * proto['build_speed'] percent_done = int(unit['done']*100/total_speed) txt = wx.StaticText(self, -1, ' %d%% %s'%(percent_done, name)) wsizer.Add(txt) if 'max_count' in proto and int(proto['max_count'])!=1: build_more = wx.Button(self, label="+", size=(20,20)) build_more.proto_id = proto['proto_id'] build_more.Bind(wx.EVT_LEFT_DOWN, self.on_build) wsizer.Add(build_more) continue if prev_units == [] or unit['proto_id'] == prev_units[0]['proto_id']: prev_units.append(unit) continue # draw prev_units self.draw_build_stack(prev_units) prev_units = [unit] self.draw_build_stack(prev_units) self.sizer.Layout()