Rewrite notifications to eliminate flicker with many in the queue
This commit is contained in:
@@ -70,7 +70,7 @@ bool ArchipelagoClient::StartClient() {
|
|||||||
|
|
||||||
apClient->set_slot_connected_handler([&](const nlohmann::json data) {
|
apClient->set_slot_connected_handler([&](const nlohmann::json data) {
|
||||||
CVarSetInteger(CVAR_REMOTE_ARCHIPELAGO("ConnectionStatus"), 3); // slot connected
|
CVarSetInteger(CVAR_REMOTE_ARCHIPELAGO("ConnectionStatus"), 3); // slot connected
|
||||||
ArchipelagoConsole_SendMessage("[LOG] Connected.", true);
|
ArchipelagoConsole_SendMessage("[LOG] Connected.");
|
||||||
ArchipelagoClient::StartLocationScouts();
|
ArchipelagoClient::StartLocationScouts();
|
||||||
|
|
||||||
slotData = data;
|
slotData = data;
|
||||||
|
|||||||
@@ -41,8 +41,7 @@ void Window::Draw() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_WindowBg,
|
ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0, 0, 0, 0));
|
||||||
ImVec4(0, 0, 0, CVarGetFloat(CVAR_SETTING("Notifications.BgOpacity"), 0.5f)));
|
|
||||||
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0, 0, 0, 0));
|
ImGui::PushStyleColor(ImGuiCol_Border, ImVec4(0, 0, 0, 0));
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 4.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 4.0f);
|
||||||
|
|
||||||
@@ -51,13 +50,15 @@ void Window::Draw() {
|
|||||||
int inverseIndex = -ABS(index - (notifications.size() - 1));
|
int inverseIndex = -ABS(index - (notifications.size() - 1));
|
||||||
|
|
||||||
ImGui::SetNextWindowViewport(vp->ID);
|
ImGui::SetNextWindowViewport(vp->ID);
|
||||||
|
// Fade out
|
||||||
if (notification.remainingTime < 4.0f) {
|
if (notification.remainingTime < 4.0f) {
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, (notification.remainingTime - 1) / 3.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, (notification.remainingTime - 1) / 3.0f);
|
||||||
} else {
|
} else {
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, 1.0f);
|
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, 1.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::Begin(("notification#" + std::to_string(notification.id)).c_str(), nullptr,
|
ImGui::SetNextWindowSize(ImVec2(0, vp->Size.y - (margin * 2)));
|
||||||
|
ImGui::Begin(("Notification#" + std::to_string(notification.id)).c_str(), nullptr,
|
||||||
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoFocusOnAppearing |
|
ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoFocusOnAppearing |
|
||||||
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar |
|
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_NoTitleBar |
|
||||||
ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoMove |
|
ImGuiWindowFlags_NoScrollWithMouse | ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoMove |
|
||||||
@@ -68,27 +69,38 @@ void Window::Draw() {
|
|||||||
ImVec2 notificationPos;
|
ImVec2 notificationPos;
|
||||||
switch (position) {
|
switch (position) {
|
||||||
case 0: // Top Left
|
case 0: // Top Left
|
||||||
notificationPos =
|
notificationPos = ImVec2(basePosition.x, basePosition.y);
|
||||||
ImVec2(basePosition.x, basePosition.y + ((ImGui::GetWindowSize().y + padding) * inverseIndex));
|
|
||||||
break;
|
break;
|
||||||
case 1: // Top Right
|
case 1: // Top Right
|
||||||
notificationPos = ImVec2(basePosition.x - ImGui::GetWindowSize().x,
|
notificationPos = ImVec2(basePosition.x - ImGui::GetWindowSize().x, basePosition.y);
|
||||||
basePosition.y + ((ImGui::GetWindowSize().y + padding) * inverseIndex));
|
|
||||||
break;
|
break;
|
||||||
case 2: // Bottom Left
|
case 2: // Bottom Left
|
||||||
notificationPos = ImVec2(basePosition.x,
|
notificationPos = ImVec2(basePosition.x, basePosition.y - (ImGui::GetWindowSize().y + padding));
|
||||||
basePosition.y - ((ImGui::GetWindowSize().y + padding) * (inverseIndex + 1)));
|
|
||||||
break;
|
break;
|
||||||
case 3: // Bottom Right
|
case 3: // Bottom Right
|
||||||
notificationPos = ImVec2(basePosition.x - ImGui::GetWindowSize().x,
|
notificationPos = ImVec2(basePosition.x - ImGui::GetWindowSize().x,
|
||||||
basePosition.y - ((ImGui::GetWindowSize().y + padding) * (inverseIndex + 1)));
|
basePosition.y - (ImGui::GetWindowSize().y + padding));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::SetWindowPos(notificationPos);
|
ImGui::SetWindowPos(notificationPos);
|
||||||
|
|
||||||
|
// If bottom aligned
|
||||||
|
if (position == 2 || position == 3) {
|
||||||
|
ImGui::SetCursorPosY(ImGui::GetWindowSize().y - (60 * (inverseIndex + 1)));
|
||||||
|
} else {
|
||||||
|
ImGui::SetCursorPosY(60 * inverseIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0, 0, 0, 0.5));
|
||||||
|
|
||||||
|
if (ImGui::BeginChild(("Notification#" + std::to_string(notification.id)).c_str(), ImVec2(0, 0),
|
||||||
|
ImGuiChildFlags_AlwaysUseWindowPadding | ImGuiChildFlags_AlwaysAutoResize |
|
||||||
|
ImGuiChildFlags_AutoResizeX | ImGuiChildFlags_AutoResizeY)) {
|
||||||
|
|
||||||
if (notification.itemIcon != nullptr) {
|
if (notification.itemIcon != nullptr) {
|
||||||
ImGui::Image(Ship::Context::GetInstance()->GetWindow()->GetGui()->GetTextureByName(notification.itemIcon),
|
ImGui::Image(
|
||||||
|
Ship::Context::GetInstance()->GetWindow()->GetGui()->GetTextureByName(notification.itemIcon),
|
||||||
ImVec2(32, 32));
|
ImVec2(32, 32));
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
}
|
}
|
||||||
@@ -101,6 +113,10 @@ void Window::Draw() {
|
|||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::TextColored(notification.suffixColor, "%s", notification.suffix.c_str());
|
ImGui::TextColored(notification.suffixColor, "%s", notification.suffix.c_str());
|
||||||
}
|
}
|
||||||
|
ImGui::EndChild();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::PopStyleColor();
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
ImGui::PopStyleVar();
|
ImGui::PopStyleVar();
|
||||||
|
|||||||
Reference in New Issue
Block a user