def parse_logbook_item(self, parameter): # json.loads() returns unicode, thus convert strings and compare to unicode # Image works with str() since pychan can only use str objects as file path if parameter and parameter[0]: # allow empty Labels parameter_type = parameter[0] if isinstance(parameter, basestring): add = Label(text=unicode(parameter), wrap_text=True, min_size=(335, 0), max_size=(335, 508)) elif parameter_type == u'Label': add = Label(text=unicode(parameter[1]), wrap_text=True, min_size=(335, 0), max_size=(335, 508)) elif parameter_type == u'Image': add = Icon(image=str(parameter[1])) elif parameter_type == u'Gallery': add = HBox() for image in parameter[1]: add.addChild(Icon(image=str(image))) elif parameter_type == u'Headline': add = Label(text=parameter[1]) add.stylize('headline') elif parameter_type == u'Message': add = None # parameters are re-read on page reload. # duplicate_message stops messages from # being duplicated on page reload. duplicate_message = parameter[1] in self._messages if not duplicate_message: self._messages[parameter[1]] = False # has not been displayed else: print '[WW] Warning: Unknown parameter type {typ} in parameter {prm}'.format( typ=parameter[0], prm=parameter) add = None self.log.debug("parameter added of type %s", parameter_type) return add
def set_construction_mode(self, resource_source_instance, build_costs): """Show resources relevant to construction and build costs @param resource_source_instance: object with StorageComponent @param build_costs: dict, { res : amount } """ if resource_source_instance is None: # Build moved out of settlement. This is usually not sane and an interaction error. # Use this heuristically computed settlement to fix preconditions. resource_source_instance = LastActivePlayerSettlementManager().get() if ( self.construction_mode and resource_source_instance == self.current_instance() and build_costs == self._last_build_costs ): return # now that's not an update self._last_build_costs = build_costs self.construction_mode = True self.set_inventory_instance(resource_source_instance, keep_construction_mode=True) # label background icons cost_icon_gold = "content/gui/images/background/widgets/resbar_stats_bottom.png" cost_icon_res = "content/gui/images/background/widgets/res_extra_bg.png" res_list = self._get_current_resources() # remove old one before, avoids duplicates self._drop_cost_labels() for res, amount in build_costs.iteritems(): assert res in res_list or res == RES.GOLD cost_label = Label(text=u"-" + unicode(amount)) cost_label.stylize(self.__class__.STYLE) # add icon below end of background icon if res in res_list: entry = res_list.index(res) cur_gui = self.gui[entry] reference_icon = cur_gui.findChild(name="background_icon") below = reference_icon.size[1] cost_icon = Icon(image=cost_icon_res, position=(0, below)) cost_label.position = (15, below) # TODO: centering cur_gui.addChild(cost_icon) cur_gui.addChild(cost_label) cur_gui.cost_gui = [cost_label, cost_icon] cur_gui.resizeToContent() # container needs to be bigger now else: # must be gold # there is an icon with scales there, use its positioning reference_icon = self.gold_gui.child_finder("balance_background") cost_icon = Icon(image=cost_icon_gold, position=(reference_icon.x, reference_icon.y)) cost_label.position = (23, 74) # TODO: centering self.gold_gui.addChild(cost_icon) self.gold_gui.addChild(cost_label) self.gold_gui.cost_gui = [cost_label, cost_icon] self.gold_gui.resizeToContent()
def set_construction_mode(self, resource_source_instance, build_costs): """Show resources relevant to construction and build costs @param resource_source_instance: object with StorageComponent @param build_costs: dict, { res : amount } """ if resource_source_instance is None: # Build moved out of settlement. This is usually not sane and an interaction error. # Use this heuristically computed settlement to fix preconditions. resource_source_instance = LastActivePlayerSettlementManager().get() if self.construction_mode and \ resource_source_instance == self.current_instance() and \ build_costs == self._last_build_costs: return # now that's not an update self._last_build_costs = build_costs self.construction_mode = True self.set_inventory_instance(resource_source_instance, keep_construction_mode=True) # label background icons cost_icon_gold = "content/gui/images/background/widgets/resbar_stats_bottom.png" cost_icon_res = "content/gui/images/background/widgets/res_extra_bg.png" res_list = self._get_current_resources() # remove old one before, avoids duplicates self._drop_cost_labels() for res, amount in build_costs.iteritems(): assert res in res_list or res == RES.GOLD cost_label = Label(text=u"-"+unicode(amount)) cost_label.stylize( self.__class__.STYLE ) # add icon below end of background icon if res in res_list: entry = res_list.index(res) cur_gui = self.gui[ entry ] reference_icon = cur_gui.findChild(name="background_icon") below = reference_icon.size[1] cost_icon = Icon(image=cost_icon_res, position=(0, below)) cost_label.position = (15, below) # TODO: centering cur_gui.addChild(cost_icon) cur_gui.addChild(cost_label) cur_gui.cost_gui = [cost_label, cost_icon] cur_gui.resizeToContent() # container needs to be bigger now else: # must be gold # there is an icon with scales there, use its positioning reference_icon = self.gold_gui.child_finder("balance_background") cost_icon = Icon(image=cost_icon_gold, position=(reference_icon.x, reference_icon.y)) cost_label.position = (23, 74) # TODO: centering self.gold_gui.addChild(cost_icon) self.gold_gui.addChild(cost_label) self.gold_gui.cost_gui = [cost_label, cost_icon] self.gold_gui.resizeToContent()
def parse_logbook_item(self, widget): # json.loads() returns unicode, thus convert strings and compare to unicode # Image works with str() since pychan can only use str objects as file path if widget and widget[0]: # allow empty Labels widget_type = widget[0] if isinstance(widget, basestring): add = Label(text=widget, wrap_text=True, max_size=(340,508)) elif widget_type == u'Label': add = Label(text=widget[1], wrap_text=True, max_size=(340,508)) elif widget_type == u'Image': add = Icon(image=str(widget[1])) elif widget_type == u'Gallery': add = HBox() for image in widget[1]: add.addChild(Icon(image=str(image))) elif widget_type == u'Headline': add = Label(text=widget[1]) add.stylize('headline') else: print '[WW] Warning: Unknown widget type {typ} in widget {wdg}'.format( typ=widget[0], wdg=widget) add = None return add