|
|
@ -3,23 +3,19 @@ use std::thread;
|
|
|
|
use std::time::Duration;
|
|
|
|
use std::time::Duration;
|
|
|
|
|
|
|
|
|
|
|
|
use eframe::egui;
|
|
|
|
use eframe::egui;
|
|
|
|
use egui::*;
|
|
|
|
|
|
|
|
use renrs::{State, Command};
|
|
|
|
use renrs::{State, Command};
|
|
|
|
|
|
|
|
|
|
|
|
pub fn run(file: PathBuf) -> Result<(), eframe::Error> {
|
|
|
|
use sfml::{
|
|
|
|
|
|
|
|
graphics::{Color, RenderTarget, RenderWindow, Shape, RectangleShape},
|
|
|
|
|
|
|
|
system::Vector2f,
|
|
|
|
|
|
|
|
window::{Event, mouse, Key, Style},
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
use egui_sfml::SfEgui;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn run(file: PathBuf) {
|
|
|
|
env_logger::init();
|
|
|
|
env_logger::init();
|
|
|
|
let options = eframe::NativeOptions {
|
|
|
|
let mut app = App::from_state(State::from_file(file));
|
|
|
|
initial_window_size: Some(egui::vec2(640.0, 480.0)),
|
|
|
|
app.run();
|
|
|
|
resizable: false, // prevent i3 from automatically resizing
|
|
|
|
|
|
|
|
..Default::default()
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
eframe::run_native(
|
|
|
|
|
|
|
|
"renrs-gui",
|
|
|
|
|
|
|
|
options,
|
|
|
|
|
|
|
|
Box::new(|_cc| Box::new(
|
|
|
|
|
|
|
|
App::from_state(State::from_file(file))
|
|
|
|
|
|
|
|
)),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct App {
|
|
|
|
struct App {
|
|
|
@ -41,13 +37,13 @@ impl App {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn next(&mut self, ctx: &Context) {
|
|
|
|
fn next(&mut self) {
|
|
|
|
if let Some(Command::Say { name, text }) = self.state.next_command() {
|
|
|
|
if let Some(Command::Say { name, text }) = self.state.next_command() {
|
|
|
|
self.text = match name {
|
|
|
|
self.text = match name {
|
|
|
|
Some(name) => format!("{name}: {text}"),
|
|
|
|
Some(name) => format!("{name}: {text}"),
|
|
|
|
None => text,
|
|
|
|
None => text,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
self.start_typing(ctx);
|
|
|
|
self.start_typing();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -63,7 +59,7 @@ impl App {
|
|
|
|
*self.typing_done.lock().unwrap() = true;
|
|
|
|
*self.typing_done.lock().unwrap() = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn start_typing(&mut self, ctx: &Context) {
|
|
|
|
fn start_typing(&mut self) {
|
|
|
|
// Kill previous typing thread if exists
|
|
|
|
// Kill previous typing thread if exists
|
|
|
|
self.kill_typing();
|
|
|
|
self.kill_typing();
|
|
|
|
|
|
|
|
|
|
|
@ -71,7 +67,6 @@ impl App {
|
|
|
|
*self.typing_done.lock().unwrap() = false;
|
|
|
|
*self.typing_done.lock().unwrap() = false;
|
|
|
|
|
|
|
|
|
|
|
|
// Set up references to be passed into thread
|
|
|
|
// Set up references to be passed into thread
|
|
|
|
let ctx = ctx.clone();
|
|
|
|
|
|
|
|
let kill = {
|
|
|
|
let kill = {
|
|
|
|
let kill = Arc::new(Mutex::new(false));
|
|
|
|
let kill = Arc::new(Mutex::new(false));
|
|
|
|
self.typing_kill = Some(kill.clone());
|
|
|
|
self.typing_kill = Some(kill.clone());
|
|
|
@ -88,7 +83,6 @@ impl App {
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*chars.lock().unwrap() = i;
|
|
|
|
*chars.lock().unwrap() = i;
|
|
|
|
ctx.request_repaint();
|
|
|
|
|
|
|
|
thread::sleep(Duration::from_millis(50));
|
|
|
|
thread::sleep(Duration::from_millis(50));
|
|
|
|
complete = true;
|
|
|
|
complete = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -98,17 +92,42 @@ impl App {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn handle_interaction(&mut self, ctx: &Context) {
|
|
|
|
fn handle_interaction(&mut self) {
|
|
|
|
if *self.typing_done.lock().unwrap() {
|
|
|
|
if *self.typing_done.lock().unwrap() {
|
|
|
|
self.next(ctx);
|
|
|
|
self.next();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
self.interrupt_typing();
|
|
|
|
self.interrupt_typing();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl eframe::App for App {
|
|
|
|
fn run(&mut self) {
|
|
|
|
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
|
|
|
let mut window = RenderWindow::new(
|
|
|
|
|
|
|
|
(800, 600),
|
|
|
|
|
|
|
|
"renrs-gui",
|
|
|
|
|
|
|
|
Style::CLOSE,
|
|
|
|
|
|
|
|
&Default::default(),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
let mut sfegui = SfEgui::new(&window);
|
|
|
|
|
|
|
|
window.set_vertical_sync_enabled(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut shape = RectangleShape::with_size(Vector2f::new(64.0, 64.0));
|
|
|
|
|
|
|
|
shape.set_fill_color(Color::RED);
|
|
|
|
|
|
|
|
shape.set_outline_color(Color::GREEN);
|
|
|
|
|
|
|
|
shape.set_outline_thickness(3.);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while window.is_open() {
|
|
|
|
|
|
|
|
while let Some(event) = window.poll_event() {
|
|
|
|
|
|
|
|
match event {
|
|
|
|
|
|
|
|
Event::Closed | Event::KeyPressed { code: Key::Escape, .. } => return,
|
|
|
|
|
|
|
|
Event::MouseButtonPressed { button: mouse::Button::Left, .. } | Event::KeyPressed { code: Key::Space, .. } => self.handle_interaction(),
|
|
|
|
|
|
|
|
_ => {}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
use egui::*;
|
|
|
|
|
|
|
|
sfegui
|
|
|
|
|
|
|
|
.do_frame(|ctx| {
|
|
|
|
egui::CentralPanel::default()
|
|
|
|
egui::CentralPanel::default()
|
|
|
|
.frame(Frame {
|
|
|
|
.frame(Frame {
|
|
|
|
fill: Color32::BLACK,
|
|
|
|
fill: Color32::BLACK,
|
|
|
@ -120,9 +139,17 @@ impl eframe::App for App {
|
|
|
|
i.key_pressed(Key::Space)
|
|
|
|
i.key_pressed(Key::Space)
|
|
|
|
|| i.pointer.button_clicked(PointerButton::Primary)
|
|
|
|
|| i.pointer.button_clicked(PointerButton::Primary)
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
self.handle_interaction(ctx);
|
|
|
|
self.handle_interaction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ui.with_layout(egui::Layout::left_to_right(Align::Max), |ui| ui.heading(&self.text[0..*self.chars.lock().unwrap()]));
|
|
|
|
ui.with_layout(egui::Layout::left_to_right(Align::Max), |ui| ui.heading(&self.text[0..*self.chars.lock().unwrap()]));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}).unwrap();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
window.clear(Color::BLACK);
|
|
|
|
|
|
|
|
window.draw(&shape);
|
|
|
|
|
|
|
|
sfegui.draw(&mut window, None);
|
|
|
|
|
|
|
|
window.display();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|