1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 21:53:51 +00:00

cleanup 3

This commit is contained in:
scrawl 2012-05-12 13:12:37 +02:00
parent 3a6fde5039
commit ed6ff0a94a
7 changed files with 173 additions and 194 deletions

View file

@ -25,177 +25,23 @@ using namespace MWGui;
using namespace Widgets; using namespace Widgets;
ContainerWindow::ContainerWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop) ContainerBase::ContainerBase(WindowManager& parWindowManager,DragAndDrop* dragAndDrop,std::string guiFile)
: WindowBase("openmw_container_window_layout.xml", parWindowManager),
mDragAndDrop(dragAndDrop),
mContainer()
{
setText("_Main", "Name of Container");
getWidget(mContainerWidget, "Items");
getWidget(mTakeButton, "TakeButton");
getWidget(mCloseButton, "CloseButton");
mCloseButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onCloseButtonClicked);
mTakeButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onTakeAllButtonClicked);
mContainerWidget->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onContainerClicked);
setText("CloseButton", MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sClose")->str);
setText("TakeButton", MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sTakeAll")->str);
// adjust buttons size to fit text
int closeButtonWidth = mCloseButton->getTextSize().width+24;
int takeButtonWidth = mTakeButton->getTextSize().width+24;
mCloseButton->setCoord(600-20-closeButtonWidth, mCloseButton->getCoord().top, closeButtonWidth, mCloseButton->getCoord().height);
mTakeButton->setCoord(600-20-closeButtonWidth-takeButtonWidth-8, mTakeButton->getCoord().top, takeButtonWidth, mTakeButton->getCoord().height);
int w = MyGUI::RenderManager::getInstance().getViewSize().width;
int h = MyGUI::RenderManager::getInstance().getViewSize().height;
setCoord(w-600,h-300,600,300);
}
ContainerWindow::ContainerWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop,std::string guiFile)
: WindowBase(guiFile, parWindowManager), : WindowBase(guiFile, parWindowManager),
mDragAndDrop(dragAndDrop), mDragAndDrop(dragAndDrop),
mContainer() mContainer()
{ {
setText("_Main", "Name of Container");
adjustWindowCaption();
getWidget(mContainerWidget, "Items"); getWidget(mContainerWidget, "Items");
mContainerWidget->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onContainerClicked); getWidget(mItemView, "ItemView");
mContainerWidget->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerBase::onContainerClicked);
static_cast<MyGUI::Window*>(mMainWidget)->eventWindowChangeCoord += MyGUI::newDelegate(this, &ContainerBase::onWindowResize);
} }
ContainerWindow::~ContainerWindow()
ContainerBase::~ContainerBase()
{ {
} }
void ContainerWindow::setName(std::string contName) void ContainerBase::onSelectedItem(MyGUI::Widget* _sender)
{
setText("_Main", contName);
adjustWindowCaption();
}
void ContainerWindow::open(MWWorld::Ptr container)
{
mContainer = container;
setName(MWWorld::Class::get(container).getName(container));
//MWWorld::ContainerStore* containerStore = container.getContainerStore();
drawItems();
setVisible(true);
}
void ContainerWindow::drawItems()
{
while (mContainerWidget->getChildCount())
{
MyGUI::Gui::getInstance().destroyWidget(mContainerWidget->getChildAt(0));
}
MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer);
//mContainerWidget->
/*MWWorld::ManualRef furRef (mWindowManager.getStore(), "fur_cuirass");
furRef.getPtr().getRefData().setCount (5);
MWWorld::ManualRef bukkitRef (mWindowManager.getStore(), "misc_com_bucket_01");
MWWorld::ManualRef broomRef (mWindowManager.getStore(), "misc_com_broom_01");
MWWorld::ManualRef goldRef (mWindowManager.getStore(), "gold_100");
containerStore.add(furRef.getPtr());
containerStore.add(furRef.getPtr());
containerStore.add(furRef.getPtr());
containerStore.add(broomRef.getPtr());
containerStore.add(broomRef.getPtr());
containerStore.add(broomRef.getPtr());
containerStore.add(broomRef.getPtr());
containerStore.add(broomRef.getPtr());
containerStore.add(broomRef.getPtr());
containerStore.add(broomRef.getPtr());
containerStore.add(broomRef.getPtr());
containerStore.add(broomRef.getPtr());
containerStore.add(broomRef.getPtr());
containerStore.add(bukkitRef.getPtr());
containerStore.add(bukkitRef.getPtr());
containerStore.add(bukkitRef.getPtr());
containerStore.add(bukkitRef.getPtr());
containerStore.add(bukkitRef.getPtr());
containerStore.add(bukkitRef.getPtr());
containerStore.add(bukkitRef.getPtr());
containerStore.add(bukkitRef.getPtr());
containerStore.add(bukkitRef.getPtr());
containerStore.add(bukkitRef.getPtr());
containerStore.add(goldRef.getPtr());*/
// ESMS::LiveCellRef<ESM::Armor, MWWorld::RefData> *ref = iter->get<ESM::Armor>();
int x = 4;
int y = 4;
int count = 0;
int index = 0;
for (MWWorld::ContainerStoreIterator iter (containerStore.begin()); iter!=containerStore.end(); ++iter)
{
index++;
if(iter->getRefData().getCount() > 0)
{
count++;
std::string path = std::string("icons\\");
path+=MWWorld::Class::get(*iter).getInventoryIcon(*iter);
ItemWidget* image = mContainerWidget->createWidget<ItemWidget>("ImageBox", MyGUI::IntCoord(x, y, 32, 32), MyGUI::Align::Default);
MyGUI::TextBox* text = image->createWidget<MyGUI::TextBox>("SandBrightText", MyGUI::IntCoord(x, y, 18, 18), MyGUI::Align::Default, std::string("Label"));
image->eventMouseButtonClick += MyGUI::newDelegate(this,&ContainerWindow::onSelectedItem);
image->mPos = index;
image->mPtr = *iter;
//image->eventMouseMove += MyGUI::newDelegate(this,&ContainerWindow::onMouseMove);
x += 36;
if(count % 20 == 0)
{
y += 36;
x = 4;
count = 0;
}
if(iter->getRefData().getCount() > 1)
text->setCaption(boost::lexical_cast<std::string>(iter->getRefData().getCount()));
int pos = path.rfind(".");
path.erase(pos);
path.append(".dds");
image->setImageTexture(path);
}
}
}
void ContainerWindow::Update()
{
if(mDragAndDrop->mIsOnDragAndDrop)
{
if(mDragAndDrop->mDraggedWidget)
mDragAndDrop->mDraggedWidget->setPosition(MyGUI::InputManager::getInstance().getMousePosition());
else mDragAndDrop->mIsOnDragAndDrop = false; //If this happens, there is a bug.
}
}
void ContainerWindow::onCloseButtonClicked(MyGUI::Widget* _sender)
{
if(!mDragAndDrop->mIsOnDragAndDrop)
{
MWBase::Environment::get().getWindowManager()->setGuiMode(GM_Game);
setVisible(false);
}
}
void ContainerWindow::onTakeAllButtonClicked(MyGUI::Widget* _sender)
{
if(!mDragAndDrop->mIsOnDragAndDrop)
{
/// \todo
MWBase::Environment::get().getWindowManager()->setGuiMode(GM_Game);
setVisible(false);
}
}
void ContainerWindow::onSelectedItem(MyGUI::Widget* _sender)
{ {
if(!mDragAndDrop->mIsOnDragAndDrop) if(!mDragAndDrop->mIsOnDragAndDrop)
{ {
@ -221,22 +67,13 @@ void ContainerWindow::onSelectedItem(MyGUI::Widget* _sender)
//std::cout << mContainerWidget->getParent()->getParent()->getName(); //std::cout << mContainerWidget->getParent()->getParent()->getName();
_sender->setUserString("drag","on"); _sender->setUserString("drag","on");
mDragAndDrop->mDraggedWidget = _sender; mDragAndDrop->mDraggedWidget = _sender;
mDragAndDrop->mContainerWindow = const_cast<MWGui::ContainerWindow*>(this); mDragAndDrop->mContainerWindow = const_cast<MWGui::ContainerBase*>(this);
drawItems(); drawItems();
std::cout << "selected!"; std::cout << "selected!";
} }
} }
void ContainerWindow::onMouseMove(MyGUI::Widget* _sender, int _left, int _top) void ContainerBase::onContainerClicked(MyGUI::Widget* _sender)
{
/*if(_sender->getUserString("drag") == "on")
{
_sender->setPosition(_left,_top);
}*/
}
void ContainerWindow::onContainerClicked(MyGUI::Widget* _sender)
{ {
std::cout << "container clicked"; std::cout << "container clicked";
if(mDragAndDrop->mIsOnDragAndDrop) //drop widget here if(mDragAndDrop->mIsOnDragAndDrop) //drop widget here
@ -255,3 +92,124 @@ void ContainerWindow::onContainerClicked(MyGUI::Widget* _sender)
drawItems(); drawItems();
} }
} }
void ContainerBase::onWindowResize(MyGUI::Window* window)
{
}
void ContainerBase::setName(std::string contName)
{
setText("_Main", contName);
adjustWindowCaption();
}
void ContainerBase::open(MWWorld::Ptr container)
{
mContainer = container;
setName(MWWorld::Class::get(container).getName(container));
drawItems();
setVisible(true);
}
void ContainerBase::drawItems()
{
while (mContainerWidget->getChildCount())
{
MyGUI::Gui::getInstance().destroyWidget(mContainerWidget->getChildAt(0));
}
MWWorld::ContainerStore& containerStore = MWWorld::Class::get(mContainer).getContainerStore(mContainer);
int x = 4;
int y = 4;
int count = 0;
int index = 0;
for (MWWorld::ContainerStoreIterator iter (containerStore.begin()); iter!=containerStore.end(); ++iter)
{
index++;
if(iter->getRefData().getCount() > 0)
{
count++;
std::string path = std::string("icons\\");
path+=MWWorld::Class::get(*iter).getInventoryIcon(*iter);
ItemWidget* image = mContainerWidget->createWidget<ItemWidget>("ImageBox", MyGUI::IntCoord(x, y, 32, 32), MyGUI::Align::Default);
MyGUI::TextBox* text = image->createWidget<MyGUI::TextBox>("SandBrightText", MyGUI::IntCoord(x, y, 18, 18), MyGUI::Align::Default, std::string("Label"));
image->eventMouseButtonClick += MyGUI::newDelegate(this,&ContainerBase::onSelectedItem);
image->mPos = index;
image->mPtr = *iter;
x += 36;
if(count % 20 == 0)
{
y += 36;
x = 4;
count = 0;
}
if(iter->getRefData().getCount() > 1)
text->setCaption(boost::lexical_cast<std::string>(iter->getRefData().getCount()));
int pos = path.rfind(".");
path.erase(pos);
path.append(".dds");
image->setImageTexture(path);
}
}
}
void ContainerBase::Update()
{
if(mDragAndDrop->mIsOnDragAndDrop)
{
if(mDragAndDrop->mDraggedWidget)
mDragAndDrop->mDraggedWidget->setPosition(MyGUI::InputManager::getInstance().getMousePosition());
else mDragAndDrop->mIsOnDragAndDrop = false; //If this happens, there is a bug.
}
}
// ------------------------------------------------------------------------------------------------
ContainerWindow::ContainerWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop)
: ContainerBase(parWindowManager, dragAndDrop, "openmw_container_window_layout.xml")
{
getWidget(mTakeButton, "TakeButton");
getWidget(mCloseButton, "CloseButton");
mCloseButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onCloseButtonClicked);
mTakeButton->eventMouseButtonClick += MyGUI::newDelegate(this, &ContainerWindow::onTakeAllButtonClicked);
setText("CloseButton", MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sClose")->str);
setText("TakeButton", MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sTakeAll")->str);
// adjust buttons size to fit text
int closeButtonWidth = mCloseButton->getTextSize().width+24;
int takeButtonWidth = mTakeButton->getTextSize().width+24;
mCloseButton->setCoord(600-20-closeButtonWidth, mCloseButton->getCoord().top, closeButtonWidth, mCloseButton->getCoord().height);
mTakeButton->setCoord(600-20-closeButtonWidth-takeButtonWidth-8, mTakeButton->getCoord().top, takeButtonWidth, mTakeButton->getCoord().height);
int w = MyGUI::RenderManager::getInstance().getViewSize().width;
int h = MyGUI::RenderManager::getInstance().getViewSize().height;
setCoord(w-600,h-300,600,300);
}
ContainerWindow::~ContainerWindow()
{
}
void ContainerWindow::onCloseButtonClicked(MyGUI::Widget* _sender)
{
if(!mDragAndDrop->mIsOnDragAndDrop)
{
MWBase::Environment::get().getWindowManager()->setGuiMode(GM_Game);
setVisible(false);
}
}
void ContainerWindow::onTakeAllButtonClicked(MyGUI::Widget* _sender)
{
if(!mDragAndDrop->mIsOnDragAndDrop)
{
/// \todo
MWBase::Environment::get().getWindowManager()->setGuiMode(GM_Game);
setVisible(false);
}
}

View file

@ -27,6 +27,7 @@ namespace MWGui
{ {
class WindowManager; class WindowManager;
class ContainerWindow; class ContainerWindow;
class ContainerBase;
} }
@ -36,44 +37,55 @@ namespace MWGui
{ {
public: public:
bool mIsOnDragAndDrop; bool mIsOnDragAndDrop;
ContainerWindow* mContainerWindow; ContainerBase* mContainerWindow;
MyGUI::Widget* mDraggedWidget; MyGUI::Widget* mDraggedWidget;
MyGUI::Widget* mDragAndDropWidget; MyGUI::Widget* mDragAndDropWidget;
MWWorld::ContainerStore mStore; MWWorld::ContainerStore mStore;
MWWorld::Ptr mItem; MWWorld::Ptr mItem;
}; };
class ContainerWindow : public WindowBase class ContainerBase : public WindowBase
{ {
public: public:
ContainerWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop); ContainerBase(WindowManager& parWindowManager, DragAndDrop* dragAndDrop, std::string guiFile);
ContainerWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop, virtual ~ContainerBase();
std::string guiFile);
void open(MWWorld::Ptr container); void open(MWWorld::Ptr container);
void setName(std::string contName); void setName(std::string contName);
void Update(); void Update();
protected:
MyGUI::ScrollView* mItemView;
MyGUI::Widget* mContainerWidget;
DragAndDrop* mDragAndDrop;
MWWorld::Ptr mContainer;
void onSelectedItem(MyGUI::Widget* _sender);
void onContainerClicked(MyGUI::Widget* _sender);
void onWindowResize(MyGUI::Window* window);
void drawItems();
};
class ContainerWindow : public ContainerBase
{
public:
ContainerWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop);
virtual ~ContainerWindow(); virtual ~ContainerWindow();
protected: protected:
std::vector<MyGUI::WidgetPtr> mContainerWidgets; std::vector<MyGUI::WidgetPtr> mContainerWidgets;
MyGUI::ItemBoxPtr mContainerWidget;
MyGUI::ButtonPtr mTakeButton; MyGUI::Button* mTakeButton;
MyGUI::ButtonPtr mCloseButton; MyGUI::Button* mCloseButton;
DragAndDrop* mDragAndDrop;
MWWorld::Ptr mContainer;
bool mIsValid;//is in the right GUI Mode bool mIsValid;//is in the right GUI Mode
void drawItems();
void onCloseButtonClicked(MyGUI::Widget* _sender); void onCloseButtonClicked(MyGUI::Widget* _sender);
void onTakeAllButtonClicked(MyGUI::Widget* _sender); void onTakeAllButtonClicked(MyGUI::Widget* _sender);
void onSelectedItem(MyGUI::Widget* _sender);
void onContainerClicked(MyGUI::Widget* _sender);
void onMouseMove(MyGUI::Widget* _sender, int _left, int _top);
}; };
} }
#endif // CONTAINER_H #endif // CONTAINER_H

View file

@ -22,7 +22,7 @@ namespace MWGui
{ {
InventoryWindow::InventoryWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop) InventoryWindow::InventoryWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop)
:ContainerWindow(parWindowManager,dragAndDrop,"openmw_inventory_window_layout.xml") : ContainerBase(parWindowManager,dragAndDrop,"openmw_inventory_window_layout.xml")
{ {
} }

View file

@ -21,7 +21,7 @@ namespace MWGui
namespace MWGui namespace MWGui
{ {
class InventoryWindow : public MWGui::ContainerWindow class InventoryWindow : public MWGui::ContainerBase
{ {
public: public:
InventoryWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop); InventoryWindow(WindowManager& parWindowManager,DragAndDrop* dragAndDrop);

View file

@ -3,8 +3,13 @@
<MyGUI type="Layout"> <MyGUI type="Layout">
<Widget type="Window" skin="MW_Window" layer="Windows" position="900 500 600 300" name="_Main"> <Widget type="Window" skin="MW_Window" layer="Windows" position="900 500 600 300" name="_Main">
<!-- Items in inventory --> <!-- Items -->
<Widget type="ItemBox" skin="MW_Box" position="5 10 570 220" name="Items"/> <Widget type="Widget" skin="MW_Box" position="5 10 570 220" name="box" align="Left Top Stretch">
<Widget type="ScrollView" skin="MW_ScrollView" position="4 4 566 216" name="ItemView" align="Left Top Stretch">
<Property key="CanvasSize" value="1024 1024"/>
<Widget type="Button" skin="" name="Items" position="0 0 566 216" name="Items" align="Left Top Stretch"/>
</Widget>
</Widget>
<!-- buttons position adjusted at runtime to fit text --> <!-- buttons position adjusted at runtime to fit text -->
<Widget type="Button" skin="MW_Button" position="0 235 75 24" name="TakeButton" align="Right Bottom"/> <Widget type="Button" skin="MW_Button" position="0 235 75 24" name="TakeButton" align="Right Bottom"/>

View file

@ -3,7 +3,7 @@
<MyGUI type="Layout"> <MyGUI type="Layout">
<Widget type="Window" skin="MW_Window" layer="Windows" position="0 0 600 300" name="_Main"> <Widget type="Window" skin="MW_Window" layer="Windows" position="0 0 600 300" name="_Main">
<!-- Player enumbrance --> <!-- Player encumbrance -->
<Widget type="ProgressBar" skin="MW_Progress_Blue" position="8 8 212 18" name="EncumbranceBar"> <Widget type="ProgressBar" skin="MW_Progress_Blue" position="8 8 212 18" name="EncumbranceBar">
<Widget type="TextBox" skin="ProgressText" position="0 0 212 18" align="Center" name="EncumbranceBarT"/> <Widget type="TextBox" skin="ProgressText" position="0 0 212 18" align="Center" name="EncumbranceBarT"/>
</Widget> </Widget>
@ -14,7 +14,12 @@
</Widget> </Widget>
<!-- Items in inventory --> <!-- Items in inventory -->
<Widget type="ItemBox" skin="MW_Box" position="228 32 300 166" name="Items"/> <Widget type="Widget" skin="MW_Box" position="228 32 300 215" name="box" align="Left Top Stretch">
<Widget type="ScrollView" skin="MW_ScrollView" position="4 4 296 211" align="Left Top Stretch" name="ItemView">
<Property key="CanvasSize" value="1024 1024"/>
<Widget type="Button" skin="" name="Items" position="0 0 296 211" name="Items" align="Left Top Stretch"/>
</Widget>
</Widget>
<!-- Categories --> <!-- Categories -->
<Widget type="Widget" position="228 8 300 18" align="ALIGN_TOP ALIGN_LEFT" name="Categories"> <Widget type="Widget" position="228 8 300 18" align="ALIGN_TOP ALIGN_LEFT" name="Categories">

View file

@ -4,7 +4,6 @@
<Skin name="MW_ScrollView" size="516 516" texture="mwgui.png"> <Skin name="MW_ScrollView" size="516 516" texture="mwgui.png">
<Child type="Widget" skin="" offset="0 0 516 516" align="Stretch" name="Client"/> <Child type="Widget" skin="" offset="0 0 516 516" align="Stretch" name="Client"/>
<Child type="ScrollBar" skin="MW_VScroll" offset="498 3 14 509" align="ALIGN_RIGHT ALIGN_VSTRETCH" name="VScroll"/> <Child type="ScrollBar" skin="MW_VScroll" offset="498 3 14 509" align="ALIGN_RIGHT ALIGN_VSTRETCH" name="VScroll"/>
</Skin> </Skin>