MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / updateValues

Method updateValues

game/ui/general/transactioncontrol.cpp:93–153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

91}
92
93void TransactionControl::updateValues()
94{
95 if (scrollBar->getMaximum() != 0)
96 {
97 if (manufacturerHostile || manufacturerUnavailable)
98 {
99 int defaultRightStock = tradeState.getRightStock();
100 if ((tradeState.getLeftIndex() == ECONOMY_IDX &&
101 scrollBar->getValue() > defaultRightStock) ||
102 (tradeState.getRightIndex() == ECONOMY_IDX &&
103 scrollBar->getValue() < defaultRightStock))
104 {
105 tradeState.cancelOrder();
106 scrollBar->setValue(tradeState.getBalance());
107
108 auto message_box = mksp<MessageBox>(
109 manufacturerName,
110 manufacturerHostile ? tr("Order canceled by the hostile manufacturer.")
111 : tr("Manufacturer has no intact buildings in this city to "
112 "deliver goods from."),
113 MessageBox::ButtonOptions::Ok);
114 fw().stageQueueCommand({StageCmd::Command::PUSH, message_box});
115 return;
116 }
117 }
118
119 // TODO: remove linked
120 if (tradeState.getBalance() != scrollBar->getValue())
121 {
122 tradeState.setBalance(scrollBar->getValue());
123 if (linked)
124 {
125 for (auto &c : *linked)
126 {
127 if (auto c_sp = c.lock())
128 {
129 c_sp->suspendUpdates = true;
130 c_sp->scrollBar->setValue(scrollBar->getValue());
131 c_sp->updateValues();
132 c_sp->suspendUpdates = false;
133 }
134 }
135 }
136 if (!suspendUpdates)
137 {
138 this->pushFormEvent(FormEventType::ScrollBarChange, nullptr);
139 }
140 }
141 }
142
143 int curDeltaRight = tradeState.getLROrder();
144 int curDeltaLeft = -curDeltaRight;
145
146 stockLeft->setText(format("%d", tradeState.getLeftStock(true)));
147 stockRight->setText(format("%d", tradeState.getRightStock(true)));
148 deltaLeft->setText(format("%s%d", curDeltaLeft > 0 ? "+" : "", curDeltaLeft));
149 deltaRight->setText(format("%s%d", curDeltaRight > 0 ? "+" : "", curDeltaRight));
150 deltaLeft->setVisible(tradeState.getLeftIndex() != ECONOMY_IDX && curDeltaLeft != 0);

Callers 2

setupCallbacksMethod · 0.95
linkMethod · 0.80

Calls 15

trFunction · 0.85
formatFunction · 0.85
getMaximumMethod · 0.80
getRightStockMethod · 0.80
getBalanceMethod · 0.80
stageQueueCommandMethod · 0.80
setBalanceMethod · 0.80
pushFormEventMethod · 0.80
getLROrderMethod · 0.80
getLeftStockMethod · 0.80
getLeftIndexMethod · 0.45
getValueMethod · 0.45

Tested by

no test coverage detected