Compare commits
3 commits
2c522c1fe0
...
3906c76b13
Author | SHA1 | Date | |
---|---|---|---|
3906c76b13 | |||
1abcc0a821 | |||
987643f334 |
6 changed files with 47 additions and 57 deletions
|
@ -22,7 +22,7 @@ impl Blueprint {
|
|||
Self {
|
||||
id,
|
||||
name: format!("Blueprint {id}"),
|
||||
board: content.to_string(),
|
||||
board: content.serialize(),
|
||||
tile_board: Some(content.clone()),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)]
|
||||
|
@ -320,7 +320,7 @@ impl Editor {
|
|||
self.exit_state = ExitState::Save;
|
||||
self.sim_state = SimState::Stepping;
|
||||
self.score = Some(Score {
|
||||
cycles: self.machine.step_count(),
|
||||
cycles: self.total_steps + self.machine.step_count(),
|
||||
tiles: self.source_board.count_tiles(),
|
||||
});
|
||||
}
|
||||
|
@ -688,12 +688,8 @@ impl Editor {
|
|||
}
|
||||
self.tooltip.add(42 + 205, y, 32, 32, "Select");
|
||||
simple_option_button(
|
||||
d,
|
||||
&self.mouse,
|
||||
42 + 205,
|
||||
y,
|
||||
32,
|
||||
32,
|
||||
(d, &self.mouse),
|
||||
rect(42 + 205, y, 32, 32),
|
||||
i,
|
||||
&mut self.selected_blueprint,
|
||||
);
|
||||
|
@ -718,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,
|
||||
|
@ -748,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;
|
||||
}
|
||||
|
@ -887,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,
|
||||
|
@ -901,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" };
|
||||
|
@ -995,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());
|
||||
|
@ -1003,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))
|
||||
{
|
||||
|
@ -1019,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 =
|
||||
|
@ -1174,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 {
|
||||
|
|
17
src/main.rs
17
src/main.rs
|
@ -92,7 +92,7 @@ impl Game {
|
|||
ExitState::ExitAndSave => {
|
||||
let solution = &mut self.solutions.get_mut(editor.level_id()).unwrap()
|
||||
[self.selected_solution];
|
||||
solution.board = editor.source_board().to_string();
|
||||
solution.board = editor.source_board().serialize();
|
||||
solution.score = editor.score();
|
||||
solution.save();
|
||||
self.open_editor = None;
|
||||
|
@ -100,7 +100,7 @@ impl Game {
|
|||
ExitState::Save => {
|
||||
let solution = &mut self.solutions.get_mut(editor.level_id()).unwrap()
|
||||
[self.selected_solution];
|
||||
solution.board = editor.source_board().to_string();
|
||||
solution.board = editor.source_board().serialize();
|
||||
solution.score = editor.score();
|
||||
solution.save();
|
||||
}
|
||||
|
@ -212,12 +212,13 @@ impl Game {
|
|||
let mut solution_y = y;
|
||||
for (solution_index, solution) in solutions.iter().enumerate() {
|
||||
if simple_option_button(
|
||||
d,
|
||||
&mouse,
|
||||
level_list_width + 10,
|
||||
solution_y,
|
||||
entry_width,
|
||||
solution_entry_height,
|
||||
(d, &mouse),
|
||||
rect(
|
||||
level_list_width + 10,
|
||||
solution_y,
|
||||
entry_width,
|
||||
solution_entry_height,
|
||||
),
|
||||
solution_index,
|
||||
&mut self.selected_solution,
|
||||
) {
|
||||
|
|
|
@ -48,7 +48,7 @@ impl Board {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn to_string(&self) -> String {
|
||||
pub fn serialize(&self) -> String {
|
||||
let mut out = String::new();
|
||||
for y in 0..self.height {
|
||||
for x in 0..self.width {
|
||||
|
|
34
src/ui.rs
34
src/ui.rs
|
@ -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,26 +200,21 @@ 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
|
||||
}
|
||||
|
||||
pub fn simple_option_button<T>(
|
||||
d: &mut RaylibDrawHandle,
|
||||
mouse: &MouseInput,
|
||||
x: i32,
|
||||
y: i32,
|
||||
width: i32,
|
||||
height: i32,
|
||||
(d, mouse): (&mut RaylibDrawHandle, &MouseInput),
|
||||
bounds: Rectangle,
|
||||
option: T,
|
||||
current: &mut T,
|
||||
) -> bool
|
||||
where
|
||||
T: PartialEq,
|
||||
{
|
||||
let bounds = Rectangle::new(x as f32, y as f32, width as f32, height as f32);
|
||||
d.draw_rectangle_rec(bounds, widget_bg(&option == current));
|
||||
let mut changed = false;
|
||||
if mouse.left_click() && mouse.is_over(bounds) && current != &option {
|
||||
|
@ -350,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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -145,3 +145,7 @@ pub fn get_scroll(rl: &RaylibHandle) -> Option<Scroll> {
|
|||
None
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue