Skip to content

Commit

Permalink
gui can show the state
Browse files Browse the repository at this point in the history
  • Loading branch information
onon1101 committed Apr 28, 2024
1 parent d6921d8 commit 16387b6
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 41 deletions.
Binary file added assets/gui/hud_slot_throw2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions include/App.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ class App {
bool m_IsMainMenu = true;
bool m_ThrowMode = false;

// music
// std::shared_ptr<Music::Player> m_MusicSystem =
// std::make_shared<Music::Player>();

// settings
glm::vec2 m_AniPlayerDestination = {0.0f, 0.0f};
Expand Down
4 changes: 3 additions & 1 deletion include/Game/Graphs/Base.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ namespace Game {
namespace Graphs {
class IBase : public Util::GameObject {
public:
std::size_t MI = 0;
virtual ~IBase() = default;
std::size_t MI = 0;

virtual void Update(Dungeon::Map* dungeonMap) = 0;
};
} // namespace Graphs
Expand Down
7 changes: 6 additions & 1 deletion include/Game/Graphs/Dagger.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ class DaggerGameObj final : public Game::Graphs::IBase {
dungeonMap->GetMapData()->GetPlayerPosition()
));
if (value == MI) {
SetVisible(false);
m_Vis = false;
}

SetVisible(m_Vis);
};

private:
bool m_Vis = true;
};
} // namespace Graphs
} // namespace Game
Expand Down
5 changes: 5 additions & 0 deletions include/Player/Equipment/IEquipment.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ class IEquipment {
return;
};

[[maybe_unused]]
virtual void PrepareThrowOut(bool state = false) {
return;
};

// getter
virtual Direction GetDirection() = 0;
virtual bool GetIsThrow() { return false; };
Expand Down
14 changes: 13 additions & 1 deletion include/Player/Equipment/Throw.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Throw final : public IEquipment {
std::shared_ptr<GameElement> GetGameObject() const override;
Direction GetDirection() override { return IEquipment::Direction::COL; };

void PrepareThrowOut(bool state = false) override;

private:
std::size_t m_ZIndex = 99;
glm::vec2 m_Scale = {DUNGEON_SCALE, DUNGEON_SCALE};
Expand All @@ -35,13 +37,23 @@ class Throw final : public IEquipment {
// ASSETS_DIR "/gui/diamond.png"

std::string m_ImagePathWindow = ASSETS_DIR "/gui/hud_slot_throw.png";
std::string m_ImagePathThrow = ASSETS_DIR "/gui/hud_slot_throw2.png";
std::string m_ImagePathItem = ASSETS_DIR "/items/weapon_dagger.png";

std::shared_ptr<GameElement> m_Window = std::make_shared<GameElement>();
std::shared_ptr<GameElement> m_Item = std::make_shared<GameElement>();
std::shared_ptr<GameElement> m_Text = std::make_shared<GameElement>();
std::shared_ptr<GameElement> m_UpperText = std::make_shared<GameElement>();
std::shared_ptr<GameElement> m_LowerText = std::make_shared<GameElement>();
std::shared_ptr<GameElement> m_Throw = std::make_shared<GameElement>();

std::shared_ptr<Util::Image> m_NormalSlot;
std::shared_ptr<Util::Image> m_ThrowSlot;

private:
void GenWin();
void GenItem();
void GeneralUpperText();
void GeneralLowerText();
};

#endif // FUCK_PTSD_THROW_H
8 changes: 4 additions & 4 deletions include/Player/Items/Tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class Tools final {
void RemoveWeapon();
void RemoveShovel();

void PrepareThrowOut(bool state);

private:
void rearrangeCol();
void rearrangeRow();
Expand All @@ -53,12 +55,10 @@ class Tools final {
std::vector<Tools::Type> m_rowPosIdx;
const std::vector<glm::vec2> m_colPosList = {
{-int(WINDOW_WIDTH) / 2 + 65, WINDOW_HEIGHT / 2 - 195},
{-int(WINDOW_WIDTH) / 2 + 65, WINDOW_HEIGHT / 2 - 335}
};
{-int(WINDOW_WIDTH) / 2 + 65, WINDOW_HEIGHT / 2 - 335}};
const std::vector<glm::vec2> m_rowPosList = {
{-int(WINDOW_WIDTH) / 2 + 65, WINDOW_HEIGHT / 2 - 55},
{-int(WINDOW_WIDTH) / 2 + 165, WINDOW_HEIGHT / 2 - 55}
};
{-int(WINDOW_WIDTH) / 2 + 165, WINDOW_HEIGHT / 2 - 55}};

std::vector<std::shared_ptr<IEquipment>> m_colEquipList;
std::vector<std::shared_ptr<IEquipment>> m_rowEquipList;
Expand Down
2 changes: 2 additions & 0 deletions include/Player/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class Player {
bool IsWeaponExist();
WeaponEnum::Type GetWeaponType();

void PrepareThrowOut(bool state);

void MoveByTime(
const unsigned long duringTimeMs,
const glm::vec2& destination,
Expand Down
7 changes: 2 additions & 5 deletions src/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ void App::Start() {
Display::BeatIndicator::Init();
m_Camera->AddUIChild(Display::BeatIndicator::GetGameElement());

// display the tempo heart in music System
// m_Camera->AddUIChild(m_MusicSystem->getGameObject());

// helper
Settings::Helper::Init(m_DungeonMap.get());

Expand All @@ -116,8 +113,6 @@ void App::Update() {
% static_cast<std::size_t>(Music::Player::GetMusicLength() * 1000);

if (Music::Tempo::IsSwitch()) {
// LOG_DEBUG("Current cycle: {}", Music::Player::LoopCounter());
// LOG_DEBUG("Current idx: {}", Music::Tempo::GetBeatIdx());
m_DungeonMap->TempoTrigger(Music::Tempo::GetBeatIdx());
Display::BeatHeart::SwitchHeart(100);
}
Expand All @@ -137,6 +132,7 @@ void App::Update() {

if (Util::Input::IsKeyDown(Util::Keycode::UP)
&& Util::Input::IsKeyDown(Util::Keycode::DOWN)) {
m_MainCharacter->PrepareThrowOut(true);
LOG_INFO("Throw Mode");
m_ThrowMode = true;
}
Expand All @@ -152,6 +148,7 @@ void App::Update() {
musicTime,
Music::Player::LoopCounter()
)) {
m_MainCharacter->PrepareThrowOut(false);
for (const auto& elem : m_MapTableCodeDire) {
if (Util::Input::IsKeyDown(elem.first)) {
Game::Actions::ThrowOutWeapon(m_DungeonMap.get(), elem.second);
Expand Down
4 changes: 3 additions & 1 deletion src/Game/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ void Game::System::Update() {
return;
}

for (auto& elem : m_IBaseList) {
for (std::size_t i = 0; i < m_IBaseList.size(); ++i) {
auto& elem = m_IBaseList.at(i);

elem->Update(m_DungeonMap);
}
}
Expand Down
84 changes: 59 additions & 25 deletions src/Player/Equipment/Throw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,27 @@

Throw::Throw() {
// const auto ItemImage = std::make_shared<Util::Image>(m_ImagePathItem);

GenWin();
GenItem();
GeneralLowerText();
GeneralUpperText();

m_Throw->SetVisible(false);
};

void Throw::GenWin() {
m_NormalSlot = std::make_shared<Util::Image>(m_ImagePathWindow);
m_ThrowSlot = std::make_shared<Util::Image>(m_ImagePathThrow);
m_Window->SetDrawable(m_NormalSlot);
m_Window->SetZIndex(m_ZIndex + 1);
m_Window->SetScale(m_Scale);
m_Window->SetPosition(m_Position);

m_Throw->AddChild(m_Window);
}

void Throw::GenItem() {
const auto ItemSize = ToolBoxs::CountImagePixel(m_ImagePathItem, 1, 2);

const auto ItemImage = std::make_shared<SpriteSheet>(
Expand All @@ -22,55 +43,68 @@ Throw::Throw() {
true,
100
);
const auto WindowImage = std::make_shared<Util::Image>(m_ImagePathWindow);
m_Item->SetDrawable(ItemImage);
m_Item->SetZIndex(m_ZIndex);
m_Item->SetScale(m_Scale);
m_Item->SetPosition({m_Position.x, m_Position.y + 5});

m_Throw->AddChild(m_Item);
}

void Throw::GeneralUpperText() {
const auto UpperTextObject = std::make_shared<Util::Text>(
m_TextStylePath,
m_FontSize,
m_Content,
m_FontColor
);

m_UpperText->SetDrawable(UpperTextObject);
m_UpperText->SetZIndex(m_ZIndex);
m_UpperText->SetScale(m_Scale);
m_UpperText->SetPosition(m_Position);

m_Throw->AddChild(m_UpperText);
}

void Throw::GeneralLowerText() {
const auto LowerTextObject = std::make_shared<Util::Text>(
m_TextStylePath,
m_FontSize,
"DOWN",
m_FontColor
);

m_Window->SetDrawable(WindowImage);
m_Item->SetDrawable(ItemImage);
m_Text->SetDrawable(UpperTextObject);
m_LowerText->SetDrawable(LowerTextObject);

m_Window->SetZIndex(m_ZIndex + 1);
m_Item->SetZIndex(m_ZIndex);
m_Text->SetZIndex(m_ZIndex);
m_LowerText->SetPosition(m_Position);
m_LowerText->SetZIndex(m_ZIndex);

m_Window->SetScale(m_Scale);
m_Item->SetScale(m_Scale);
m_Text->SetScale(m_Scale);
m_LowerText->SetScale(m_Scale);

m_Window->SetPosition(m_Position);
m_Item->SetPosition({m_Position.x, m_Position.y + 5});
m_Text->SetPosition(m_Position);
m_LowerText->SetPosition(m_Position);

m_Throw->AddChild(m_Window);
m_Throw->AddChild(m_Item);
m_Throw->AddChild(m_Text);
m_Throw->AddChild(m_LowerText);

m_Throw->SetVisible(false);
};
}

void Throw::setPosition(const glm::vec2 position) {
m_Window->SetPosition(position);
m_Item->SetPosition({position.x, position.y + 5});
m_Text->SetPosition({position.x + 15, position.y - 40});
m_LowerText->SetPosition({position.x + 15, position.y - 60});
m_UpperText->SetPosition({position.x + 30, position.y - 40});
m_LowerText->SetPosition({position.x + 27, position.y - 60});
}

std::shared_ptr<GameElement> Throw::GetGameObject() const {
return m_Throw;
}

void Throw::PrepareThrowOut(bool state) {
if (!state) {
m_LowerText->SetVisible(true);
m_UpperText->SetVisible(true);

m_Window->SetDrawable(m_NormalSlot);
return;
}

m_LowerText->SetVisible(false);
m_UpperText->SetVisible(false);

m_Window->SetDrawable(m_ThrowSlot);
}
5 changes: 5 additions & 0 deletions src/Player/Items/Tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ void Tools::SetWeapon(WeaponEnum::Type type) {
}
}

void Tools::PrepareThrowOut(bool state) {
auto p = getListIdx(m_colPosIdx, THROW);
m_colEquipList.at(p)->PrepareThrowOut(state);
}

void Tools::RemoveThrow() {
auto f = getListIdx(m_colPosIdx, THROW);
m_colPosIdx.erase(m_colPosIdx.begin() + f);
Expand Down
4 changes: 4 additions & 0 deletions src/Player/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ WeaponEnum::Type Player::GetWeaponType() {
return m_WeaponType;
}

void Player::PrepareThrowOut(bool state) {
m_Tools->PrepareThrowOut(state);
}

void Player::MoveByTime(
const unsigned long duringTimeMs,
const glm::vec2& destination,
Expand Down

0 comments on commit 16387b6

Please sign in to comment.