diff options
| author | troido <troido@hotmail.com> | 2017-10-26 21:43:38 +0200 |
|---|---|---|
| committer | troido <troido@hotmail.com> | 2017-10-26 21:43:38 +0200 |
| commit | b821aa6cc7e4bd137eb57a0ccebb5b514eb0031b (patch) | |
| tree | 1c1cd968860bd1ecf0c3d1871246f8fc976e6530 /asciifarm/client | |
| parent | 092d91ca44bd8b571e3ae3e00d01a90f723eb8a4 (diff) | |
included inventorypad in right location
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) |
