mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-21 09:53:50 +00:00
Refactor TradeWindow balance buttons to use ControllerRepeatClick
This commit is contained in:
parent
ebab911e44
commit
7fa3100993
3 changed files with 24 additions and 33 deletions
|
@ -22,6 +22,7 @@
|
||||||
#include "tradeitemmodel.hpp"
|
#include "tradeitemmodel.hpp"
|
||||||
#include "countdialog.hpp"
|
#include "countdialog.hpp"
|
||||||
#include "dialogue.hpp"
|
#include "dialogue.hpp"
|
||||||
|
#include "controllers.hpp"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
@ -44,8 +45,6 @@ namespace MWGui
|
||||||
TradeWindow::TradeWindow()
|
TradeWindow::TradeWindow()
|
||||||
: WindowBase("openmw_trade_window.layout")
|
: WindowBase("openmw_trade_window.layout")
|
||||||
, mCurrentBalance(0)
|
, mCurrentBalance(0)
|
||||||
, mBalanceButtonsState(BBS_None)
|
|
||||||
, mBalanceChangePause(0.0)
|
|
||||||
, mItemToSell(-1)
|
, mItemToSell(-1)
|
||||||
, mTradeModel(NULL)
|
, mTradeModel(NULL)
|
||||||
, mSortModel(NULL)
|
, mSortModel(NULL)
|
||||||
|
@ -240,21 +239,6 @@ namespace MWGui
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TradeWindow::onFrame(float frameDuration)
|
|
||||||
{
|
|
||||||
if (!mMainWidget->getVisible() || mBalanceButtonsState == BBS_None)
|
|
||||||
return;
|
|
||||||
|
|
||||||
mBalanceChangePause -= frameDuration;
|
|
||||||
if (mBalanceChangePause < 0.0) {
|
|
||||||
mBalanceChangePause += sBalanceChangeInterval;
|
|
||||||
if (mBalanceButtonsState == BBS_Increase)
|
|
||||||
onIncreaseButtonTriggered();
|
|
||||||
else if (mBalanceButtonsState == BBS_Decrease)
|
|
||||||
onDecreaseButtonTriggered();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void TradeWindow::onOfferButtonClicked(MyGUI::Widget* _sender)
|
void TradeWindow::onOfferButtonClicked(MyGUI::Widget* _sender)
|
||||||
{
|
{
|
||||||
TradeItemModel* playerItemModel = MWBase::Environment::get().getWindowManager()->getInventoryWindow()->getTradeModel();
|
TradeItemModel* playerItemModel = MWBase::Environment::get().getWindowManager()->getInventoryWindow()->getTradeModel();
|
||||||
|
@ -407,23 +391,38 @@ namespace MWGui
|
||||||
updateLabels();
|
updateLabels();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TradeWindow::addRepeatController(MyGUI::Widget *widget)
|
||||||
|
{
|
||||||
|
MyGUI::ControllerItem* item = MyGUI::ControllerManager::getInstance().createItem(Controllers::ControllerRepeatClick::getClassTypeName());
|
||||||
|
Controllers::ControllerRepeatClick* controller = item->castType<Controllers::ControllerRepeatClick>();
|
||||||
|
controller->eventRepeatClick += MyGUI::newDelegate(this, &TradeWindow::onRepeatClick);
|
||||||
|
controller->setRepeat(sBalanceChangeInitialPause, sBalanceChangeInterval);
|
||||||
|
MyGUI::ControllerManager::getInstance().addItem(widget, controller);
|
||||||
|
}
|
||||||
|
|
||||||
void TradeWindow::onIncreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id)
|
void TradeWindow::onIncreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id)
|
||||||
{
|
{
|
||||||
mBalanceButtonsState = BBS_Increase;
|
addRepeatController(_sender);
|
||||||
mBalanceChangePause = sBalanceChangeInitialPause;
|
|
||||||
onIncreaseButtonTriggered();
|
onIncreaseButtonTriggered();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TradeWindow::onDecreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id)
|
void TradeWindow::onDecreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id)
|
||||||
{
|
{
|
||||||
mBalanceButtonsState = BBS_Decrease;
|
addRepeatController(_sender);
|
||||||
mBalanceChangePause = sBalanceChangeInitialPause;
|
onDecreaseButtonTriggered();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TradeWindow::onRepeatClick(MyGUI::Widget* widget, MyGUI::ControllerItem* controller)
|
||||||
|
{
|
||||||
|
if (widget == mIncreaseButton)
|
||||||
|
onIncreaseButtonTriggered();
|
||||||
|
else if (widget == mDecreaseButton)
|
||||||
onDecreaseButtonTriggered();
|
onDecreaseButtonTriggered();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TradeWindow::onBalanceButtonReleased(MyGUI::Widget *_sender, int _left, int _top, MyGUI::MouseButton _id)
|
void TradeWindow::onBalanceButtonReleased(MyGUI::Widget *_sender, int _left, int _top, MyGUI::MouseButton _id)
|
||||||
{
|
{
|
||||||
mBalanceButtonsState = BBS_None;
|
MyGUI::ControllerManager::getInstance().removeItem(_sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TradeWindow::onBalanceEdited(MyGUI::EditBox *_sender)
|
void TradeWindow::onBalanceEdited(MyGUI::EditBox *_sender)
|
||||||
|
|
|
@ -28,8 +28,6 @@ namespace MWGui
|
||||||
|
|
||||||
void startTrade(const MWWorld::Ptr& actor);
|
void startTrade(const MWWorld::Ptr& actor);
|
||||||
|
|
||||||
void onFrame(float frameDuration);
|
|
||||||
|
|
||||||
void borrowItem (int index, size_t count);
|
void borrowItem (int index, size_t count);
|
||||||
void returnItem (int index, size_t count);
|
void returnItem (int index, size_t count);
|
||||||
|
|
||||||
|
@ -71,14 +69,6 @@ namespace MWGui
|
||||||
int mCurrentBalance;
|
int mCurrentBalance;
|
||||||
int mCurrentMerchantOffer;
|
int mCurrentMerchantOffer;
|
||||||
|
|
||||||
enum BalanceButtonsState {
|
|
||||||
BBS_None,
|
|
||||||
BBS_Increase,
|
|
||||||
BBS_Decrease
|
|
||||||
} mBalanceButtonsState;
|
|
||||||
/// pause before next balance change will trigger while user holds +/- button pressed
|
|
||||||
float mBalanceChangePause;
|
|
||||||
|
|
||||||
void sellToNpc(const MWWorld::Ptr& item, int count, bool boughtItem); ///< only used for adjusting the gold balance
|
void sellToNpc(const MWWorld::Ptr& item, int count, bool boughtItem); ///< only used for adjusting the gold balance
|
||||||
void buyFromNpc(const MWWorld::Ptr& item, int count, bool soldItem); ///< only used for adjusting the gold balance
|
void buyFromNpc(const MWWorld::Ptr& item, int count, bool soldItem); ///< only used for adjusting the gold balance
|
||||||
|
|
||||||
|
@ -93,6 +83,9 @@ namespace MWGui
|
||||||
void onDecreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id);
|
void onDecreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id);
|
||||||
void onBalanceButtonReleased(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id);
|
void onBalanceButtonReleased(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id);
|
||||||
void onBalanceEdited(MyGUI::EditBox* _sender);
|
void onBalanceEdited(MyGUI::EditBox* _sender);
|
||||||
|
void onRepeatClick(MyGUI::Widget* widget, MyGUI::ControllerItem* controller);
|
||||||
|
|
||||||
|
void addRepeatController(MyGUI::Widget* widget);
|
||||||
|
|
||||||
void onIncreaseButtonTriggered();
|
void onIncreaseButtonTriggered();
|
||||||
void onDecreaseButtonTriggered();
|
void onDecreaseButtonTriggered();
|
||||||
|
|
|
@ -848,7 +848,6 @@ namespace MWGui
|
||||||
mHud->onFrame(frameDuration);
|
mHud->onFrame(frameDuration);
|
||||||
|
|
||||||
mTrainingWindow->onFrame (frameDuration);
|
mTrainingWindow->onFrame (frameDuration);
|
||||||
mTradeWindow->onFrame(frameDuration);
|
|
||||||
|
|
||||||
mTrainingWindow->checkReferenceAvailable();
|
mTrainingWindow->checkReferenceAvailable();
|
||||||
mDialogueWindow->checkReferenceAvailable();
|
mDialogueWindow->checkReferenceAvailable();
|
||||||
|
|
Loading…
Reference in a new issue