def draw_gui(self): if not hasattr(self, "action_set"): try: level = self._class.default_level_on_build except AttributeError: level = self.session.world.player.settler_level action_set = self._class.get_random_action_set(level=level) action_sets = ActionSetLoader.get_sets() for action_option in ['idle', 'idle_full', 'single', 'abcd']: if action_option in action_sets[action_set]: action = action_option break else: # If no idle, idle_full or abcd animation found, use the first you find action = action_sets[action_set].keys()[0] rotation = (self.rotation + int(self.session.view.cam.getRotation()) - 45) % 360 image = sorted(action_sets[action_set][action][rotation].keys())[0] if GFX.USE_ATLASES: # Make sure the preview is loaded horizons.globals.fife.animationloader.load_image(image, action_set, action, rotation) building_icon = self.gui.findChild(name='building') loaded_image = horizons.globals.fife.imagemanager.load(image) building_icon.image = fife.GuiImage(loaded_image) width = loaded_image.getWidth() # TODO: Remove hardcoded 220 max_width = 220 if width > max_width: height = loaded_image.getHeight() size = (max_width, (height * max_width) // width) building_icon.max_size = building_icon.min_size = building_icon.size = size # TODO: Remove hardcoded 70 gui_x, gui_y = self.__class__.gui.size icon_x, icon_y = building_icon.size building_icon.position = (gui_x // 2 - icon_x // 2, gui_y // 2 - icon_y // 2 - 70) self.__class__.gui.adaptLayout()
def __get__(self, obj, objtype=None): d = getattr(obj, self.prop_name, {}) image = d.get("image", None) if not image: image = fife.GuiImage() image.source = "" return image
def __set__(self, obj, image): image_info = getattr(obj, self.prop_name, {}) if not image: image_info["source"] = "" image_info["image"] = fife.GuiImage() image_info["image"]._source = "" self._getSetter(obj)(None) elif isinstance(image, (str, new_str)): image_info["source"] = image # to catch or not to catch ... # we just let the NotFound exception trickle here. # depedning on complains we can catch and print a warning. image_info["image"] = get_manager().loadImage(image) image_info["image"].source = image self._getSetter(obj)(image_info["image"]) elif isinstance(image, fife.GuiImage): # FIXME - this trickery with the hidden annotation # with an _source attribute isn't really clean. # Is it even necessary image_info["source"] = getattr(image, "source", "") image_info["image"] = image if image_info["source"]: image_info["image"] = get_manager().loadImage( image_info["source"]) self._getSetter(obj)(image_info["image"]) else: attribute_name = "%s.%s" % (obj.__class__.__name__, self.name) error_message = "%s only accepts GuiImage and python strings, not '%s'" raise RuntimeError(error_message % (attribute_name, repr(image))) setattr(obj, self.prop_name, image_info)
def _getImage(self, obj): """ Returns an image for the given object. @param: fife.Object for which an image is to be returned @return: fife.GuiImage""" visual = None try: visual = obj.get2dGfxVisual() except: print 'Visual Selection created for type without a visual?' raise # Try to find a usable image index = visual.getStaticImageIndexByAngle(self.rotation) image = None # if no static image available, try default action if index == -1: action = obj.getAction(self.action) if action: animation_id = action.get2dGfxVisual().getAnimationIndexByAngle(self.rotation) animation = self.engine.getAnimationPool().getAnimation(animation_id) image = animation.getFrameByTimestamp(0) index = image.getPoolId() # Construct the new GuiImage that is to be returned if index != -1: image = fife.GuiImage(index, self.engine.getImagePool()) return image
def _show_modal_background(self): """ Loads transparent background that de facto prohibits access to other gui elements by eating all input events. """ height = horizons.globals.fife.engine_settings.getScreenHeight() width = horizons.globals.fife.engine_settings.getScreenWidth() image = horizons.globals.fife.imagemanager.loadBlank(width, height) image = fife.GuiImage(image) self._modal_background = Icon(image=image) self._modal_background.position = (0, 0) self._modal_background.show()
def show_modal_background(self): """ Loads transparent background that de facto prohibits access to other gui elements by eating all input events. Used for modal popups and our in-game menu. """ height = horizons.globals.fife.engine_settings.getScreenHeight() width = horizons.globals.fife.engine_settings.getScreenWidth() image = horizons.globals.fife.imagemanager.loadBlank(width, height) image = fife.GuiImage(image) self.additional_widget = pychan.Icon(image=image) self.additional_widget.position = (0, 0) self.additional_widget.show()
def draw_data(self, data): """Display data from dump_data""" # only icon mode for now self.minimap_image.reset() self.icon.image = fife.GuiImage(self.minimap_image.image) self.minimap_image.set_drawing_enabled() rt = self.minimap_image.rendertarget render_name = self._get_render_name("base") drawPoint = rt.addPoint point = fife.Point() for x, y, r, g, b in json.loads(data): point.set(x, y) drawPoint(render_name, point, r, g, b)
def draw(self): """Recalculates and draws the whole minimap of self.session.world or world. The world you specified is reused for every operation until the next draw(). """ if self.world is None and self.session.world is not None: self.world = self.session.world # in case minimap has been constructed before the world if not self.world.inited: return # don't draw while loading if self.transform is None: self.transform = _MinimapTransform(self.world.map_dimensions, self.location, 0, self._get_rotation_setting()) self.update_rotation() self.__class__._instances.append(self) # update cam when view updates if self.view is not None and not self.view.has_change_listener( self.update_cam): self.view.add_change_listener(self.update_cam) if not hasattr(self, "icon"): # add to global generic renderer with id specific to this instance self.renderer.removeAll("minimap_image" + self._id) self.minimap_image.reset() # NOTE: this is for the generic renderer interface, the offrenderer has slightly different methods node = fife.RendererNode( fife.Point(self.location.center.x, self.location.center.y)) self.renderer.addImage("minimap_image" + self._id, node, self.minimap_image.image, False) else: # attach image to pychan icon (recommended) self.minimap_image.reset() self.icon.image = fife.GuiImage(self.minimap_image.image) self.update_cam() self._recalculate() if not self.preview: self._timed_update(force=True) ExtScheduler().rem_all_classinst_calls(self) ExtScheduler().add_new_object(self._timed_update, self, self.SHIP_DOT_UPDATE_INTERVAL, -1)
def draw_data(self, data): """Display data from dump_data""" # only icon mode for now self.minimap_image.reset() self.icon.image = fife.GuiImage(self.minimap_image.image) self.minimap_image.set_drawing_enabled() rt = self.minimap_image.rendertarget render_name = self._get_render_name("base") draw_point = rt.addPoint point = fife.Point() # XXX There have been reports about `data` containing Fife debug # output (e.g. #2193). As temporary workaround, we try to only # parse what looks like valid json in there and ignore the rest. found_json = re.findall(r'\[\[.*\]\]', data)[0] for x, y, r, g, b in json.loads(found_json): point.set(x, y) draw_point(render_name, point, r, g, b)
def _get_image(self, object_data=None, object=None): """ returns an image for the given object data @type object: fife.Object @param object: object instance @type object_data: ListItem @param object_data: wrapper class containing obj id and namespace @rtype result: fife.GuiImage @return result: gui image of the visual of the given object @return: fife.GuiImage """ if object_data is None and object is None: return if object_data is not None: object_id = object_data.object_id namespace = object_data.namespace object = self._engine.getModel().getObject(object_id, namespace) if object is None: return visual = object.get2dGfxVisual() result = None imageptr = None # try to find a usable image index = visual.getStaticImageIndexByAngle(0) # if no static image available, try default action if index == -1: action = object.getDefaultAction() if action: animation = action.get2dGfxVisual().getAnimationByAngle(0) imageptr = animation.getFrameByTimestamp(0) else: # static image found use the index to get the image from the image manager imageptr = self._engine.getImageManager().get(index) if imageptr is not None: result = fife.GuiImage(imageptr) return result
def _fife_load_image(filename, gui=True): img = engine.getImageManager().load(filename) if gui: return fife.GuiImage(img) return img
def _fife_load_image(filename): img = engine.getImageManager().load(filename) return fife.GuiImage(img)