summaryrefslogtreecommitdiff
path: root/asciifarm/client/display
diff options
context:
space:
mode:
authortroido <troido@hotmail.com>2017-10-27 22:18:51 +0200
committertroido <troido@hotmail.com>2017-10-27 22:18:51 +0200
commit687bc04dd7988b2b9a34e91397f948c6fa44aad9 (patch)
tree4d1c05c36cb480bc1a45ddc7508e2b38a4368b56 /asciifarm/client/display
parentb821aa6cc7e4bd137eb57a0ccebb5b514eb0031b (diff)
merged master changes from today into package branch
Diffstat (limited to 'asciifarm/client/display')
-rw-r--r--asciifarm/client/display/__init__.py19
-rw-r--r--asciifarm/client/display/colours.py18
-rw-r--r--asciifarm/client/display/fieldpad.py6
-rw-r--r--asciifarm/client/display/healthpad.py6
4 files changed, 34 insertions, 15 deletions
diff --git a/asciifarm/client/display/__init__.py b/asciifarm/client/display/__init__.py
index 80e2904..dc553a8 100644
--- a/asciifarm/client/display/__init__.py
+++ b/asciifarm/client/display/__init__.py
@@ -6,32 +6,33 @@ from .infopad import InfoPad
from .healthpad import HealthPad
from .inventorypad import InventoryPad
from .screen import Screen
+from .colours import Colours
SIDEWIDTH = 20
-HEALTHHEIGHT = 2
-INVENTORYHEIGHT = 12
class Display:
def __init__(self, stdscr, charMap, colours=False):
+ if colours:
+ self.colours = Colours()
+ else:
+ self.colours = None
self.screen = Screen(stdscr)
- self.fieldPad = FieldPad((64, 32), charMap.get("charwidth", 1), colours)
+ 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, ("@",39), ("-",23), colours)
+ self.healthPad = HealthPad(20,
+ charMap.get("healthfull", ("@",7, 2)),
+ charMap.get("healthempty", ("-",7, 1)),
+ self.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)):
- curses.init_pair(i, i%16, i//16)
def resizeField(self, size):
diff --git a/asciifarm/client/display/colours.py b/asciifarm/client/display/colours.py
new file mode 100644
index 0000000..cef2675
--- /dev/null
+++ b/asciifarm/client/display/colours.py
@@ -0,0 +1,18 @@
+
+import curses
+
+class Colours:
+
+ def __init__(self):
+
+ self.colours = min(curses.COLORS, 16)
+ self.pairs = self.colours*self.colours
+
+ curses.use_default_colors()
+ for i in range(0, self.pairs):
+ curses.init_pair(i, i%self.colours, i//self.colours)
+
+ def get(self, fg=0, bg=0):
+ fg %= self.colours
+ bg %= self.colours
+ return curses.color_pair(fg + bg*self.colours)
diff --git a/asciifarm/client/display/fieldpad.py b/asciifarm/client/display/fieldpad.py
index 461cb57..8d177d5 100644
--- a/asciifarm/client/display/fieldpad.py
+++ b/asciifarm/client/display/fieldpad.py
@@ -17,11 +17,11 @@ class FieldPad:
def resize(self, width, height):
self.size = (width, height)
- self.pad.resize(height+1, width*self.charSize1)
+ self.pad.resize(height+1, width*self.charSize+1)
- def changeCell(self, x, y, char, colour=None):
+ def changeCell(self, x, y, char, colour=None, bgcolour=0):
if colour != None and self.colours:
- self.pad.addstr(y, x*self.charSize, char, curses.color_pair(colour))
+ self.pad.addstr(y, x*self.charSize, char, self.colours.get(colour, bgcolour))
else:
self.pad.addstr(y, x*self.charSize, char)
self.changed = True
diff --git a/asciifarm/client/display/healthpad.py b/asciifarm/client/display/healthpad.py
index 64838d3..8c7a9b1 100644
--- a/asciifarm/client/display/healthpad.py
+++ b/asciifarm/client/display/healthpad.py
@@ -3,7 +3,7 @@ import curses
class HealthPad:
- def __init__(self, width=1, char=('@',0), emptyChar=('-',0), colours=False):
+ def __init__(self, width=1, char=('@',7,0), emptyChar=('-',7,0), colours=False):
self.char = char
self.emptyChar = emptyChar
self.pad = curses.newpad(2, width+1)
@@ -17,8 +17,8 @@ class HealthPad:
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, curses.color_pair(self.char[1]))
- self.pad.addstr(1,barEnd, self.emptyChar[0]*(self.width-barEnd), curses.color_pair(self.emptyChar[1]))
+ 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))