Stop using nested viewports

This commit is contained in:
2024-11-28 10:50:06 -05:00
parent 08680b27ae
commit 83377ff5fa
6 changed files with 364 additions and 478 deletions
+22 -16
View File
@@ -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 {