-1

enter image description hereI wrote authorization by key in imgui, then I made an injection and a game selection (but it opened in a new window) I would like to make sure that after successful authorization, the old elements are deleted and new ones are drawn without adding a new window

made different windows but the authorization window did not close and it looked ugly

ImGui::SetNextWindowSize(ImVec2(284, 309));
    if (ImGui::Begin("sd1", NULL, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoSavedSettings))
    {
        ImGui::InputText("##keyinput", &inputlicencekey, CHAR_MAX, ImGuiInputTextFlags_Password);

        if (ImGui::Button("Login"))
        {
            if (&inputlicencekey == key)
            {
                logged = true;
            }
        }
    }ImGui::End();

    ImGui::SetNextWindowSize(ImVec2(284, 309));
    if (!logged && ImGui::Begin("sd1", NULL, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoSavedSettings))
    {
            ImGui::Checkbox("Test", &testbool);
            if (ImGui::Button("injcet"))
            {
                testbool = true;
            }
            ImGui::Text("Int");
            ImGui::SliderInt("##dd", &inttest, 0.1f, 15.f);
            ImGui::Text("Float");
    }ImGui::End();
  • 1
    solution: write code to "close" the authorization window, or more likely: stop drawing the authorization window. However you did not show us any code to help you with. – Botje Mar 10 '23 at 13:40

1 Answers1

0

Change the first line of code to

if (!logged && ImGui::Begin(...))

such that the window only renders if logged is not set.

Better still, consider adding a state variable:

// at top level
enum class State { START, LOGGED_IN };
State my_state = State::START;

and then your rendering code can inspect my_state:

switch (my_state) {
  case State::START: {
    ImGui::Begin(...);
    ...
    my_state = State::LOGGED_IN;
    break;
  }
  case State::LOGGED_IN: {
    ImGui::Begin(...)
    ...
    break;
  }
}

Here is the exact change you need to make:

    if (!logged && ImGui::Begin("sd1", NULL, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoSavedSettings))
    {
        ImGui::InputText("##keyinput", &inputlicencekey, CHAR_MAX, ImGuiInputTextFlags_Password);

        if (ImGui::Button("Login"))
        {
            if (&inputlicencekey == key)
            {
                logged = true;
            }
        }
    ImGui::End();
    }

    ImGui::SetNextWindowSize(ImVec2(284, 309));
    if (logged && ImGui::Begin("sd1", NULL, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoSavedSettings))
    {
            ImGui::Checkbox("Test", &testbool);
            if (ImGui::Button("injcet"))
            {
                testbool = true;
            }
            ImGui::Text("Int");
            ImGui::SliderInt("##dd", &inttest, 0.1f, 15.f);
            ImGui::Text("Float");
    ImGui::End()
    }
Botje
  • 26,269
  • 3
  • 31
  • 41
  • check my update code he don`t render – helpplease Mar 10 '23 at 14:29
  • You were supposed to pick one approach OR the other. not both. – Botje Mar 10 '23 at 14:30
  • I study c++ for a week, but with imgui and I work for 3-4 hours, sorry, I don't quite understand if it's not difficult for you, you can take my code and redo it, I'm grateful in advance – helpplease Mar 10 '23 at 14:31
  • As I said, you only need to change the first if statement from your *original code* to test that `logged == false`. Moving to an explicit state can come later. – Botje Mar 10 '23 at 14:55
  • now imgui rendering but render immediately both authorization and inject (although I haven't entered the key yet) – helpplease Mar 10 '23 at 15:04
  • That is impossible. You have one block of code that expects `logged` to be false, and a second that expects `logged` to be true. Both cannot be true at the same time. Again, please edit your question with the **actual code you have now**. – Botje Mar 10 '23 at 15:06
  • check now i so beginer – helpplease Mar 10 '23 at 15:13
  • Surely you know how if statements work ... – Botje Mar 10 '23 at 15:17
  • yes but now I'm very confused because I don't really understand what you mean – helpplease Mar 10 '23 at 15:18