Changeset 383:87246b84a851


Ignore:
Timestamp:
04/09/11 14:02:51 (12 years ago)
Author:
Jeremy Thurgood <firxen@…>
Branch:
default
Phase:
public
Message:

Notification text.

Location:
skaapsteker
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/engine.py

    r339 r383  
    122122        super(OpenDialog, cls).post(npc=npc)
    123123
     124class OpenNotification(UserEvent):
     125
     126    utype = "OPEN_NOTIFICATION"
     127
     128    @classmethod
     129    def post(cls, text):
     130        # request to open dialog box for given NPC sprite
     131        # will do nothing if the NPC's current state has
     132        # no text
     133        super(OpenNotification, cls).post(text=text)
     134
    124135class CloseDialog(UserEvent):
    125136
  • skaapsteker/levelscene.py

    r357 r383  
    1616from .sprites import player
    1717from .widgets.text import Text
    18 from .widgets.bubble import DialogueWidget
     18from .widgets.bubble import DialogueWidget, NotificationWidget
    1919
    2020
     
    134134        else:
    135135            self._close_dialogue()
     136
     137    def _open_notification(self, text):
     138        if self._dialogue is not None:
     139            self._dialogue.close()
     140        self._world.freeze()
     141        self._dialogue = NotificationWidget(text)
    136142
    137143    def _close_dialogue(self):
     
    326332        elif engine.OpenDialog.matches(ev):
    327333            self._open_dialogue(ev.npc)
     334        elif engine.OpenNotification.matches(ev):
     335            self._open_notification(ev.text)
    328336        elif engine.CloseDialog.matches(ev):
    329337            self._close_dialogue()
  • skaapsteker/sprites/items.py

    r354 r383  
    1 from base import Item
     1from .. import engine
     2from .base import Item
    23
    34
     
    7475            self._me.brewed = True
    7576            player.discard_item()
     77            engine.OpenNotification.post(text="A nice cup of tea is brewing.")
    7678            return
    7779        if player.has_item('teacup'):
     
    8284            else:
    8385                print "Sadly, the teapot is empty."
     86            return
     87        engine.OpenNotification.post(text="A proper tea ceremony requires a cup.")
    8488
    8589
  • skaapsteker/widgets/bubble.py

    r338 r383  
    77from ..engine import OpenDialog, CloseDialog
    88from .text import Text, TextChoice
     9
     10
     11class NotificationWidget(object):
     12
     13    def __init__(self, text):
     14        pos = pygame.Rect((0, 0), (300, 1))
     15        self._text = Text(text, pos, wrap=True)
     16
     17
     18    def draw(self, level_surface):
     19        if self._text:
     20            self._text.rect.center = level_surface.get_clip().center
     21
     22            bgrect = self._text.rect.inflate(10, 10)
     23            bgrect2 = bgrect.move(0, 0) #
     24            bgrect2.topleft = (0, 0)
     25            bgsurf = pygame.Surface(bgrect.size, flags=SRCALPHA)
     26            bgsurf.fill((255, 255, 127, 120))
     27            pygame.draw.rect(bgsurf, (0, 0, 0, 120), bgrect2, 1)
     28            level_surface.blit(bgsurf, bgrect)
     29
     30            self._text.draw(level_surface)
     31
     32    def close(self):
     33        pass
     34
     35    def dispatch(self, ev):
     36        if ev.type == KEYDOWN and ev.key == K_RETURN:
     37            CloseDialog.post(None)
     38
    939
    1040
Note: See TracChangeset for help on using the changeset viewer.