+ # a dialgoue ID of 0 always exits the conversation
+ # return the unique response ID
+ if dlg_id == "0":
+ return current_resp
+
+ # not reply mode
+ if reply_mode is False:
+ if npc.portrait is not None:
+ screen.blit (npc.portrait, (leftedge, topedge))
+
+ # get the lines to display wrapped using textwrap module
+ lines = []
+ textnpc = textwrap.wrap (convtree[dlg_id][0], 40)
+ for text in textnpc:
+ lines.append ((10, 0, 0, 0, text))
+
+ put_lines (screen, lines,
+ pygame.Rect(leftedge+marginleft, topedge+margintop,
+ bgwidth-marginleft-marginright, bgheight-margintop-marginbottom))
+ pygame.display.update ()
+
+ for event in pygame.event.get ():
+ if event.type == pygame.QUIT:
+ sys.exit (0)
+ elif event.type == pygame.KEYDOWN:
+ # now continue the dialog
+ if event.key == pygame.K_RETURN or event.key == pygame.K_SPACE:
+ reply_mode = True
+ current_resp = convtree[dlg_id][1][0][1]
+ sel = 0
+ # reply mode
+ else:
+ if responder_portrait is not None:
+ screen.blit (responder_portrait, (leftedge, topedge))
+
+ lines = []
+ for resptext, respid, nextdlgid in convtree[dlg_id][1]:
+ if respid == current_resp:
+ lines.append ((10, 255, 0, 0, resptext))
+ else:
+ lines.append ((10, 0, 0, 0, resptext))
+
+ put_lines (screen, lines,
+ pygame.Rect (leftedge+marginleft, topedge+margintop,
+ bgwidth-marginleft-marginright, bgheight-margintop-marginbottom))
+
+ pygame.display.update ()
+ for event in pygame.event.get ():
+ if event.type == pygame.QUIT:
+ sys.exit (0)
+ elif event.type == pygame.KEYDOWN:
+ if event.key == pygame.K_UP or event.key == pygame.K_LEFT:
+ sel -= 1
+ if sel < 0:
+ sel = 0
+ current_resp = convtree[dlg_id][1][sel][1]
+ elif event.key == pygame.K_DOWN or event.key == pygame.K_RIGHT:
+ sel += 1
+ if sel >= len (convtree[dlg_id][1]):
+ sel = len(convtree[dlg_id][1]) - 1
+ current_resp = convtree[dlg_id][1][sel][1]
+
+ elif event.key == pygame.K_RETURN or event.key == pygame.K_SPACE:
+ dlg_id = convtree[dlg_id][1][sel][2]
+ reply_mode = False