summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortroido <troido@hotmail.com>2018-01-01 20:09:23 +0100
committertroido <troido@hotmail.com>2018-01-01 20:09:23 +0100
commit6e38056beff444b54dab65f8f8e3830cbcb05e88 (patch)
treeb670ba6b95419d94c8b28267e416f7bf06c53072
parent123edfd17cd9aa38d6d5e511a8c686d5d71ab140 (diff)
inventory, equipment and ground object lists now scroll with the selector
-rw-r--r--asciifarm/client/display/inventorypad.py21
-rw-r--r--asciifarm/client/display/screen.py8
-rw-r--r--asciifarm/common/utils.py2
3 files changed, 24 insertions, 7 deletions
diff --git a/asciifarm/client/display/inventorypad.py b/asciifarm/client/display/inventorypad.py
index 0ee9ca0..595313c 100644
--- a/asciifarm/client/display/inventorypad.py
+++ b/asciifarm/client/display/inventorypad.py
@@ -29,10 +29,27 @@ class InventoryPad:
def update(self):
win = self.widget.getWin()
height, width = win.getmaxyx()
+ height -= 1
+ selected = self.selector.getValue()
+ start = min(selected - height//2, len(self.items)-height)
+ start = max(start, 0)
+ end = start + height
win.erase()
win.addstr(0,0, (self.title + ":")[:width])
- for i, item in enumerate(self.items[:height-1]):
- if i == self.selector.getValue():
+ for i, item in enumerate(self.items[start:end]):
+ if i + start == selected:
win.addstr(i+1, 0, '*')
win.addstr(i+1, 1, item)
+ if end < len(self.items):
+ try:
+ win.addstr(height, width-1, "+")
+ except curses.error:
+ # ncurses has a weird problem:
+ # it always raises an error when drawing to the last character in the window
+ # it draws first and then raises the error
+ # therefore to draw in the last place of the window the last character needs to be ingored
+ # other solutions might be possible, but are more hacky
+ pass
+ if start > 0:
+ win.addstr(1, width-1, "-")
win.noutrefresh()
diff --git a/asciifarm/client/display/screen.py b/asciifarm/client/display/screen.py
index a09c2a9..b563c00 100644
--- a/asciifarm/client/display/screen.py
+++ b/asciifarm/client/display/screen.py
@@ -1,12 +1,12 @@
import curses
from .fieldpad import FieldPad
+from asciifarm.common.utils import clamp
import signal
class Screen:
-
def __init__(self, display, stdscr):
self.display = display
curses.curs_set(0)
@@ -22,16 +22,16 @@ class Screen:
sideW = 20
sideX = width-sideW
- msgH = max(3, min(height // 5, 5))
+ msgH = clamp(height // 5, 3, 5)
msgY = height - msgH-1
inputH = 1
inputY = msgY + msgH
healthY = 0
healthH = self._limitHeight(2, healthY)
groundY = healthY + healthH
- groundH = self._limitHeight(7, groundY)
+ groundH = self._limitHeight(6, groundY)
invY = groundY + groundH
- invH = self._limitHeight(12, invY)
+ invH = self._limitHeight(9, invY)
eqY = invY + invH
eqH = self._limitHeight(5, eqY)
infoY = eqY + eqH
diff --git a/asciifarm/common/utils.py b/asciifarm/common/utils.py
index 729c85f..b37ec02 100644
--- a/asciifarm/common/utils.py
+++ b/asciifarm/common/utils.py
@@ -3,7 +3,7 @@ import os
def clamp(val, lower, upper):
""" val if it's between lower and upper, else the closest of the two"""
- return min(max(val, lower), upper)
+ return max(min(val, upper), lower)
def concat(arr):