Skip to content

Commit 0d89042

Browse files
committed
Tuning: Added 'OK' button to the conflicts doublecheck dialog.
Also moved the code from CacheSystem.cpp to AddonPartFileFormat.cpp, into a new func `DoubleCheckForAddonpartConflict()` Also extended the GUI_MessageBox.cpp to always reprint the dialog to RoR.log
1 parent 16abc89 commit 0d89042

File tree

5 files changed

+76
-36
lines changed

5 files changed

+76
-36
lines changed

source/main/Application.h

+1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ enum MsgType
124124
MSG_GUI_CLOSE_SELECTOR_REQUESTED,
125125
MSG_GUI_MP_CLIENTS_REFRESH,
126126
MSG_GUI_SHOW_MESSAGE_BOX_REQUESTED, //!< Payload = MessageBoxConfig* (owner)
127+
MSG_GUI_HIDE_MESSAGE_BOX_REQUESTED,
127128
MSG_GUI_DOWNLOAD_PROGRESS,
128129
MSG_GUI_DOWNLOAD_FINISHED,
129130
MSG_GUI_REFRESH_TUNING_MENU_REQUESTED,

source/main/gui/panels/GUI_MessageBox.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ void MessageBoxDialog::Show(MessageBoxConfig const& cfg)
5656
{
5757
m_close_handle = nullptr;
5858
}
59+
60+
std::stringstream ss;
61+
ss << "[RoR|MessageBox] title='" << cfg.mbc_title << "'\n text='" << cfg.mbc_text << "'";
62+
for (MessageBoxButton const& button: cfg.mbc_buttons)
63+
{
64+
ss << "\n button='" << button.mbb_caption << "' (message: " << MsgTypeToString(button.mbb_mq_message) << ")";
65+
}
66+
LOG(ss.str());
5967
}
6068

6169
void MessageBoxDialog::Show(const char* title, const char* text, bool allow_close, const char* button1_text, const char* button2_text)

source/main/resources/CacheSystem.cpp

+19-36
Original file line numberDiff line numberDiff line change
@@ -1817,47 +1817,30 @@ void CacheSystem::ModifyProject(ModifyProjectRequest* request)
18171817
case ModifyProjectRequestType::TUNEUP_USE_ADDONPART_SET:
18181818
{
18191819
request->mpr_target_actor->ensureWorkingTuneupDef();
1820-
if (request->mpr_target_actor->getWorkingTuneupDef()->use_addonparts.count(request->mpr_subject) == 0)
1820+
if (request->mpr_target_actor->getWorkingTuneupDef()->use_addonparts.count(request->mpr_subject) != 0)
18211821
{
1822-
// Re-check conflicts (request may come from 'Browse all' button or script).
1823-
CacheEntryPtr subject_entry = this->FindEntryByFilename(LT_AddonPart, /*partial=*/false, request->mpr_subject);
1824-
AddonPartConflictVec conflicts;
1825-
for (const std::string& use_addonpart: request->mpr_target_actor->getWorkingTuneupDef()->use_addonparts)
1826-
{
1827-
CacheEntryPtr use_entry = this->FindEntryByFilename(LT_AddonPart, /*partial=*/false, use_addonpart);
1828-
AddonPartUtility::RecordAddonpartConflicts(subject_entry, use_entry, conflicts);
1829-
}
1830-
if (conflicts.size() == 0)
1831-
{
1832-
request->mpr_target_actor->getWorkingTuneupDef()->use_addonparts.insert(request->mpr_subject);
1833-
}
1834-
else
1835-
{
1836-
GUI::MessageBoxConfig* dialog = new GUI::MessageBoxConfig;
1837-
dialog->mbc_allow_close = true;
1838-
dialog->mbc_content_width = 700.f;
1839-
dialog->mbc_title = fmt::format(_LC("Tuning", "Cannot install addon part, conflicts were detected."), request->mpr_subject);
1840-
dialog->mbc_text = fmt::format(_LC("Tuning", "Requested addon part: '{}' (file '{}')."), subject_entry->dname, subject_entry->fname);
1841-
dialog->mbc_text += "\n";
1842-
dialog->mbc_text += fmt::format(_LC("Tuning", "Total conflicts: {}."), conflicts.size());
1843-
dialog->mbc_text += "\n";
1844-
for (size_t i=0; i < conflicts.size(); i++)
1845-
{
1846-
dialog->mbc_text += "\n";
1847-
dialog->mbc_text += fmt::format(_LC("Tuning", "[{}/{}] '{}' (file '{}') conflicts with '{}' #{}."),
1848-
i+1, conflicts.size(),
1849-
conflicts[i].atc_addonpart2->dname, conflicts[i].atc_addonpart2->fname,
1850-
conflicts[i].atc_keyword, conflicts[i].atc_element_id);
1851-
}
1852-
App::GetGameContext()->PushMessage(Message(MSG_GUI_SHOW_MESSAGE_BOX_REQUESTED, (void*)dialog));
1853-
}
1822+
App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_ACTOR, Console::CONSOLE_SYSTEM_WARNING,
1823+
fmt::format(_LC("Tuning", "Addon part '{}' is already equipped."), request->mpr_subject));
1824+
return; // Nothing to do!
18541825
}
1855-
else
1826+
1827+
CacheEntryPtr subject_entry = this->FindEntryByFilename(LT_AddonPart, /*partial=*/false, request->mpr_subject);
1828+
if (!subject_entry)
18561829
{
18571830
App::GetConsole()->putMessage(Console::CONSOLE_MSGTYPE_ACTOR, Console::CONSOLE_SYSTEM_WARNING,
1858-
fmt::format(_LC("Tuning", "Addon part '{}' is already installed."), request->mpr_subject));
1831+
fmt::format(_LC("Tuning", "Addon part '{}' was not found in mod cache (probably not installed)."), request->mpr_subject));
1832+
return; // Nothing to do!
18591833
}
1860-
1834+
1835+
if (AddonPartUtility::DoubleCheckForAddonpartConflict(request->mpr_target_actor, subject_entry))
1836+
{
1837+
return; // Error message box already shown
1838+
}
1839+
else
1840+
{
1841+
request->mpr_target_actor->getWorkingTuneupDef()->use_addonparts.insert(request->mpr_subject);
1842+
}
1843+
18611844
break;
18621845
}
18631846

source/main/resources/addonpart_fileformat/AddonPartFileFormat.cpp

+46
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@
2121

2222
#include "AddonPartFileFormat.h"
2323

24+
#include "Actor.h"
2425
#include "Application.h"
2526
#include "CacheSystem.h"
2627
#include "Console.h"
28+
#include "GameContext.h"
2729
#include "GenericFileFormat.h"
30+
#include "GUI_MessageBox.h"
2831
#include "RigDef_Parser.h"
2932
#include "TuneupFileFormat.h"
3033

@@ -868,3 +871,46 @@ void AddonPartUtility::Log(const std::string& text)
868871
LOG(text);
869872
}
870873
}
874+
875+
bool AddonPartUtility::DoubleCheckForAddonpartConflict(ActorPtr target_actor, CacheEntryPtr addonpart_entry)
876+
{
877+
// Re-check conflicts (request may come from 'Browse all' button or script).
878+
// -------------------------------------------------------------------------
879+
880+
AddonPartConflictVec conflicts;
881+
for (const std::string& use_addonpart: target_actor->getWorkingTuneupDef()->use_addonparts)
882+
{
883+
CacheEntryPtr use_entry = App::GetCacheSystem()->FindEntryByFilename(LT_AddonPart, /*partial=*/false, use_addonpart);
884+
AddonPartUtility::RecordAddonpartConflicts(addonpart_entry, use_entry, conflicts);
885+
}
886+
887+
if (conflicts.size() > 0)
888+
{
889+
// Messagebox text
890+
GUI::MessageBoxConfig* dialog = new GUI::MessageBoxConfig;
891+
dialog->mbc_content_width = 700.f;
892+
dialog->mbc_title = _LC("Tuning", "Cannot install addon part, conflicts were detected.");
893+
dialog->mbc_text = fmt::format(_LC("Tuning", "Requested addon part: '{}' (file '{}')."), addonpart_entry->dname, addonpart_entry->fname);
894+
dialog->mbc_text += "\n";
895+
dialog->mbc_text += fmt::format(_LC("Tuning", "Total conflicts: {}."), conflicts.size());
896+
dialog->mbc_text += "\n";
897+
for (size_t i=0; i < conflicts.size(); i++)
898+
{
899+
dialog->mbc_text += "\n";
900+
dialog->mbc_text += fmt::format(_LC("Tuning", "[{}/{}] '{}' (file '{}') conflicts with '{}' #{}."),
901+
i+1, conflicts.size(),
902+
conflicts[i].atc_addonpart2->dname, conflicts[i].atc_addonpart2->fname,
903+
conflicts[i].atc_keyword, conflicts[i].atc_element_id);
904+
}
905+
906+
// Messagebox OK button
907+
GUI::MessageBoxButton ok_btn;
908+
ok_btn.mbb_caption = _LC("Tuning", "OK");
909+
ok_btn.mbb_mq_message = MSG_GUI_HIDE_MESSAGE_BOX_REQUESTED;
910+
dialog->mbc_buttons.push_back(ok_btn);
911+
912+
// Show the messagebox
913+
App::GetGameContext()->PushMessage(Message(MSG_GUI_SHOW_MESSAGE_BOX_REQUESTED, (void*)dialog));
914+
}
915+
return conflicts.size() > 0;
916+
}

source/main/resources/addonpart_fileformat/AddonPartFileFormat.h

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ class AddonPartUtility
6666

6767
static bool CheckForAddonpartConflict(CacheEntryPtr addonpart1, CacheEntryPtr addonpart2, AddonPartConflictVec& conflicts);
6868

69+
static bool DoubleCheckForAddonpartConflict(ActorPtr target_actor, CacheEntryPtr addonpart_entry);
70+
6971
private:
7072
// Helpers of `TransformToRigDefModule()`, they expect `m_context` to be in position:
7173
void ProcessManagedMaterial();

0 commit comments

Comments
 (0)