X-Git-Url: https://git.ctpug.org.za/?a=blobdiff_plain;f=naja%2Fwidgets%2Fselector.py;h=b1f0cbf5f64f029cc2cd2f39d7f80ec7683b1b93;hb=68445d365c053ecfad14680003a6fce97453ef13;hp=f4706ee096c5833f4c362f8c090bf0393fd35da9;hpb=a0657c281733cdca517e046af77b0288677a88e4;p=naja.git diff --git a/naja/widgets/selector.py b/naja/widgets/selector.py index f4706ee..b1f0cbf 100644 --- a/naja/widgets/selector.py +++ b/naja/widgets/selector.py @@ -3,7 +3,7 @@ import pygame.locals as pgl from naja.constants import KEYS from naja.widgets.base import Container from naja.resources import resources -from naja.resources.mutators import EIGHT_BIT, R270 +from naja.resources.mutators import EIGHT_BIT, R270, R90 from naja.sound import sound @@ -11,26 +11,40 @@ class SelectorWidget(Container): def __init__(self, *args, **kwargs): super(SelectorWidget, self).__init__(*args, **kwargs) self.position = 0 - self.selector = resources.get_image('bits', 'arrow_on.png', - transforms=(R270, EIGHT_BIT)) + self.left_selector = resources.get_image('bits', 'arrow_on.png', + transforms=(R270, EIGHT_BIT)) + self.right_selector = resources.get_image('bits', 'arrow_on.png', + transforms=(R90, EIGHT_BIT)) def render(self, surface): super(SelectorWidget, self).render(surface) - pos = self.selector.get_rect() + pos = self.left_selector.get_rect() selected = self.widgets[self.position] + if not selected.is_selectable(): + selected = self.change_pos(1) + pos = pos.move(selected.pos) - pos = pos.move(-pos.width * 1.5, (selected.size[1] - pos.height) / 2) - surface.blit(self.selector, pos) + left_pos = pos.move(-pos.width * 1.5, + (selected.size[1] - pos.height) / 2) + right_pos = pos.move(selected.size[0] + pos.width * 0.5, + (selected.size[1] - pos.height) / 2) + surface.blit(self.left_selector, left_pos) + surface.blit(self.right_selector, right_pos) + + def change_pos(self, change): + self.position = (self.position + change) % len(self.widgets) + while not self.widgets[self.position].is_selectable(): + self.position = (self.position + change) % len(self.widgets) + return self.widgets[self.position] def handle_event(self, ev): if ev.type == pgl.KEYDOWN: if ev.key in KEYS.UP + KEYS.DOWN: if ev.key in KEYS.DOWN: - self.position += 1 + self.change_pos(1) else: - self.position -= 1 - self.position %= len(self.widgets) - sound.play_sound('change_action.ogg', volume=0.05) + self.change_pos(-1) + sound.play_sound('zoop.ogg', volume=0.05) return True elif ev.key in KEYS.SELECT: return self.widgets[self.position].callback('click')