generated from hheik/bevy-template
Added simplest inventory UI
parent
f422d0afe4
commit
ef0c80a3f9
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,93 @@
|
|||
Copyright 2020 The Open Sans Project Authors (https://github.com/googlefonts/opensans)
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
This license is copied below, and is also available with a FAQ at:
|
||||
http://scripts.sil.org/OFL
|
||||
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font creation
|
||||
efforts of academic and linguistic communities, and to provide a free and
|
||||
open framework in which fonts may be shared and improved in partnership
|
||||
with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply
|
||||
to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software components as
|
||||
distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||
or substituting -- in part or in whole -- any of the components of the
|
||||
Original Version, by changing formats or by porting the Font Software to a
|
||||
new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||
redistribute, and sell modified and unmodified copies of the Font
|
||||
Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components,
|
||||
in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the corresponding
|
||||
Copyright Holder. This restriction only applies to the primary font name as
|
||||
presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created
|
||||
using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
|
|
@ -0,0 +1,100 @@
|
|||
Open Sans Variable Font
|
||||
=======================
|
||||
|
||||
This download contains Open Sans as both variable fonts and static fonts.
|
||||
|
||||
Open Sans is a variable font with these axes:
|
||||
wdth
|
||||
wght
|
||||
|
||||
This means all the styles are contained in these files:
|
||||
OpenSans-VariableFont_wdth,wght.ttf
|
||||
OpenSans-Italic-VariableFont_wdth,wght.ttf
|
||||
|
||||
If your app fully supports variable fonts, you can now pick intermediate styles
|
||||
that aren’t available as static fonts. Not all apps support variable fonts, and
|
||||
in those cases you can use the static font files for Open Sans:
|
||||
static/OpenSans_Condensed/OpenSans_Condensed-Light.ttf
|
||||
static/OpenSans_Condensed/OpenSans_Condensed-Regular.ttf
|
||||
static/OpenSans_Condensed/OpenSans_Condensed-Medium.ttf
|
||||
static/OpenSans_Condensed/OpenSans_Condensed-SemiBold.ttf
|
||||
static/OpenSans_Condensed/OpenSans_Condensed-Bold.ttf
|
||||
static/OpenSans_Condensed/OpenSans_Condensed-ExtraBold.ttf
|
||||
static/OpenSans_SemiCondensed/OpenSans_SemiCondensed-Light.ttf
|
||||
static/OpenSans_SemiCondensed/OpenSans_SemiCondensed-Regular.ttf
|
||||
static/OpenSans_SemiCondensed/OpenSans_SemiCondensed-Medium.ttf
|
||||
static/OpenSans_SemiCondensed/OpenSans_SemiCondensed-SemiBold.ttf
|
||||
static/OpenSans_SemiCondensed/OpenSans_SemiCondensed-Bold.ttf
|
||||
static/OpenSans_SemiCondensed/OpenSans_SemiCondensed-ExtraBold.ttf
|
||||
static/OpenSans/OpenSans-Light.ttf
|
||||
static/OpenSans/OpenSans-Regular.ttf
|
||||
static/OpenSans/OpenSans-Medium.ttf
|
||||
static/OpenSans/OpenSans-SemiBold.ttf
|
||||
static/OpenSans/OpenSans-Bold.ttf
|
||||
static/OpenSans/OpenSans-ExtraBold.ttf
|
||||
static/OpenSans_Condensed/OpenSans_Condensed-LightItalic.ttf
|
||||
static/OpenSans_Condensed/OpenSans_Condensed-Italic.ttf
|
||||
static/OpenSans_Condensed/OpenSans_Condensed-MediumItalic.ttf
|
||||
static/OpenSans_Condensed/OpenSans_Condensed-SemiBoldItalic.ttf
|
||||
static/OpenSans_Condensed/OpenSans_Condensed-BoldItalic.ttf
|
||||
static/OpenSans_Condensed/OpenSans_Condensed-ExtraBoldItalic.ttf
|
||||
static/OpenSans_SemiCondensed/OpenSans_SemiCondensed-LightItalic.ttf
|
||||
static/OpenSans_SemiCondensed/OpenSans_SemiCondensed-Italic.ttf
|
||||
static/OpenSans_SemiCondensed/OpenSans_SemiCondensed-MediumItalic.ttf
|
||||
static/OpenSans_SemiCondensed/OpenSans_SemiCondensed-SemiBoldItalic.ttf
|
||||
static/OpenSans_SemiCondensed/OpenSans_SemiCondensed-BoldItalic.ttf
|
||||
static/OpenSans_SemiCondensed/OpenSans_SemiCondensed-ExtraBoldItalic.ttf
|
||||
static/OpenSans/OpenSans-LightItalic.ttf
|
||||
static/OpenSans/OpenSans-Italic.ttf
|
||||
static/OpenSans/OpenSans-MediumItalic.ttf
|
||||
static/OpenSans/OpenSans-SemiBoldItalic.ttf
|
||||
static/OpenSans/OpenSans-BoldItalic.ttf
|
||||
static/OpenSans/OpenSans-ExtraBoldItalic.ttf
|
||||
|
||||
Get started
|
||||
-----------
|
||||
|
||||
1. Install the font files you want to use
|
||||
|
||||
2. Use your app's font picker to view the font family and all the
|
||||
available styles
|
||||
|
||||
Learn more about variable fonts
|
||||
-------------------------------
|
||||
|
||||
https://developers.google.com/web/fundamentals/design-and-ux/typography/variable-fonts
|
||||
https://variablefonts.typenetwork.com
|
||||
https://medium.com/variable-fonts
|
||||
|
||||
In desktop apps
|
||||
|
||||
https://theblog.adobe.com/can-variable-fonts-illustrator-cc
|
||||
https://helpx.adobe.com/nz/photoshop/using/fonts.html#variable_fonts
|
||||
|
||||
Online
|
||||
|
||||
https://developers.google.com/fonts/docs/getting_started
|
||||
https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Fonts/Variable_Fonts_Guide
|
||||
https://developer.microsoft.com/en-us/microsoft-edge/testdrive/demos/variable-fonts
|
||||
|
||||
Installing fonts
|
||||
|
||||
MacOS: https://support.apple.com/en-us/HT201749
|
||||
Linux: https://www.google.com/search?q=how+to+install+a+font+on+gnu%2Blinux
|
||||
Windows: https://support.microsoft.com/en-us/help/314960/how-to-install-or-remove-a-font-in-windows
|
||||
|
||||
Android Apps
|
||||
|
||||
https://developers.google.com/fonts/docs/android
|
||||
https://developer.android.com/guide/topics/ui/look-and-feel/downloadable-fonts
|
||||
|
||||
License
|
||||
-------
|
||||
Please read the full license text (OFL.txt) to understand the permissions,
|
||||
restrictions and requirements for usage, redistribution, and modification.
|
||||
|
||||
You can use them in your products & projects – print or digital,
|
||||
commercial or otherwise.
|
||||
|
||||
This isn't legal advice, please consider consulting a lawyer and see the full
|
||||
license for all details.
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
Venice Classic
|
||||
by soixantedeux
|
||||
28 December 2006
|
||||
|
||||
This font is free. It may not be resold for profit; however, it may be
|
||||
redistributed and sold at cost of redistribution. Distribute this font freely,
|
||||
on the condition that this notice remain with it unmodified. The font, however,
|
||||
may be modified on the condition that it is distributed under the same
|
||||
conditions as above.
|
||||
|
||||
This is a hand-made TrueType version of the out-of-use Apple bitmap font
|
||||
"Venice." I didn't make the original font; I did, however, make this font,
|
||||
which is based very heavily on the original font.
|
||||
|
||||
If you like this font, feel free to let me know! My website, which contains
|
||||
other things I've done, is located at http://www.soixantedeux.co.nr/, or if
|
||||
that doesn't work, http://www.freewebtown.com/62/. If you have any questions
|
||||
regarding this font, contact me. Also, if you use this font somewhere and
|
||||
you're particularly proud of the way you used it, don't hesitate to let me
|
||||
know. :) I'm interested in what will happen to this font after I put it up for
|
||||
download on my website.
|
||||
|
||||
Thanks for downloading Venice!
|
||||
|
||||
soixantedeux
|
||||
13
src/game.rs
13
src/game.rs
|
|
@ -21,6 +21,7 @@ pub fn init(app: &mut App) {
|
|||
app.register_type::<item::Item>()
|
||||
.register_type::<item::ItemSource>()
|
||||
.register_type::<item::Inventory>()
|
||||
.register_type::<item::InventoryUi>()
|
||||
.register_type::<work::WorkDuration>()
|
||||
.register_type::<work::Worker>()
|
||||
.register_type::<creature::Mover>()
|
||||
|
|
@ -32,17 +33,21 @@ pub fn init(app: &mut App) {
|
|||
.add_systems(
|
||||
Update,
|
||||
(
|
||||
(systems::spawn_items,),
|
||||
(
|
||||
systems::demo_2d,
|
||||
systems::work_select,
|
||||
systems::worker_movement,
|
||||
systems::spawn_items,
|
||||
systems::change_inventory_ui_font,
|
||||
),
|
||||
(systems::work_select,),
|
||||
(systems::do_work,),
|
||||
(systems::apply_task_result,),
|
||||
(systems::apply_work_result,),
|
||||
)
|
||||
.chain(),
|
||||
)
|
||||
.add_systems(PostUpdate, item::update_item_sprite)
|
||||
.add_systems(
|
||||
PostUpdate,
|
||||
(systems::update_item_sprite, systems::update_inventory_ui),
|
||||
)
|
||||
.add_systems(Update, (systems::draw_job_targets).in_set(debug::DebugSet));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,6 +40,12 @@ pub struct ItemSource {
|
|||
pub gather_limit: Option<u32>,
|
||||
}
|
||||
|
||||
/// Flag component that tells the UI to update according to the inventory contents
|
||||
#[derive(Clone, Debug, Default, Component, Reflect)]
|
||||
#[reflect(Component)]
|
||||
#[require(Text2d)]
|
||||
pub struct InventoryUi;
|
||||
|
||||
#[derive(Clone, Debug, Default, Component, Reflect, PartialEq, Eq)]
|
||||
#[reflect(Component)]
|
||||
pub struct Inventory {
|
||||
|
|
@ -215,19 +221,6 @@ impl Inventory {
|
|||
#[require(Inventory)]
|
||||
pub struct Stockpile;
|
||||
|
||||
pub fn update_item_sprite(
|
||||
mut query: Query<(&mut Sprite, &Item), Changed<Item>>,
|
||||
assets: Res<AssetServer>,
|
||||
) {
|
||||
for (mut sprite, item) in query.iter_mut() {
|
||||
sprite.image = assets.load(match item {
|
||||
Item::Wood => "sprites/wood.png",
|
||||
Item::Stone => "sprites/stone.png",
|
||||
// _ => "sprites/missing.png",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Event, Clone, Debug)]
|
||||
pub struct SpawnItem {
|
||||
pub item: Item,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use bevy::{prelude::*, sprite::Anchor};
|
||||
use bevy_rapier2d::prelude::*;
|
||||
use creature::{Mover, WeightSlowdown};
|
||||
use item::{Inventory, Item, ItemSource, ItemStack, Stockpile};
|
||||
use item::{Inventory, InventoryUi, Item, ItemSource, ItemStack, Stockpile};
|
||||
use work::{WorkDuration, Worker};
|
||||
|
||||
use super::*;
|
||||
|
|
@ -18,6 +18,7 @@ use crate::util::SpriteLoader;
|
|||
SpriteLoader(|| SpriteLoader::from("sprites/glorb.png")),
|
||||
Worker,
|
||||
Inventory(|| Inventory::with_capacity(1)),
|
||||
InventoryUi,
|
||||
WeightSlowdown(|| WeightSlowdown { halfpoint: 50.0 }),
|
||||
RigidBody(|| RigidBody::KinematicPositionBased),
|
||||
Mover,
|
||||
|
|
@ -48,6 +49,7 @@ pub struct Tree;
|
|||
}),
|
||||
SpriteLoader(|| SpriteLoader::from("sprites/box.png")),
|
||||
Inventory,
|
||||
InventoryUi,
|
||||
Stockpile,
|
||||
)]
|
||||
pub struct Chest;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
mod creature;
|
||||
mod demo;
|
||||
mod item;
|
||||
mod ui;
|
||||
mod worker;
|
||||
|
||||
pub use creature::*;
|
||||
pub use demo::*;
|
||||
pub use item::*;
|
||||
pub use ui::*;
|
||||
pub use worker::*;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,23 @@
|
|||
use bevy::prelude::*;
|
||||
use bevy_rapier2d::prelude::{Damping, RigidBody, Velocity};
|
||||
|
||||
use crate::game::{item::SpawnItem, work::WorkDuration};
|
||||
use crate::game::{
|
||||
item::{Item, SpawnItem},
|
||||
work::WorkDuration,
|
||||
};
|
||||
|
||||
pub fn update_item_sprite(
|
||||
mut query: Query<(&mut Sprite, &Item), Changed<Item>>,
|
||||
assets: Res<AssetServer>,
|
||||
) {
|
||||
for (mut sprite, item) in query.iter_mut() {
|
||||
sprite.image = assets.load(match item {
|
||||
Item::Wood => "sprites/wood.png",
|
||||
Item::Stone => "sprites/stone.png",
|
||||
// _ => "sprites/missing.png",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
pub fn spawn_items(mut spawn_item_events: EventReader<SpawnItem>, mut commands: Commands) {
|
||||
for event in spawn_item_events.read() {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
use crate::game::item::{Inventory, InventoryUi};
|
||||
|
||||
pub fn change_inventory_ui_font(
|
||||
assets: Res<AssetServer>,
|
||||
mut inventory_ui_added: Query<&mut TextFont, Added<InventoryUi>>,
|
||||
mut font: Local<Option<Handle<Font>>>,
|
||||
) {
|
||||
for mut text_font in inventory_ui_added.iter_mut() {
|
||||
if font.is_none() {
|
||||
*font = Some(assets.load("fonts/venice_classic.ttf"));
|
||||
}
|
||||
if let Some(font) = font.as_ref() {
|
||||
text_font.font = font.clone();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_inventory_ui(
|
||||
mut inventory_changed: Query<
|
||||
(&mut Text2d, &Inventory),
|
||||
(Changed<Inventory>, With<InventoryUi>),
|
||||
>,
|
||||
) {
|
||||
for (mut text_2d, inventory) in inventory_changed.iter_mut() {
|
||||
let new_string = inventory
|
||||
.items
|
||||
.iter()
|
||||
.map(|stack| format!("{:?}: {}", stack.item, stack.count))
|
||||
.collect::<Vec<String>>()
|
||||
.join("\n");
|
||||
text_2d.0 = new_string;
|
||||
}
|
||||
}
|
||||
|
|
@ -190,7 +190,7 @@ pub fn do_work(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn apply_task_result(
|
||||
pub fn apply_work_result(
|
||||
mut commands: Commands,
|
||||
mut spawn_item: EventWriter<SpawnItem>,
|
||||
mut on_task_finish: EventReader<OnTaskFinish>,
|
||||
|
|
|
|||
Loading…
Reference in New Issue