Skip to content

Commit

Permalink
cd time showing on UI initial version, UI text, font
Browse files Browse the repository at this point in the history
  • Loading branch information
jonylu7 committed Mar 19, 2024
1 parent 6461f14 commit 0d9782e
Show file tree
Hide file tree
Showing 12 changed files with 370 additions and 312 deletions.
Binary file modified assets/.DS_Store
Binary file not shown.
Binary file added assets/fonts/sackersgothicstd-heavy.otf
Binary file not shown.
Binary file added assets/fonts/sackersgothicstd-light.otf
Binary file not shown.
Binary file added assets/fonts/sackersgothicstd-medium.otf
Binary file not shown.
Binary file added assets/sprites/p05.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 3 additions & 7 deletions include/Map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,17 @@ class MapClass : public Core::Drawable {
int(cellCoord[1] * CELL_SIZE.y) + 0.5 * CELL_SIZE.y);
}

static std::shared_ptr<TileClass> getTileByCellPosition(glm::vec2 position) {
/*
std::shared_ptr<TileClass> getTileByCellPosition(glm::vec2 position) {

if (position.x > m_MapWdith - 1 || position.y > m_MapHeight - 1 ||
position.x < 0 || position.y < 0) {
LOG_DEBUG("False Position Getting");
return std::make_shared<TileClass>("null", 0, 0, 0, 0);
}
return m_Map[position.x][position.y];
*/
return std::make_shared<TileClass>("null", 0, 0, 0, 0);

}

static void setTileByCellPosition(glm::vec2 position,
std::shared_ptr<TileClass> tile) {
std::shared_ptr<TileClass> tile) {
/*
if (position.x > m_MapWdith - 1 || position.y > m_MapHeight - 1 ||
position.x < 0 || position.y < 0) {
Expand Down
25 changes: 21 additions & 4 deletions include/UI/UI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,31 @@ class UIClass {
s_unitConstructCount[type] += value;
}
static void resetUnitConstructCount(unitType type) {
s_unitConstructCount[type] =0;
s_unitConstructCount[type] = 0;
}

std::unique_ptr<Structure> getSelectedBuilding();
bool getIfAnythingCanSelectToBuild();//避免Scene收到空的getSelectedBuilding
bool
getIfAnythingCanSelectToBuild(); // 避免Scene收到空的getSelectedBuilding

private:
UIScriptProcess ButtonScript;
void InitUnitQueue();
void ShowCursorSelectionRegion(ImVec2 *start_pos, ImVec2 *end_pos,
ImGuiMouseButton mouse_button);
void ShowPlayerConstructionMenu();
void ShowHeaderSection();
void ShowBuildingTab();
void ShowInfantryTab();
void ShowDefTab();
void ShowVehTab();

std::vector<ImVec2>
getSpriteSheetCoordByIndex(std::shared_ptr<SpriteSheet> spritesheet,
int index);

std::shared_ptr<Util::CustomizableImage> m_image =
std::make_shared<Util::CustomizableImage>("../assets/sprites/p05.png");
bool
getImageButtonBySpriteSheetIndex(std::shared_ptr<SpriteSheet> spritesheet,
int index);
Expand All @@ -57,12 +66,20 @@ class UIClass {
Grid m_Grid;
glm::vec2 m_GridSize = {100, 100};


//0318
// 0318
bool getIfSelectToBuild(unitType type);
void setSelectToBuild(unitType type);
bool selectLock();

ImGuiIO &io = ImGui::GetIO();

ImFont *sacker_med = io.Fonts->AddFontFromFileTTF(
"../assets/fonts/sackersgothicstd-medium.otf", 100);
ImFont *sacker_heav = io.Fonts->AddFontFromFileTTF(
"../assets/fonts/sackersgothicstd-heavy.otf", 100);
ImFont *sacker_light = io.Fonts->AddFontFromFileTTF(
"../assets/fonts/sackersgothicstd-light.otf", 100);

bool b_Baracks = false;
bool b_OreRefinery = false;
bool b_PowerPlants = false;
Expand Down
33 changes: 18 additions & 15 deletions include/UI/UIScriptProcess.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,52 @@

#ifndef PRACTICALTOOLSFORSIMPLEDESIGN_UISCRIPTPROCESS_HPP
#define PRACTICALTOOLSFORSIMPLEDESIGN_UISCRIPTPROCESS_HPP
#include "Structure/Structure.hpp"
#include "GameObjectID.hpp"
#include "Structure/AdvencePowerPlants.hpp"
#include "Structure/Barracks.hpp"
#include "Structure/OreRefinery.hpp"
#include "Structure/PowerPlants.hpp"
#include "Structure/Structure.hpp"
#include "Structure/WarFactory.hpp"
#include "Structure/AdvencePowerPlants.hpp"
#include "GameObjectID.hpp"
#include <queue>
#include <future>
#include <chrono>
#include "Util/GameObject.hpp"
#include <chrono>
#include <future>
#include <queue>


class UIScriptProcess{
class UIScriptProcess {
private:
bool b_Baracks = false;
bool b_OreRefinery = false;
bool b_PowerPlants = false;
bool b_WarFactory = false;
bool b_ADVPowerPlant = false;
float TargetTime=0.F;
float m_CDLeft=0.f;
float TargetTime = 0.F;
unitType m_currentStructure;
bool b_STALL=false;
bool b_STALL = false;
std::deque<unitType> buildQueue;
std::chrono::time_point<std::chrono::high_resolution_clock> m_StartTime;
std::chrono::time_point<std::chrono::high_resolution_clock>
m_CountDownCurrentTime;

public:
UIScriptProcess(){};
~UIScriptProcess(){};
//
bool GetIfFinished(unitType type);
void SetFinished(unitType type);
void SetUsed(unitType type);
float GetCDLeft(){ return m_CDLeft;}
//Event
float GetCDLeft();
std::string GetFormattedCD();
// Event
void buttonEvent(unitType type);
void Update();

//CountDown
// CountDown
void SetCoolDown(float time);
void CountDown();
//transform to ptr
// transform to ptr
float GetStructureTime(unitType type);

private:
std::shared_ptr<Structure> barracks = std::make_shared<Barracks>();
std::shared_ptr<Structure> oreRefinery = std::make_shared<OreRefinery>();
Expand Down
1 change: 1 addition & 0 deletions src/Core/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Context::Context() {
// init Imgui
ImGui::CreateContext();
ImGuiIO &io = ImGui::GetIO();

(void)io;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;

Expand Down
19 changes: 7 additions & 12 deletions src/Scene/DefaultScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ void DefaultScene::Start() {
m_TileSetSpriteSheet->Start("../assets/sprites/TILESET_Field.png", 24, 24,
20, 0);

m_OgMap = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
m_OgMap = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
std::vector<std::shared_ptr<TileClass>> maps;
for (unsigned int i = 0; i < 10; i++) {
maps.push_back(std::make_shared<TileClass>("rock-" + std::to_string(i),
Expand All @@ -31,20 +29,18 @@ void DefaultScene::Start() {
DrawOverlays::OverlayShapes::R_CROSS);
// m_GameObjectManager.Start();


//m_dummy.Start();
m_waypointUnit.setCurrentCell({glm::vec2(0,0)});
m_waypointUnit.setNextCell({glm::vec2(0,0)});
m_waypointUnit.findPath(15,10);

// m_dummy.Start();
m_waypointUnit.setCurrentCell({glm::vec2(0, 0)});
m_waypointUnit.setNextCell({glm::vec2(0, 0)});
m_waypointUnit.findPath(15, 10);
}

void DefaultScene::Update() {
//m_dummy.Update();
// m_dummy.Update();

m_waypointUnit.Update();

for(auto i :m_BuiltStructure){
for (auto i : m_BuiltStructure) {
i->Update();
}

Expand All @@ -70,8 +66,7 @@ void DefaultScene::Update() {
m_testdraw.DrawUsingCamera(trans2, 1);
// m_GameObjectManager.Update();


if(m_UI.getIfAnythingCanSelectToBuild()){
if (m_UI.getIfAnythingCanSelectToBuild()) {
m_BuiltStructure.push_back(m_UI.getSelectedBuilding());
m_BuiltStructure.back()->Start();
printf("(Scene) Structure Started\n");
Expand Down
Loading

0 comments on commit 0d9782e

Please sign in to comment.