Compare commits
3 commits
cfadd8a0b6
...
bc0d1ab94a
Author | SHA1 | Date | |
---|---|---|---|
bc0d1ab94a | |||
2d961608e2 | |||
2ecb86d283 |
3 changed files with 44 additions and 24 deletions
|
@ -623,7 +623,7 @@ impl Editor {
|
|||
d.draw_rectangle_rec(bounds, BG_DARK);
|
||||
let x = bounds.x as i32;
|
||||
let y = bounds.y as i32;
|
||||
d.draw_text("Menu", x + 5, y+5, 30, Color::LIGHTBLUE);
|
||||
d.draw_text("Menu", x + 5, y + 5, 30, Color::LIGHTBLUE);
|
||||
}
|
||||
Popup::None => (),
|
||||
}
|
||||
|
@ -777,10 +777,9 @@ impl Editor {
|
|||
self.tooltip.add(40, 4, 32, 32, "save");
|
||||
}
|
||||
|
||||
if simple_button(d, &self.mouse, 76, 5, 60, 30) {
|
||||
if text_button(d, &self.mouse, 76, 5, 50, "info") {
|
||||
self.popup = Popup::LevelInfo;
|
||||
}
|
||||
d.draw_text("info", 80, 10, 20, Color::WHITE);
|
||||
|
||||
if self.sim_state == SimState::Editing {
|
||||
self.tooltip.add(150, 4, 32, 32, "Undo");
|
||||
|
|
19
src/main.rs
19
src/main.rs
|
@ -18,7 +18,7 @@ use editor::{Editor, ExitState};
|
|||
use level::{Chapter, Level};
|
||||
use solution::Solution;
|
||||
use theme::*;
|
||||
use ui::{simple_button, simple_option_button, text_input, ShapedText};
|
||||
use ui::{simple_option_button, text_button, text_input, ShapedText};
|
||||
use util::*;
|
||||
|
||||
const TITLE_TEXT: &str = concat!("Marble Machinations v", env!("CARGO_PKG_VERSION"));
|
||||
|
@ -240,24 +240,17 @@ impl Game {
|
|||
}
|
||||
|
||||
let next_id = get_free_id(solutions, Solution::id);
|
||||
if simple_button(
|
||||
if text_button(
|
||||
d,
|
||||
&mouse,
|
||||
level_list_width + 10,
|
||||
solution_y,
|
||||
entry_width,
|
||||
30,
|
||||
"new solution",
|
||||
) {
|
||||
self.selected_solution = solutions.len();
|
||||
solutions.push(Solution::new(level, next_id));
|
||||
}
|
||||
d.draw_text(
|
||||
"new solution",
|
||||
level_list_width + 15,
|
||||
solution_y + 5,
|
||||
20,
|
||||
Color::WHITE,
|
||||
);
|
||||
|
||||
if let Some(solution) = solutions.get_mut(self.selected_solution) {
|
||||
let column_x = level_list_width + entry_width + 20;
|
||||
|
@ -276,20 +269,18 @@ impl Game {
|
|||
let id_text = format!("{}", solution.id());
|
||||
d.draw_text(&id_text, column_x, y + 35, 10, Color::GRAY);
|
||||
|
||||
if simple_button(d, &mouse, column_x, y + 50, 220, 30) {
|
||||
if text_button(d, &mouse, column_x, y + 50, 220, "clone") {
|
||||
let cloned = solution.new_copy(next_id);
|
||||
self.selected_solution = solutions.len();
|
||||
solutions.push(cloned);
|
||||
return;
|
||||
}
|
||||
d.draw_text("clone", column_x + 5, y + 55, 20, Color::WHITE);
|
||||
|
||||
if simple_button(d, &mouse, column_x, y + 85, 220, 30) {
|
||||
if text_button(d, &mouse, column_x, y + 85, 220, "edit") {
|
||||
let mut editor = Editor::new(solution.clone(), level.clone());
|
||||
editor.center_view(d);
|
||||
self.open_editor = Some(editor);
|
||||
}
|
||||
d.draw_text("edit", column_x + 5, y + 90, 20, Color::WHITE);
|
||||
}
|
||||
} else {
|
||||
self.solutions.insert(level.id().to_owned(), Vec::new());
|
||||
|
|
44
src/ui.rs
44
src/ui.rs
|
@ -178,6 +178,22 @@ pub fn simple_button(
|
|||
pressed
|
||||
}
|
||||
|
||||
pub fn text_button(
|
||||
d: &mut RaylibDrawHandle,
|
||||
mouse: &MouseInput,
|
||||
x: i32,
|
||||
y: i32,
|
||||
width: i32,
|
||||
text: &str,
|
||||
) -> bool {
|
||||
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);
|
||||
d.draw_text(text, x + margin, y + margin, font_size, Color::WHITE);
|
||||
clicked
|
||||
}
|
||||
|
||||
pub fn simple_option_button<T>(
|
||||
d: &mut RaylibDrawHandle,
|
||||
mouse: &MouseInput,
|
||||
|
@ -211,6 +227,7 @@ pub fn text_input(
|
|||
editable: bool,
|
||||
) -> bool {
|
||||
let mut changed = false;
|
||||
let font_size = 20;
|
||||
d.draw_rectangle_rec(bounds, widget_bg(*is_selected));
|
||||
d.draw_rectangle_rec(
|
||||
Rectangle::new(
|
||||
|
@ -221,18 +238,24 @@ pub fn text_input(
|
|||
),
|
||||
BG_DARK,
|
||||
);
|
||||
let drawn_text = if *is_selected {
|
||||
&format!("{text}_")
|
||||
} else {
|
||||
text.as_str()
|
||||
};
|
||||
d.draw_text(
|
||||
drawn_text,
|
||||
text,
|
||||
bounds.x as i32 + 4,
|
||||
bounds.y as i32 + 4,
|
||||
20,
|
||||
font_size,
|
||||
Color::WHITE,
|
||||
);
|
||||
// blinking cursor
|
||||
if *is_selected && d.get_time().fract() < 0.5 {
|
||||
let width = d.measure_text(text, font_size);
|
||||
d.draw_rectangle(
|
||||
bounds.x as i32 + 6 + width,
|
||||
bounds.y as i32 + 4,
|
||||
2,
|
||||
font_size,
|
||||
Color::WHITE,
|
||||
);
|
||||
};
|
||||
if editable && mouse.left_click() && (mouse.is_over(bounds) || *is_selected) {
|
||||
*is_selected = !*is_selected;
|
||||
}
|
||||
|
@ -244,6 +267,13 @@ pub fn text_input(
|
|||
if d.is_key_pressed(KeyboardKey::KEY_BACKSPACE) && !text.is_empty() {
|
||||
changed = true;
|
||||
text.pop();
|
||||
if d.is_key_down(KeyboardKey::KEY_LEFT_CONTROL) {
|
||||
while let Some(c) = text.pop() {
|
||||
if c == ' ' {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if text.len() < max_len {
|
||||
let char_code = unsafe { ffi::GetCharPressed() };
|
||||
|
|
Loading…
Add table
Reference in a new issue