2021-01-27 18:20:47 +00:00
|
|
|
use crate::framework::context::Context;
|
|
|
|
use crate::framework::error::GameResult;
|
2022-11-19 17:20:03 +00:00
|
|
|
use crate::game::shared_game_state::SharedGameState;
|
2020-11-28 19:25:51 +00:00
|
|
|
use crate::input::player_controller::PlayerController;
|
|
|
|
|
|
|
|
pub struct CombinedMenuController {
|
|
|
|
controllers: Vec<Box<dyn PlayerController>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl CombinedMenuController {
|
|
|
|
pub fn new() -> CombinedMenuController {
|
2022-02-12 18:32:48 +00:00
|
|
|
CombinedMenuController { controllers: Vec::new() }
|
2020-11-28 19:25:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn update(&mut self, state: &mut SharedGameState, ctx: &mut Context) -> GameResult {
|
2022-01-17 22:29:30 +00:00
|
|
|
for cont in &mut self.controllers {
|
2020-11-28 19:25:51 +00:00
|
|
|
cont.update(state, ctx)?;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn update_trigger(&mut self) {
|
2022-01-17 22:29:30 +00:00
|
|
|
for cont in &mut self.controllers {
|
2020-11-28 19:25:51 +00:00
|
|
|
cont.update_trigger();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn add(&mut self, controller: Box<dyn PlayerController>) {
|
|
|
|
self.controllers.push(controller);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn trigger_up(&self) -> bool {
|
2022-01-17 22:29:30 +00:00
|
|
|
for cont in &self.controllers {
|
2020-11-28 19:25:51 +00:00
|
|
|
if cont.trigger_up() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn trigger_down(&self) -> bool {
|
2022-01-17 22:29:30 +00:00
|
|
|
for cont in &self.controllers {
|
2020-11-28 19:25:51 +00:00
|
|
|
if cont.trigger_down() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
2021-03-23 01:49:55 +00:00
|
|
|
pub fn trigger_left(&self) -> bool {
|
2022-01-17 22:29:30 +00:00
|
|
|
for cont in &self.controllers {
|
2021-03-23 01:49:55 +00:00
|
|
|
if cont.trigger_left() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn trigger_right(&self) -> bool {
|
2022-01-17 22:29:30 +00:00
|
|
|
for cont in &self.controllers {
|
2021-03-23 01:49:55 +00:00
|
|
|
if cont.trigger_right() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
2020-11-28 19:25:51 +00:00
|
|
|
pub fn trigger_ok(&self) -> bool {
|
2022-01-17 22:29:30 +00:00
|
|
|
for cont in &self.controllers {
|
2020-11-28 19:25:51 +00:00
|
|
|
if cont.trigger_menu_ok() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn trigger_back(&self) -> bool {
|
2022-01-17 22:29:30 +00:00
|
|
|
for cont in &self.controllers {
|
2020-11-28 19:25:51 +00:00
|
|
|
if cont.trigger_menu_back() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
false
|
|
|
|
}
|
2022-02-12 18:32:48 +00:00
|
|
|
|
|
|
|
pub fn trigger_shift_left(&self) -> bool {
|
|
|
|
for cont in &self.controllers {
|
|
|
|
if cont.trigger_prev_weapon() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn trigger_shift_right(&self) -> bool {
|
|
|
|
for cont in &self.controllers {
|
|
|
|
if cont.trigger_next_weapon() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
false
|
|
|
|
}
|
2020-11-28 19:25:51 +00:00
|
|
|
}
|