111 const std::deque<protocol::Chat>& lines,
const Content& content) {
112 const ImVec2 display = ImGui::GetIO().DisplaySize;
113 const bool enter = !ImGui::GetIO().WantTextInput &&
114 ImGui::IsKeyPressed(ImGuiKey_Enter,
false);
117 const float radius =
Ui(kButton);
121 const float room =
Ui(kRim);
122 ImGui::SetNextWindowPos(
123 {
Ui(kMargin) - room, display.y -
Ui(kMargin) + room}, ImGuiCond_Always,
125 ImGui::SetNextWindowSize(
126 {room + radius * 2.0f +
Ui(14.0f),
Ui(6.0f) + radius * 2.0f + room});
127 ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {0.0f, 0.0f});
128 ImGui::Begin(
"Chat closed",
nullptr,
129 ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove |
130 ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoNav |
131 ImGuiWindowFlags_NoFocusOnAppearing |
132 ImGuiWindowFlags_NoSavedSettings);
133 ImGui::PopStyleVar();
134 const ImVec2 corner = ImGui::GetWindowPos();
135 const ImVec2 centre{corner.x + room + radius, corner.y +
Ui(6.0f) + radius};
136 ImGui::SetCursorScreenPos({centre.x - radius, centre.y - radius});
138 ImGui::InvisibleButton(
"##open", {radius * 2.0f, radius * 2.0f});
139 const bool hovered = ImGui::IsItemHovered();
141 ImGui::SetTooltip(
"%s",
Tr(
"Chat (Enter)"));
143 ImDrawList* draw = ImGui::GetWindowDrawList();
145 if (
const std::size_t unread =
Unread(lines, seen_); unread > 0) {
146 const std::string count = unread > 99 ?
"99+" : std::to_string(unread);
148 const float size =
Ui(13.0f);
149 const ImVec2 count_extent =
150 bold->CalcTextSizeA(size, FLT_MAX, 0.0f, count.c_str());
151 const ImVec2 badge{centre.x + radius * 0.75f, centre.y - radius * 0.75f};
152 const float badge_radius =
153 std::max(
Ui(9.0f), count_extent.x / 2.0f +
Ui(4.0f));
158 {badge.x - count_extent.x / 2.0f, badge.y - count_extent.y / 2.0f},
162 if (clicked || enter) {
169 ImGui::SetNextWindowPos({
Ui(kMargin), display.y -
Ui(kMargin)},
170 ImGuiCond_Always, {0.0f, 1.0f});
171 ImGui::SetNextWindowSize(
Ui(kSize));
173 const bool using_it =
174 ImGui::GetIO().WantTextInput ||
175 ImGui::IsMouseHoveringRect(
176 {
Ui(kMargin), display.y -
Ui(kMargin) -
Ui(kSize.y)},
177 {
Ui(kMargin) +
Ui(kSize.x), display.y -
Ui(kMargin)},
false);
182 ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoNavInputs |
183 ImGuiWindowFlags_NoFocusOnAppearing |
184 ImGuiWindowFlags_NoSavedSettings,
185 using_it ? 0.94f : 0.6f);
187 ImGui::BeginChild(
"Lines", {0.0f, -ImGui::GetFrameHeightWithSpacing()});
188 for (
const protocol::Chat& line : lines) {
191 const std::string text =
192 line.has_message() ?
Translated(line.message(), content) : line.text();
195 if (line.channel() == protocol::CHANNEL_LAND) {
196 ImGui::PushFont(
GetFonts().bold, 0.0f);
197 ImGui::PushStyleColor(ImGuiCol_Text, kLand);
198 ImGui::TextWrapped(
"%s", text.c_str());
199 ImGui::PopStyleColor();
205 const bool from_server = line.name().empty() && line.npc() == 0;
206 if (from_server && line.channel() == protocol::CHANNEL_GUILD) {
207 ImGui::PushStyleColor(ImGuiCol_Text, kGuild);
208 ImGui::TextWrapped(
"%s",
209 absl::Substitute(
Tr(
"[Guild] $0"), text).c_str());
210 ImGui::PopStyleColor();
214 ImGui::PushStyleColor(ImGuiCol_Text,
kServer);
215 ImGui::TextWrapped(
"%s", text.c_str());
216 ImGui::PopStyleColor();
220 const bool guild = line.channel() == protocol::CHANNEL_GUILD;
222 ImGui::PushStyleColor(ImGuiCol_Text, kGuild);
224 ImGui::PushFont(
GetFonts().bold, 0.0f);
225 const std::string speaker = SpeakerOf(line, content);
227 ImGui::TextUnformatted(
228 absl::Substitute(
Tr(
"[Guild] $0:"), speaker).c_str());
230 ImGui::TextColored(kName,
"%s:", speaker.c_str());
234 ImGui::TextWrapped(
"%s", text.c_str());
236 ImGui::PopStyleColor();
240 if (ImGui::GetScrollY() >= ImGui::GetScrollMaxY()) {
241 ImGui::SetScrollHereY(1.0f);
245 if (enter || focus_) {
246 ImGui::SetKeyboardFocusHere();
249 ImGui::SetNextItemWidth(-FLT_MIN);
250 std::optional<std::string> said;
251 if (ImGui::InputTextWithHint(
252 "##say",
Tr(
"Press Enter to chat, /g for your guild"), typing_.data(),
253 typing_.size(), ImGuiInputTextFlags_EnterReturnsTrue) &&
254 typing_[0] !=
'\0') {
255 said = typing_.data();
260 if (!lines.empty()) {
261 seen_ = lines.back();