add scrolling to config menu, use new input system for tile group cycling
This commit is contained in:
parent
8d81f94b70
commit
d62dbe3462
4 changed files with 51 additions and 41 deletions
|
@ -15,7 +15,6 @@ logic mostly like https://git.crispypin.cc/CrispyPin/marble
|
|||
- accessibility
|
||||
- ui scaling
|
||||
- background colour setting
|
||||
- configurable hotkeys
|
||||
- hotkeys for everything (no mouse needed to play)
|
||||
- font selection (probably a lot of work)
|
||||
- more levels
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
use raylib::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{input::Input, theme::FG_CHAPTER_TITLE, ui::text_button, Globals};
|
||||
use crate::{input::Input, theme::FG_CHAPTER_TITLE, ui::text_button, util::Scroll, Globals};
|
||||
|
||||
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Config {
|
||||
pub input: Input,
|
||||
#[serde(skip)]
|
||||
scroll_offset: u32,
|
||||
}
|
||||
|
||||
pub enum MenuReturn {
|
||||
|
@ -18,19 +20,26 @@ pub enum MenuReturn {
|
|||
impl Config {
|
||||
#[must_use]
|
||||
pub fn draw_edit(&mut self, d: &mut RaylibDrawHandle, globals: &mut Globals) -> MenuReturn {
|
||||
d.draw_text("Settings", 16, 16, 30, FG_CHAPTER_TITLE);
|
||||
match globals.mouse.scroll() {
|
||||
Some(Scroll::Down) => self.scroll_offset += 64,
|
||||
Some(Scroll::Up) => self.scroll_offset = self.scroll_offset.saturating_sub(64),
|
||||
None => (),
|
||||
}
|
||||
let y = -(self.scroll_offset as i32);
|
||||
|
||||
if text_button(d, &globals.mouse, 10, 60, 80, "apply") {
|
||||
d.draw_text("Settings", 16, y + 16, 30, FG_CHAPTER_TITLE);
|
||||
|
||||
if text_button(d, &globals.mouse, 10, y + 60, 80, "apply") {
|
||||
return MenuReturn::StaySave;
|
||||
}
|
||||
if text_button(d, &globals.mouse, 100, 60, 80, "done") {
|
||||
if text_button(d, &globals.mouse, 100, y + 60, 80, "done") {
|
||||
return MenuReturn::ReturnSave;
|
||||
}
|
||||
if text_button(d, &globals.mouse, 190, 60, 80, "cancel") {
|
||||
if text_button(d, &globals.mouse, 190, y + 60, 80, "cancel") {
|
||||
return MenuReturn::ReturnCancel;
|
||||
}
|
||||
|
||||
self.input.draw_edit(d, globals);
|
||||
self.input.draw_edit(d, globals, y);
|
||||
MenuReturn::Stay
|
||||
}
|
||||
}
|
||||
|
|
|
@ -345,28 +345,6 @@ impl Editor {
|
|||
}
|
||||
}
|
||||
|
||||
fn rotate_tool(&mut self, shift: bool) {
|
||||
if shift {
|
||||
match &self.active_tool {
|
||||
Tool::Math => self.tool_math.prev(),
|
||||
Tool::Comparator => self.tool_comparator.prev(),
|
||||
Tool::Arrow => self.tool_arrow = self.tool_arrow.left(),
|
||||
Tool::Mirror => self.tool_mirror.flip(),
|
||||
Tool::Wire => self.tool_wire.prev(),
|
||||
_ => (),
|
||||
}
|
||||
} else {
|
||||
match &self.active_tool {
|
||||
Tool::Math => self.tool_math.next(),
|
||||
Tool::Comparator => self.tool_comparator.next(),
|
||||
Tool::Arrow => self.tool_arrow = self.tool_arrow.right(),
|
||||
Tool::Mirror => self.tool_mirror.flip(),
|
||||
Tool::Wire => self.tool_wire.next(),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn center_view(&mut self, d: &RaylibHandle) {
|
||||
let tile_size = TILE_TEXTURE_SIZE * self.zoom;
|
||||
let tile_x = self.source_board.grid.width() as f32 / 2. * tile_size;
|
||||
|
@ -543,8 +521,28 @@ impl Editor {
|
|||
self.center_view(rl);
|
||||
}
|
||||
|
||||
if rl.is_key_pressed(KeyboardKey::KEY_R) {
|
||||
self.rotate_tool(rl.is_key_down(KeyboardKey::KEY_LEFT_SHIFT));
|
||||
if globals.is_pressed(ActionId::CycleGroup) {
|
||||
if globals.is_held(ActionId::CycleGroupRevMod) {
|
||||
println!("rotate reverse");
|
||||
match &self.active_tool {
|
||||
Tool::Math => self.tool_math.prev(),
|
||||
Tool::Comparator => self.tool_comparator.prev(),
|
||||
Tool::Arrow => self.tool_arrow = self.tool_arrow.left(),
|
||||
Tool::Mirror => self.tool_mirror.flip(),
|
||||
Tool::Wire => self.tool_wire.prev(),
|
||||
_ => (),
|
||||
}
|
||||
} else {
|
||||
println!("rotate");
|
||||
match &self.active_tool {
|
||||
Tool::Math => self.tool_math.next(),
|
||||
Tool::Comparator => self.tool_comparator.next(),
|
||||
Tool::Arrow => self.tool_arrow = self.tool_arrow.right(),
|
||||
Tool::Mirror => self.tool_mirror.flip(),
|
||||
Tool::Wire => self.tool_wire.next(),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if rl.is_key_pressed(KeyboardKey::KEY_N) {
|
||||
|
|
24
src/input.rs
24
src/input.rs
|
@ -26,6 +26,8 @@ pub enum ActionId {
|
|||
StartSim,
|
||||
StopSim,
|
||||
StepSim,
|
||||
CycleGroup,
|
||||
CycleGroupRevMod,
|
||||
// just like in C, because this way doesn't need more dependencies
|
||||
_EnumSize,
|
||||
}
|
||||
|
@ -49,11 +51,13 @@ impl Default for Input {
|
|||
bind_key(ActionId::StartSim, vec![], Enter);
|
||||
bind_key(ActionId::StopSim, vec![], Enter);
|
||||
bind_key(ActionId::StepSim, vec![], Space);
|
||||
bind_key(ActionId::CycleGroup, vec![], R);
|
||||
bind_key(ActionId::CycleGroupRevMod, vec![], LShift);
|
||||
|
||||
Self {
|
||||
bindings,
|
||||
states: Default::default(),
|
||||
editing_input: None,
|
||||
editing_binding: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +79,7 @@ pub struct Input {
|
|||
bindings: [Vec<Binding>; ActionId::SIZE],
|
||||
states: [BindingState; ActionId::SIZE],
|
||||
#[serde(skip)]
|
||||
editing_input: Option<(ActionId, usize, BindingEdit)>,
|
||||
editing_binding: Option<(ActionId, usize, BindingEdit)>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
@ -86,9 +90,9 @@ enum BindingEdit {
|
|||
}
|
||||
|
||||
impl Input {
|
||||
pub fn draw_edit(&mut self, d: &mut RaylibDrawHandle, globals: &mut Globals) {
|
||||
let mut y = 96;
|
||||
if self.editing_input.is_some() {
|
||||
pub fn draw_edit(&mut self, d: &mut RaylibDrawHandle, globals: &mut Globals, y: i32) {
|
||||
let mut y = y + 96;
|
||||
if self.editing_binding.is_some() {
|
||||
globals.mouse.clear();
|
||||
}
|
||||
|
||||
|
@ -105,7 +109,7 @@ impl Input {
|
|||
return;
|
||||
}
|
||||
if text_button(d, &globals.mouse, 245, y, 45, "edit") {
|
||||
self.editing_input = Some((action, binding_index, BindingEdit::Init));
|
||||
self.editing_binding = Some((action, binding_index, BindingEdit::Init));
|
||||
}
|
||||
let trigger = format!("{:?}", binding.trigger);
|
||||
d.draw_text(&trigger, 300, y, 20, Color::LIMEGREEN);
|
||||
|
@ -115,13 +119,13 @@ impl Input {
|
|||
y += 32;
|
||||
}
|
||||
if text_button(d, &globals.mouse, 160, y, 130, "add binding") {
|
||||
self.editing_input =
|
||||
self.editing_binding =
|
||||
Some((action, self.bindings[action_index].len(), BindingEdit::Init));
|
||||
}
|
||||
y += 45;
|
||||
}
|
||||
|
||||
if let Some((action, binding_index, edit_state)) = &mut self.editing_input {
|
||||
if let Some((action, binding_index, edit_state)) = &mut self.editing_binding {
|
||||
globals.mouse.update(d);
|
||||
let border = screen_centered_rect(d, 368, 128);
|
||||
d.draw_rectangle_rec(border, BG_LIGHT);
|
||||
|
@ -198,11 +202,11 @@ impl Input {
|
|||
} else {
|
||||
binding_list.push(binding.clone());
|
||||
}
|
||||
self.editing_input = None;
|
||||
self.editing_binding = None;
|
||||
}
|
||||
}
|
||||
if text_button(d, &globals.mouse, x + 100, y + 40, 80, "cancel") {
|
||||
self.editing_input = None;
|
||||
self.editing_binding = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue