mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-03 13:09:40 +00:00
InterMessageBox game mode
This commit is contained in:
parent
e77240dceb
commit
5db8e8c449
5 changed files with 68 additions and 31 deletions
|
@ -2,11 +2,13 @@
|
|||
|
||||
using namespace MWGui;
|
||||
|
||||
MessageBoxManager::MessageBoxManager (WindowManager *windowManager)
|
||||
MessageBoxManager::MessageBoxManager (WindowManager *windowManager, MyGUI::Gui *_gui)
|
||||
{
|
||||
mWindowManager = windowManager;
|
||||
gui = _gui;
|
||||
// defines
|
||||
mMessageBoxSpeed = 0.1;
|
||||
mInterMessageBoxe = NULL;
|
||||
}
|
||||
|
||||
void MessageBoxManager::onFrame (float frameDuration)
|
||||
|
@ -72,23 +74,24 @@ void MessageBoxManager::createMessageBox (const std::string& message)
|
|||
}
|
||||
}
|
||||
|
||||
void MessageBoxManager::createInteractiveMessageBox (const std::string& message, const std::vector<std::string>& buttons)
|
||||
bool MessageBoxManager::createInteractiveMessageBox (const std::string& message, const std::vector<std::string>& buttons)
|
||||
{
|
||||
if(mInterMessageBoxe != NULL) {
|
||||
std::cout << "there is a MessageBox already" << std::endl;
|
||||
return false;
|
||||
}
|
||||
std::cout << "interactive MessageBox: " << message << " - ";
|
||||
std::copy (buttons.begin(), buttons.end(), std::ostream_iterator<std::string> (std::cout, ", "));
|
||||
std::cout << std::endl;
|
||||
|
||||
InteractiveMessageBox *box = new InteractiveMessageBox(*this, message, buttons);
|
||||
mInterMessageBoxes.push_back(box);
|
||||
mInterMessageBoxe = new InteractiveMessageBox(*this, gui, message, buttons);
|
||||
|
||||
// delete all non-interactive MessageBox'es
|
||||
std::vector<MessageBox*>::iterator it = mMessageBoxes.begin();
|
||||
while(it != mMessageBoxes.end())
|
||||
{
|
||||
delete (*it);
|
||||
it = mMessageBoxes.erase(it);
|
||||
}
|
||||
mMessageBoxes.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MessageBoxManager::isInteractiveMessageBox ()
|
||||
{
|
||||
return mInterMessageBoxe != NULL;
|
||||
}
|
||||
|
||||
void MessageBoxManager::removeMessageBox (float time, MessageBox *msgbox)
|
||||
|
@ -181,15 +184,41 @@ int MessageBox::getHeight ()
|
|||
|
||||
|
||||
|
||||
InteractiveMessageBox::InteractiveMessageBox(MessageBoxManager& parMessageBoxManager, const std::string& message, const std::vector<std::string>& buttons)
|
||||
InteractiveMessageBox::InteractiveMessageBox(MessageBoxManager& parMessageBoxManager, MyGUI::Gui *_gui, const std::string& message, const std::vector<std::string>& buttons)
|
||||
: Layout("openmw_interactive_messagebox_layout.xml")
|
||||
, mMessageBoxManager(parMessageBoxManager)
|
||||
, mGUI(_gui)
|
||||
{
|
||||
getWidget(mMessageWidget, "message");
|
||||
getWidget(mButtonsWidget, "buttons");
|
||||
|
||||
mMessageWidget->setOverflowToTheLeft(true);
|
||||
mMessageWidget->addText(message);
|
||||
|
||||
MyGUI::IntSize textSize = mMessageWidget->_getTextSize();
|
||||
std::cout << "textSize.width " << textSize.width << " textSize.height " << textSize.height << std::endl;
|
||||
|
||||
MyGUI::IntSize size;
|
||||
size.width = 500; // 500 is fixed width
|
||||
size.height = textSize.height + 100; // 100 is mButtonWidget high
|
||||
|
||||
mMainWidget->setSize(size);
|
||||
size.width = 480; // fixed width (500) - 2*padding (10)
|
||||
size.height = textSize.height;
|
||||
mMessageWidget->setSize(size);
|
||||
|
||||
std::vector<std::string>::const_iterator it;
|
||||
for(it = buttons.begin(); it != buttons.end(); ++it)
|
||||
{
|
||||
std::cout << "add button " << *it << std::endl;
|
||||
MyGUI::ButtonPtr button = mGUI->createWidget<MyGUI::Button>("button1", 10, textSize.height, 480, 100, MyGUI::Align::Default, "buttons");
|
||||
button->setCaption(*it);
|
||||
//mButtons.push_back(button);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -24,10 +24,11 @@ namespace MWGui
|
|||
class MessageBoxManager
|
||||
{
|
||||
public:
|
||||
MessageBoxManager (WindowManager* windowManager);
|
||||
MessageBoxManager (WindowManager* windowManager, MyGUI::Gui *_gui);
|
||||
void onFrame (float frameDuration);
|
||||
void createMessageBox (const std::string& message);
|
||||
void createInteractiveMessageBox (const std::string& message, const std::vector<std::string>& buttons);
|
||||
bool createInteractiveMessageBox (const std::string& message, const std::vector<std::string>& buttons);
|
||||
bool isInteractiveMessageBox ();
|
||||
|
||||
void removeMessageBox (float time, MessageBox *msgbox);
|
||||
bool removeMessageBox (MessageBox *msgbox);
|
||||
|
@ -37,8 +38,9 @@ namespace MWGui
|
|||
|
||||
private:
|
||||
std::vector<MessageBox*> mMessageBoxes;
|
||||
std::vector<InteractiveMessageBox*> mInterMessageBoxes;
|
||||
InteractiveMessageBox* mInterMessageBoxe;
|
||||
std::vector<MessageBoxManagerTimer> mTimers;
|
||||
MyGUI::Gui *gui;
|
||||
float mMessageBoxSpeed;
|
||||
};
|
||||
|
||||
|
@ -65,12 +67,14 @@ namespace MWGui
|
|||
class InteractiveMessageBox : public OEngine::GUI::Layout
|
||||
{
|
||||
public:
|
||||
InteractiveMessageBox (MessageBoxManager& parMessageBoxManager, const std::string& message, const std::vector<std::string>& buttons);
|
||||
InteractiveMessageBox (MessageBoxManager& parMessageBoxManager, MyGUI::Gui *_gui, const std::string& message, const std::vector<std::string>& buttons);
|
||||
|
||||
protected:
|
||||
MessageBoxManager& mMessageBoxManager;
|
||||
MyGUI::EditPtr mMessageWidget;
|
||||
MyGUI::WidgetPtr mButtonsWidget;
|
||||
MyGUI::Gui *mGUI;
|
||||
//std::vector<MyGUI::Button> mButtons;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -26,7 +26,10 @@ namespace MWGui
|
|||
GM_ClassGenerate,
|
||||
GM_ClassPick,
|
||||
GM_ClassCreate,
|
||||
GM_Review
|
||||
GM_Review,
|
||||
|
||||
// interactive MessageBox
|
||||
GM_InterMessageBox
|
||||
};
|
||||
|
||||
// Windows shown in inventory mode
|
||||
|
|
|
@ -61,7 +61,7 @@ WindowManager::WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment
|
|||
inventory = new InventoryWindow ();
|
||||
#endif
|
||||
console = new Console(w,h, environment, extensions);
|
||||
mMessageBoxManager = new MessageBoxManager(this);
|
||||
mMessageBoxManager = new MessageBoxManager(this, (MyGUI::Gui*)gui);
|
||||
|
||||
// The HUD is always on
|
||||
hud->setVisible(true);
|
||||
|
@ -330,6 +330,14 @@ void WindowManager::updateVisible()
|
|||
return;
|
||||
}
|
||||
|
||||
if(mode == GM_InterMessageBox)
|
||||
{
|
||||
if(!mMessageBoxManager->isInteractiveMessageBox()) {
|
||||
setGuiMode(GM_Game);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Unsupported mode, switch back to game
|
||||
// Note: The call will eventually end up this method again but
|
||||
|
@ -449,14 +457,6 @@ void WindowManager::removeDialog(OEngine::GUI::Layout*dialog)
|
|||
|
||||
void WindowManager::messageBox (const std::string& message, const std::vector<std::string>& buttons)
|
||||
{
|
||||
/*std::cout << "message box: " << message << std::endl;
|
||||
|
||||
if (!buttons.empty())
|
||||
{
|
||||
std::cout << "buttons: ";
|
||||
std::copy (buttons.begin(), buttons.end(), std::ostream_iterator<std::string> (std::cout, ", "));
|
||||
std::cout << std::endl;
|
||||
}*/
|
||||
if (buttons.empty())
|
||||
{
|
||||
mMessageBoxManager->createMessageBox(message);
|
||||
|
@ -464,6 +464,7 @@ void WindowManager::messageBox (const std::string& message, const std::vector<st
|
|||
else
|
||||
{
|
||||
mMessageBoxManager->createInteractiveMessageBox(message, buttons);
|
||||
setGuiMode(GM_InterMessageBox);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<MyGUI type="Layout">
|
||||
<Widget type="Window" skin="MW_Dialog" layer="Windows" position="0 0 0 0" name="_Main">
|
||||
<Widget type="Edit" skin="MW_TextEditClient" position="5 -5 0 0" align="ALIGN_LEFT ALIGN_TOP STRETCH" name="message">
|
||||
<Widget type="Window" skin="MW_Dialog" layer="Windows" position="0 0 500 400" name="_Main">
|
||||
<Widget type="Edit" skin="MW_TextEditClient" position="10 10 490 20" align="ALIGN_LEFT ALIGN_TOP STRETCH" name="message">
|
||||
<Property key="Edit_Static" value="true"/>
|
||||
<Property key="Edit_WordWrap" value="true"/>
|
||||
<Property key="Text_FontHeight" value="18"/>
|
||||
|
@ -12,8 +12,8 @@
|
|||
<Property key="FontName" value = "MyGUI_CoreFont.18" />
|
||||
<Property key="TextColour" value = "0.7 0.7 0.7" />
|
||||
</Widget>
|
||||
<Widget type="Widget" skin="" position="0 0 0 0" align="ALIGN_STRETCH" name="buttons">
|
||||
<!--buttons-->
|
||||
<Widget type="Widget" skin="" position="0 0 500 400" align="ALIGN_STRETCH" name="buttons">
|
||||
<Widget type="Button" skin="MW_Button" position="0 0 30 18" name="somefunnybutton"/>
|
||||
</Widget>
|
||||
</Widget>
|
||||
</MyGUI>
|
||||
|
|
Loading…
Reference in a new issue