clean up ui, more upgrades

This commit is contained in:
Vinzenz Schroeter 2025-07-06 22:03:11 +02:00
commit 2a4f92c9b3
6 changed files with 132 additions and 175 deletions

View file

@ -1,10 +1,7 @@
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 crate::{Currency, unlocks::UnlockSystem};
use servicepoint::{Bitmap, CharGrid, TILE_SIZE, WindowMut};
use std::time::Duration;
#[derive(Debug)]
@ -23,9 +20,8 @@ pub struct State {
}
impl Game {
const BAR_NAMES: [&'static str; 10] = [
const BAR_NAMES: [&'static str; 11] = [
"Powering infrastructure",
"Dusting ServicePoint",
"Activating colorful lights",
"Dimming darkroom",
"Refilling Matemat",
@ -34,7 +30,8 @@ impl Game {
"Untangling 'block chain'",
"Refilling sticker box",
"Setting room to public",
// "Welcoming creatures",
"Welcoming creatures",
"Making Discordia proud",
];
pub fn new() -> Self {
@ -43,7 +40,7 @@ impl Game {
.enumerate()
.map(|(index, name)| {
Row::new(
2usize.pow(index as u32) as f64,
5usize.pow(index as u32) as f64,
1.0 * (0.5f64.powi(index as i32)),
*name,
)
@ -90,52 +87,31 @@ impl Game {
);
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
let (unlocks_text, bars_text) = text_layer.split_vertical_mut(unlocks_height).unwrap();
let (unlocks_pixel, bars_pixel) = pixel_layer
.split_vertical_mut(unlocks_height * TILE_SIZE)
.unwrap();
self.unlocks.draw(unlocks_text, unlocks_pixel);
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);
let free_row_bottom = text_layer.height() - 1;
self.draw_stats(text_layer, free_row_bottom);
}
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 {
right
.set_row_str(0, &format!(" Unlocks: {}", self.unlocks.bought()))
.unwrap();
}
}
fn draw_bars<C: GridMut<char>, P: GridMut<bool>>(
fn draw_bars(
&self,
text_layer: WindowMut<char, C>,
pixel_layer: WindowMut<bool, P>,
text_layer: WindowMut<char, CharGrid>,
pixel_layer: WindowMut<bool, Bitmap>,
) {
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
let bar_window = pixel_layer
.window_mut(0, index * TILE_SIZE, pixel_layer.width(), TILE_SIZE)
.unwrap();
let mut label_window = text_layer
let label_window = text_layer
.window_mut(0, index, text_layer.width(), 1)
.unwrap();
row.draw(&mut label_window, &mut bar_window);
row.draw(label_window, bar_window);
}
}
}