Shop GUI supports three options, improved navigation, still buggy for shops with no sell option.
Justin Armstrong justinmeister@gmail.com
Fri, 28 Mar 2014 18:29:37 -0700
3 files changed,
57 insertions(+),
32 deletions(-)
M
data/components/person.py
→
data/components/person.py
@@ -352,8 +352,8 @@
class FemaleVillager2(Person): """A second female person for town""" - def __init__(self, x, y): - super(FemaleVillager2, self).__init__('femvillager2', x, y) + def __init__(self, x, y, direction='down'): + super(FemaleVillager2, self).__init__('femvillager2', x, y, direction) self.index = 1
M
data/shopgui.py
→
data/shopgui.py
@@ -29,8 +29,11 @@ self.accept_dialogue = level.accept_dialogue
self.accept_sale_dialogue = level.accept_sale_dialogue self.arrow = textbox.NextArrow() self.selection_arrow = textbox.NextArrow() - self.arrow_pos1 = (50, 485) - self.arrow_pos2 = (50, 535) + self.arrow_pos1 = (50, 475) + self.arrow_pos2 = (50, 515) + self.arrow_pos3 = (50, 555) + self.arrow_pos_list = [self.arrow_pos1, self.arrow_pos2, self.arrow_pos3] + self.arrow_index = 0 self.selection_arrow.rect.topleft = self.arrow_pos1 self.dialogue_box = self.make_dialogue_box(self.dialogue, self.index) self.gold_box = self.make_gold_box()@@ -74,7 +77,8 @@ choices = ['Yes',
'No'] elif self.state == 'buysell': choices = ['Buy', - 'Sell'] + 'Sell', + 'Leave'] elif self.state == 'sell': choices = [self.item_to_be_sold, 'Cancel']@@ -82,11 +86,15 @@ else:
choices = ['Not', 'assigned'] choice1 = self.font.render(choices[0], True, c.NEAR_BLACK) - choice1_rect = choice1.get_rect(x=200, y=25) + choice1_rect = choice1.get_rect(x=200, y=15) choice2 = self.font.render(choices[1], True, c.NEAR_BLACK) - choice2_rect = choice2.get_rect(x=200, y=75) + choice2_rect = choice2.get_rect(x=200, y=55) surface.blit(choice1, choice1_rect) surface.blit(choice2, choice2_rect) + if len(choices) >= 3: + choice3 = self.font.render(choices[2], True, c.NEAR_BLACK) + choice3_rect = choice3.get_rect(x=200, y=95) + surface.blit(choice3, choice3_rect) sprite = pg.sprite.Sprite() sprite.image = surface sprite.rect = rect@@ -164,6 +172,8 @@ self.dialogue_box = self.make_dialogue_box(self.dialogue, self.index)
self.selection_box = self.make_selection_box() self.gold_box = self.make_gold_box() + + if keys[pg.K_DOWN]: self.selection_arrow.rect.topleft = self.arrow_pos2 elif keys[pg.K_UP]:@@ -171,11 +181,11 @@ self.selection_arrow.rect.topleft = self.arrow_pos1
elif keys[pg.K_SPACE] and (current_time - self.timer) > 200: if self.allow_input: if self.selection_arrow.rect.topleft == self.arrow_pos2: - self.level.done = True - self.level.game_data['last direction'] = 'down' + self.state = 'buysell' + self.arrow_index = 0 + self.allow_input = False elif self.selection_arrow.rect.topleft == self.arrow_pos1: self.state = 'confirmpurchase' - self.timer = current_time self.allow_input = False if not keys[pg.K_SPACE]:@@ -334,24 +344,37 @@ dialogue = ["Would you like to buy or sell an item?"]
self.dialogue_box = self.make_dialogue_box(dialogue, 0) self.selection_box = self.make_selection_box() - if keys[pg.K_DOWN]: - self.selection_arrow.rect.topleft = self.arrow_pos2 - elif keys[pg.K_UP]: - self.selection_arrow.rect.topleft = self.arrow_pos1 + self.selection_arrow.rect.topleft = self.arrow_pos_list[self.arrow_index] + + if keys[pg.K_DOWN] and self.allow_input: + if self.arrow_index < (len(self.arrow_pos_list) - 1): + self.arrow_index += 1 + self.allow_input = False + + elif keys[pg.K_UP] and self.allow_input: + if self.arrow_index > 0: + self.arrow_index -= 1 + self.allow_input = False elif keys[pg.K_SPACE] and self.allow_input: - if self.selection_arrow.rect.topleft == self.arrow_pos1: + if self.arrow_index == 0: self.state = 'select' self.allow_input = False - else: + elif self.arrow_index == 1: if self.check_for_sellable_items(): self.state = 'sell' self.allow_input = False + self.arrow_index = 0 else: self.state = 'cantsell' self.allow_input = False - self.selection_arrow.rect.topleft = self.arrow_pos1 + + else: + self.level.done = True + self.level.game_data['last direction'] = 'down' + + self.arrow_index = 0 - if not keys[pg.K_SPACE]: + if not keys[pg.K_SPACE] and not keys[pg.K_DOWN] and not keys[pg.K_UP]: self.allow_input = True@@ -360,24 +383,26 @@ """Have player select items to sell"""
dialogue = ["What would you like to sell?"] self.dialogue_box = self.make_dialogue_box(dialogue, 0) self.selection_box = self.make_selection_box() + self.selection_arrow.rect.topleft = self.arrow_pos_list[self.arrow_index] - if keys[pg.K_DOWN]: - self.selection_arrow.rect.topleft = self.arrow_pos2 + if keys[pg.K_DOWN] and self.allow_input: + if self.arrow_index < (len(self.arrow_pos_list) - 1): + self.arrow_index += 1 + self.allow_input = False elif keys[pg.K_UP]: - self.selection_arrow.rect.topleft = self.arrow_pos1 + if self.arrow_index > 0: + self.arrow_index -= 1 + self.allow_input = False elif keys[pg.K_SPACE] and self.allow_input: - if self.selection_arrow.rect.topleft == self.arrow_pos1: + if self.arrow_index == 0: self.state = 'confirmsell' self.allow_input = False else: - self.state = 'buysell' self.allow_input = False + self.arrow_index = 0 - self.selection_arrow.rect.topleft = self.arrow_pos1 - - - if not keys[pg.K_SPACE]: + if not keys[pg.K_SPACE] and not keys[pg.K_DOWN] and not keys[pg.K_UP]: self.allow_input = True
M
data/states/shop.py
→
data/states/shop.py
@@ -139,7 +139,7 @@
def make_purchasable_items(self): """Make list of items to be chosen""" dialogue = ['Rent a room. (30 gold)', - 'Leave.'] + 'Back.'] item = {'type': 'room', 'price': 30,@@ -168,7 +168,7 @@
def make_purchasable_items(self): """Make list of items to be chosen""" dialogue = ['Long Sword. (100 gold)', - 'Leave.'] + 'Back.'] item = {'type': 'Long Sword', 'price': 100,@@ -196,7 +196,7 @@
def make_purchasable_items(self): """Make list of items to be chosen""" dialogue = ['Chain Mail. (50 gold)', - 'Leave.'] + 'Back.'] item = {'type': 'Chain Mail', 'price': 50,@@ -223,7 +223,7 @@
def make_purchasable_items(self): """Make list of items to be chosen""" dialogue = ['Fire Spell. (150 gold)', - 'Leave.'] + 'Back.'] item = {'type': 'Fire Spell', 'price': 150,@@ -251,7 +251,7 @@
def make_purchasable_items(self): """Make list of items to be chosen""" dialogue = ['Healing Potion. (15 gold)', - 'Leave.'] + 'Back.'] item = {'type': 'Healing Potion', 'price': 15,