Permalink
Browse files

Add functionality to load single images from atlas, use it to load build

previews
  • Loading branch information...
1 parent 3f851ef commit 9b43cb898be8197307dd0f8ccac8f1cd8f653a2d @nihathrael nihathrael committed Apr 3, 2012
Showing with 30 additions and 8 deletions.
  1. +5 −1 horizons/gui/mousetools/buildingtool.py
  2. +25 −7 horizons/util/sqliteatlasloader.py
View
6 horizons/gui/mousetools/buildingtool.py
@@ -240,7 +240,11 @@ def draw_gui(self):
action = 'idle_full'
else: # If no idle animation found, use the first you find
action = action_sets[action_set].keys()[0]
- image = sorted(action_sets[action_set][action][(self.rotation+int(self.session.view.cam.getRotation())-45)%360].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.main.fife.animationloader.load_image(image, action_set, action, rotation)
building_icon = self.gui.findChild(name='building')
building_icon.image = image
# TODO: Remove hardcoded 70
View
32 horizons/util/sqliteatlasloader.py
@@ -67,13 +67,7 @@ def loadResource(self, location):
ani = fife.Animation.createAnimation()
# Set the correct loader based on the actionset
- loader = None
- if actionset.startswith("ts_"):
- loader = TileSetLoader
- elif actionset.startswith("as_"):
- loader = ActionSetLoader
- else:
- assert False, "Invalid set being loaded: " + actionset
+ loader = self._get_loader(actionset)
frame_start, frame_end = 0.0, 0.0
@@ -120,4 +114,28 @@ def loadResource(self, location):
ani.setActionFrame(0)
return ani
+ def _get_loader(self, actionset):
+ if actionset.startswith("ts_"):
+ loader = TileSetLoader
+ elif actionset.startswith("as_"):
+ loader = ActionSetLoader
+ else:
+ assert False, "Invalid set being loaded: " + actionset
+ return loader
+
+ def load_image(self, file, actionset, action, rotation):
+ loader = self._get_loader(actionset)
+ entry = loader.get_sets()[actionset][action][int(rotation)][file]
+ # we don't need to load images at this point to query for its parameters
+ # such as width and height because we can get those from json file
+ xpos, ypos, width, height = entry[2:]
+
+ if horizons.main.fife.imagemanager.exists(file):
+ img = horizons.main.fife.imagemanager.get(file)
+ else:
+ img = horizons.main.fife.imagemanager.create(file)
+ region = fife.Rect(xpos, ypos, width, height)
+ img.useSharedImage(self.atlaslib[entry[1]], region)
+
+ return img

0 comments on commit 9b43cb8

Please sign in to comment.