Implement script setting pages' descriptions

C++20
uramer 3 years ago
parent a005f25c4b
commit 5f7ab49880

@ -243,6 +243,8 @@ namespace MWGui
getWidget(mScriptBox, "ScriptBox");
getWidget(mScriptView, "ScriptView");
getWidget(mScriptDisabled, "ScriptDisabled");
getWidget(mScriptDescription, "ScriptDescription");
mScriptChild = nullptr;
#ifndef WIN32
// hide gamma controls since it currently does not work under Linux
@ -331,6 +333,7 @@ namespace MWGui
mScriptFilter->eventEditTextChange += MyGUI::newDelegate(this, &SettingsWindow::onScriptFilterChange);
mScriptList->eventListMouseItemActivate += MyGUI::newDelegate(this, &SettingsWindow::onScriptListSelection);
mScriptList->eventListMouseItemFocus += MyGUI::newDelegate(this, &SettingsWindow::onScriptListFocus);
}
void SettingsWindow::onTabChanged(MyGUI::TabControl* /*_sender*/, size_t /*index*/)
@ -745,7 +748,7 @@ namespace MWGui
for (size_t i = 0; i < scriptSettings.size(); ++i)
{
LuaUi::ScriptSettingsPage page = scriptSettings[i];
if (std::regex_match(page.mName, filterRegex) || std::regex_match(page.mSearchHints, filterRegex))
if (std::regex_match(page.mName, filterRegex) || std::regex_match(page.mDescription, filterRegex))
mScriptList->addItem(page.mName, i);
}
@ -767,14 +770,32 @@ namespace MWGui
if (mCurrentPage >= 0)
LuaUi::attachToWidget(mCurrentPage);
mCurrentPage = -1;
if (index < mScriptList->getItemCount())
{
mCurrentPage = *mScriptList->getItemDataAt<size_t>(index);
LuaUi::attachToWidget(mCurrentPage, mScriptView);
}
mScriptChild = mScriptView->getChildCount() > 0 ? mScriptView->getChildAt(0) : nullptr;
MyGUI::IntSize canvasSize = mScriptChild ? mScriptChild->getSize() : MyGUI::IntSize();
if (mScriptChild)
mScriptChild->setVisible(mScriptView->isVisible());
mScriptView->setCanvasSize(canvasSize);
}
void SettingsWindow::onScriptListFocus(MyGUI::ListBox*, size_t index)
{
if (index >= mScriptList->getItemCount())
{
mScriptDescription->setVisible(false);
mScriptView->setVisible(true);
if (mScriptChild)
mScriptChild->setVisible(true);
return;
mCurrentPage = *mScriptList->getItemDataAt<size_t>(index);
LuaUi::attachToWidget(mCurrentPage, mScriptView);
MyGUI::IntSize canvasSize;
if (mScriptView->getChildCount() > 0)
canvasSize = mScriptView->getChildAt(0)->getSize();
mScriptView->setCanvasSize(canvasSize);
}
size_t page = *mScriptList->getItemDataAt<size_t>(index);
mScriptDescription->setCaption(LuaUi::scriptSettingsPages()[page].mDescription);
mScriptDescription->setVisible(true);
mScriptView->setVisible(false);
}
void SettingsWindow::onRebindAction(MyGUI::Widget* _sender)

@ -49,8 +49,13 @@ namespace MWGui
MyGUI::Widget* mScriptBox;
MyGUI::ScrollView* mScriptView;
MyGUI::EditBox* mScriptDisabled;
MyGUI::EditBox* mScriptDescription;
int mCurrentPage;
// only necessary to work around a MyGUI bug
// adding a child to an invisible widget doesn't make the child invisible
MyGUI::Widget* mScriptChild;
void onTabChanged(MyGUI::TabControl* _sender, size_t index);
void onOkButtonClicked(MyGUI::Widget* _sender);
void onTextureFilteringChanged(MyGUI::ComboBox* _sender, size_t pos);
@ -80,6 +85,7 @@ namespace MWGui
void onScriptFilterChange(MyGUI::EditBox*);
void onScriptListSelection(MyGUI::ListBox*, size_t index);
void onScriptListFocus(MyGUI::ListBox*, size_t index);
void apply();

@ -245,7 +245,7 @@ namespace MWLua
page.mName = options.get_or("name", std::string());
if (page.mName.empty())
throw std::logic_error("No name provided for the settings page");
page.mSearchHints = options.get_or("searchHints", std::string());
page.mDescription = options.get_or("description", std::string());
auto element = options.get_or<std::shared_ptr<LuaUi::Element>>("element", nullptr);
if (!element)
throw std::logic_error("No UI element provided for the settings page");

@ -13,7 +13,7 @@ namespace LuaUi
struct ScriptSettingsPage
{
std::string mName;
std::string mSearchHints;
std::string mDescription;
Element* mElement; // TODO: figure out if this can lead to use after free
};
const std::vector<ScriptSettingsPage>& scriptSettingsPages();

@ -665,6 +665,14 @@
<Property key="CanvasAlign" value="Left Top"/>
<Property key="CanvasSize" value="246 246"/>
</Widget>
<Widget name="ScriptDescription" type = "EditBox" skin="SandText" position="2 2 246 246" align="Stretch">
<Property key="Visible" value="false"/>
<Property key="Caption" value="Scripts settings are only available when a game is loaded."/>
<Property key="TextAlign" value="Center" />
<Property key="MultiLine" value="true" />
<Property key="WordWrap" value="true" />
<Property key="Static" value="true"/>
</Widget>
</Widget>
<Widget name="ScriptDisabled" type="EditBox" skin="SandText" position="0 0 360 308" align="Center">
<Property key="Visible" value="false"/>

Loading…
Cancel
Save