summaryrefslogtreecommitdiff
path: root/asciifarm/client/display/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'asciifarm/client/display/__init__.py')
-rw-r--r--asciifarm/client/display/__init__.py45
1 files changed, 38 insertions, 7 deletions
diff --git a/asciifarm/client/display/__init__.py b/asciifarm/client/display/__init__.py
index 41383d6..80e2904 100644
--- a/asciifarm/client/display/__init__.py
+++ b/asciifarm/client/display/__init__.py
@@ -4,8 +4,15 @@ import curses
from .fieldpad import FieldPad
from .infopad import InfoPad
from .healthpad import HealthPad
+from .inventorypad import InventoryPad
from .screen import Screen
+
+SIDEWIDTH = 20
+HEALTHHEIGHT = 2
+INVENTORYHEIGHT = 12
+
+
class Display:
def __init__(self, stdscr, charMap, colours=False):
@@ -15,9 +22,12 @@ class Display:
self.characters = charMap["mapping"]
self.defaultChar = charMap.get("default", "?")
self.infoPad = InfoPad((100, 100))
- self.healthPad = HealthPad((20, 1))
+ self.healthPad = HealthPad(20, ("@",39), ("-",23), colours)
+ self.inventoryPad = InventoryPad("Inventory", 16)
+ self.groundPad = InventoryPad("Ground", 8)
self.lastinfostring = None
self.colours = colours
+ self.changed = False
if colours:
curses.use_default_colors()
for i in range(0, min(256, curses.COLORS, curses.COLOR_PAIRS)):
@@ -32,28 +42,49 @@ class Display:
(x, y), spriteName = cell
sprite = self.getChar(spriteName)
self.fieldPad.changeCell(x, y, *sprite)
- self.screen.change()
+ self.change()
def setFieldCenter(self, pos):
self.fieldPad.setCenter(pos)
- def showHealth(self, health, maxHealth):
+ def setHealth(self, health, maxHealth):
self.healthPad.setHealth(health, maxHealth)
- self.screen.change()
+ self.change()
def showInfo(self, infostring):
if infostring != self.lastinfostring:
self.infoPad.showString(infostring)
- self.screen.change()
+ self.change()
self.lastinfostring = infostring
+ def setInventory(self, items):
+ self.inventoryPad.setInventory(items)
+ self.change()
+
+ def setGround(self, items):
+ self.groundPad.setInventory(items)
+ self.change()
+
def getChar(self, sprite):
char = self.characters.get(sprite, self.defaultChar)
if isinstance(char, str):
return [char]
return char
- def update(self):
- self.screen.update(self.fieldPad, self.infoPad, self.healthPad)
+ def change(self):
+ self.changed = True
+ def update(self):
+ if self.changed:
+ fieldRight = min(self.fieldPad.getWidth(), self.screen.getWidth()-SIDEWIDTH-1)
+ healthBottom = self.healthPad.getHeight()
+ inventoryBottom = healthBottom + self.inventoryPad.getHeight()
+ groundBottom = inventoryBottom + self.groundPad.getHeight()
+ self.fieldPad.update(self, 0,0,fieldRight, min(self.fieldPad.getHeight(), self.screen.getHeight()))
+ self.healthPad.update(self, fieldRight+1,0, self.screen.getWidth(), healthBottom)
+ self.inventoryPad.update(self, fieldRight+1, healthBottom, self.screen.getWidth(), min(self.screen.getHeight(), inventoryBottom))
+ self.groundPad.update(self, fieldRight+1, inventoryBottom, self.screen.getWidth(), min(self.screen.getHeight(), groundBottom))
+ self.infoPad.update(self, fieldRight+1,groundBottom+1, self.screen.getWidth(), self.screen.getHeight())
+ curses.doupdate()
+ self.changed = False