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