Skip to content

Commit

Permalink
menu update
Browse files Browse the repository at this point in the history
  • Loading branch information
jonylu7 committed Jun 11, 2024
1 parent 3064875 commit c260e30
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 37 deletions.
12 changes: 6 additions & 6 deletions Sample_2024-03-22-005901.collapsed

Large diffs are not rendered by default.

Binary file removed assets/images/cnc_title.jpg
Binary file not shown.
Binary file added assets/images/cnc_title.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/images/menuImages.jpg
Binary file not shown.
Binary file added assets/images/menu_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion include/Scene/Scene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Scene {
std::shared_ptr<UnitManager> m_EnemyObjectManager =
std::make_shared<UnitManager>();
Util::Renderer m_Renderer;
std::shared_ptr<UIClass> m_UI = std::make_shared<UIClass>();
std::shared_ptr<IngamUI> m_UI = std::make_shared<IngamUI>();
std::shared_ptr<Player> m_Player = std::make_shared<Player>();
};

Expand Down
2 changes: 1 addition & 1 deletion include/UI/IngameUI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "pch.hpp"
#include <unordered_map>

class UIClass {
class IngamUI {
public:
void Start(std::shared_ptr<MapClass> map,
std::shared_ptr<UnitManager> gameobjectmanager);
Expand Down
11 changes: 8 additions & 3 deletions include/UI/MenuUI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,27 @@ class MenuUI : public UI {
}

void Draw() override {
m_BackgroundImage->Draw(
Util::Transform({glm::vec2(0, 0), float(0), glm::vec2(0.68, 0.68)}),
0.1);
m_Title->Draw(
Util::Transform({glm::vec2(0, 70), float(0), glm::vec2(0.6, 0.6)}),
Util::Transform({glm::vec2(0, 40), float(0), glm::vec2(0.6, 0.6)}),
1);
m_StartButton->Draw();
m_ExitButton->Draw();
}

private:
std::shared_ptr<Util::Image> m_Title =
std::make_shared<Util::Image>("../assets/images/cnc_title.jpg");
std::make_shared<Util::Image>("../assets/images/cnc_title.png");
std::shared_ptr<Util::Image> m_BackgroundImage =
std::make_shared<Util::Image>("../assets/images/menu_image.png");
std::shared_ptr<Button> m_StartButton = std::make_shared<Button>(
std::make_shared<Util::Image>("../assets/images/start.png"), 1, true,
Util::Transform({glm::vec2(0, -100), float(0), glm::vec2(0.4, 0.4)}));

std::shared_ptr<Button> m_ExitButton = std::make_shared<Button>(
std::make_shared<Util::Image>("../assets/images/exit.png"), 1, true,
Util::Transform({glm::vec2(0, -200), float(0), glm::vec2(0.4, 0.4)}));
Util::Transform({glm::vec2(0, -160), float(0), glm::vec2(0.4, 0.4)}));
};
#endif // PRACTICALTOOLSFORSIMPLEDESIGN_MENUUI_HPP
File renamed without changes.
52 changes: 26 additions & 26 deletions src/UI/IngameUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include "UI/IngameUI.hpp"
#include "Map/Map.hpp"

std::unordered_map<UnitType, unsigned int> UIClass::s_unitConstructCount;
std::unordered_map<UnitType, unsigned int> IngamUI::s_unitConstructCount;

void UIClass::Start(std::shared_ptr<MapClass> map,
void IngamUI::Start(std::shared_ptr<MapClass> map,
std::shared_ptr<UnitManager> gameobjectmanager) {
InitUnitQueue();
// start
Expand All @@ -23,12 +23,12 @@ void UIClass::Start(std::shared_ptr<MapClass> map,
"../assets/sprites/ICON_Allied_Vehicles.png", 64, 48, 12, 0);
}

void UIClass::Update() {
void IngamUI::Update() {
ShowPlayerConstructionMenu();
m_UIScriptProcess->Update(getIfAnyBuildingReadyToBuild());
}

void UIClass::ShowPlayerStatus() {
void IngamUI::ShowPlayerStatus() {
glm::vec2 CursorGlobalPosition = MapUtil::ScreenToGlobalCoord(
glm::vec2(Util::Input::GetCursorPosition()));
ImGui::Text(std::string("X: " + std::to_string(CursorGlobalPosition.x) +
Expand All @@ -47,7 +47,7 @@ void UIClass::ShowPlayerStatus() {
ImGui::PushFont(sacker_med);
}

void UIClass::ShowHeaderSection() {
void IngamUI::ShowHeaderSection() {

if (ImGui::Button("Grid on")) {
m_Map->setGridActive(true);
Expand All @@ -66,7 +66,7 @@ void UIClass::ShowHeaderSection() {

ImGui::PopFont();
}
void UIClass::ShowPlayerConstructionMenu() {
void IngamUI::ShowPlayerConstructionMenu() {
auto windowSettings = ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoScrollbar |
ImGuiWindowFlags_NoResize;
Expand All @@ -91,7 +91,7 @@ void UIClass::ShowPlayerConstructionMenu() {
}

std::vector<ImVec2>
UIClass::getSpriteSheetCoordByIndex(std::shared_ptr<SpriteSheet> spritesheet,
IngamUI::getSpriteSheetCoordByIndex(std::shared_ptr<SpriteSheet> spritesheet,
int index) {
return std::vector<ImVec2>(
{ImVec2(
Expand All @@ -104,7 +104,7 @@ UIClass::getSpriteSheetCoordByIndex(std::shared_ptr<SpriteSheet> spritesheet,
.y)});
}

void UIClass::ShowBuildingTab() {
void IngamUI::ShowBuildingTab() {
if (ImGui::BeginTabItem("Build")) {
if (getImageButtonBySpriteSheetIndex(m_StructureIconSpriteSheet, 7)) {
// power plants
Expand Down Expand Up @@ -215,7 +215,7 @@ void UIClass::ShowBuildingTab() {
}
};

void UIClass::ShowInfantryTab() {
void IngamUI::ShowInfantryTab() {
ImDrawList *dl = ImGui::GetWindowDrawList();
ImVec2 p = ImGui::GetCursorScreenPos();
if (ImGui::BeginTabItem("Inf")) {
Expand Down Expand Up @@ -260,7 +260,7 @@ void UIClass::ShowInfantryTab() {
ImGui::EndTabItem();
}
};
void UIClass::ShowDefTab() {
void IngamUI::ShowDefTab() {
if (ImGui::BeginTabItem("Def")) {
if (getImageButtonBySpriteSheetIndex(m_StructureIconSpriteSheet, 18)) {
// sandbags
Expand All @@ -283,7 +283,7 @@ void UIClass::ShowDefTab() {
ImGui::EndTabItem();
}
};
void UIClass::ShowVehTab() {
void IngamUI::ShowVehTab() {
if (ImGui::BeginTabItem("Veh")) {
if (getImageButtonBySpriteSheetIndex(m_VehiclesIconSpriteSheet, 0)) {
// lightTank
Expand Down Expand Up @@ -343,7 +343,7 @@ void UIClass::ShowVehTab() {
}
};

bool UIClass::getImageButtonBySpriteSheetIndex(
bool IngamUI::getImageButtonBySpriteSheetIndex(
std::shared_ptr<SpriteSheet> spritesheet, int index) {

auto uvcoord = getSpriteSheetCoordByIndex(spritesheet, index);
Expand All @@ -353,19 +353,19 @@ bool UIClass::getImageButtonBySpriteSheetIndex(
uvcoord[0], uvcoord[1]);
}

void UIClass::InitUnitQueue() {
UIClass::s_unitConstructCount[UnitType::POWER_PLANT] = 0;
UIClass::s_unitConstructCount[UnitType::BARRACKS] = 0;
UIClass::s_unitConstructCount[UnitType::ORE_REF] = 0;
UIClass::s_unitConstructCount[UnitType::WAR_FACT] = 0;
UIClass::s_unitConstructCount[UnitType::ADV_POWER_PLANT] = 0;
UIClass::s_unitConstructCount[UnitType::SANDBAGS] = 0;
UIClass::s_unitConstructCount[UnitType::PILLBOX] = 0;
UIClass::s_unitConstructCount[UnitType::TURRET] = 0;
UIClass::s_unitConstructCount[UnitType::INFANTRY] = 0;
UIClass::s_unitConstructCount[UnitType::TRUCK] = 0;
void IngamUI::InitUnitQueue() {
IngamUI::s_unitConstructCount[UnitType::POWER_PLANT] = 0;
IngamUI::s_unitConstructCount[UnitType::BARRACKS] = 0;
IngamUI::s_unitConstructCount[UnitType::ORE_REF] = 0;
IngamUI::s_unitConstructCount[UnitType::WAR_FACT] = 0;
IngamUI::s_unitConstructCount[UnitType::ADV_POWER_PLANT] = 0;
IngamUI::s_unitConstructCount[UnitType::SANDBAGS] = 0;
IngamUI::s_unitConstructCount[UnitType::PILLBOX] = 0;
IngamUI::s_unitConstructCount[UnitType::TURRET] = 0;
IngamUI::s_unitConstructCount[UnitType::INFANTRY] = 0;
IngamUI::s_unitConstructCount[UnitType::TRUCK] = 0;
}
std::unique_ptr<Structure> UIClass::getSelectedBuilding() {
std::unique_ptr<Structure> IngamUI::getSelectedBuilding() {
switch (m_selectedStructureType) {
case UnitType::BARRACKS: {
setUnitConstructCount(UnitType::BARRACKS, 1);
Expand Down Expand Up @@ -403,7 +403,7 @@ std::unique_ptr<Structure> UIClass::getSelectedBuilding() {
}
}

bool UIClass::getIfAnyBuildingReadyToBuild() {
bool IngamUI::getIfAnyBuildingReadyToBuild() {

return m_selectedStructureType != UnitType::NONE &&
(m_UIScriptProcess->GetIfFinishedBuilding(UnitType::BARRACKS) ||
Expand All @@ -414,7 +414,7 @@ bool UIClass::getIfAnyBuildingReadyToBuild() {
UnitType::ADV_POWER_PLANT));
}

void UIClass::checkExistBuilding(
void IngamUI::checkExistBuilding(
std::vector<std::shared_ptr<Structure>> buildingList) {
b_barackBuilt = false;
b_warfactoryBuilt = false;
Expand Down

0 comments on commit c260e30

Please sign in to comment.