diff options
Diffstat (limited to 'asciifarm/client')
| -rw-r--r-- | asciifarm/client/display/inventorypad.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/asciifarm/client/display/inventorypad.py b/asciifarm/client/display/inventorypad.py new file mode 100644 index 0000000..0b3bdf9 --- /dev/null +++ b/asciifarm/client/display/inventorypad.py @@ -0,0 +1,36 @@ + +import curses + +class InventoryPad: + + def __init__(self, title, maxItems=20): + self.title = title + self.maxItems = maxItems + self.pad = curses.newpad(maxItems+2, 100) + self.setInventory([]) + self.changed = False + self.lastView = None + + def setInventory(self, items): + self.items = items + self.pad.erase() + self.pad.addstr(0,0, self.title + ":\n") + for i, item in enumerate(items[:self.maxItems]): + self.pad.addstr(i+1, 2, item) + self.changed = True + + def getHeight(self): + return len(self.items)+2 + + def update(self, screen, x, y, xmax, ymax): + if not self.changed and (x, y, xmax, ymax) == self.lastView: + return + self.lastView = (x, y, xmax, ymax) + self.changed = False + self.pad.noutrefresh( + 0, + 0, + y, + x, + ymax-1, + xmax-1) |
