46protocol::TradeOffer
OfferOf(
const protocol::TradeSide& side) {
47 protocol::TradeOffer offer;
48 const std::vector<uint32_t> places = PlacesOf(side);
49 offer.mutable_bag()->Add(places.begin(), places.end());
50 offer.set_gold(side.gold());
55 const protocol::Trade& trade) {
56 if (trade.partner().empty()) {
60 const protocol::TradeSide& yours = trade.yours();
61 const protocol::TradeSide& theirs = trade.theirs();
62 const char* partner = trade.partner().c_str();
63 std::optional<protocol::TradeAction> action;
64 const ImVec2 display = ImGui::GetIO().DisplaySize;
65 ImGui::SetNextWindowPos({display.x * 0.5f, display.y * 0.45f},
66 ImGuiCond_FirstUseEver, {0.5f, 0.5f});
69 const std::string title =
70 absl::StrCat(absl::Substitute(
Tr(
"Trade with $0"), partner),
"###Trade");
72 ImGuiWindowFlags_AlwaysAutoResize |
73 ImGuiWindowFlags_NoSavedSettings)) {
74 const float slot =
Ui(kSlot);
75 ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing,
Ui(ImVec2{5.0f, 5.0f}));
79 protocol::TradeOffer offer =
OfferOf(yours);
81 const std::vector<uint32_t> offered = PlacesOf(yours);
83 ImGui::TextUnformatted(
Tr(
"You offer"));
84 for (std::size_t i = 0; i < SlotsFor(offered.size()); ++i) {
85 if (i % kColumns != 0) {
88 ImGui::PushID(
static_cast<int>(i));
89 const items::Stack* stack =
90 i < offered.size() ? &yours.bag().at(offered[i]) :
nullptr;
94 for (
const uint32_t place : offered) {
95 if (place != offered[i]) {
101 if (ImGui::BeginDragDropTarget()) {
102 if (
const std::optional<protocol::Place> from =
AcceptItem();
103 from && from->has_bag() && !yours.bag().contains(from->bag())) {
104 offer.add_bag(from->bag());
107 ImGui::EndDragDropTarget();
113 gold_ = yours.gold();
115 ImGui::TextColored(ImGui::ColorConvertU32ToFloat4(
colors::kGold),
118 ImGui::SetNextItemWidth(
Ui(110.0f));
119 ImGui::InputScalar(
TrLabel(
"gold##yours"), ImGuiDataType_U32, &gold_);
120 typing_ = ImGui::IsItemActive();
121 if (ImGui::IsItemDeactivatedAfterEdit()) {
122 offer.set_gold(gold_);
127 *action.emplace().mutable_offer() = offer;
131 ImGui::SameLine(0.0f,
Ui(kBetween));
133 ImGui::TextUnformatted(absl::Substitute(
Tr(
"$0 offers"), partner).c_str());
134 const std::vector<uint32_t> places = PlacesOf(theirs);
135 for (std::size_t i = 0; i < SlotsFor(places.size()); ++i) {
136 if (i % kColumns != 0) {
139 ImGui::PushID(
static_cast<int>(100 + i));
141 i < places.size() ? &theirs.bag().at(places[i]) :
nullptr, slot,
146 ImGui::ColorConvertU32ToFloat4(
colors::kGold), ICON_FA_COINS
" %s",
147 absl::Substitute(
TrN(
"$0 gold",
"$0 gold", theirs.gold()),
151 ImGui::PopStyleVar();
154 if (
GameButton(yours.ready() ?
"Not ready" :
"Ready", {Ui(150.0f), 0.0f},
156 action.emplace().set_ready(!yours.ready());
157 action->set_revision(trade.revision());
160 if (theirs.ready()) {
161 ImGui::TextColored(ImGui::ColorConvertU32ToFloat4(
colors::kGood),
"%s",
162 absl::Substitute(
Tr(
"$0 is ready."), partner).c_str());
165 "%s", absl::Substitute(
Tr(
"$0 isn't ready yet."), partner).c_str());
170 action.emplace().set_cancel(
true);
const char * TrN(const char *one, const char *many, uint64_t n)
The form for the count: in English, one for 1 and many for the rest.