summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortroido <troido@hotmail.com>2017-11-13 14:09:16 +0100
committertroido <troido@hotmail.com>2017-11-13 14:09:16 +0100
commitf2bc01bae95fa66b9ebbb0d7f14f851ca4a2c7fb (patch)
treed67d2da36cc607983323be7375d24b40349466eb
parent8f614ac7812edf99e019bb318655f172d095f2f5 (diff)
fixed small terminal sizes
-rw-r--r--asciifarm/client/display/__init__.py2
-rw-r--r--asciifarm/client/display/fieldpad.py2
-rw-r--r--asciifarm/client/display/healthpad.py4
-rw-r--r--asciifarm/client/display/inventorypad.py2
-rw-r--r--asciifarm/client/display/screen.py18
5 files changed, 18 insertions, 10 deletions
diff --git a/asciifarm/client/display/__init__.py b/asciifarm/client/display/__init__.py
index fc48d55..159330a 100644
--- a/asciifarm/client/display/__init__.py
+++ b/asciifarm/client/display/__init__.py
@@ -35,6 +35,8 @@ class Display:
self.lastinfostring = None
self.changed = False
self.messagePad = messagepad.MessagePad(5)
+
+ self.screen.update(True)
def resizeField(self, size):
diff --git a/asciifarm/client/display/fieldpad.py b/asciifarm/client/display/fieldpad.py
index 1966611..e9e3ee1 100644
--- a/asciifarm/client/display/fieldpad.py
+++ b/asciifarm/client/display/fieldpad.py
@@ -39,7 +39,7 @@ class FieldPad:
return x // self.charSize * self.charSize
def update(self, win, force=False):
- if not self.changed and not force:
+ if not self.changed and not force or not win:
return
#self.lastView = (x, y, xmax, ymax)
height, width = win.getmaxyx()
diff --git a/asciifarm/client/display/healthpad.py b/asciifarm/client/display/healthpad.py
index 2ca0a89..1b5c7e2 100644
--- a/asciifarm/client/display/healthpad.py
+++ b/asciifarm/client/display/healthpad.py
@@ -35,13 +35,13 @@ class HealthPad:
#return 2
def update(self, win, force=False):
- if not self.changed and not force:
+ if not self.changed and not force or not win:
return
#self.lastView = (x, y, xmax, ymax)
self.changed = False
height, width = win.getmaxyx()
width -= 1
- barEnd = round(self.health/self.maxHealth * width)
+ barEnd = round(self.health/self.maxHealth * width) if self.maxHealth > 0 else 0
win.erase()
win.addstr(0,0,"Health: {}/{}".format(self.health, self.maxHealth)[:width])
if self.colours:
diff --git a/asciifarm/client/display/inventorypad.py b/asciifarm/client/display/inventorypad.py
index 8ef3296..6ad00c4 100644
--- a/asciifarm/client/display/inventorypad.py
+++ b/asciifarm/client/display/inventorypad.py
@@ -29,7 +29,7 @@ class InventoryPad:
self.changed = False
height, width = win.getmaxyx()
win.erase()
- win.addstr(0,0, self.title + ":\n")
+ win.addstr(0,0, (self.title + ":")[:width])
for i, item in enumerate(self.items[:height-1]):
win.addstr(i+1, 2, item)
win.noutrefresh()
diff --git a/asciifarm/client/display/screen.py b/asciifarm/client/display/screen.py
index d007792..0b8aff0 100644
--- a/asciifarm/client/display/screen.py
+++ b/asciifarm/client/display/screen.py
@@ -35,14 +35,20 @@ class Screen:
infoH = self._limitHeight(20, infoY)
self.windows = {
- "field": curses.newwin(msgY, sideX - 1, 0, 0),
- "msg": curses.newwin(msgH, sideX - 1, msgY, 0),
- "health": curses.newwin(healthH, sideW, healthY, sideX),
- "ground": curses.newwin(groundH, sideW, groundY, sideX),
- "inventory": curses.newwin(invH, sideW, invY, sideX),
- "info": curses.newwin(infoH, sideW, infoY, sideX)
+ "field": self.makeWin(0, 0, sideX - 1, msgY),#curses.newwin(msgY, sideX - 1, 0, 0),
+ "msg": self.makeWin(0, msgY, sideX - 1, msgH),#curses.newwin(msgH, sideX - 1, msgY, 0),
+ "health": self.makeWin(sideX, healthY, sideW, healthH),#curses.newwin(healthH, sideW, healthY, sideX),
+ "ground": self.makeWin(sideX, groundY, sideW, groundH),#curses.newwin(groundH, sideW, groundY, sideX),
+ "inventory": self.makeWin(sideX, invY, sideW, invH),#curses.newwin(invH, sideW, invY, sideX),
+ "info": self.makeWin(sideX, infoY, sideW, infoH)#curses.newwin(infoH, sideW, infoY, sideX)
}
+ def makeWin(self, x, y, width, height):
+ if width < 1 or height < 1:
+ #raise Exception("too small"+str((x, y, width, height)))
+ return None
+ return curses.newwin(height, width, y, x)
+
def updateSize(self, *args):
curses.endwin()