74 const std::vector<Figure>& figures,
const protocol::World& world,
75 const protocol::Inventory& bag) {
79 const auto you = std::ranges::find_if(figures, &
Figure::you);
80 if (you == figures.end() || you->level == 0) {
83 std::optional<protocol::ItemAction> action;
84 const ImVec2 display = ImGui::GetIO().DisplaySize;
85 ImGui::SetNextWindowPos({display.x * 0.3f, display.y * 0.5f},
86 ImGuiCond_FirstUseEver, {0.5f, 0.5f});
88 ImGuiWindowFlags_AlwaysAutoResize |
89 ImGuiWindowFlags_NoSavedSettings)) {
90 const float slot =
Ui(kSlot);
91 const float gap =
Ui(kGap);
92 const ImVec2 stage =
Ui(kStage);
93 const ImVec2 origin = ImGui::GetCursorScreenPos();
94 ImDrawList* draw = ImGui::GetWindowDrawList();
97 const ImVec2 stage_min{origin.x + slot + gap, origin.y};
98 const ImVec2 stage_max{stage_min.x + stage.x, stage_min.y + stage.y};
99 DrawStage(draw, stage_min, stage_max);
101 draw->AddImage(
static_cast<ImTextureID
>(preview_.texture().id), stage_min,
102 stage_max, {0.0f, 1.0f}, {1.0f, 0.0f});
104 const auto slots = [&](
auto column,
float x) {
105 for (std::size_t i = 0; i < column.size(); ++i) {
106 ImGui::SetCursorScreenPos(
107 {x, origin.y +
static_cast<float>(i) * (slot + gap)});
108 if (std::optional<protocol::ItemAction> done =
110 action = std::move(done);
114 slots(kLeft, origin.x);
115 slots(kRight, stage_max.x + gap);
118 const float width = stage_max.x + gap + slot - origin.x;
119 const float bars = stage_max.y + gap;
120 const std::string health =
121 absl::Substitute(
Tr(
"Health $0 / $1"), you->health, you->max_health);
122 DrawBar(draw, {origin.x, bars}, {origin.x + width, bars +
Ui(18.0f)},
124 ?
static_cast<float>(you->health) / you->max_health
127 const std::string experience = absl::Substitute(
128 Tr(
"Experience $0 / $1"), world.experience(), world.next_level());
129 DrawBar(draw, {origin.x, bars +
Ui(24.0f)},
130 {origin.x + width, bars +
Ui(42.0f)},
131 world.next_level() > 0 ?
static_cast<float>(world.experience()) /
132 static_cast<float>(world.next_level())
135 ImGui::SetCursorScreenPos({origin.x, bars +
Ui(42.0f)});
136 ImGui::Dummy({width,
Ui(4.0f)});
void DrawBar(ImDrawList *draw, ImVec2 min, ImVec2 max, float share, ImU32 color, ImU32 dark, const char *text)