Skip to content

Commit

Permalink
Fix viewport bug
Browse files Browse the repository at this point in the history
  • Loading branch information
rewin123 committed Oct 23, 2023
1 parent 9dc4535 commit 6c85e8f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/editor/ui/game_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@ impl EditorTab for GameViewTab {
}
}

pub fn reset_camera_viewport(
primary_window: Query<&mut Window, With<PrimaryWindow>>,
mut cameras: Query<&mut Camera, With<EditorCameraMarker>>,
) {
let mut cam = cameras.single_mut();

let Ok(window) = primary_window.get_single() else {
return;
};

cam.viewport = Some(bevy::render::camera::Viewport {
physical_position: UVec2::new(0, 0),
physical_size: UVec2::new(window.width() as u32, window.height() as u32),
depth: 0.0..1.0,
});
}

pub fn set_camera_viewport(
ui_state: Res<GameViewTab>,
primary_window: Query<&mut Window, With<PrimaryWindow>>,
Expand Down
13 changes: 11 additions & 2 deletions src/editor/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub mod debug_panels;
use bevy::{prelude::*, utils::HashMap, window::PrimaryWindow};
use bevy_egui::{egui, EguiContext};

use crate::EditorSet;
use crate::{EditorSet, EditorState};

use self::tools::gizmo::GizmoTool;

Expand Down Expand Up @@ -62,7 +62,12 @@ impl Plugin for EditorUiPlugin {

app.add_plugins(bot_menu::BotMenuPlugin);

app.configure_set(Update, UiSystemSet.in_set(EditorSet::Editor));
app.configure_set(
Update,
UiSystemSet
.in_set(EditorSet::Editor)
.run_if(in_state(EditorState::Editor)),
);

app.init_resource::<EditorUi>();
app.init_resource::<ScheduleEditorTabStorage>();
Expand All @@ -76,6 +81,10 @@ impl Plugin for EditorUiPlugin {
)
.in_set(UiSystemSet),
);
app.add_systems(
Update,
reset_camera_viewport.run_if(in_state(EditorState::Game)),
);
app.editor_tab_by_trait(EditorTabName::GameView, GameViewTab::default());

app.editor_tab_by_trait(
Expand Down

0 comments on commit 6c85e8f

Please sign in to comment.