Skip to content

Commit

Permalink
fix: fixed tracking variable buggy behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
klonyyy committed Nov 9, 2024
1 parent e0ba38f commit 0b374bc
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 19 deletions.
4 changes: 4 additions & 0 deletions src/ConfigHandler/ConfigHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ void ConfigHandler::loadVariables(std::map<std::string, std::shared_ptr<Variable
if (trackedName.empty())
trackedName = name;
newVar->setTrackedName(trackedName);

if (trackedName != name)
newVar->setIsTrackedNameDifferent(true);

newVar->setAddress(atoi(ini->get(varFieldFromID(varId)).get("address").c_str()));
newVar->setType(static_cast<Variable::Type>(atoi(ini->get(varFieldFromID(varId)).get("type").c_str())));
newVar->setColor(static_cast<uint32_t>(atol(ini->get(varFieldFromID(varId)).get("color").c_str())));
Expand Down
38 changes: 20 additions & 18 deletions src/Gui/GuiVariablesEdit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class VariableEditWindow
if (ImGui::Button("Done", ImVec2(-1, buttonHeight)))
{
showVariableEditWindow = false;
selection.clear();
ImGui::CloseCurrentPopup();
}

Expand Down Expand Up @@ -61,7 +62,7 @@ class VariableEditWindow
std::string shift = std::to_string(editedVariable->getShift());
std::string mask = std::string("0x") + std::string(GuiHelper::intToHexString(editedVariable->getMask()));
bool shouldUpdateFromElf = editedVariable->getShouldUpdateFromElf();
static bool selectNameManually = false;
bool selectNameManually = editedVariable->getIsTrackedNameDifferent();

ImGui::Dummy(ImVec2(-1, 5));
GuiHelper::drawCenteredText("Variable");
Expand All @@ -79,27 +80,28 @@ class VariableEditWindow

GuiHelper::drawTextAlignedToSize("specify tracked name:", alignment);
ImGui::SameLine();
ImGui::Checkbox("##selectNameManually", &selectNameManually);
if (ImGui::Checkbox("##selectNameManually", &selectNameManually))
editedVariable->setIsTrackedNameDifferent(selectNameManually);

if (selectNameManually)
{
GuiHelper::drawTextAlignedToSize("tracked variable:", alignment);
ImGui::SameLine();
ImGui::BeginDisabled(!selectNameManually);

std::string trackedVarName = selection.empty() ? editedVariable->getTrackedName() : *selection.begin();
GuiHelper::drawTextAlignedToSize("tracked variable:", alignment);
ImGui::SameLine();

if (ImGui::InputText("##trackedVarName", &trackedVarName, ImGuiInputTextFlags_None, NULL, NULL) || editedVariable->getTrackedName() != trackedVarName)
{
editedVariable->setTrackedName(trackedVarName);
editedVariable->setAddress(vars->at(trackedVarName)->getAddress());
editedVariable->setType(vars->at(trackedVarName)->getType());
}
ImGui::SameLine();
if (ImGui::Button("select...", ImVec2(65 * GuiHelper::contentScale, 19 * GuiHelper::contentScale)))
selectVariableWindow->setShowState(true);
std::string trackedVarName = selection.empty() ? editedVariable->getTrackedName() : *selection.begin();

if (ImGui::InputText("##trackedVarName", &trackedVarName, ImGuiInputTextFlags_None, NULL, NULL) || editedVariable->getTrackedName() != trackedVarName)
{
editedVariable->setTrackedName(trackedVarName);
editedVariable->setAddress(vars->at(trackedVarName)->getAddress());
editedVariable->setType(vars->at(trackedVarName)->getType());
selection.clear();
}
else
editedVariable->setTrackedName(name);
ImGui::SameLine();
if (ImGui::Button("select...", ImVec2(65 * GuiHelper::contentScale, 19 * GuiHelper::contentScale)))
selectVariableWindow->setShowState(true);

ImGui::EndDisabled();

GuiHelper::drawTextAlignedToSize("update from *.elf:", alignment);
ImGui::SameLine();
Expand Down
13 changes: 13 additions & 0 deletions src/Variable/Variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ void Variable::rename(const std::string& newName)
if (renameCallback)
renameCallback(name, newName);
name = newName;

if (!isTrackedNameDifferent)
trackedName = newName;
}

void Variable::setColor(float r, float g, float b, float a)
Expand Down Expand Up @@ -226,6 +229,16 @@ void Variable::setShouldUpdateFromElf(bool shouldUpdateFromElf)
this->shouldUpdateFromElf = shouldUpdateFromElf;
}

bool Variable::getIsTrackedNameDifferent() const
{
return isTrackedNameDifferent;
}

void Variable::setIsTrackedNameDifferent(bool isDifferent)
{
this->isTrackedNameDifferent = isDifferent;
}

std::string Variable::getTrackedName() const
{
return trackedName;
Expand Down
5 changes: 4 additions & 1 deletion src/Variable/Variable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ class Variable
bool getShouldUpdateFromElf() const;
void setShouldUpdateFromElf(bool shouldUpdateFromElf);

bool getIsTrackedNameDifferent() const;
void setIsTrackedNameDifferent(bool isDifferent);

std::string getTrackedName() const;
void setTrackedName(const std::string& trackedName);

Expand All @@ -95,7 +98,6 @@ class Variable
std::function<void(const std::string&, const std::string&)> renameCallback;

private:

std::string name = "";
std::string trackedName = "";
Type type = Type::UNKNOWN;
Expand All @@ -113,6 +115,7 @@ class Variable
Color color{};
bool isFound = false;
bool shouldUpdateFromElf = true;
bool isTrackedNameDifferent = false;
};

#endif

0 comments on commit 0b374bc

Please sign in to comment.