This commit is contained in:
Crispy 2024-12-24 23:23:46 +01:00
parent 987643f334
commit 1abcc0a821
3 changed files with 29 additions and 35 deletions

View file

@ -28,7 +28,7 @@ const MAX_ZOOM: f32 = 8.;
const MIN_ZOOM: f32 = 0.25;
const BOARD_MARGIN: PosInt = 3;
const MAX_SPEED_POWER: u8 = 16;
const SPEED_DIGITS: u8 = 5;
const SPEED_DIGITS: i32 = 5;
const MAX_FRAME_TIME_MICROS: u128 = 1_000_000 / 30;
#[derive(Debug)]
@ -714,19 +714,18 @@ impl Editor {
d.draw_text("Level Complete!", x + 45, y + 10, 30, Color::LIME);
if let Some(score) = &self.score {
d.draw_text("cycles", x + 15, y + 45, 20, Color::WHITE);
draw_usize(d, textures, score.cycles, x + 10, y + 70, 9, 2);
draw_usize(d, textures, score.cycles, (x + 10, y + 70), 9, 2);
d.draw_text("tiles", x + 215, y + 45, 20, Color::WHITE);
draw_usize(d, textures, score.tiles, x + 210, y + 70, 5, 2);
draw_usize(d, textures, score.tiles, (x + 210, y + 70), 5, 2);
}
if simple_button(d, &self.mouse, x + 10, y + 110, 140, 45) {
if simple_button((d, &self.mouse), x + 10, y + 110, 140, 45) {
self.popup = Popup::None;
self.dismissed_end = true;
}
d.draw_text("continue\nediting", x + 15, y + 115, 20, Color::WHITE);
if simple_button(
d,
&self.mouse,
(d, &self.mouse),
x + END_POPUP_WIDTH / 2 + 5,
y + 110,
140,
@ -744,7 +743,7 @@ impl Editor {
} else {
d.draw_text("Level Failed!", x + 45, y + 10, 30, Color::RED);
d.draw_text("incorrect output", x + 45, y + 45, 20, Color::WHITE);
if simple_button(d, &self.mouse, x + 10, y + 110, 300, 25) {
if simple_button((d, &self.mouse), x + 10, y + 110, 300, 25) {
self.popup = Popup::None;
self.dismissed_end = true;
}
@ -883,7 +882,7 @@ impl Editor {
}
self.tooltip.add(368, 4, 48, 32, "Speed");
draw_usize(d, textures, 1 << self.sim_speed, 368, 4, SPEED_DIGITS, 1);
draw_usize(d, textures, 1 << self.sim_speed, (368, 4), SPEED_DIGITS, 1);
slider(
d,
&self.mouse,
@ -897,18 +896,18 @@ impl Editor {
);
self.tooltip.add(420, 4, 180, 32, "Steps");
draw_usize(d, textures, self.machine.step_count(), 420, 4, 9, 2);
draw_usize(d, textures, self.machine.step_count(), (420, 4), 9, 2);
if self.stage > Some(0) {
self.tooltip.add(420, 44, 180, 32, "Total steps");
let total_steps = self.total_steps + self.machine.step_count();
draw_usize(d, textures, total_steps, 420, 44, 9, 2);
draw_usize(d, textures, total_steps, (420, 44), 9, 2);
}
draw_usize(d, textures, self.step_time as usize, 260, 42, 9, 1);
draw_usize(d, textures, self.max_step_time as usize, 260, 60, 9, 1);
draw_usize(d, textures, self.step_time as usize, (260, 42), 9, 1);
draw_usize(d, textures, self.max_step_time as usize, (260, 60), 9, 1);
d.draw_text("input:", 603, 8, 10, Color::WHITE);
if simple_button(d, &self.mouse, 600, 20, 35, 15) {
if simple_button((d, &self.mouse), 600, 20, 35, 15) {
self.input_as_text = !self.input_as_text
}
let input_mode_text = if self.input_as_text { "text" } else { "bytes" };
@ -991,7 +990,7 @@ impl Editor {
let y = footer_top as i32 + 49;
self.tooltip.add(100, y, 40, 40, "Cancel");
if simple_button(d, &self.mouse, 100, y, 40, 40)
if simple_button((d, &self.mouse), 100, y, 40, 40)
|| d.is_key_pressed(KeyboardKey::KEY_ESCAPE)
{
self.active_tool = Tool::SelectArea(Selection::default());
@ -999,13 +998,13 @@ impl Editor {
draw_scaled_texture(d, textures.get("cancel"), 104, y + 4, 2.);
self.tooltip.add(144, y, 40, 40, "Save blueprint");
if simple_button(d, &self.mouse, 144, y, 40, 40) {
if simple_button((d, &self.mouse), 144, y, 40, 40) {
self.save_blueprint(selection);
}
draw_scaled_texture(d, textures.get("save"), 148, y + 4, 2.);
self.tooltip.add(188, y, 40, 40, "Copy");
if simple_button(d, &self.mouse, 188, y, 40, 40)
if simple_button((d, &self.mouse), 188, y, 40, 40)
|| (d.is_key_pressed(KeyboardKey::KEY_C)
&& d.is_key_down(KeyboardKey::KEY_LEFT_CONTROL))
{
@ -1015,7 +1014,7 @@ impl Editor {
draw_scaled_texture(d, textures.get("copy"), 192, y + 4, 2.);
self.tooltip.add(232, y, 40, 40, "Delete");
if simple_button(d, &self.mouse, 232, y, 40, 40) {
if simple_button((d, &self.mouse), 232, y, 40, 40) {
let min = selection.0.min(selection.1);
let max = selection.0.max(selection.1);
let board =
@ -1170,7 +1169,7 @@ impl Editor {
let output_cell_width = 43;
let output_cells = (d.get_screen_width() - output_x) as usize / output_cell_width as usize;
if simple_button(d, &self.mouse, output_x, y + 70, 65, 15) {
if simple_button((d, &self.mouse), output_x, y + 70, 65, 15) {
self.output_as_text = !self.output_as_text
}
let output_mode_text = if self.output_as_text {

View file

@ -158,8 +158,7 @@ impl Tooltip {
}
pub fn simple_button(
d: &mut RaylibDrawHandle,
mouse: &MouseInput,
(d, mouse): (&mut RaylibDrawHandle, &MouseInput),
x: i32,
y: i32,
width: i32,
@ -189,7 +188,7 @@ pub fn text_button(
let font_size = 20;
let margin = font_size / 4;
let height = font_size + margin * 2;
let clicked = simple_button(d, mouse, x, y, width, height);
let clicked = simple_button((d, mouse), x, y, width, height);
d.draw_text(text, x + margin, y + margin, font_size, Color::WHITE);
clicked
}
@ -201,7 +200,7 @@ pub fn tex32_button(
(tooltip, text): (&mut Tooltip, &'static str),
) -> bool {
let size = 32;
let clicked = simple_button(d, mouse, x, y, 32, 32);
let clicked = simple_button((d, mouse), x, y, 32, 32);
draw_scaled_texture(d, texture, x, y, 2.);
tooltip.add(x, y, size, size, text);
clicked
@ -345,24 +344,20 @@ where
pub fn draw_usize(
d: &mut RaylibDrawHandle,
textures: &Textures,
number: usize,
x: i32,
y: i32,
digits: u8,
scale: u8,
mut number: usize,
(x, y): (i32, i32),
digits: i32,
scale: i32,
) {
let digits = digits as i32;
let scale = scale as i32;
for i in 0..digits {
d.draw_rectangle(x + 10 * i * scale, y, 8 * scale, 16 * scale, BG_LIGHT);
}
let mut num = number;
let mut i = 0;
while (num != 0 || i == 0) && i < digits {
let texture = textures.get(&format!("digit_{}", num % 10));
while (number != 0 || i == 0) && i < digits {
let texture = textures.get(&format!("digit_{}", number % 10));
let x = x + (digits - i - 1) * 10 * scale;
draw_scaled_texture(d, texture, x, y, scale as f32);
num /= 10;
number /= 10;
i += 1;
}
}

View file

@ -146,6 +146,6 @@ pub fn get_scroll(rl: &RaylibHandle) -> Option<Scroll> {
}
}
pub fn rect(x: i32, y: i32, width: i32, height: i32) -> Rectangle{
pub fn rect(x: i32, y: i32, width: i32, height: i32) -> Rectangle {
Rectangle::new(x as f32, y as f32, width as f32, height as f32)
}