Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ryankopf committed Aug 20, 2023
1 parent d300a67 commit dbf74e3
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 22 deletions.
8 changes: 6 additions & 2 deletions src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub enum GameState {

#[derive(PartialEq)]
pub enum MenuStates { // Sorted in order of display.
Home, Tasks, Farm, Zone, Build, Craft
Home, Tasks, Farm, Build, Zone
}

impl MenuStates {
Expand All @@ -50,7 +50,6 @@ impl MenuStates {
MenuStates::Farm => 2,
MenuStates::Zone => 3,
MenuStates::Build => 4,
MenuStates::Craft => 5,
}
}
}
Expand Down Expand Up @@ -587,6 +586,10 @@ pub struct Foragable;

#[derive(Component)]
pub struct Choppable;
#[derive(Component)]
pub struct Huntable;
#[derive(Component)]
pub struct Mineable;

#[derive(Component)]
pub struct SetNest;
Expand Down Expand Up @@ -734,6 +737,7 @@ pub enum SelectableType {
Foragable,
Gatherable,
Harvestable,
Huntable,
Mineable,
Nothing,
Unselecting,
Expand Down
33 changes: 14 additions & 19 deletions src/interface/game_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,14 @@ pub fn start_game_ui(
let buttons = [vec![
"TASKS",
"FARM",
"ZONE",
"BUILD",
"CRAFT",
"ZONE",
],vec![ // tasks
"BACK",
"CLEAR",
"CHOP",
"FORAGE",
"GATHER",
"COLLECT",
"HUNT",
"MINE",
],vec![ // farm
Expand Down Expand Up @@ -172,9 +171,8 @@ pub fn game_ui_click(
match button_index {
0 => { menu_state.state = MenuStates::Tasks },
1 => { menu_state.state = MenuStates::Farm },
2 => { menu_state.state = MenuStates::Zone },
3 => { menu_state.state = MenuStates::Build },
4 => { menu_state.state = MenuStates::Craft },
2 => { menu_state.state = MenuStates::Build },
3 => { menu_state.state = MenuStates::Zone },
_ => { },
}
}
Expand Down Expand Up @@ -233,37 +231,34 @@ pub fn game_ui_click(
_ => { },
}
}
MenuStates::Zone => {
MenuStates::Build => {
match button_index {
5 => {
1 => {
dragging.looking_for = SelectableType::Unzoning;
},
2 => {
dragging.looking_for = SelectableType::Zoning;
dragging.zone_type = ZoneType::Avoid;
dragging.zone_type = ZoneType::Construction;
dragging.item_type = ItemType::WallWood;
},
_ => {
dragging.looking_for = SelectableType::Nothing;
menu_state.state = MenuStates::Home;
},
}
}
MenuStates::Build => {
MenuStates::Zone => {
match button_index {
1 => {
dragging.looking_for = SelectableType::Unzoning;
},
2 => {
5 => {
dragging.looking_for = SelectableType::Zoning;
dragging.zone_type = ZoneType::Construction;
dragging.item_type = ItemType::WallWood;
dragging.zone_type = ZoneType::Avoid;
},
_ => {
dragging.looking_for = SelectableType::Nothing;
menu_state.state = MenuStates::Home;
},
}
}
MenuStates::Craft => {
menu_state.state = MenuStates::Home;
}
}
start_game_ui(commands, font, menu_state, game_buttons);
}
Expand Down
2 changes: 1 addition & 1 deletion src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub use super::components::{
ActorType, Affliction, AfflictionType, AfflictionLocation, Attackable, Attacked, Attributeset,
Bed, Brain, Choppable, ClickedOn, Danger, DangerType, Dying, Food, Foragable, ForageType, GameState, GeneratedBy,
GiveMeAName, HasName, HasNameShown, HighlightBox, Highlighted, HoverNote, InfoPanel, InGameButton, IsName,
GiveMeAName, HasName, HasNameShown, HighlightBox, Highlighted, HoverNote, Huntable, InfoPanel, InGameButton, IsName,
Logs, MainMenuOverlay, MapTile, MenuStates, MonsterGenerator, Motivation, MoveRandom,
MoveTowardsNearestAttackable, MoveTowardsTarget, NearestEntity, Need, Nest,
Order, Pathing, PauseOverlay, PersonalityTrait, PhysicalBody, Plant, Position,
Expand Down
40 changes: 40 additions & 0 deletions src/selection_systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,23 @@ pub fn select_foragables(
highlightboxes: Query<Entity, With<HighlightBox>>,
event: EventReader<SelectionEvent>,
dragging: Res<Dragging>,
font: Res<MyFont>,
) {
if event.is_empty() { return; }
if dragging.looking_for != SelectableType::Foragable { return; }
for (entity, foragable) in query.iter_mut() {
if foragable.is_some() {
commands.entity(entity).insert(WorkTarget);
let child = commands.spawn((
Text2dBundle {
text: Text::from_section("X", TextStyle { font: font.0.clone(), ..default() })
.with_alignment(TextAlignment::Center),
..default()
},
WorkMarker
))
.insert(Transform::from_xyz(10.0, 20.0, 100.0)).id();
commands.entity(entity).push_children(&[child]);
}
}
unhighlight(commands, highlighteds, highlightboxes);
Expand Down Expand Up @@ -83,6 +94,35 @@ pub fn select_choppables(
unhighlight(commands, highlighteds, highlightboxes);
}

pub fn select_huntables(
mut commands: Commands,
mut query: Query<(Entity, Option<&Huntable>), With<Highlighted>>,
highlighteds: Query<Entity, With<Highlighted>>,
highlightboxes: Query<Entity, With<HighlightBox>>,
event: EventReader<SelectionEvent>,
dragging: Res<Dragging>,
font: Res<MyFont>,
) {
if event.is_empty() { return; }
if dragging.looking_for != SelectableType::Huntable { return; }
for (entity, selection_reason) in query.iter_mut() {
if selection_reason.is_some() {
commands.entity(entity).insert(WorkTarget);
let child = commands.spawn((
Text2dBundle {
text: Text::from_section("X", TextStyle { font: font.0.clone(), ..default() })
.with_alignment(TextAlignment::Center),
..default()
},
WorkMarker
))
.insert(Transform::from_xyz(10.0, 20.0, 100.0)).id();
commands.entity(entity).push_children(&[child]);
}
}
unhighlight(commands, highlighteds, highlightboxes);
}

pub fn select_zoning(
mut commands: Commands,
query: Query<(Entity, Option<&MapTile>), With<Highlighted>>,
Expand Down
1 change: 1 addition & 0 deletions src/task_system/forage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub fn task_system_forage(
if distance <= 1 && targeting.is_some() && targeting.unwrap().target == foragable_entity {
commands.entity(entity).remove::<Targeting>();
spawn_food(&mut commands, foragable_entity, foragable_position, &sprite_sheet, &mut plant);
commands.entity(entity).remove::<WorkTarget>();
did_foraging = true;
nearest_entity = None;
break;
Expand Down

0 comments on commit dbf74e3

Please sign in to comment.