add borders around panels
This commit is contained in:
parent
74d146242b
commit
12f48497ae
6 changed files with 368 additions and 197 deletions
125
src/game.rs
125
src/game.rs
|
|
@ -1,6 +1,10 @@
|
|||
use crate::unlocks::{Unlock, UnlockSystem};
|
||||
use crate::{Currency, bar::Bar};
|
||||
use servicepoint::{Bitmap, CharGrid, CharGridMutExt, TILE_SIZE, WindowMut};
|
||||
use crate::border_panel::{INNER_BORDER, OUTER_BORDER, draw_border_panel};
|
||||
use crate::row::Row;
|
||||
use crate::{
|
||||
Currency,
|
||||
unlocks::{Unlock, UnlockSystem},
|
||||
};
|
||||
use servicepoint::{Bitmap, CharGrid, CharGridMutExt, GridMut, TILE_SIZE, WindowMut};
|
||||
use std::time::Duration;
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
@ -12,14 +16,14 @@ pub struct Game {
|
|||
|
||||
#[derive(Debug)]
|
||||
pub struct State {
|
||||
pub(crate) currency: Currency,
|
||||
pub(crate) speed: f64,
|
||||
pub(crate) productivity: f64,
|
||||
pub(crate) bars: Vec<Bar>,
|
||||
pub currency: Currency,
|
||||
pub speed: f64,
|
||||
pub productivity: f64,
|
||||
pub rows: Vec<Row>,
|
||||
}
|
||||
|
||||
impl Game {
|
||||
const BAR_NAMES: [&'static str; 11] = [
|
||||
const BAR_NAMES: [&'static str; 10] = [
|
||||
"Powering infrastructure",
|
||||
"Dusting ServicePoint",
|
||||
"Activating colorful lights",
|
||||
|
|
@ -30,7 +34,7 @@ impl Game {
|
|||
"Untangling 'block chain'",
|
||||
"Refilling sticker box",
|
||||
"Setting room to public",
|
||||
"Welcoming creatures",
|
||||
// "Welcoming creatures",
|
||||
];
|
||||
|
||||
pub fn new() -> Self {
|
||||
|
|
@ -38,7 +42,7 @@ impl Game {
|
|||
.iter()
|
||||
.enumerate()
|
||||
.map(|(index, name)| {
|
||||
Bar::new(
|
||||
Row::new(
|
||||
2usize.pow(index as u32) as f64,
|
||||
1.0 * (0.5f64.powi(index as i32)),
|
||||
*name,
|
||||
|
|
@ -46,7 +50,7 @@ impl Game {
|
|||
})
|
||||
.collect();
|
||||
let state = State {
|
||||
bars,
|
||||
rows: bars,
|
||||
currency: 1f64,
|
||||
speed: 1f64,
|
||||
productivity: 1f64,
|
||||
|
|
@ -58,93 +62,80 @@ impl Game {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn progress(&mut self, delta: Duration) {
|
||||
pub fn progress(&mut self, delta: Duration) {
|
||||
let adjusted_delta = delta.mul_f64(self.state.speed);
|
||||
|
||||
let extra_currency = self.state.productivity
|
||||
* self
|
||||
.state
|
||||
.bars
|
||||
.rows
|
||||
.iter_mut()
|
||||
.map(|bar| bar.progress(adjusted_delta))
|
||||
.sum::<Currency>();
|
||||
self.state.currency += extra_currency;
|
||||
self.total_currency += extra_currency;
|
||||
self.unlocks.check_next(&mut self.state);
|
||||
self.unlocks.progress(&mut self.state);
|
||||
}
|
||||
|
||||
pub(crate) fn draw(
|
||||
pub fn draw(
|
||||
&self,
|
||||
text_layer: &mut WindowMut<char, CharGrid>,
|
||||
pixel_layer: &mut WindowMut<bool, Bitmap>,
|
||||
text_layer: WindowMut<char, CharGrid>,
|
||||
pixel_layer: WindowMut<bool, Bitmap>,
|
||||
) {
|
||||
text_layer
|
||||
.set_row_str(0, "Discordia Boot Procedure")
|
||||
let (text_layer, pixel_layer) = draw_border_panel(
|
||||
text_layer,
|
||||
pixel_layer,
|
||||
" Discordia Boot Procedure ",
|
||||
OUTER_BORDER,
|
||||
);
|
||||
|
||||
let unlocks_height = 3 + 2;
|
||||
let (unlocks_text, text_layer) = text_layer.split_vertical_mut(unlocks_height).unwrap();
|
||||
let (unlocks_pixel, pixel_layer) = pixel_layer
|
||||
.split_vertical_mut(unlocks_height * TILE_SIZE)
|
||||
.unwrap();
|
||||
self.draw_bars(text_layer, pixel_layer, 1);
|
||||
self.unlocks.draw(unlocks_text, unlocks_pixel);
|
||||
|
||||
let mut row = text_layer.height() - 1;
|
||||
self.draw_stats(text_layer, row);
|
||||
row -= 1;
|
||||
let bars_height = self.state.rows.len() + 2;
|
||||
let (bars_text, text_layer) = text_layer.split_vertical_mut(bars_height).unwrap();
|
||||
let (bars_pixel, _) = pixel_layer
|
||||
.split_vertical_mut(bars_height * TILE_SIZE)
|
||||
.unwrap();
|
||||
self.draw_bars(bars_text, bars_pixel);
|
||||
|
||||
if let Some(next_upgrade) = self.unlocks.peek_next() {
|
||||
self.draw_next_upgrade(text_layer, row, next_upgrade);
|
||||
row -= 1;
|
||||
}
|
||||
|
||||
if let Some(prev_unlock) = self.unlocks.previous() {
|
||||
self.draw_prev_unlock(text_layer, row, prev_unlock);
|
||||
}
|
||||
let free_row_bottom = text_layer.height() - 1;
|
||||
self.draw_stats(text_layer, free_row_bottom);
|
||||
}
|
||||
|
||||
fn draw_next_upgrade(&self, text_layer: &mut WindowMut<char, CharGrid>, row: usize, next_upgrade: &Unlock) {
|
||||
text_layer
|
||||
.window_mut(0, row, text_layer.width(), 1)
|
||||
.unwrap()
|
||||
.set_row_str(0, &format!("Next unlock: {:.0}/{} Hacks", self.state.currency, next_upgrade.cost))
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
fn draw_stats(&self, text_layer: &mut WindowMut<char, CharGrid>, row: usize) {
|
||||
text_layer
|
||||
.window_mut(0, row, text_layer.width() / 2, 1)
|
||||
.unwrap()
|
||||
.set_row_str(0, &format!("Hack Score: {:.2}", self.total_currency))
|
||||
fn draw_stats<C: GridMut<char>>(&self, text_layer: WindowMut<char, C>, row: usize) {
|
||||
let middle = text_layer.width() / 2;
|
||||
let (mut left, mut right) = text_layer.split_horizontal_mut(middle).unwrap();
|
||||
left.set_row_str(0, &format!("Hack Score: {:.2}", self.total_currency))
|
||||
.unwrap();
|
||||
|
||||
if self.unlocks.bought() > 0 {
|
||||
text_layer
|
||||
.window_mut(
|
||||
text_layer.width() / 2,
|
||||
row,
|
||||
text_layer.width() / 2,
|
||||
1,
|
||||
)
|
||||
.unwrap()
|
||||
right
|
||||
.set_row_str(0, &format!(" Unlocks: {}", self.unlocks.bought()))
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_bars(&self, text_layer: &mut WindowMut<char, CharGrid>, pixel_layer: &mut WindowMut<bool, Bitmap>, mut row: usize) {
|
||||
for bar in self.state.bars.iter() {
|
||||
fn draw_bars<C: GridMut<char>, P: GridMut<bool>>(
|
||||
&self,
|
||||
text_layer: WindowMut<char, C>,
|
||||
pixel_layer: WindowMut<bool, P>,
|
||||
) {
|
||||
let (mut text_layer, mut pixel_layer) =
|
||||
draw_border_panel(text_layer, pixel_layer, " Processes ", INNER_BORDER);
|
||||
|
||||
for (index, row) in self.state.rows.iter().enumerate() {
|
||||
let mut bar_window = pixel_layer
|
||||
.window_mut(0, row * TILE_SIZE, pixel_layer.width(), TILE_SIZE)
|
||||
.window_mut(0, index * TILE_SIZE, pixel_layer.width(), TILE_SIZE)
|
||||
.unwrap();
|
||||
let mut label_window = text_layer
|
||||
.window_mut(0, row, text_layer.width(), 1)
|
||||
.window_mut(0, index, text_layer.width(), 1)
|
||||
.unwrap();
|
||||
bar.draw(&mut label_window, &mut bar_window);
|
||||
|
||||
row += 1;
|
||||
row.draw(&mut label_window, &mut bar_window);
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_prev_unlock(&self, chars: &mut WindowMut<char, CharGrid>, row: usize, prev: &String) {
|
||||
chars
|
||||
.window_mut(0, row, chars.width(), 1)
|
||||
.unwrap()
|
||||
.set_row_str(0, &format!("Unlocked: {}", prev))
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue