Display weapon name on GUI.
This commit is contained in:
parent
203a34f0a0
commit
9d133392bc
7 changed files with 27 additions and 6 deletions
|
@ -34,10 +34,9 @@ Game::Game(tgui::Window& window) :
|
|||
mWorld.insertCharacter(mPlayer);
|
||||
|
||||
mAmmo = window.add<tgui::Label>();
|
||||
setAmmoText();
|
||||
mAmmo->setTextSize(20);
|
||||
mAmmo->setPosition(mWindow.getSize().x - mAmmo->getSize().x,
|
||||
mWindow.getSize().y - mAmmo->getSize().y);
|
||||
mCurrentWeapon = window.add<tgui::Label>();
|
||||
mCurrentWeapon->setTextSize(14);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,7 +62,7 @@ Game::loop() {
|
|||
|
||||
mWorld.step(elapsed);
|
||||
|
||||
setAmmoText();
|
||||
updateGui();
|
||||
|
||||
render();
|
||||
|
||||
|
@ -75,7 +74,7 @@ Game::loop() {
|
|||
* Displays current player ammo in the ammo widget.
|
||||
*/
|
||||
void
|
||||
Game::setAmmoText() {
|
||||
Game::updateGui() {
|
||||
int mag = mPlayer->getMagazineAmmo();
|
||||
int total = mPlayer->getTotalAmmo();
|
||||
|
||||
|
@ -87,6 +86,12 @@ Game::setAmmoText() {
|
|||
if (total < 10) totalString = "0" + totalString;
|
||||
|
||||
mAmmo->setText(magString + "/" + totalString);
|
||||
mCurrentWeapon->setText(mPlayer->getWeaponName());
|
||||
|
||||
mAmmo->setPosition(mWindow.getSize().x - mAmmo->getSize().x,
|
||||
mWindow.getSize().y - mAmmo->getSize().y);
|
||||
mCurrentWeapon->setPosition(mWindow.getSize().x - mCurrentWeapon->getSize().x,
|
||||
mAmmo->getPosition().y - mCurrentWeapon->getSize().y);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -37,7 +37,7 @@ private:
|
|||
void mouseUp(const sf::Event& event);
|
||||
|
||||
sf::Vector2<float> convertCoordinates(int x, int y);
|
||||
void setAmmoText();
|
||||
void updateGui();
|
||||
|
||||
private:
|
||||
static const int FPS_GOAL;
|
||||
|
@ -46,6 +46,7 @@ private:
|
|||
sf::Clock mClock;
|
||||
sf::View mWorldView;
|
||||
tgui::Label* mAmmo;
|
||||
tgui::Label* mCurrentWeapon;
|
||||
|
||||
World mWorld;
|
||||
Pathfinder mPathfinder;
|
||||
|
|
|
@ -182,6 +182,11 @@ Character::getTotalAmmo() const {
|
|||
return mActiveWeapon->getTotalAmmo();
|
||||
}
|
||||
|
||||
std::string
|
||||
Character::getWeaponName() const {
|
||||
return mActiveWeapon->getName();
|
||||
}
|
||||
|
||||
void
|
||||
Character::reload() {
|
||||
mActiveWeapon->reload();
|
||||
|
|
|
@ -49,6 +49,7 @@ protected:
|
|||
std::vector<std::shared_ptr<Character> > getCharacters() const;
|
||||
int getMagazineAmmo() const;
|
||||
int getTotalAmmo() const;
|
||||
std::string getWeaponName() const;
|
||||
void reload();
|
||||
void toggleWeapon();
|
||||
void selectFirstWeapon();
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
Weapon::Weapon(World& world, Character& holder, const Yaml& config) :
|
||||
mWorld(world),
|
||||
mHolder(holder),
|
||||
mName(config.get("name", std::string())),
|
||||
mProjectile(config.get("bullet", std::string("bullet.yaml"))),
|
||||
mDamage(config.get("damage", 0)),
|
||||
mProjectileSpeed(config.get("projectile_speed", 0.0f)),
|
||||
|
@ -120,6 +121,11 @@ Weapon::getTotalAmmo() const {
|
|||
return mTotalAmmo;
|
||||
}
|
||||
|
||||
std::string
|
||||
Weapon::getName() const {
|
||||
return mName;
|
||||
}
|
||||
|
||||
void
|
||||
Weapon::reload() {
|
||||
if (mMagazineAmmo == mMagazineSize)
|
||||
|
|
|
@ -31,6 +31,7 @@ public:
|
|||
void onThink(int elapsed);
|
||||
int getMagazineAmmo() const;
|
||||
int getTotalAmmo() const;
|
||||
std::string getName() const;
|
||||
void reload();
|
||||
void cancelReload();
|
||||
|
||||
|
@ -43,6 +44,7 @@ private:
|
|||
Character& mHolder;
|
||||
|
||||
thor::Timer mTimer;
|
||||
const std::string mName;
|
||||
const Yaml mProjectile;
|
||||
const int mDamage;
|
||||
const float mProjectileSpeed;
|
||||
|
|
|
@ -38,6 +38,7 @@ public:
|
|||
void setDestination(const sf::Vector2f& destination);
|
||||
using Character::getMagazineAmmo;
|
||||
using Character::getTotalAmmo;
|
||||
using Character::getWeaponName;
|
||||
using Character::reload;
|
||||
using Character::toggleWeapon;
|
||||
using Character::selectFirstWeapon;
|
||||
|
|
Reference in a new issue