Skip to content

Commit 216cc3b

Browse files
committed
Rework GUI for menus. Fix bugs
1 parent d39118a commit 216cc3b

File tree

6 files changed

+52
-46
lines changed

6 files changed

+52
-46
lines changed

Source/Menu/AttributeMenu/gui_menuAttribute.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,16 @@ void guiMenuAttribute(bool* open, GuiMenuGeneralVars& gVars)
173173
static common::Text description{};
174174
static GuiMenuAttributeState state{ gVars, vars };
175175

176+
if (showGuiQuestionUndoChanges) {
177+
YesNo result{ YesNo::INVALID };
178+
guiGetYesNo(&showGuiQuestionUndoChanges, u8"##QuestionUndoChanges",
179+
text.questionUndoChanges().c_str(), result);
180+
if (result == YesNo::YES) {
181+
pChar->attribute().reject();
182+
}
183+
return;
184+
}
185+
176186
///********** Windows
177187
ImGuiWindowFlags window_flags{ 0 };
178188
guiCommonInitialization(window_flags);
@@ -315,15 +325,6 @@ void guiMenuAttribute(bool* open, GuiMenuGeneralVars& gVars)
315325
showGuiQuestionUndoChanges = true;
316326
}
317327
}
318-
319-
if (showGuiQuestionUndoChanges) {
320-
YesNo result{ YesNo::INVALID };
321-
guiGetYesNo(&showGuiQuestionUndoChanges, u8"##QuestionUndoChanges",
322-
text.questionUndoChanges().c_str(), result);
323-
if (result == YesNo::YES) {
324-
pChar->attribute().reject();
325-
}
326-
}
327328
}
328329
ImGui::End();
329330
}

Source/Menu/GeneralMenu/gui_menuGeneral.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,13 @@ void guiWindowUnit(GuiMenuGeneralVars& gVars,
226226
break;
227227
}
228228
}
229-
int totalWidth =
230-
windowSize.x - style.WindowPadding.x * 2.0f - style.ScrollbarSize;
229+
int totalWidth = ImGui::GetWindowContentRegionMax().x - style.WindowPadding.x;
231230
guiShowStats(*pChar, sign::dot, totalWidth);
232231
}
233232
else if (gVars.curSM_ == Submenu::INVENTORY) {
234233
ImVec2 buttonSize{
235-
windowSize.x - style.ItemSpacing.x * 2.0f, ImGui::GetFrameHeight()
234+
ImGui::GetWindowContentRegionMax().x - style.WindowPadding.x,
235+
ImGui::GetFrameHeight()
236236
};
237237
ostringstream oss;
238238
for (int i = 0; i < pChar->slotWeapon().size(); ++i) {

Source/Menu/InventoryMenu/gui_menuInventory.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,13 @@ void guiMenuInventory(bool* open, GuiMenuGeneralVars& gVars)
9191
if (itemIsSelected && !iItem.isValid()) {
9292
pItem = nullptr;
9393
}
94+
return;
9495
}
9596

96-
if (showGuiModifyItem) guiMenuItemModify(&showGuiModifyItem, squad, *pItem);
97+
if (showGuiModifyItem) {
98+
guiMenuItemModify(&showGuiModifyItem, squad, *pItem);
99+
return;
100+
}
97101

98102
if (showGuiEquipItem) {
99103
auto newMod{ squad.inventory().extract(iItem) };

Source/Menu/MainMenu/gui_menuMain.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ void guiMenuMain(bool* open,
3636
static bool showGuiMenuSaveGame { false };
3737
static bool showGuiMenuLoadGame { false };
3838

39-
if (showGuiMenuOption) guiMenuOptions(&showGuiMenuOption);
40-
if (showGuiMenuGeneral) guiMenuGeneral(&showGuiMenuGeneral, *squad);
41-
if (showGuiMenuSaveGame) guiMenuSaveGame(&showGuiMenuSaveGame, squad, shop);
42-
if (showGuiMenuLoadGame) guiMenuLoadGame(&showGuiMenuLoadGame, squad, shop);
39+
///********** Show GUI
40+
if (showGuiMenuOption) { guiMenuOptions(&showGuiMenuOption); return; }
41+
if (showGuiMenuGeneral) { guiMenuGeneral(&showGuiMenuGeneral, *squad); return; }
42+
if (showGuiMenuSaveGame) { guiMenuSaveGame(&showGuiMenuSaveGame, squad, shop); return; }
43+
if (showGuiMenuLoadGame) { guiMenuLoadGame(&showGuiMenuLoadGame, squad, shop); return; }
4344

4445
ImGuiWindowFlags window_flags{ 0 };
4546
guiCommonInitialization(window_flags);

Source/Menu/SkillMenu/gui_menuSkill.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,16 @@ void guiMenuSkill(bool* open, GuiMenuGeneralVars& gVars)
173173
static common::Text description{};
174174
static GuiMenuSkillState state{ gVars, vars };
175175

176+
if (showGuiQuestionUndoChanges) {
177+
YesNo result{ YesNo::INVALID };
178+
guiGetYesNo(&showGuiQuestionUndoChanges, u8"##QuestionUndoChanges",
179+
text.questionUndoChanges().c_str(), result);
180+
if (result == YesNo::YES) {
181+
pChar->skill().reject();
182+
}
183+
return;
184+
}
185+
176186
///********** Windows
177187
ImGuiWindowFlags window_flags{ 0 };
178188
guiCommonInitialization(window_flags);
@@ -314,15 +324,6 @@ void guiMenuSkill(bool* open, GuiMenuGeneralVars& gVars)
314324
showGuiQuestionUndoChanges = true;
315325
}
316326
}
317-
318-
if (showGuiQuestionUndoChanges) {
319-
YesNo result{ YesNo::INVALID };
320-
guiGetYesNo(&showGuiQuestionUndoChanges, u8"##QuestionUndoChanges",
321-
text.questionUndoChanges().c_str(), result);
322-
if (result == YesNo::YES) {
323-
pChar->skill().reject();
324-
}
325-
}
326327
}
327328
ImGui::End();
328329
}

Source/Menu/gui_menuCommon.cpp

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -84,41 +84,40 @@ void guiGetYesNo(bool* open,
8484
assert(messageText != nullptr);
8585
if (open == nullptr || windowTitle == nullptr || messageText == nullptr) return;
8686

87-
const auto& comT{ MenuCommonText::common() };
88-
89-
ImVec2 center{ ImGui::GetMainViewport()->GetCenter() };
90-
ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2{ 0.5f, 0.5f });
91-
const float textPadding{ 20 };
92-
const float windowWidth{ ImGui::CalcTextSize(messageText).x + textPadding };
93-
const float minWindowWidth{ 300 };
94-
ImVec2 windowSize{ max(windowWidth, minWindowWidth), 0 };
95-
ImGui::SetNextWindowSize(windowSize, ImGuiCond_Always);
96-
97-
ImGuiWindowFlags window_flags{ ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoSavedSettings };
98-
if (ImGui::Begin(windowTitle, open, window_flags)) {
87+
ImGuiWindowFlags window_flags{ 0 };
88+
guiCommonInitialization(window_flags);
89+
window_flags &= ~ImGuiWindowFlags_NoBringToFrontOnFocus;
90+
91+
string s{ string{ windowTitle } + u8"###YesNo" };
92+
if (ImGui::Begin(s.c_str(), nullptr, window_flags)) {
93+
const auto& comT{ MenuCommonText::common() };
94+
95+
ImVec2 center{ ImGui::GetMainViewport()->GetCenter() };
96+
const float textWidth{ ImGui::CalcTextSize(messageText).x };
97+
ImVec2 textPos{ center.x - textWidth / 2, center.y - ImGui::GetFrameHeight() };
98+
ImGui::SetCursorScreenPos(textPos);
9999
ImGui::Text(messageText);
100100

101-
const float buttonTextPadding{ 40 };
101+
const float buttonTextPadding{ 40.0f };
102102
const char* buttonTextYes{ comT.yes().c_str() };
103-
ImVec2 buttonSizeYes{ ImGui::CalcTextSize(buttonTextYes).x + buttonTextPadding, 0 };
103+
ImVec2 buttonSizeYes{ ImGui::CalcTextSize(buttonTextYes).x + buttonTextPadding, 0.0f };
104104
const char* buttonTextNo{ comT.no().c_str() };
105-
ImVec2 buttonSizeNo{ ImGui::CalcTextSize(buttonTextNo).x + buttonTextPadding, 0 };
105+
ImVec2 buttonSizeNo{ ImGui::CalcTextSize(buttonTextNo).x + buttonTextPadding, 0.0f };
106106

107-
const float buttonPadding{ 10 };
108-
ImVec2 buttonSize{ max(buttonSizeYes.x, buttonSizeNo.x), 0 };
107+
const float buttonPadding{ 10.0f };
108+
ImVec2 buttonSize{ max(buttonSizeYes.x, buttonSizeNo.x), 0.0f };
109109
float indent{ ImGui::GetWindowWidth() / 2 - buttonSize.x - buttonPadding };
110-
ImGui::NewLine();
110+
ImGui::Dummy(ImVec2{ 0.0f, ImGui::GetFrameHeight() });
111111
ImGui::SameLine(indent);
112112
if (ImGui::Button(buttonTextYes, buttonSize)) {
113113
result = YesNo::YES;
114114
*open = false;
115115
}
116-
ImGui::SameLine(0, buttonPadding * 2);
116+
ImGui::SameLine(0.0f, buttonPadding * 2);
117117
if (ImGui::Button(buttonTextNo, buttonSize)) {
118118
result = YesNo::NO;
119119
*open = false;
120120
}
121-
122121
}
123122
ImGui::End();
124123
}

0 commit comments

Comments
 (0)