diff options
Diffstat (limited to 'asciifarm')
| -rw-r--r-- | asciifarm/client/display/__init__.py | 22 | ||||
| -rw-r--r-- | asciifarm/client/display/fieldpad.py | 4 | ||||
| -rw-r--r-- | asciifarm/client/display/healthpad.py | 28 | ||||
| -rw-r--r-- | asciifarm/client/display/infopad.py | 18 | ||||
| -rw-r--r-- | asciifarm/client/display/inventorypad.py | 18 | ||||
| -rw-r--r-- | asciifarm/client/display/messagepad.py | 16 | ||||
| -rw-r--r-- | asciifarm/client/display/screen.py | 17 |
7 files changed, 23 insertions, 100 deletions
diff --git a/asciifarm/client/display/__init__.py b/asciifarm/client/display/__init__.py index 159330a..d806889 100644 --- a/asciifarm/client/display/__init__.py +++ b/asciifarm/client/display/__init__.py @@ -25,16 +25,16 @@ class Display: self.fieldPad = FieldPad((1, 1), charMap.get("charwidth", 1), self.colours) self.characters = charMap["mapping"] self.defaultChar = charMap.get("default", "?") - self.infoPad = InfoPad((100, 100)) - self.healthPad = HealthPad(20, + self.infoPad = InfoPad() + self.healthPad = HealthPad( charMap.get("healthfull", ("@",7, 2)), charMap.get("healthempty", ("-",7, 1)), self.colours) - self.inventoryPad = InventoryPad("Inventory", 10) - self.groundPad = InventoryPad("Ground", 5) + self.inventoryPad = InventoryPad("Inventory") + self.groundPad = InventoryPad("Ground") self.lastinfostring = None self.changed = False - self.messagePad = messagepad.MessagePad(5) + self.messagePad = messagepad.MessagePad() self.screen.update(True) @@ -86,18 +86,6 @@ class Display: def update(self): if self.changed: self.screen.update() - #fieldRight = min(self.fieldPad.getWidth(), self.screen.getWidth()-SIDEWIDTH-1) - #fieldBottom = min(self.fieldPad.getHeight(), self.screen.getHeight()-self.messagePad.getHeight()) - #healthBottom = self.healthPad.getHeight() - #groundBottom = healthBottom + self.groundPad.getHeight() - #inventoryBottom = groundBottom + self.inventoryPad.getHeight() - #self.fieldPad.update(self, 0,0,fieldRight, fieldBottom) - #self.messagePad.update(self, 0,fieldBottom, fieldRight, min(self.screen.getHeight(), fieldBottom+self.messagePad.getHeight())) - #self.healthPad.update(self, fieldRight+1,0, self.screen.getWidth(), healthBottom) - #self.groundPad.update(self, fieldRight+1, healthBottom, self.screen.getWidth(), min(self.screen.getHeight(), groundBottom)) - #self.inventoryPad.update(self, fieldRight+1, groundBottom, self.screen.getWidth(), min(self.screen.getHeight(), inventoryBottom)) - #self.infoPad.update(self, fieldRight+1,inventoryBottom+1, self.screen.getWidth(), self.screen.getHeight()) - curses.doupdate() self.changed = False diff --git a/asciifarm/client/display/fieldpad.py b/asciifarm/client/display/fieldpad.py index e9e3ee1..1c749b6 100644 --- a/asciifarm/client/display/fieldpad.py +++ b/asciifarm/client/display/fieldpad.py @@ -13,7 +13,6 @@ class FieldPad: self.center = (0, 0) self.colours = colours self.changed = False - #self.lastView = None def resize(self, width, height): self.size = (width, height) @@ -38,10 +37,9 @@ class FieldPad: def _roundWidth(self, x): return x // self.charSize * self.charSize - def update(self, win, force=False): + def update(self, win, force): if not self.changed and not force or not win: return - #self.lastView = (x, y, xmax, ymax) height, width = win.getmaxyx() y, x = win.getparyx() xmax = x + width diff --git a/asciifarm/client/display/healthpad.py b/asciifarm/client/display/healthpad.py index 1b5c7e2..f5a9cc4 100644 --- a/asciifarm/client/display/healthpad.py +++ b/asciifarm/client/display/healthpad.py @@ -3,13 +3,10 @@ import curses class HealthPad: - def __init__(self, width=1, char=('@',7,0), emptyChar=('-',7,0), colours=False): + def __init__(self, char=('@',7,0), emptyChar=('-',7,0), colours=False): self.char = char self.emptyChar = emptyChar - #self.pad = curses.newpad(2, width+1) - #self.width = width self.changed = False - #self.lastView = None self.colours = colours self.health = 0 self.maxHealth = 0 @@ -17,27 +14,12 @@ class HealthPad: def setHealth(self, health, maxHealth): self.health = health self.maxHealth = maxHealth - - - #self.pad.erase() - #barEnd = round(health/maxHealth * self.width) - #self.pad.addstr(0,0,"Health: {}/{}".format(health, maxHealth)[:self.width]) - #if self.colours: - #self.pad.addstr(1,0, self.char[0]*barEnd, self.colours.get(*self.char[1:])) - #self.pad.addstr(1,barEnd, self.emptyChar[0]*(self.width-barEnd), self.colours.get(*self.emptyChar[1:])) - #else: - #self.pad.addstr(1,0, self.char[0]*barEnd) - #self.pad.addstr(1,barEnd, self.emptyChar[0]*(self.width-barEnd)) self.changed = True - #def getHeight(self): - #return 2 - - def update(self, win, force=False): + def update(self, win, 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 @@ -51,9 +33,3 @@ class HealthPad: win.addstr(1,0, self.char[0]*barEnd) win.addstr(1,barEnd, self.emptyChar[0]*(width-barEnd)) win.noutrefresh() - #0, - #0, - #y, - #x, - #ymax-1, - #xmax-1) diff --git a/asciifarm/client/display/infopad.py b/asciifarm/client/display/infopad.py index 7c9fef0..c98b7cd 100644 --- a/asciifarm/client/display/infopad.py +++ b/asciifarm/client/display/infopad.py @@ -7,33 +7,21 @@ class InfoPad: - def __init__(self, size=(1,1), *args): - #self.pad = curses.newpad(size[1], size[0]) - #self.size = size + def __init__(self): self.changed = False self.lines = [] - #self.lastView = None def showString(self, string): self.lines = string.split('\n') - #self.pad.clear() - #self.pad.addstr(0,0,string) self.changed = True - def update(self, win, force=False): + def update(self, win, force): if not self.changed and not force or not win: return - #self.lastView = (x, y, xmax, ymax) height, width = win.getmaxyx() - lines = [line[:width] for line in self.lines][:height] + lines = [line[:width-1] for line in self.lines][:height] text = '\n'.join(lines) win.erase() win.addstr(0, 0, text) self.changed = False win.noutrefresh() - #0, - #0, - #y, - #x, - #ymax-1, - #xmax-1) diff --git a/asciifarm/client/display/inventorypad.py b/asciifarm/client/display/inventorypad.py index 6ad00c4..6f12127 100644 --- a/asciifarm/client/display/inventorypad.py +++ b/asciifarm/client/display/inventorypad.py @@ -3,29 +3,21 @@ import curses class InventoryPad: - def __init__(self, title, maxItems=20): + def __init__(self, title): 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 self.maxItems+2 - def update(self, win, force=False): + def update(self, win, 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() win.erase() @@ -33,9 +25,3 @@ class InventoryPad: for i, item in enumerate(self.items[:height-1]): win.addstr(i+1, 2, item) win.noutrefresh() - #0, - #0, - #y, - #x, - #ymax-1, - #xmax-1) diff --git a/asciifarm/client/display/messagepad.py b/asciifarm/client/display/messagepad.py index f447e44..095e53a 100644 --- a/asciifarm/client/display/messagepad.py +++ b/asciifarm/client/display/messagepad.py @@ -4,21 +4,15 @@ import textwrap class MessagePad(): - def __init__(self, maxLines=10): - #self.maxLines = maxLines - #self.pad = curses.newpad(maxLines+2, 200) + def __init__(self): self.changed = False - #self.lastView = None self.messages = [] def addMessage(self, message): self.messages.append(message) self.changed = True - #def getHeight(self): - #return self.maxLines - - def update(self, win, force=False): + def update(self, win, force): if not self.changed and not force or not win: return height, width = win.getmaxyx() @@ -33,9 +27,3 @@ class MessagePad(): win.addstr(0,0,'\n'.join(lines)) self.changed = False win.noutrefresh() - #0, - #0, - #y, - #x, - #ymax-1, - #xmax-1) diff --git a/asciifarm/client/display/screen.py b/asciifarm/client/display/screen.py index 0b8aff0..41b7e12 100644 --- a/asciifarm/client/display/screen.py +++ b/asciifarm/client/display/screen.py @@ -11,7 +11,6 @@ class Screen: self.display = display curses.curs_set(0) self.stdscr = stdscr - #self.height, self.width = self.stdscr.getmaxyx() self.setWins() signal.signal(signal.SIGWINCH, self.updateSize) @@ -35,17 +34,16 @@ class Screen: infoH = self._limitHeight(20, infoY) self.windows = { - "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) + "field": self.makeWin(0, 0, sideX - 1, msgY), + "msg": self.makeWin(0, msgY, sideX - 1, msgH), + "health": self.makeWin(sideX, healthY, sideW, healthH), + "ground": self.makeWin(sideX, groundY, sideW, groundH), + "inventory": self.makeWin(sideX, invY, sideW, invH), + "info": self.makeWin(sideX, infoY, sideW, infoH) } 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) @@ -54,7 +52,6 @@ class Screen: curses.endwin() curses.initscr() self.setWins() - #self.height, self.width = self.stdscr.getmaxyx() self.stdscr.clear() self.update(True) @@ -66,6 +63,8 @@ class Screen: d.groundPad.update(self.windows["ground"], force) d.inventoryPad.update(self.windows["inventory"], force) d.infoPad.update(self.windows["info"], force) + + curses.doupdate() def getWidth(self): return self.width |
