Some UI
This commit is contained in:
parent
21e2d1819a
commit
26991b0d90
Binary file not shown.
BIN
data/menu.ui
BIN
data/menu.ui
Binary file not shown.
|
|
@ -1,11 +1,10 @@
|
|||
use fyrox::{
|
||||
core::{
|
||||
algebra::{Point2, Vector2, Vector3},
|
||||
impl_component_provider,
|
||||
pool::Handle,
|
||||
reflect::prelude::*,
|
||||
uuid_provider,
|
||||
visitor::prelude::*,
|
||||
algebra::{Point2, Vector2, Vector3}, impl_component_provider, pool::Handle, reflect::prelude::*, uuid_provider, visitor::prelude::*
|
||||
},
|
||||
gui::{
|
||||
message::MessageDirection,
|
||||
widget::WidgetMessage,
|
||||
},
|
||||
scene::{
|
||||
animation::spritesheet::SpriteSheetAnimation,
|
||||
|
|
@ -177,19 +176,24 @@ impl Enemy {
|
|||
return Some(buffer);
|
||||
}
|
||||
|
||||
fn attack_player(&mut self, graph: &mut Graph) {
|
||||
fn attack_player(&mut self, ctx: &mut ScriptContext) {
|
||||
if self.win {
|
||||
return;
|
||||
}
|
||||
if !self.fight {
|
||||
return;
|
||||
}
|
||||
match graph.try_get_script_of_mut::<Player>(self.player_handle) {
|
||||
match ctx.scene.graph.try_get_script_of_mut::<Player>(self.player_handle) {
|
||||
Some(script) => {
|
||||
if script.get_health() <= 0.0 {
|
||||
self.fight = false;
|
||||
self.block = false;
|
||||
self.win = true;
|
||||
ctx.user_interface.send_message(WidgetMessage::visibility(
|
||||
ctx.user_interface.root(),
|
||||
MessageDirection::ToWidget,
|
||||
true,
|
||||
));
|
||||
return;
|
||||
}
|
||||
self.block = false;
|
||||
|
|
@ -346,7 +350,7 @@ impl Enemy {
|
|||
}
|
||||
self.attack_timer += context.dt;
|
||||
if self.attack_timer >= self.attack_speed {
|
||||
self.attack_player(&mut context.scene.graph);
|
||||
self.attack_player(context);
|
||||
self.attack_timer = 0.0;
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,25 +4,27 @@ use fyrox::{
|
|||
core::{log::Log, pool::Handle},
|
||||
engine::GraphicsContext,
|
||||
event::{Event, WindowEvent},
|
||||
gui::{message::UiMessage, UserInterface},
|
||||
gui::{
|
||||
button::ButtonMessage,
|
||||
message::{MessageDirection, UiMessage},
|
||||
widget::WidgetMessage,
|
||||
UiNode, UserInterface,
|
||||
},
|
||||
plugin::{Plugin, PluginConstructor, PluginContext, PluginRegistrationContext},
|
||||
scene::{
|
||||
graph::Graph, Scene
|
||||
}
|
||||
scene::{graph::Graph, Scene},
|
||||
};
|
||||
use std::path::Path;
|
||||
mod map;
|
||||
mod player;
|
||||
mod enemy;
|
||||
mod enemy_spawn;
|
||||
mod map;
|
||||
mod msg;
|
||||
mod player;
|
||||
|
||||
use map::build_map;
|
||||
use player::Player;
|
||||
use enemy::Enemy;
|
||||
use enemy_spawn::EnemySpawn;
|
||||
use map::build_map;
|
||||
use msg::Message;
|
||||
|
||||
use player::Player;
|
||||
|
||||
pub struct GameConstructor;
|
||||
|
||||
|
|
@ -41,24 +43,30 @@ impl PluginConstructor for GameConstructor {
|
|||
|
||||
pub struct Game {
|
||||
scene: Handle<Scene>,
|
||||
|
||||
new_game: Handle<UiNode>,
|
||||
exit: Handle<UiNode>,
|
||||
}
|
||||
|
||||
impl Game {
|
||||
pub fn new(scene_path: Option<&str>, context: PluginContext) -> Self {
|
||||
context
|
||||
.async_scene_loader
|
||||
.request(scene_path.unwrap_or("data/scene.rgs"));
|
||||
context.task_pool.spawn_plugin_task(
|
||||
UserInterface::load_from_file("data/menu.ui", context.resource_manager.clone()),
|
||||
pub fn new(_scene_path: Option<&str>, ctx: PluginContext) -> Self {
|
||||
ctx.task_pool.spawn_plugin_task(
|
||||
UserInterface::load_from_file("data/menu.ui", ctx.resource_manager.clone()),
|
||||
|result, game: &mut Game, ctx| match result {
|
||||
Ok(menu) => {
|
||||
*ctx.user_interface = menu;
|
||||
game.new_game = ctx.user_interface.find_by_name_down_from_root("NewGame");
|
||||
game.exit = ctx.user_interface.find_by_name_down_from_root("Exit");
|
||||
}
|
||||
Err(e) => Log::err(format!("Unable to load main menu! Reason: {:?}", e)),
|
||||
// let ui = ctx.user_interface.clone();
|
||||
// *ui = result.unwrap();
|
||||
},
|
||||
);
|
||||
Self {
|
||||
scene: Handle::NONE,
|
||||
new_game: Handle::NONE,
|
||||
exit: Handle::NONE,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -79,7 +87,7 @@ impl Plugin for Game {
|
|||
for script_scene in &context.script_processor.scripted_scenes {
|
||||
script_scene.message_sender.send_global(Message::Resize {
|
||||
width: window_size.width,
|
||||
height: window_size.height
|
||||
height: window_size.height,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -89,15 +97,29 @@ impl Plugin for Game {
|
|||
for script_scene in &context.script_processor.scripted_scenes {
|
||||
script_scene.message_sender.send_global(Message::Resize {
|
||||
width: size.width,
|
||||
height: size.height
|
||||
height: size.height,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn on_ui_message(&mut self, _context: &mut PluginContext, _message: &UiMessage) {
|
||||
// Handle UI events here.
|
||||
fn on_ui_message(&mut self, ctx: &mut PluginContext, message: &UiMessage) {
|
||||
if let Some(ButtonMessage::Click) = message.data() {
|
||||
if message.destination() == self.new_game {
|
||||
ctx.user_interface.send_message(WidgetMessage::visibility(
|
||||
ctx.user_interface.root(),
|
||||
MessageDirection::ToWidget,
|
||||
false,
|
||||
));
|
||||
ctx.async_scene_loader
|
||||
.request("data/scene.rgs");
|
||||
} else if message.destination() == self.exit {
|
||||
if let Some(window_target) = ctx.window_target {
|
||||
window_target.exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn on_scene_begin_loading(&mut self, _path: &Path, ctx: &mut PluginContext) {
|
||||
|
|
|
|||
1024
settings.ron
1024
settings.ron
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue