Skip to content

Commit

Permalink
Enemy preview bottom panel
Browse files Browse the repository at this point in the history
  • Loading branch information
makscee committed Jan 2, 2024
1 parent ca8264e commit 1d1d735
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 124 deletions.
10 changes: 6 additions & 4 deletions src/plugins/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,12 @@ impl LoginPlugin {
}
}
}
let mut led = LOGIN_EVENT_DISPATCHED.lock().unwrap();
if !*led {
world.send_event(LoginEvent);
*led = true;
if Self::get_username().is_some() {
let mut led = LOGIN_EVENT_DISPATCHED.lock().unwrap();
if !*led {
world.send_event(LoginEvent);
*led = true;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/panels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl PanelsPlugin {
)
.show(&egui_context(world), |ui| {
let mut margin = Margin::same(4.0);
margin.top = 1.0;
margin.top = 2.0;
Frame::none().inner_margin(margin).show(ui, |ui| {
let columns = top_data.len();
ui.set_max_width(columns as f32 * 150.0);
Expand Down
91 changes: 37 additions & 54 deletions src/plugins/shop.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::*;

use bevy::input::common_conditions::input_just_pressed;
use bevy_egui::egui::Order;
use rand::seq::IteratorRandom;

pub struct ShopPlugin;
Expand All @@ -10,8 +11,8 @@ pub struct ShopData {
pub next_team: PackedTeam,
pub next_team_cards: Vec<(UnitCard, usize)>,
pub next_level_num: usize,
pub enemy_panel_expanded: bool,
pub phase: ShopPhase,
pub bottom_expanded: bool,
}

const G_PER_ROUND: i32 = 4;
Expand Down Expand Up @@ -212,7 +213,7 @@ impl ShopPlugin {
next_team,
next_level_num: next_level_num + 1,
phase,
enemy_panel_expanded: false,
bottom_expanded: false,
});
}

Expand Down Expand Up @@ -270,7 +271,9 @@ impl ShopPlugin {
let save = Save::get(world).unwrap();
match &mut data.phase {
ShopPhase::Buy => {
ShopOffer::draw_buy_panels(world);
if !data.bottom_expanded {
ShopOffer::draw_buy_panels(world);
}
Area::new("reroll").fixed_pos(pos).show(ctx, |ui| {
ui.set_width(120.0);
frame(ui, |ui| {
Expand All @@ -289,7 +292,7 @@ impl ShopPlugin {
}
});
});
Self::show_next_enemy_window(&mut data, world);
Self::show_next_enemy_preview_panel(&mut data, world);
}
ShopPhase::Sacrifice { selected } => {
for unit in UnitPlugin::collect_faction(Faction::Team, world) {
Expand Down Expand Up @@ -376,60 +379,40 @@ impl ShopPlugin {
world.insert_resource(data);
}

fn show_next_enemy_window(data: &mut ShopData, world: &mut World) {
let len = data.next_team_cards.len();
window("NEXT ENEMY")
.anchor(Align2::RIGHT_CENTER, [-10.0, 0.0])
.show(&egui_context(world), |ui| {
Frame::none().inner_margin(8.0).show(ui, |ui| {
ui.vertical(|ui| {
ui.label(
format!(
"Level {}/{}",
data.next_level_num - 1,
Tower::total_levels()
)
fn show_next_enemy_preview_panel(data: &mut ShopData, world: &mut World) {
let ctx = &egui_context(world);
let response = TopBottomPanel::bottom("enemy preview")
.frame(
Frame::none()
.fill(light_black())
.inner_margin(Margin::same(8.0)),
)
.show(ctx, |ui| {
ui.with_layout(Layout::right_to_left(egui::Align::Max), |ui| {
ui.add_space(30.0);
if ui.button("START BATTLE").clicked() {
Self::go_to_battle(world);
}
ui.label(
format!("{}/{}", data.next_level_num - 1, Tower::total_levels())
.add_color(white())
.rich_text(),
);
let mut can_expand = false;
ui.columns(len, |ui| {
for (ind, (card, count)) in data.next_team_cards.iter().enumerate() {
can_expand |=
!card.description.is_empty() || !card.statuses.is_empty();
ui[ind].vertical_centered(|ui| {
if data.enemy_panel_expanded {
card.show_frames(true, ui);
} else {
card.show_name(false, ui);
}
if *count > 1 {
ui.heading(
format!("x{count}").add_color(white()).rich_text(),
);
}
});
}
});

if can_expand
&& if data.enemy_panel_expanded {
ui.button_primary("EXPAND")
} else {
ui.button("EXPAND")
}
.clicked()
{
data.enemy_panel_expanded = !data.enemy_panel_expanded;
);
ui.add_space(50.0);
for (card, count) in data.next_team_cards.iter().rev() {
if *count > 1 {
ui.label(format!("x{count}").add_color(white()).rich_text());
}
ui.with_layout(Layout::right_to_left(egui::Align::Min), |ui| {
if ui.button_primary(RichText::new("GO").heading()).clicked() {
Self::go_to_battle(world);
}
});
});
card.show_ui(data.bottom_expanded, ui);
}
ui.label("NEXT ENEMY:");
});
});
})
.response;
if data.bottom_expanded && !response.hovered() {
ctx.data_mut(|w| w.clear());
}
data.bottom_expanded = response.hovered();
}

fn go_to_battle(world: &mut World) {
Expand Down
85 changes: 45 additions & 40 deletions src/plugins/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ use super::*;
pub fn light_gray() -> Color32 {
hex_color!("#6F6F6F")
}
fn dark_gray() -> Color32 {
pub fn dark_gray() -> Color32 {
hex_color!("#393939")
}
fn black() -> Color32 {
pub fn black() -> Color32 {
hex_color!("#000000")
}
pub fn light_black() -> Color32 {
hex_color!("#202020")
}
pub fn white() -> Color32 {
hex_color!("#ffffff")
}
Expand Down Expand Up @@ -164,49 +167,51 @@ pub struct GameWindow<'a> {
}

impl GameWindow<'_> {
pub fn show(mut self, ctx: &egui::Context, add_contents: impl FnOnce(&mut Ui)) {
pub fn show(self, ctx: &egui::Context, add_contents: impl FnOnce(&mut Ui)) {
self.area.show(ctx, |ui| {
self.show_ui(ui, add_contents);
});
}
pub fn show_ui(mut self, ui: &mut Ui, add_contents: impl FnOnce(&mut Ui)) {
if !self.stroke {
self.frame = Some(Frame::none());
}
let style = ctx.style();
let style = ui.style();
let mut stroke = style.visuals.window_stroke;
stroke.color = self.color.unwrap_or(style.visuals.window_stroke.color);
self.area.show(ctx, |ui| {
ui.set_width(self.width);
self.frame
.unwrap_or(Frame::window(&style).stroke(stroke))
.show(ui, |ui| {
if self.title_bar {
let v = &ui.style().visuals.clone();
let mut rounding = v.window_rounding;
rounding.se = 0.0;
rounding.sw = 0.0;
Frame::none()
.fill(stroke.color)
.rounding(rounding)
.stroke(stroke)
.show(ui, |ui| {
ui.with_layout(
Layout::top_down(egui::Align::Min).with_cross_justify(true),
|ui| {
Frame::none()
.inner_margin(Margin::symmetric(8.0, 0.0))
.show(ui, |ui| {
ui.label(
RichText::new(self.title)
.text_style(TextStyle::Heading)
.size(15.0)
.color(black()),
);
})
},
);
});
}
add_contents(ui)
});
});
ctx.set_style(style);
self.frame
.unwrap_or(Frame::window(&style).stroke(stroke))
.show(ui, |ui| {
ui.set_width(self.width);
if self.title_bar {
let v = &ui.style().visuals.clone();
let mut rounding = v.window_rounding;
rounding.se = 0.0;
rounding.sw = 0.0;
Frame::none()
.fill(stroke.color)
.rounding(rounding)
.stroke(stroke)
.show(ui, |ui| {
ui.with_layout(
Layout::top_down(egui::Align::Min).with_cross_justify(true),
|ui| {
Frame::none()
.inner_margin(Margin::symmetric(8.0, 0.0))
.show(ui, |ui| {
ui.label(
RichText::new(self.title)
.text_style(TextStyle::Heading)
.size(15.0)
.color(black()),
);
})
},
);
});
}
add_contents(ui)
});
}
pub fn default_pos_vec(mut self, pos: Vec2) -> Self {
self.area = self.area.default_pos(pos2(pos.x, pos.y));
Expand Down
60 changes: 35 additions & 25 deletions src/resourses/unit_card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,35 +151,37 @@ impl UnitCard {
}

pub fn show_frames(&self, open: bool, ui: &mut Ui) {
self.show_name(open, ui);
if !open {
return;
}
frame(ui, |ui| {
if !self.description.is_empty() {
ui.vertical(|ui| {
ui.label(self.description.widget());
});
ui.vertical(|ui| {
self.show_name(open, ui);
if !open {
return;
}
// self.show_status_lines(false, ui);
});

for (name, text) in &self.definitions {
frame(ui, |ui| {
ui.label(name.rich_text().family(FontFamily::Name("bold".into())));
ui.horizontal_wrapped(|ui| {
ui.label(text.widget());
});
if !self.description.is_empty() {
ui.vertical(|ui| {
ui.label(self.description.widget());
});
}
// self.show_status_lines(false, ui);
});
}
if !self.statuses.is_empty() {
frame(ui, |ui| {
ui.vertical_centered(|ui| {
ui.heading(RichText::new("Statuses").color(white()));

for (name, text) in &self.definitions {
frame(ui, |ui| {
ui.label(name.rich_text().family(FontFamily::Name("bold".into())));
ui.horizontal_wrapped(|ui| {
ui.label(text.widget());
});
});
self.show_status_lines(open, ui);
});
}
}
if !self.statuses.is_empty() {
frame(ui, |ui| {
ui.vertical_centered(|ui| {
ui.heading(RichText::new("Statuses").color(white()));
});
self.show_status_lines(open, ui);
});
}
});
}

pub fn show_window(&self, open: bool, ctx: &egui::Context, world: &World) {
Expand Down Expand Up @@ -209,6 +211,14 @@ impl UnitCard {
});
}

pub fn show_ui(&self, open: bool, ui: &mut Ui) {
window("UNIT")
.id(self.entity)
.set_width(if open { 200.0 } else { 120.0 })
.title_bar(false)
.show_ui(ui, |ui| self.show_frames(open, ui));
}

pub fn set_open(mut self, value: bool) -> Self {
self.open = value;
self
Expand Down

0 comments on commit 1d1d735

Please sign in to comment.