Commits

Arne Babenhauserheide  committed f704412

added foreground sprites for showing more interesting dialogue.

  • Participants
  • Parent commits 71b7f44

Comments (0)

Files changed (2)

File hexbattle_gui.py

         self.overlay.append(self.command_overlay)
         self.overlay.append(self.movement_overlay)
         
+        self.theater_overlay = TheaterOverlay(self)
+        self.overlay.append(self.theater_overlay)
+        self.theater_overlay.show(join("graphics", "wesnoth", "druid.png"))
+        self.theater_overlay.show(join("graphics", "wesnoth", "druid.png"),position="right")
+
         self.text_overlay = TextOverlay(self)
         self.text_overlay.show("""
 Select a white hex to move
      < enter to hide >     """)
         self.overlay.append(self.text_overlay)
 
-
     def update(self, dt=0): 
         """Update the stats of all scene objects. 
         

File hexbattle_overlays.py

         image_path=join("graphics", "hex-textbackground.png")
         super(TextBackground, self).__init__(scene, image_path=image_path,
                                      *args, **kwds)
-        
+
+class CharacterImage(Hexfield): 
+    """The background hexes for text overlays."""
+    def __init__(self, scene, img=None, char=None, *args, **kwds):
+        image_path=img
+        super(CharacterImage, self).__init__(scene, image_path=image_path,
+                                     *args, **kwds)        
 
 class Overlay(object):
     @property
             return action
     
 
+
 class TextOverlay(Overlay):
     """An overlay to show Text.
 
         self.text = Label("")
 
 
+class TheaterOverlay(TextOverlay):
+    """An overlay to show Character Images.
+
+    >>> # Use the overlay without scene — nonfunctional ⇒ only for testing. 
+    >>> c = TextOverlay(None)
+    """
+    def __init__(self, scene, leftimage=None, rightimage=None):
+        self.scene = scene
+        self.hex_x = 0
+        self.hex_y = 0
+        self.leftimage = leftimage
+        self.rightimage = rightimage
+        #: The fields on which we want to be.
+        self.fields = {}
+        #: The hexes we want to place stuff on, relative to our position.
+
+    @property
+    def visible(self):
+        return self.fields.values() + [im for im in (
+                self.leftimage, self.rightimage) if im]
+
+    @property
+    def is_visible(self):
+        return self.fields or self.leftimage or self.rightimage
+
+    def show(self, image, position=None):
+        winwidth = self.scene.core.win.width
+        winheight = self.scene.core.win.height
+
+        if position=="right" or self.leftimage:
+            self.rightimage = CharacterImage(self.scene, image)
+            # mirror the image
+            self.rightimage.image = self.rightimage.image.get_texture().get_transform(flip_x=True)
+            # move it to the right side
+            self.rightimage.x = winwidth
+            if not position: position = "right"
+        else:
+            self.leftimage = CharacterImage(self.scene, image)
+            if not position: position = "left"
+
+        if self.leftimage:
+            width,height = self.leftimage.width, self.leftimage.height
+            leftmin = coordinate_to_hexgrid(0, 0)
+            # +36 to make sure that it gives a border around the text
+            leftmax = coordinate_to_hexgrid(width,height)
+            leftpositions = self.squarehexes(leftmin, leftmax)
+        else: leftpositions = []
+
+        if self.rightimage:
+            width,height = self.rightimage.width, self.rightimage.height
+            rightmin = coordinate_to_hexgrid(winwidth - width, winheight - height)
+            rightmax = coordinate_to_hexgrid(winwidth, winheight)
+            rightpositions = self.squarehexes(rightmin, rightmax)
+        else: rightpositions = []
+        
+        for pos in []:#leftpositions+rightpositions:
+            x, y = hexgrid_to_coordinate(*pos)
+            a = TextBackground(self.scene, x=x, y=y)
+            a.move_to_hex(*pos)
+            self.fields[pos] = a
+            
+    def draw(self):
+        for field in self.fields.values():
+            field.draw()
+        if self.leftimage:
+            self.leftimage.draw()
+        if self.rightimage:
+            self.rightimage.draw()
+
+    def hide(self, position=None):
+        """Let one or all chars disappear."""
+        if not position:
+            self.fields = {}
+            self.text = Label("")
+            self.leftimage, self.rightimage = None, None
+        elif position == "left":
+            self.leftimage = None
+        elif position == "right":
+            self.rightimage = None
+
+
+
 if __name__ == "__main__":
     # there’s only one reason for calling this file: doctests
     from doctest import testmod