def execute(self,actionNum = 0): if len (self.actions) == 0: g.LOG.log("Its not working!") return 0 if len(self.actions) == 1: return self.actions[0].execute() else: ##display menu of possible actions g.SCREEN.fill((0,0,0)) startx = 10 starty = 10 xoffset = 0 yoffset = 0 #TODO replace with itemlist object - duplicate code for i in range (len(self.actions)): if yoffset >= 19 * (g.FONTSIZE+5): yoffset = 0 xoffset += (32 * (g.FONTSIZE//2)) + 5 misc.printText("- " + str(i), g.FONTNAME, g.FONTSIZE, startx + xoffset, starty + yoffset) description = self.actions[i].description if len(description) > 30: description = description [:-3] + "..." misc.printText(description, g.FONTNAME, g.FONTSIZE, startx + xoffset + g.FONTSIZE, starty + yoffset) yoffset += g.FONTSIZE + 5 pygame.display.update() while True: for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.unicode == " ": return 0 elif event.unicode in "1023456789": return self.actions[int(event.unicode)].execute()
def processMessages(self): if len(self.pending) == 0: self.display() return self.pending = logLines(self.pending) numLines = len(self.pending) ystart = self.image.get_height() - g.FONTSIZE ##Keep going until out of new lines to display while True: self.image.fill(g.BLACK) #blank the message log yoffset = 0 available = 6 numLines = len(self.pending) #see how many new lines need to be displayed if numLines > available:#if its more than a single screen self.history += self.pending[:available - 1]#add appropriate number to self.pending = self.pending[available - 1:] self.history.append("--More--") for i in range(1, available+1 if len(self.history) >= available else len(self.history)+1): misc.printText(self.history[-i], "Courier", g.MSGSIZE, 0, ystart + yoffset, surface = self.image) yoffset -= g.FONTSIZE self.display() pygame.display.update() waiting = True while waiting: for event in pygame.event.get(): if event.type == pygame.KEYDOWN: waiting = False else: self.history += self.pending self.pending.clear() for i in range(1, available+1 if len(self.history) >= available else len(self.history)+1): misc.printText(self.history[-i], "Courier", g.MSGSIZE, 0, ystart + yoffset, surface = self.image) yoffset -= g.FONTSIZE self.display() pygame.display.update() break if len(self.pending) == 0: break
def displayItems(self): g.SCREEN.fill((0,0,0)) keys = list(self.items.keys()) keys.sort() startx = 10 starty = 10 xoffset = 0 yoffset = 0 for key in keys: if yoffset >= 19 * (g.FONTSIZE+5): yoffset = 0 xoffset += (22 * (g.FONTSIZE//2)) + 5 misc.printText("- " + key, g.FONTNAME, g.FONTSIZE, startx + xoffset, starty + yoffset) itemName = self.items[key].name if len(itemName) > 20: itemName = itemName [:-3] + "..." misc.printText(itemName, g.FONTNAME, g.FONTSIZE, startx + xoffset + g.FONTSIZE, starty + yoffset) yoffset += g.FONTSIZE + 5 pygame.display.update()
def prompt(self, promptString): inputString = "" inputSurface = pygame.Surface( (self.image.get_width(), g.MSGSIZE) ) self.logNow(promptString) inputStart = (len(promptString) +4) * (g.MSGSIZE//2) while True: self.display() pygame.display.update() #TODO need input handler class for newEvent in pygame.event.get(): if newEvent.type == pygame.KEYDOWN: if newEvent.key == 8: if len(inputString) != 0: inputString = inputString [:-1] elif newEvent.key == 13: self.history[-1] += inputString return inputString else: inputString += (newEvent.unicode) inputSurface.fill(g.BLACK) misc.printText(inputString, "Courier", g.MSGSIZE, 0,0 , g.WHITE, surface = inputSurface) self.image.blit(inputSurface, (inputStart,self.image.get_height() - g.FONTSIZE) )
def update_display(self): self.surface.fill(g.BLACK) keys = list(self.items.keys()) keys.sort() print("keys are" , keys) xoffset = yoffset = 0 for key in keys: if yoffset >= 19 * (self.fontsize+5): yoffset = 0 xoffset += (22 * (self.fontsize//2)) + 5 misc.printText("- " + key, self.font, self.fontsize, xoffset, yoffset, surface = self.surface) if type(self.items[key]) == str: itemName = self.items[key] else: itemName = self.items[key].name if len(itemName) > 20: itemName = itemName [:-3] + "..." print("printing:" , itemName) misc.printText(itemName, self.font, self.fontsize, xoffset + self.fontsize, yoffset,surface = self.surface) yoffset += self.fontsize + 5