aboutsummaryrefslogtreecommitdiff
path: root/src/gui.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui.rs')
-rw-r--r--src/gui.rs47
1 files changed, 29 insertions, 18 deletions
diff --git a/src/gui.rs b/src/gui.rs
index 428c8c1..bd7ca7c 100644
--- a/src/gui.rs
+++ b/src/gui.rs
@@ -117,10 +117,9 @@ pub struct BoardGUI {
black_colour: u8,
}
-#[derive(PartialEq)]
pub enum BGAction {
Quit,
- None,
+ Selected(Action),
}
impl BoardGUI {
@@ -194,11 +193,21 @@ impl BoardGUI {
fn draw_stack(&self, pos: &Position, stack: &Stack) {
if let Some(win) = self.cell_windows.get(self.pos_to_idx(pos)) {
win.clear();
- let l = stack.len() as i32;
- if l > 0 {
- for i in 0..l {
- let piece = &stack[i as usize];
- self.draw_stone(win, i == l - 1, &piece.player, &piece.stone);
+ let height = stack.len() as usize;
+ if height > 0 {
+ let carry_capacity = self.size as usize;
+ let tall = height > carry_capacity;
+ if tall {
+ win.attrset(Attribute::Normal);
+ win.addch('(');
+ }
+ for i in 0..height {
+ let piece = &stack[i];
+ self.draw_stone(win, i + 1 == height, &piece.player, &piece.stone);
+ if tall && i + 2 == carry_capacity {
+ win.attrset(Attribute::Normal);
+ win.addch(')');
+ }
}
}
win.refresh();
@@ -208,14 +217,6 @@ impl BoardGUI {
pub fn update(&self, game: &Game, squares: Vec<Position>) {
// Is this really the `best' way?
assert!(game.get_size() == self.size);
- // for x in 0..self.size {
- // for y in 0..self.size {
- // let pos = Position { x: x, y: y };
- // if let Some(stack) = game.query_square(&pos) {
- // self.draw_stack(&pos, stack);
- // }
- // }
- // }
for p in squares {
if let Some(stack) = game.query_square(&p) {
self.draw_stack(&p, stack);
@@ -369,9 +370,19 @@ impl ActionEntry {
Character('\n') => return result,
KeyEnter => return result, // TODO: is this ever used?
Character(c) => {
- if result.len() < self.max_len {
- result.push(c);
- self.window.addch(c);
+ // Annoyingly there are two backspace possibilities
+ let ascii = c as usize;
+ if !result.is_empty() && (ascii == 127) || (ascii == 8) {
+ result.pop();
+ let (y, x) = (self.window.get_cur_y(), self.window.get_cur_x());
+ self.window.mv(y, x - 1);
+ self.window.addch('_');
+ self.window.mv(y, x - 1);
+ } else {
+ if result.len() < self.max_len {
+ result.push(c);
+ self.window.addch(c);
+ }
}
}
KeyBackspace => {