Skip to content

Commit

Permalink
Merge branch 'main' into buttonUpdate01
Browse files Browse the repository at this point in the history
  • Loading branch information
jonylu7 authored Apr 12, 2024
2 parents eb1ec3b + 8c46d7b commit c1bdb69
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 142 deletions.
6 changes: 6 additions & 0 deletions include/Map/Map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ class MapClass : public Core::Drawable {
std::shared_ptr<TileClass> tile);

void setGridActive(bool value) { m_Grid.SetActivate(value); }

void
AppendSelectableObjectByCellPosition(glm::vec2 position,
std::shared_ptr<Selectable> object) {
m_Map[position.x][position.y]->pushSelectableObjects(object);
}

protected:
void InitGrid();
Expand Down
2 changes: 2 additions & 0 deletions include/Mechanics/GameObjectManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ class GameObjectManager {
newstruct->Start();
// newstruct->importMap(m_Map);
m_BuiltStructure.push_back(newstruct);
m_Map->AppendSelectableObjectByCellPosition(
newstruct->GetObjectLocation(), newstruct);
}
void Append(std::shared_ptr<Avatar> newUnit) {
m_UnitArray.push_back(newUnit);
Expand Down
2 changes: 1 addition & 1 deletion include/Selectable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ class Selectable {
void setSelected(bool value) { b_Selected = value; }

protected:
bool b_Selected;
bool b_Selected = false;
};
#endif // PRACTICALTOOLSFORSIMPLEDESIGN_SELECTABLE_HPP
42 changes: 13 additions & 29 deletions include/Structure/Structure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#define PRACTICALTOOLSFORSIMPLEDESIGN_STRUCTURE_HPP
#include "HighLight.h"
#include "Mechanics//GameObjectID.hpp"

#include "Selectable.hpp"
#include "Unit/AttackAndDamageUnit.hpp"

#include "Util/GameObject.hpp"
#include "Util/Image.hpp"
Expand All @@ -17,15 +17,16 @@
#define DEFAULT_ZINDEX 15
#define CHEAT 0.1F

class Structure : public Util::GameObject, public Selectable {
class Structure : public Util::GameObject,
public Selectable,
public AttackAndDamageUnit {

public:
enum class updateMode { Invisidable, Moveable, Fixed };
Structure()
: electricPower(100.F),
buildingTime(100.F),
buildingCost(100.F),
buildingHp(100.F),
m_ID(GameObjectID(unitType::null, HouseType::NONE)) {
m_CurrentState = updateMode::Invisidable;
};
Expand All @@ -35,7 +36,6 @@ class Structure : public Util::GameObject, public Selectable {
: electricPower(electricPower),
buildingTime(buildingTime),
buildingCost(buildingCost),
buildingHp(buildingHp),
m_ID(id) {
m_Transform.scale = {1, 1};
// this->SetZIndex(DEFAULT_ZINDEX);
Expand All @@ -46,51 +46,38 @@ class Structure : public Util::GameObject, public Selectable {
void Update() override;
virtual void updateFixed();
virtual void updateMoveable();
virtual void updateInvinsible();
virtual void updateInvinsible() { this->SetAttachVisible(false); }

void Start() override;
updateMode GetCurrentUpdateMode() const { return m_CurrentState; };
void SetCurrentUpdateMode(updateMode mode) { m_CurrentState = mode; };
virtual void SetObjectLocation(glm::vec2 location);

glm::vec2 GetObjectLocation() { return this->ObjectLocation; }
glm::vec2 GetTranScale() { return m_Transform.scale; };
virtual void SetAttachVisible(bool visible);
glm::vec2 GetDrawLocation() { return DrawLocation; };
void SetID(GameObjectID id) { m_ID = id; };

static glm::vec2 ChangeToCell(glm::vec2 location);
void onSelected();
virtual void attachmentUpdate(); // this function now will update
// attachment's location and draw as
// well
void onSelected() { this->SetAttachVisible(getSelected()); };
virtual void attachmentUpdate();
bool getBuilt() {
if (m_CurrentState == updateMode::Fixed) {
return true;
} else {
return false;
}
}
/*
void SetElectricPower(float electricPower);
void SetBuildingTime(float buildingTime);
void SetBuildingCost(float buildingCost);
void SetBuildingHp(float buildingHp);
void DecreaseElectricPower(float Power);
void IncreaseBuildingTime(float Time);
void DecreaseBuildingCost(float Cost);
*/

void DecreaseHp(float Hp);

float GetElectricPower();
float GetBuildingTime();
float GetBuildingCost();
float GetElectricPower() { return this->electricPower; }
float GetBuildingTime() { return this->buildingTime; }
float GetBuildingCost() { return this->buildingCost; }
virtual float GetBuildingIncome() { return buildingIncome; };
void SetBuildingIncome(float income) { buildingIncome = income; }
float GetBuildingHp();
GameObjectID GetID() { return m_ID; }

// void importMap(std::shared_ptr<MapClass> map){m_Map=map;}
void SetBuildingIncome(float income) { buildingIncome = income; }

private:
updateMode m_CurrentState = updateMode::Invisidable;
glm::vec2 ObjectLocation = {100, 100};
Expand All @@ -99,14 +86,11 @@ class Structure : public Util::GameObject, public Selectable {
float electricPower;
float buildingTime;
float buildingCost;
float buildingHp;
float buildingIncome = 0.F;
HighLight m_HighLight;
GameObjectID m_ID;

protected:
// std::shared_ptr<MapClass> m_Map;
bool b_selectingNewWayPoint = false;
};

#endif // PRACTICALTOOLSFORSIMPLEDESIGN_STRUCTURE_HPP
2 changes: 1 addition & 1 deletion include/UI/UI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "Camera.hpp"
#include "Mechanics/GameObjectID.hpp"
#include "Mechanics/GameObjectManager.hpp"
#include "Mechanics/Player.hpp"
#include "Mechanics//Player.hpp"
#include "SpriteSheet.hpp"
#include "UI/UIScriptProcess.hpp"
#include "imgui.h"
Expand Down
4 changes: 2 additions & 2 deletions include/UI/UIScriptProcess.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class UIScriptProcess {
bool b_isReadyToSpawn = false;
float m_spawnCoolDownTime = 0.F;
float m_offPowerSpawnCoolDownTime = 0.F;
unitType m_currentAvatarType;
unitType m_currentInfType;
bool b_isSpawningInCooldown = false;
std::deque<unitType> m_spawnQueue;
std::chrono::time_point<std::chrono::high_resolution_clock>
Expand Down Expand Up @@ -94,7 +94,7 @@ class UIScriptProcess {
float GetSpawnTime(unitType type);

unitType GetCurrentStructure() { return m_currentStructureType; };

unitType GetCurrentInfType() { return m_currentInfType; };
// spawn unit
std::shared_ptr<Avatar> spawnAvatar();
bool getIfReadytoSpawn() { return b_isReadyToSpawn; }
Expand Down
21 changes: 0 additions & 21 deletions src/Structure/Structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,7 @@ void Structure::updateMoveable() {
MapClass::setTileByCellPosition(cellPos,tile);*/
}
}
void Structure::updateInvinsible() {
this->SetAttachVisible(false);
}

void Structure::DecreaseHp(float Hp) {
this->buildingHp -= Hp;
}
float Structure::GetElectricPower() {
return this->electricPower;
}
float Structure::GetBuildingTime() {
return this->buildingTime;
}
float Structure::GetBuildingCost() {
return this->buildingCost;
}
float Structure::GetBuildingHp() {
return this->buildingHp;
}
glm::vec2 Structure::ChangeToCell(glm::vec2 location) {
int _x = location.x / CELL_SIZE.x;
int _y = location.y / CELL_SIZE.y;
Expand All @@ -94,9 +76,6 @@ void Structure::SetObjectLocation(glm::vec2 location) {
location.y + 0.5 * CELL_SIZE.y};
m_Transform.translation = DrawLocation;
}
void Structure::onSelected() {
this->SetAttachVisible(getSelected());
};

void Structure::SetAttachVisible(bool visible) {
m_HighLight.SetObjectLocation(this->DrawLocation);
Expand Down
19 changes: 8 additions & 11 deletions src/Structure/WayPointStructure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ void WayPointStructure::updateMoveable() {
this->SetVisible(true);
this->Draw();
glm::vec2 cellPos = MapUtil::GlobalCoordToCellCoord(location);
// std::shared_ptr<TileClass> tileClass = m_Map->getTileByCellPosition(cellPos);
if (Util::Input::IsKeyPressed(Util::Keycode::MOUSE_LB) /*tileClass->getBuildable()*/) {
// std::shared_ptr<TileClass> tileClass =
// m_Map->getTileByCellPosition(cellPos);
if (Util::Input::IsKeyPressed(
Util::Keycode::MOUSE_LB) /*tileClass->getBuildable()*/) {
this->SetObjectLocation(location);
this->SetWayPointLocation({GetDrawLocation().x + CELL_SIZE.x,
GetDrawLocation().y + CELL_SIZE.y});
onSelected();
this->SetCurrentUpdateMode(updateMode::Fixed);
// tileClass->setBuildable(false);
// tileClass->setWalkable(false);
// tileClass->setBuildable(false);
// tileClass->setWalkable(false);
// 在這裡增加設置Tile屬性
/*
std::shared_ptr<TileClass>tile =
Expand All @@ -31,18 +33,13 @@ void WayPointStructure::updateMoveable() {
}
}
void WayPointStructure::onSelected() {
if (b_selectingNewWayPoint) {
if (getSelected()) {
this->SetWayPointLocation(
MapUtil::ScreenToGlobalCoord(Util::Input::GetCursorPosition()));
b_selectingNewWayPoint = false;
setSelected(false);
}
attachmentUpdate();
this->SetAttachVisible(getSelected());
if (getSelected()) {
if (Util::Input::IsKeyPressed(Util::Keycode::V)) {
b_selectingNewWayPoint = true;
}
}
}
void WayPointStructure::SetAttachVisible(bool visible) {
m_wayPoint->SetVisible(visible);
Expand Down
19 changes: 8 additions & 11 deletions src/UI/UI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,6 @@ void UIClass::ShowBuildingTab() {
ButtonScript.AddToBuildQueue(unitType::WAR_FACT);
}
}
dl = ImGui::GetWindowDrawList();
p = ImGui::GetCursorScreenPos();
p.x += 5.F;
p.y -= 38.F;
if (ButtonScript.GetCurrentStructure() == unitType::WAR_FACT) {
Expand Down Expand Up @@ -209,6 +207,8 @@ void UIClass::ShowBuildingTab() {
};

void UIClass::ShowInfantryTab() {
ImDrawList *dl = ImGui::GetWindowDrawList();
ImVec2 p = ImGui::GetCursorScreenPos();
if (ImGui::BeginTabItem("Inf")) {
if (getImageButtonBySpriteSheetIndex(m_InfantryIconSpriteSheet, 0)) {
// rifle
Expand All @@ -217,6 +217,11 @@ void UIClass::ShowInfantryTab() {
setUnitConstructCount(unitType::INFANTRY, 1);
}

if (ButtonScript.GetCurrentInfType() == unitType::INFANTRY) {
dl->AddText(p, IM_COL32(2, 255, 2, 255),
ButtonScript.GetFormattedCD().c_str());
}

LOG_DEBUG("TEST");
}
ImGui::SameLine();
Expand Down Expand Up @@ -331,7 +336,6 @@ void UIClass::ShowVehTab() {

bool UIClass::getImageButtonBySpriteSheetIndex(
std::shared_ptr<SpriteSheet> spritesheet, int index) {
std::string Text = "test";

auto uvcoord = getSpriteSheetCoordByIndex(spritesheet, index);
return ImGui::ImageButton(
Expand Down Expand Up @@ -475,14 +479,7 @@ std::shared_ptr<Avatar> UIClass::getUnitFromUI() {

Avatar->Start({m_barrackCell.x+1,m_barrackCell.y+1});
Avatar->setNewDestination(m_barrackTargetCell);

} /*else if(std::dynamic_pointer_cast< >(Avatar)){
Avatar->Start(m_warfactoryCell,m_Map);
Avatar->setNewDestination(m_warfactoryTargetCell);
} else if(std::dynamic_pointer_cast< >(Avatar)){
Avatar->Start(m_orerefineryCell,m_Map);
Avatar->setNewDestination(m_orerefineryTargetCell);
}*/
}
printf("(UI)return to GOM success\n");
return Avatar;
}
Loading

0 comments on commit c1bdb69

Please sign in to comment.