Merge remote branch 'swick/MessageBox' into MessageBox
commit
e3d05e90d4
@ -0,0 +1,160 @@
|
||||
#include "messagebox.hpp"
|
||||
|
||||
using namespace MWGui;
|
||||
|
||||
MessageBoxManager::MessageBoxManager (WindowManager *windowManager)
|
||||
{
|
||||
mWindowManager = windowManager;
|
||||
// defines
|
||||
mMessageBoxSpeed = 0.1;
|
||||
}
|
||||
|
||||
void MessageBoxManager::onFrame (float frameDuration)
|
||||
{
|
||||
std::vector<MessageBoxManagerTimer>::iterator it;
|
||||
for(it = mTimers.begin(); it != mTimers.end();)
|
||||
{
|
||||
it->current += frameDuration;
|
||||
if(it->current >= it->max)
|
||||
{
|
||||
removeMessageBox(it->messageBox);
|
||||
it = mTimers.erase(it);
|
||||
}
|
||||
else
|
||||
{
|
||||
it++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MessageBoxManager::createMessageBox (const std::string& message)
|
||||
{
|
||||
std::cout << "MessageBox: " << message << std::endl;
|
||||
|
||||
MessageBox *box = new MessageBox(*this, message);
|
||||
|
||||
removeMessageBox(message.length()*mMessageBoxSpeed, box);
|
||||
|
||||
mMessageBoxes.insert(mMessageBoxes.begin(), box);
|
||||
int height = box->getHeight();
|
||||
std::vector<MessageBox*>::iterator it;
|
||||
|
||||
int i = 0;
|
||||
for(it = mMessageBoxes.begin()+1; it != mMessageBoxes.end(); ++it)
|
||||
{
|
||||
if(i == 2) {
|
||||
delete (*it);
|
||||
mMessageBoxes.erase(it);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
(*it)->update(height);
|
||||
height += (*it)->getHeight();
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MessageBoxManager::createInteractiveMessageBox (const std::string& message, const std::vector<std::string>& buttons)
|
||||
{
|
||||
std::cout << "interactive MessageBox: " << message << " - ";
|
||||
std::copy (buttons.begin(), buttons.end(), std::ostream_iterator<std::string> (std::cout, ", "));
|
||||
std::cout << std::endl;
|
||||
|
||||
std::vector<MessageBox*>::iterator it = mMessageBoxes.begin();
|
||||
while(it != mMessageBoxes.end())
|
||||
{
|
||||
delete (*it);
|
||||
it = mMessageBoxes.erase(it);
|
||||
}
|
||||
mMessageBoxes.clear();
|
||||
}
|
||||
|
||||
void MessageBoxManager::removeMessageBox (float time, MessageBox *msgbox)
|
||||
{
|
||||
MessageBoxManagerTimer timer;
|
||||
timer.current = 0;
|
||||
timer.max = time;
|
||||
timer.messageBox = msgbox;
|
||||
|
||||
mTimers.insert(mTimers.end(), timer);
|
||||
}
|
||||
|
||||
bool MessageBoxManager::removeMessageBox (MessageBox *msgbox)
|
||||
{
|
||||
std::vector<MessageBox*>::iterator it;
|
||||
for(it = mMessageBoxes.begin(); it != mMessageBoxes.end(); ++it)
|
||||
{
|
||||
if((*it) == msgbox)
|
||||
{
|
||||
delete (*it);
|
||||
mMessageBoxes.erase(it);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void MessageBoxManager::setMessageBoxSpeed (int speed)
|
||||
{
|
||||
mMessageBoxSpeed = speed;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
MessageBox::MessageBox(MessageBoxManager& parMessageBoxManager, const std::string& message)
|
||||
: Layout("openmw_messagebox_layout.xml")
|
||||
, mMessageBoxManager(parMessageBoxManager)
|
||||
, cMessage(message)
|
||||
{
|
||||
// defines
|
||||
mFixedWidth = 300;
|
||||
mBottomPadding = 20;
|
||||
mNextBoxPadding = 20;
|
||||
|
||||
getWidget(mMessageWidget, "message");
|
||||
|
||||
mMessageWidget->setOverflowToTheLeft(true);
|
||||
mMessageWidget->addText(cMessage);
|
||||
|
||||
MyGUI::IntSize size;
|
||||
size.width = mFixedWidth;
|
||||
size.height = 100; // dummy
|
||||
|
||||
MyGUI::IntCoord coord;
|
||||
coord.left = 10; // dummy
|
||||
coord.top = 10; // dummy
|
||||
|
||||
mMessageWidget->setSize(size);
|
||||
|
||||
MyGUI::IntSize textSize = mMessageWidget->_getTextSize();
|
||||
size.height = mHeight = textSize.height + 20; // this is the padding between the text and the box
|
||||
|
||||
mMainWidget->setSize(size);
|
||||
size.width -= 5; // this is to center the text (see messagebox_layout.xml, Widget type="Edit" position="-2 -3 0 0")
|
||||
mMessageWidget->setSize(size);
|
||||
|
||||
update(0);
|
||||
}
|
||||
|
||||
void MessageBox::update (int height)
|
||||
{
|
||||
MyGUI::IntSize gameWindowSize = mMessageBoxManager.mWindowManager->getGui()->getViewSize();
|
||||
MyGUI::IntCoord coord;
|
||||
coord.left = (gameWindowSize.width - mFixedWidth)/2;
|
||||
coord.top = (gameWindowSize.height - mHeight - height - mBottomPadding);
|
||||
|
||||
MyGUI::IntSize size;
|
||||
size.width = mFixedWidth;
|
||||
size.height = mHeight;
|
||||
|
||||
mMainWidget->setCoord(coord);
|
||||
mMainWidget->setSize(size);
|
||||
mMainWidget->setVisible(true);
|
||||
}
|
||||
|
||||
int MessageBox::getHeight ()
|
||||
{
|
||||
return mHeight+mNextBoxPadding; // 20 is the padding between this and the next MessageBox
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
#ifndef MWGUI_MESSAGE_BOX_H
|
||||
#define MWGUI_MESSAGE_BOX_H
|
||||
|
||||
#include <openengine/gui/layout.hpp>
|
||||
#include <MyGUI.h>
|
||||
|
||||
#include "window_base.hpp"
|
||||
#include "window_manager.hpp"
|
||||
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
|
||||
class MessageBoxManager;
|
||||
class MessageBox;
|
||||
|
||||
struct MessageBoxManagerTimer {
|
||||
float current;
|
||||
float max;
|
||||
MessageBox *messageBox;
|
||||
};
|
||||
|
||||
class MessageBoxManager
|
||||
{
|
||||
public:
|
||||
MessageBoxManager (WindowManager* windowManager);
|
||||
void onFrame (float frameDuration);
|
||||
void createMessageBox (const std::string& message);
|
||||
void createInteractiveMessageBox (const std::string& message, const std::vector<std::string>& buttons);
|
||||
|
||||
void removeMessageBox (float time, MessageBox *msgbox);
|
||||
bool removeMessageBox (MessageBox *msgbox);
|
||||
void setMessageBoxSpeed (int speed);
|
||||
|
||||
WindowManager *mWindowManager;
|
||||
|
||||
private:
|
||||
std::vector<MessageBox*> mMessageBoxes;
|
||||
std::vector<MessageBoxManagerTimer> mTimers;
|
||||
float mMessageBoxSpeed;
|
||||
};
|
||||
|
||||
class MessageBox : public OEngine::GUI::Layout
|
||||
{
|
||||
public:
|
||||
MessageBox (MessageBoxManager& parMessageBoxManager, const std::string& message);
|
||||
void setMessage (const std::string& message);
|
||||
int getHeight ();
|
||||
void update (int height);
|
||||
|
||||
protected:
|
||||
MessageBoxManager& mMessageBoxManager;
|
||||
int mHeight;
|
||||
const std::string& cMessage;
|
||||
MyGUI::EditPtr mMessageWidget;
|
||||
int mFixedWidth;
|
||||
int mBottomPadding;
|
||||
int mNextBoxPadding;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,17 @@
|
||||
<?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="StaticText" skin="StaticText" position="4 4 4 4" name="message" />
|
||||
</Widget-->
|
||||
<Widget type="Window" skin="MW_Dialog" layer="Windows" position="0 0 0 0" name="_Main">
|
||||
<Widget type="Edit" skin="MW_TextEditClient" position="-2 -3 0 0" name="message" align="ALIGN_LEFT ALIGN_TOP STRETCH">
|
||||
<Property key="Edit_Static" value="true"/>
|
||||
<Property key="Edit_WordWrap" value="true"/>
|
||||
<Property key="Text_FontHeight" value="18"/>
|
||||
<Property key="Edit_MultiLine" value="1" />
|
||||
<Property key="Edit_VisibleVScroll" value="1" />
|
||||
<Property key="Widget_AlignText" value="ALIGN_CENTER" />
|
||||
</Widget>
|
||||
</Widget>
|
||||
</MyGUI>
|
Loading…
Reference in New Issue