Skip to content

Commit

Permalink
imgui settings
Browse files Browse the repository at this point in the history
  • Loading branch information
jonylu7 committed Mar 11, 2024
1 parent 0b7d32c commit 861c02a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 19 deletions.
2 changes: 1 addition & 1 deletion include/Grid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Grid : public Core::Drawable {
void DrawUsingCamera(const Util::Transform &transform,
const float zIndex) override;

void setLine(glm::vec2 from, glm::vec2 to);
void setLine(glm::vec2 from, glm::vec2 to, glm::vec3 color = {1, 1, 1});
void SetActivate(bool active) { m_Activate = active; };

void setLineWidth(float linewidth) { m_lineWidth = linewidth; }
Expand Down
4 changes: 2 additions & 2 deletions src/Grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ void Grid::InitVertexAndColor() {
m_VertexArray->AddVertexBuffer(
std::make_unique<Core::VertexBuffer>(color, 3));
}
void Grid::setLine(glm::vec2 from, glm::vec2 to) {
void Grid::setLine(glm::vec2 from, glm::vec2 to, glm::vec3 color) {

m_VertexArray = std::make_unique<Core::VertexArray>();
m_lineVector.clear(); // 清空原有的線段
m_lineVector.push_back(Line(from, to));
m_lineVector.push_back(Line(from, to, color));
InitVertexAndColor(); // 重新初始化頂點和顏色
}
2 changes: 0 additions & 2 deletions src/Scene/DefaultScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ void DefaultScene::Start() {
}

void DefaultScene::Update() {
std::cout << UIClass::getUnitConstructCount(unitType::POWER_PLANT)
<< std::endl;
Util::Transform trans;
m_Map.Draw(trans, 0);
m_SceneCamera.Update();
Expand Down
27 changes: 15 additions & 12 deletions src/Structure/OreRefinery.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "Structure/OreRefinery.hpp"

void OreRefinery::Start(){
void OreRefinery::Start() {
// Set Texture----------------------------------------
this->SetDrawable(
std::make_unique<Util::Image>("../assets/sprites/barracks.png"));
Expand All @@ -11,7 +11,7 @@ void OreRefinery::Start(){
// Set ZIndex
this->SetZIndex(DEFAULT_ZINDEX);
m_wayPoint->SetZIndex(DEFAULT_ZINDEX);
m_HighLight.SetZIndex(DEFAULT_ZINDEX-1);
m_HighLight.SetZIndex(DEFAULT_ZINDEX - 1);
// Set Attachment Scale &
// Visibility----------------------------------------
m_HighLight.SetHLScale(this->GetTranScale());
Expand All @@ -20,7 +20,7 @@ void OreRefinery::Start(){
SetCurrentUpdateMode(Structure::updateMode::Moveable);
}

void OreRefinery::updateMoveable(){
void OreRefinery::updateMoveable() {
glm::vec2 location = Util::Input::GetCursorPosition();
location = MapClass::ScreenToGlobalCoord(location);
location = MapClass::GlobalCoordToCellCoord(location);
Expand All @@ -30,21 +30,23 @@ void OreRefinery::updateMoveable(){
this->Draw();
if (Util::Input::IsKeyPressed(Util::Keycode::MOUSE_LB)) {
this->SetObjectLocation(location);
this->SetWayPointLocation({GetDrawLocation().x+CELL_SIZE.x,GetDrawLocation().y+CELL_SIZE.y});
this->SetWayPointLocation({GetDrawLocation().x + CELL_SIZE.x,
GetDrawLocation().y + CELL_SIZE.y});
onSelected(false);
this->SetCurrentUpdateMode(updateMode::Fixed);
}
}
void OreRefinery::onSelected(bool selected) {
if(b_selectingNewWayPoint){
this->SetWayPointLocation(MapClass::ScreenToGlobalCoord(Util::Input::GetCursorPosition()));
b_selectingNewWayPoint= false;
if (b_selectingNewWayPoint) {
this->SetWayPointLocation(
MapClass::ScreenToGlobalCoord(Util::Input::GetCursorPosition()));
b_selectingNewWayPoint = false;
}
attachmentUpdate();
this->SetAttachVisible(selected);
if (selected) {
if (Util::Input::IsKeyPressed(Util::Keycode::V)){
b_selectingNewWayPoint= true;
if (Util::Input::IsKeyPressed(Util::Keycode::V)) {
b_selectingNewWayPoint = true;
}
}
}
Expand All @@ -53,12 +55,13 @@ void OreRefinery::SetAttachVisible(bool visible) {
m_HighLight.SetVisible(visible);
m_Grid.SetActivate(visible);
}
void OreRefinery::attachmentUpdate(){
void OreRefinery::attachmentUpdate() {
m_HighLight.SetObjectLocation(this->GetDrawLocation());
m_wayPoint->SetObjectLocation(this->GetWayPointLocation());
m_Grid.setLine(GetDrawLocation(), GetWayPointLocation());
m_Grid.setLine(GetDrawLocation(), GetWayPointLocation(),
glm::vec3(0, 0, 1));
m_wayPoint->Draw();
m_HighLight.Draw();
Util::Transform Trans;
m_Grid.DrawUsingCamera(Trans, DEFAULT_ZINDEX);
}
}
12 changes: 10 additions & 2 deletions src/UI/UI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ void UIClass::ShowCursorSelectionRegion(ImVec2 *start_pos, ImVec2 *end_pos,
}

void UIClass::ShowPlayerConstructionMenu() {
auto windowSettings = ImGuiWindowFlags_NoMove |
ImGuiWindowFlags_NoScrollbar |
ImGuiWindowFlags_NoResize;

// put the stuff in here
ImGui::Begin("Structure Selection Menu");
ImGui::Begin("Structure Selection Menu", nullptr, windowSettings);

glm::vec2 CursorGlobalPosition = MapClass::ScreenToGlobalCoord(
glm::vec2(Util::Input::GetCursorPosition()));
Expand All @@ -66,7 +69,8 @@ void UIClass::ShowPlayerConstructionMenu() {
// m_SceneCamera.getCameraZoom()).c_str());
ImGui::Text(fmt::format("$ {}", 1000).c_str());
ImGui::Text(fmt::format("Power {}", 50).c_str());

ImGui::SetWindowSize(ImVec2(240, 576));
ImGui::SetWindowPos(ImVec2(992, 48));
if (ImGui::Button("Grid")) {
}
if (ImGui::BeginTabBar("", ImGuiTabBarFlags_None)) {
Expand All @@ -75,6 +79,7 @@ void UIClass::ShowPlayerConstructionMenu() {

if (getImageButtonBySpriteSheetIndex(7)) {
// power plants

setUnitConstructCount(unitType::POWER_PLANT, 1);
ButtonScript.buttonEvent(powerPlant);
LOG_DEBUG("TEST");
Expand Down Expand Up @@ -157,6 +162,9 @@ void UIClass::ShowPlayerConstructionMenu() {
}

std::vector<ImVec2> UIClass::getSpriteSheetCoordByIndex(int index) {
std::string Text = "test";
ImDrawList *dl = ImGui::GetWindowDrawList();
dl->AddText(ImVec2(100.f, 100.f), IM_COL32(255, 255, 255, 100), "TEST");
return std::vector<ImVec2>(
{ImVec2(SpriteSheet::UVtoImGuiCoord(
this->m_IconSpriteSheet.getUVbyIndex(index))[0]
Expand Down

0 comments on commit 861c02a

Please sign in to comment.