mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-31 19:45:32 +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 "countdialog.hpp"
|
||||
#include "dialogue.hpp"
|
||||
#include "controllers.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
@ -44,8 +45,6 @@ namespace MWGui
|
|||
TradeWindow::TradeWindow()
|
||||
: WindowBase("openmw_trade_window.layout")
|
||||
, mCurrentBalance(0)
|
||||
, mBalanceButtonsState(BBS_None)
|
||||
, mBalanceChangePause(0.0)
|
||||
, mItemToSell(-1)
|
||||
, mTradeModel(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)
|
||||
{
|
||||
TradeItemModel* playerItemModel = MWBase::Environment::get().getWindowManager()->getInventoryWindow()->getTradeModel();
|
||||
|
@ -407,23 +391,38 @@ namespace MWGui
|
|||
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)
|
||||
{
|
||||
mBalanceButtonsState = BBS_Increase;
|
||||
mBalanceChangePause = sBalanceChangeInitialPause;
|
||||
addRepeatController(_sender);
|
||||
onIncreaseButtonTriggered();
|
||||
}
|
||||
|
||||
void TradeWindow::onDecreaseButtonPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id)
|
||||
{
|
||||
mBalanceButtonsState = BBS_Decrease;
|
||||
mBalanceChangePause = sBalanceChangeInitialPause;
|
||||
addRepeatController(_sender);
|
||||
onDecreaseButtonTriggered();
|
||||
}
|
||||
|
||||
void TradeWindow::onRepeatClick(MyGUI::Widget* widget, MyGUI::ControllerItem* controller)
|
||||
{
|
||||
if (widget == mIncreaseButton)
|
||||
onIncreaseButtonTriggered();
|
||||
else if (widget == mDecreaseButton)
|
||||
onDecreaseButtonTriggered();
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
|
@ -28,8 +28,6 @@ namespace MWGui
|
|||
|
||||
void startTrade(const MWWorld::Ptr& actor);
|
||||
|
||||
void onFrame(float frameDuration);
|
||||
|
||||
void borrowItem (int index, size_t count);
|
||||
void returnItem (int index, size_t count);
|
||||
|
||||
|
@ -71,14 +69,6 @@ namespace MWGui
|
|||
int mCurrentBalance;
|
||||
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 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 onBalanceButtonReleased(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id);
|
||||
void onBalanceEdited(MyGUI::EditBox* _sender);
|
||||
void onRepeatClick(MyGUI::Widget* widget, MyGUI::ControllerItem* controller);
|
||||
|
||||
void addRepeatController(MyGUI::Widget* widget);
|
||||
|
||||
void onIncreaseButtonTriggered();
|
||||
void onDecreaseButtonTriggered();
|
||||
|
|
|
@ -848,7 +848,6 @@ namespace MWGui
|
|||
mHud->onFrame(frameDuration);
|
||||
|
||||
mTrainingWindow->onFrame (frameDuration);
|
||||
mTradeWindow->onFrame(frameDuration);
|
||||
|
||||
mTrainingWindow->checkReferenceAvailable();
|
||||
mDialogueWindow->checkReferenceAvailable();
|
||||
|
|
Loading…
Reference in a new issue