forked from teamnwah/openmw-tes3coop
Merge branch 'master' into master
commit
065bf47e38
@ -1,10 +1,11 @@
|
||||
#!/bin/sh
|
||||
|
||||
brew update
|
||||
|
||||
brew rm cmake || true
|
||||
brew rm pkgconfig || true
|
||||
brew rm qt5 || true
|
||||
brew install cmake pkgconfig qt5
|
||||
brew install cmake pkgconfig qt55
|
||||
|
||||
curl http://downloads.openmw.org/osx/dependencies/openmw-deps-263d4a8.zip -o ~/openmw-deps.zip
|
||||
unzip ~/openmw-deps.zip -d /private/tmp/openmw-deps > /dev/null
|
||||
|
@ -0,0 +1,212 @@
|
||||
#include "itemchargeview.hpp"
|
||||
|
||||
#include <set>
|
||||
|
||||
#include <MyGUI_Gui.h>
|
||||
#include <MyGUI_TextBox.h>
|
||||
#include <MyGUI_ScrollView.h>
|
||||
#include <MyGUI_FactoryManager.h>
|
||||
|
||||
#include <components/esm/loadench.hpp>
|
||||
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/world.hpp"
|
||||
|
||||
#include "../mwworld/class.hpp"
|
||||
#include "../mwworld/esmstore.hpp"
|
||||
|
||||
#include "itemmodel.hpp"
|
||||
#include "itemwidget.hpp"
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
ItemChargeView::ItemChargeView()
|
||||
: mScrollView(NULL),
|
||||
mDisplayMode(DisplayMode_Health)
|
||||
{
|
||||
}
|
||||
|
||||
void ItemChargeView::registerComponents()
|
||||
{
|
||||
MyGUI::FactoryManager::getInstance().registerFactory<ItemChargeView>("Widget");
|
||||
}
|
||||
|
||||
void ItemChargeView::initialiseOverride()
|
||||
{
|
||||
Base::initialiseOverride();
|
||||
|
||||
assignWidget(mScrollView, "ScrollView");
|
||||
if (mScrollView == NULL)
|
||||
throw std::runtime_error("Item charge view needs a scroll view");
|
||||
|
||||
mScrollView->setCanvasAlign(MyGUI::Align::Left | MyGUI::Align::Top);
|
||||
}
|
||||
|
||||
void ItemChargeView::setModel(ItemModel* model)
|
||||
{
|
||||
mModel.reset(model);
|
||||
}
|
||||
|
||||
void ItemChargeView::setDisplayMode(ItemChargeView::DisplayMode type)
|
||||
{
|
||||
mDisplayMode = type;
|
||||
update();
|
||||
}
|
||||
|
||||
void ItemChargeView::update()
|
||||
{
|
||||
if (!mModel.get())
|
||||
{
|
||||
layoutWidgets();
|
||||
return;
|
||||
}
|
||||
|
||||
mModel->update();
|
||||
|
||||
Lines lines;
|
||||
std::set<Lines::const_iterator> visitedLines;
|
||||
|
||||
for (size_t i = 0; i < mModel->getItemCount(); ++i)
|
||||
{
|
||||
ItemStack stack = mModel->getItem(static_cast<ItemModel::ModelIndex>(i));
|
||||
|
||||
bool found = false;
|
||||
for (Lines::const_iterator iter = mLines.begin(); iter != mLines.end(); ++iter)
|
||||
{
|
||||
if (iter->mItemPtr == stack.mBase)
|
||||
{
|
||||
found = true;
|
||||
visitedLines.insert(iter);
|
||||
|
||||
// update line widgets
|
||||
updateLine(*iter);
|
||||
lines.push_back(*iter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
// add line widgets
|
||||
Line line;
|
||||
line.mItemPtr = stack.mBase;
|
||||
|
||||
line.mText = mScrollView->createWidget<MyGUI::TextBox>("SandText", MyGUI::IntCoord(), MyGUI::Align::Default);
|
||||
line.mText->setNeedMouseFocus(false);
|
||||
|
||||
line.mIcon = mScrollView->createWidget<ItemWidget>("MW_ItemIconSmall", MyGUI::IntCoord(), MyGUI::Align::Default);
|
||||
line.mIcon->setItem(line.mItemPtr);
|
||||
line.mIcon->setUserString("ToolTipType", "ItemPtr");
|
||||
line.mIcon->setUserData(line.mItemPtr);
|
||||
line.mIcon->eventMouseButtonClick += MyGUI::newDelegate(this, &ItemChargeView::onIconClicked);
|
||||
line.mIcon->eventMouseWheel += MyGUI::newDelegate(this, &ItemChargeView::onMouseWheelMoved);
|
||||
|
||||
line.mCharge = mScrollView->createWidget<Widgets::MWDynamicStat>("MW_ChargeBar", MyGUI::IntCoord(), MyGUI::Align::Default);
|
||||
line.mCharge->setNeedMouseFocus(false);
|
||||
|
||||
updateLine(line);
|
||||
|
||||
lines.push_back(line);
|
||||
}
|
||||
}
|
||||
|
||||
for (Lines::iterator iter = mLines.begin(); iter != mLines.end(); ++iter)
|
||||
{
|
||||
if (visitedLines.count(iter))
|
||||
continue;
|
||||
|
||||
// remove line widgets
|
||||
MyGUI::Gui::getInstance().destroyWidget(iter->mText);
|
||||
MyGUI::Gui::getInstance().destroyWidget(iter->mIcon);
|
||||
MyGUI::Gui::getInstance().destroyWidget(iter->mCharge);
|
||||
}
|
||||
|
||||
mLines.swap(lines);
|
||||
|
||||
layoutWidgets();
|
||||
}
|
||||
|
||||
void ItemChargeView::layoutWidgets()
|
||||
{
|
||||
int currentY = 0;
|
||||
|
||||
for (Lines::const_iterator iter = mLines.begin(); iter != mLines.end(); ++iter)
|
||||
{
|
||||
iter->mText->setCoord(8, currentY, mScrollView->getWidth()-8, 18);
|
||||
currentY += 19;
|
||||
|
||||
iter->mIcon->setCoord(16, currentY, 32, 32);
|
||||
iter->mCharge->setCoord(72, currentY+2, std::max(199, mScrollView->getWidth()-72-38), 20);
|
||||
currentY += 32 + 4;
|
||||
}
|
||||
|
||||
// Canvas size must be expressed with VScroll disabled, otherwise MyGUI would expand the scroll area when the scrollbar is hidden
|
||||
mScrollView->setVisibleVScroll(false);
|
||||
mScrollView->setCanvasSize(MyGUI::IntSize(mScrollView->getWidth(), std::max(mScrollView->getHeight(), currentY)));
|
||||
mScrollView->setVisibleVScroll(true);
|
||||
}
|
||||
|
||||
void ItemChargeView::resetScrollbars()
|
||||
{
|
||||
mScrollView->setViewOffset(MyGUI::IntPoint(0, 0));
|
||||
}
|
||||
|
||||
void ItemChargeView::setSize(const MyGUI::IntSize& value)
|
||||
{
|
||||
bool changed = (value.width != getWidth() || value.height != getHeight());
|
||||
Base::setSize(value);
|
||||
if (changed)
|
||||
layoutWidgets();
|
||||
}
|
||||
|
||||
void ItemChargeView::setCoord(const MyGUI::IntCoord& value)
|
||||
{
|
||||
bool changed = (value.width != getWidth() || value.height != getHeight());
|
||||
Base::setCoord(value);
|
||||
if (changed)
|
||||
layoutWidgets();
|
||||
}
|
||||
|
||||
void ItemChargeView::updateLine(const ItemChargeView::Line& line)
|
||||
{
|
||||
line.mText->setCaption(line.mItemPtr.getClass().getName(line.mItemPtr));
|
||||
|
||||
line.mCharge->setVisible(false);
|
||||
switch (mDisplayMode)
|
||||
{
|
||||
case DisplayMode_Health:
|
||||
if (!line.mItemPtr.getClass().hasItemHealth(line.mItemPtr))
|
||||
break;
|
||||
|
||||
line.mCharge->setVisible(true);
|
||||
line.mCharge->setValue(line.mItemPtr.getClass().getItemHealth(line.mItemPtr),
|
||||
line.mItemPtr.getClass().getItemMaxHealth(line.mItemPtr));
|
||||
break;
|
||||
case DisplayMode_EnchantmentCharge:
|
||||
std::string enchId = line.mItemPtr.getClass().getEnchantment(line.mItemPtr);
|
||||
if (enchId.empty())
|
||||
break;
|
||||
const ESM::Enchantment* ench = MWBase::Environment::get().getWorld()->getStore().get<ESM::Enchantment>().search(enchId);
|
||||
if (!ench)
|
||||
break;
|
||||
|
||||
line.mCharge->setVisible(true);
|
||||
line.mCharge->setValue(static_cast<int>(line.mItemPtr.getCellRef().getEnchantmentCharge()),
|
||||
ench->mData.mCharge);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ItemChargeView::onIconClicked(MyGUI::Widget* sender)
|
||||
{
|
||||
eventItemClicked(this, *sender->getUserData<MWWorld::Ptr>());
|
||||
}
|
||||
|
||||
void ItemChargeView::onMouseWheelMoved(MyGUI::Widget* /*sender*/, int rel)
|
||||
{
|
||||
if (mScrollView->getViewOffset().top + rel*0.3f > 0)
|
||||
mScrollView->setViewOffset(MyGUI::IntPoint(0, 0));
|
||||
else
|
||||
mScrollView->setViewOffset(MyGUI::IntPoint(0, static_cast<int>(mScrollView->getViewOffset().top + rel*0.3f)));
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
#ifndef MWGUI_ITEMCHARGEVIEW_H
|
||||
#define MWGUI_ITEMCHARGEVIEW_H
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#include <MyGUI_Widget.h>
|
||||
|
||||
#include "../mwworld/ptr.hpp"
|
||||
|
||||
#include "widgets.hpp"
|
||||
|
||||
namespace MyGUI
|
||||
{
|
||||
class TextBox;
|
||||
class ScrollView;
|
||||
}
|
||||
|
||||
namespace MWGui
|
||||
{
|
||||
class ItemModel;
|
||||
class ItemWidget;
|
||||
|
||||
class ItemChargeView : public MyGUI::Widget
|
||||
{
|
||||
MYGUI_RTTI_DERIVED(ItemChargeView)
|
||||
public:
|
||||
enum DisplayMode
|
||||
{
|
||||
DisplayMode_Health,
|
||||
DisplayMode_EnchantmentCharge
|
||||
};
|
||||
|
||||
ItemChargeView();
|
||||
|
||||
/// Register needed components with MyGUI's factory manager
|
||||
static void registerComponents();
|
||||
|
||||
virtual void initialiseOverride();
|
||||
|
||||
/// Takes ownership of \a model
|
||||
void setModel(ItemModel* model);
|
||||
|
||||
void setDisplayMode(DisplayMode type);
|
||||
|
||||
void update();
|
||||
void layoutWidgets();
|
||||
void resetScrollbars();
|
||||
|
||||
virtual void setSize(const MyGUI::IntSize& value);
|
||||
virtual void setCoord(const MyGUI::IntCoord& value);
|
||||
|
||||
MyGUI::delegates::CMultiDelegate2<MyGUI::Widget*, const MWWorld::Ptr&> eventItemClicked;
|
||||
|
||||
private:
|
||||
struct Line
|
||||
{
|
||||
MWWorld::Ptr mItemPtr;
|
||||
MyGUI::TextBox* mText;
|
||||
ItemWidget* mIcon;
|
||||
Widgets::MWDynamicStatPtr mCharge;
|
||||
};
|
||||
|
||||
void updateLine(const Line& line);
|
||||
|
||||
void onIconClicked(MyGUI::Widget* sender);
|
||||
void onMouseWheelMoved(MyGUI::Widget* sender, int rel);
|
||||
|
||||
typedef std::vector<Line> Lines;
|
||||
Lines mLines;
|
||||
|
||||
std::auto_ptr<ItemModel> mModel;
|
||||
MyGUI::ScrollView* mScrollView;
|
||||
DisplayMode mDisplayMode;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue