debug menu additions (#124)

This commit is contained in:
Daedliy 2022-04-24 12:01:31 -03:00 committed by GitHub
parent c97ed04fea
commit 934df79f85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 106 additions and 40 deletions

View File

@ -21,6 +21,7 @@ pub struct LiveDebugger {
events_visible: bool,
flags_visible: bool,
npc_inspector_visible: bool,
hotkey_list_visible: bool,
last_stage_id: usize,
stages: Vec<ImString>,
selected_stage: i32,
@ -38,6 +39,7 @@ impl LiveDebugger {
events_visible: false,
flags_visible: false,
npc_inspector_visible: false,
hotkey_list_visible: false,
last_stage_id: usize::MAX,
stages: Vec::new(),
selected_stage: -1,
@ -70,7 +72,7 @@ impl LiveDebugger {
.resizable(false)
.collapsed(true, Condition::FirstUseEver)
.position([5.0, 5.0], Condition::FirstUseEver)
.size([400.0, 190.0], Condition::FirstUseEver)
.size([400.0, 235.0], Condition::FirstUseEver)
.build(ui, || {
ui.text(format!(
"Player position: ({:.1},{:.1}), velocity: ({:.1},{:.1})",
@ -147,6 +149,20 @@ impl LiveDebugger {
if ui.button("NPC Inspector") {
self.npc_inspector_visible = !self.npc_inspector_visible;
}
ui.same_line();
if state.textscript_vm.state == TextScriptExecutionState::Ended {
if ui.button("Save") {
let _ = state.save_game(game_scene, ctx);
}
} else if ui.button("Busy") {
}
ui.same_line();
if ui.button("Hotkey List") {
self.hotkey_list_visible = !self.hotkey_list_visible;
}
ui.checkbox("noclip", &mut state.settings.noclip);
});
if self.map_selector_visible {
@ -382,6 +398,35 @@ impl LiveDebugger {
});
}
if self.hotkey_list_visible {
Window::new("Hotkeys")
.position([400.0, 5.0], Condition::FirstUseEver)
.size([300.0, 240.0], Condition::FirstUseEver)
.resizable(false)
.build(ui, || {
let key = vec![
"ESC + F2 > Quick Reset",
"F3 > Godmode",
"F4 > Infinite Booster Fuel",
"F5 > Toggle Subpixel Scrolling",
"F6 > Toggle Motion Interpolation",
"F7 > Reset TPS",
"F8 > Decrease TPS",
"F9 > Increase TPS",
"F10 > Debug Overlay",
"F11 > Toggle FPS Counter",
"F12 > Toggle Debugger",
];
for hotkeys in key.iter() {
match hotkeys {
_ => "",
};
ui.bullet();
ui.same_line();
ui.text(format!("{}", hotkeys));
}
});
}
let mut remove = -1;
for (idx, (_, title, contents)) in self.text_windows.iter().enumerate() {
let mut opened = true;

View File

@ -621,7 +621,6 @@ impl Player {
fn tick_ironhead(&mut self, state: &mut SharedGameState) -> GameResult {
self.up = false;
self.down = false;
if state.control_flags.control_enabled() {
if self.controller.move_left() || self.controller.move_right() {
if self.controller.move_left() {
@ -648,6 +647,10 @@ impl Player {
} else {
self.vel_y = 0;
}
if state.settings.noclip {
self.target_x = self.x + self.camera_target_x;
self.target_y = self.y + self.camera_target_y;
}
} else {
if self.vel_x > 0x7f || self.vel_x < -0x7f {
self.vel_x += 0x80 * -self.vel_x.signum();
@ -661,25 +664,26 @@ impl Player {
self.vel_y = 0;
}
}
//Toggles bonk particles
if !state.settings.noclip {
if self.vel_y < -0x200 && self.flags.hit_top_wall() {
state.create_caret(
self.x,
self.y - self.hit_bounds.top as i32,
CaretType::LittleParticles,
Direction::FacingPlayer,
);
}
if self.vel_y < -0x200 && self.flags.hit_top_wall() {
state.create_caret(
self.x,
self.y - self.hit_bounds.top as i32,
CaretType::LittleParticles,
Direction::FacingPlayer,
);
if self.vel_y > 0x200 && self.flags.hit_bottom_wall() {
state.create_caret(
self.x,
self.y + self.hit_bounds.bottom as i32,
CaretType::LittleParticles,
Direction::FacingPlayer,
);
}
}
if self.vel_y > 0x200 && self.flags.hit_bottom_wall() {
state.create_caret(
self.x,
self.y + self.hit_bounds.bottom as i32,
CaretType::LittleParticles,
Direction::FacingPlayer,
);
}
self.vel_x = self.vel_x.clamp(-0x400, 0x400);
self.vel_y = self.vel_y.clamp(-0x400, 0x400);
@ -926,9 +930,10 @@ impl GameEntity<&NPCList> for Player {
self.damage_taken = 0;
}
match self.control_mode {
ControlMode::Normal => self.tick_normal(state, npc_list)?,
ControlMode::IronHead => self.tick_ironhead(state)?,
match (self.control_mode, state.settings.noclip) {
(_, true) => self.tick_ironhead(state)?,
(ControlMode::Normal, _) => self.tick_normal(state, npc_list)?,
(ControlMode::IronHead, _) => self.tick_ironhead(state)?,
}
self.popup.x = self.x;

View File

@ -1380,25 +1380,27 @@ impl GameScene {
&mut self.flash,
),
)?;
//decides if the player is tangible or not
if !state.settings.noclip {
self.player1.tick_map_collisions(state, &self.npc_list, &mut self.stage);
self.player2.tick_map_collisions(state, &self.npc_list, &mut self.stage);
self.player1.tick_map_collisions(state, &self.npc_list, &mut self.stage);
self.player2.tick_map_collisions(state, &self.npc_list, &mut self.stage);
self.player1.tick_npc_collisions(
TargetPlayer::Player1,
state,
&self.npc_list,
&mut self.boss,
&mut self.inventory_player1,
);
self.player2.tick_npc_collisions(
TargetPlayer::Player2,
state,
&self.npc_list,
&mut self.boss,
&mut self.inventory_player2,
);
self.player1.tick_npc_collisions(
TargetPlayer::Player1,
state,
&self.npc_list,
&mut self.boss,
&mut self.inventory_player1,
);
self.player2.tick_npc_collisions(
TargetPlayer::Player2,
state,
&self.npc_list,
&mut self.boss,
&mut self.inventory_player2,
);
}
for npc in self.npc_list.iter_alive() {
if !npc.npc_flags.ignore_solidity() {
npc.tick_map_collisions(state, &self.npc_list, &mut self.stage);
@ -2099,6 +2101,18 @@ impl Scene for GameScene {
)?;
}
if state.settings.noclip {
let debug_name = "NOCLIP";
state.font.draw_text_with_shadow(
debug_name.chars(),
state.canvas_size.0 - state.font.text_width(debug_name.chars(), &state.constants) - 10.0,
56.0,
&state.constants,
&mut state.texture_set,
ctx,
)?;
}
self.replay.draw(state, ctx, &self.frame)?;
self.pause_menu.draw(state, ctx)?;

View File

@ -51,6 +51,7 @@ pub struct Settings {
#[serde(default = "default_vsync")]
pub vsync_mode: VSyncMode,
pub debug_mode: bool,
pub noclip: bool,
}
fn default_true() -> bool {
@ -197,6 +198,7 @@ impl Default for Settings {
locale: Language::English,
vsync_mode: VSyncMode::VSync,
debug_mode: false,
noclip: false,
}
}
}