Stop using nested viewports
This commit is contained in:
+22
-16
@@ -1,40 +1,32 @@
|
||||
use std::sync::{
|
||||
atomic::{AtomicBool, Ordering},
|
||||
Arc,
|
||||
use crate::{
|
||||
app::UserEvent,
|
||||
emulator::{EmulatorClient, EmulatorCommand, SimId},
|
||||
};
|
||||
|
||||
use crate::emulator::{EmulatorClient, EmulatorCommand, SimId};
|
||||
use egui::{
|
||||
menu, Button, CentralPanel, Color32, Context, Response, TopBottomPanel, Ui, ViewportBuilder,
|
||||
ViewportCommand, ViewportId, WidgetText,
|
||||
};
|
||||
use winit::event_loop::EventLoopProxy;
|
||||
|
||||
use super::{game_screen::GameScreen, AppWindow};
|
||||
|
||||
pub struct GameWindow {
|
||||
client: EmulatorClient,
|
||||
proxy: EventLoopProxy<UserEvent>,
|
||||
sim_id: SimId,
|
||||
input_window_open: Arc<AtomicBool>,
|
||||
screen: Option<GameScreen>,
|
||||
}
|
||||
|
||||
impl GameWindow {
|
||||
pub fn new(client: EmulatorClient, sim_id: SimId, input_window_open: Arc<AtomicBool>) -> Self {
|
||||
pub fn new(client: EmulatorClient, proxy: EventLoopProxy<UserEvent>, sim_id: SimId) -> Self {
|
||||
Self {
|
||||
client,
|
||||
proxy,
|
||||
sim_id,
|
||||
input_window_open,
|
||||
screen: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn init_renderer(&mut self, render_state: &egui_wgpu::RenderState) {
|
||||
let (screen, sink) = GameScreen::init(render_state);
|
||||
self.client
|
||||
.send_command(EmulatorCommand::SetRenderer(self.sim_id, sink));
|
||||
self.screen = Some(screen)
|
||||
}
|
||||
|
||||
fn show_menu(&mut self, ctx: &Context, ui: &mut Ui) {
|
||||
ui.menu_button("ROM", |ui| {
|
||||
if ui.button("Open ROM").clicked() {
|
||||
@@ -101,7 +93,7 @@ impl GameWindow {
|
||||
});
|
||||
ui.menu_button("Input", |ui| {
|
||||
if ui.button("Bind Inputs").clicked() {
|
||||
self.input_window_open.store(true, Ordering::Relaxed);
|
||||
self.proxy.send_event(UserEvent::OpenInput).unwrap();
|
||||
ui.close_menu();
|
||||
}
|
||||
});
|
||||
@@ -112,6 +104,7 @@ impl GameWindow {
|
||||
{
|
||||
self.client
|
||||
.send_command(EmulatorCommand::StartSecondSim(None));
|
||||
self.proxy.send_event(UserEvent::OpenPlayer2).unwrap();
|
||||
ui.close_menu();
|
||||
}
|
||||
if self.client.has_player_2() {
|
||||
@@ -157,6 +150,19 @@ impl AppWindow for GameWindow {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn on_init(&mut self, render_state: &egui_wgpu::RenderState) {
|
||||
let (screen, sink) = GameScreen::init(render_state);
|
||||
self.client
|
||||
.send_command(EmulatorCommand::SetRenderer(self.sim_id, sink));
|
||||
self.screen = Some(screen)
|
||||
}
|
||||
|
||||
fn on_destroy(&mut self) {
|
||||
if self.sim_id == SimId::Player2 {
|
||||
self.client.send_command(EmulatorCommand::StopSecondSim);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
trait UiExt {
|
||||
|
||||
@@ -10,7 +10,7 @@ pub struct GameScreen {
|
||||
}
|
||||
|
||||
impl GameScreen {
|
||||
pub fn init_pipeline(render_state: &egui_wgpu::RenderState) {
|
||||
fn init_pipeline(render_state: &egui_wgpu::RenderState) {
|
||||
let device = &render_state.device;
|
||||
|
||||
let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||
@@ -101,6 +101,8 @@ impl GameScreen {
|
||||
}
|
||||
|
||||
pub fn init(render_state: &egui_wgpu::RenderState) -> (Self, TextureSink) {
|
||||
Self::init_pipeline(render_state);
|
||||
|
||||
let device = &render_state.device;
|
||||
let queue = &render_state.queue;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user