InterMessageBox game mode

actorid
Sebastian Wick 14 years ago
parent e77240dceb
commit 5db8e8c449

@ -2,11 +2,13 @@
using namespace MWGui; using namespace MWGui;
MessageBoxManager::MessageBoxManager (WindowManager *windowManager) MessageBoxManager::MessageBoxManager (WindowManager *windowManager, MyGUI::Gui *_gui)
{ {
mWindowManager = windowManager; mWindowManager = windowManager;
gui = _gui;
// defines // defines
mMessageBoxSpeed = 0.1; mMessageBoxSpeed = 0.1;
mInterMessageBoxe = NULL;
} }
void MessageBoxManager::onFrame (float frameDuration) 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::cout << "interactive MessageBox: " << message << " - ";
std::copy (buttons.begin(), buttons.end(), std::ostream_iterator<std::string> (std::cout, ", ")); std::copy (buttons.begin(), buttons.end(), std::ostream_iterator<std::string> (std::cout, ", "));
std::cout << std::endl; std::cout << std::endl;
InteractiveMessageBox *box = new InteractiveMessageBox(*this, message, buttons); mInterMessageBoxe = new InteractiveMessageBox(*this, gui, message, buttons);
mInterMessageBoxes.push_back(box);
// delete all non-interactive MessageBox'es return true;
std::vector<MessageBox*>::iterator it = mMessageBoxes.begin(); }
while(it != mMessageBoxes.end())
{ bool MessageBoxManager::isInteractiveMessageBox ()
delete (*it); {
it = mMessageBoxes.erase(it); return mInterMessageBoxe != NULL;
}
mMessageBoxes.clear();
} }
void MessageBoxManager::removeMessageBox (float time, MessageBox *msgbox) 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") : Layout("openmw_interactive_messagebox_layout.xml")
, mMessageBoxManager(parMessageBoxManager) , mMessageBoxManager(parMessageBoxManager)
, mGUI(_gui)
{ {
getWidget(mMessageWidget, "message"); getWidget(mMessageWidget, "message");
getWidget(mButtonsWidget, "buttons"); getWidget(mButtonsWidget, "buttons");
mMessageWidget->setOverflowToTheLeft(true); mMessageWidget->setOverflowToTheLeft(true);
mMessageWidget->addText(message); 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 class MessageBoxManager
{ {
public: public:
MessageBoxManager (WindowManager* windowManager); MessageBoxManager (WindowManager* windowManager, MyGUI::Gui *_gui);
void onFrame (float frameDuration); void onFrame (float frameDuration);
void createMessageBox (const std::string& message); 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); void removeMessageBox (float time, MessageBox *msgbox);
bool removeMessageBox (MessageBox *msgbox); bool removeMessageBox (MessageBox *msgbox);
@ -37,8 +38,9 @@ namespace MWGui
private: private:
std::vector<MessageBox*> mMessageBoxes; std::vector<MessageBox*> mMessageBoxes;
std::vector<InteractiveMessageBox*> mInterMessageBoxes; InteractiveMessageBox* mInterMessageBoxe;
std::vector<MessageBoxManagerTimer> mTimers; std::vector<MessageBoxManagerTimer> mTimers;
MyGUI::Gui *gui;
float mMessageBoxSpeed; float mMessageBoxSpeed;
}; };
@ -65,12 +67,14 @@ namespace MWGui
class InteractiveMessageBox : public OEngine::GUI::Layout class InteractiveMessageBox : public OEngine::GUI::Layout
{ {
public: 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: protected:
MessageBoxManager& mMessageBoxManager; MessageBoxManager& mMessageBoxManager;
MyGUI::EditPtr mMessageWidget; MyGUI::EditPtr mMessageWidget;
MyGUI::WidgetPtr mButtonsWidget; MyGUI::WidgetPtr mButtonsWidget;
MyGUI::Gui *mGUI;
//std::vector<MyGUI::Button> mButtons;
}; };
} }

@ -26,7 +26,10 @@ namespace MWGui
GM_ClassGenerate, GM_ClassGenerate,
GM_ClassPick, GM_ClassPick,
GM_ClassCreate, GM_ClassCreate,
GM_Review GM_Review,
// interactive MessageBox
GM_InterMessageBox
}; };
// Windows shown in inventory mode // Windows shown in inventory mode

@ -61,7 +61,7 @@ WindowManager::WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment
inventory = new InventoryWindow (); inventory = new InventoryWindow ();
#endif #endif
console = new Console(w,h, environment, extensions); console = new Console(w,h, environment, extensions);
mMessageBoxManager = new MessageBoxManager(this); mMessageBoxManager = new MessageBoxManager(this, (MyGUI::Gui*)gui);
// The HUD is always on // The HUD is always on
hud->setVisible(true); hud->setVisible(true);
@ -330,6 +330,14 @@ void WindowManager::updateVisible()
return; return;
} }
if(mode == GM_InterMessageBox)
{
if(!mMessageBoxManager->isInteractiveMessageBox()) {
setGuiMode(GM_Game);
}
return;
}
// Unsupported mode, switch back to game // Unsupported mode, switch back to game
// Note: The call will eventually end up this method again but // 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) 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()) if (buttons.empty())
{ {
mMessageBoxManager->createMessageBox(message); mMessageBoxManager->createMessageBox(message);
@ -464,6 +464,7 @@ void WindowManager::messageBox (const std::string& message, const std::vector<st
else else
{ {
mMessageBoxManager->createInteractiveMessageBox(message, buttons); mMessageBoxManager->createInteractiveMessageBox(message, buttons);
setGuiMode(GM_InterMessageBox);
} }
} }

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<MyGUI type="Layout"> <MyGUI type="Layout">
<Widget type="Window" skin="MW_Dialog" layer="Windows" position="0 0 0 0" name="_Main"> <Widget type="Window" skin="MW_Dialog" layer="Windows" position="0 0 500 400" name="_Main">
<Widget type="Edit" skin="MW_TextEditClient" position="5 -5 0 0" align="ALIGN_LEFT ALIGN_TOP STRETCH" name="message"> <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_Static" value="true"/>
<Property key="Edit_WordWrap" value="true"/> <Property key="Edit_WordWrap" value="true"/>
<Property key="Text_FontHeight" value="18"/> <Property key="Text_FontHeight" value="18"/>
@ -12,8 +12,8 @@
<Property key="FontName" value = "MyGUI_CoreFont.18" /> <Property key="FontName" value = "MyGUI_CoreFont.18" />
<Property key="TextColour" value = "0.7 0.7 0.7" /> <Property key="TextColour" value = "0.7 0.7 0.7" />
</Widget> </Widget>
<Widget type="Widget" skin="" position="0 0 0 0" align="ALIGN_STRETCH" name="buttons"> <Widget type="Widget" skin="" position="0 0 500 400" align="ALIGN_STRETCH" name="buttons">
<!--buttons--> <Widget type="Button" skin="MW_Button" position="0 0 30 18" name="somefunnybutton"/>
</Widget> </Widget>
</Widget> </Widget>
</MyGUI> </MyGUI>

Loading…
Cancel
Save