| 91 | } |
| 92 | |
| 93 | void 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); |
no test coverage detected