def __init__(self,text,command,size="normal"): self.on_surf = typefaces.prepare(text,size=size,colour=(0,0,0)) self.off_surf = typefaces.prepare(text,size=size,colour=(150,150,150)) self.command = command self.width = self.on_surf.get_width() self.height = self.on_surf.get_height() self.selectable = True
def make_titledbox(position,title,text,width,titlesize="subtitle", textsize="normal",gap=12,indent=20,colour=(0,0,0)): titlewidget = SurfWidget( typefaces.prepare(title,size=titlesize,colour=colour)) textwidget = SurfWidget( typefaces.prepare_passage(text,width-indent*2,size=textsize,colour=colour)) return TextFrame(position, [titlewidget, SpaceWidget(gap), textwidget],width)
def update_pricetag(self, item): text = None r = self.repairable colour = WHITE if item: if item == "REPAIR" and r: cost = int((float(r.damage)/r.durability)*r.cost) price = lsb(cost) if cost>0 else "free" text = "Repair %s for %s"%(r.name,price) if cost > self.situation.wealth: colour = RED elif item.human: price = ("for %s"%lsb(item.cost)) if item.cost>0 else "" if self.situation.population < 1 or item.cost > self.situation.wealth: colour = RED text = "Deploy %s %s"%(item.name,price) else: price = lsb(item.cost) if item.cost>0 else "free" text = "Build %s for %s"%(item.name,price) if item.cost > self.situation.wealth: colour = RED self.pricetag = typefaces.prepare(text, size="small", colour=colour)
def update(self): self.textsurf = typefaces.prepare(self.text+"|")
def __init__(self, position): self.position = position self.message = typefaces.prepare("Return key to punch the card", size="small") self.text = "" self.update()
def set_unit_name(self, unit_name): if unit_name: self.unit_name = typefaces.prepare(unit_name, size="small", colour=(255,255,240)) else: self.unit_name = None