Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion resources/docs/files.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ The browser (Alt+B) connects ALIEN with the ALIEN server, where users share simu
- **Visibility.** *Community* makes the upload visible to everyone in the **Community** workspace and also posts it on the ALIEN Discord server. *My uploads* keeps it visible only to you. Every upload of yours is listed in **My uploads**, where the right column switches its visibility between *Community* and *Only me*. After the upload, **Show in browser** selects the new entry in the browser.
- **Managing.** Select one of your uploads to rename it, to change its description, to switch it between private and community or to delete it in the right column. To replace an upload with a newer version, save the current simulation under the same name with the same target.
- **Reacting.** No account is needed. Click the heart on the picture of an entry to give it a heart and click it again to take it back. A right click chooses another reaction, and the right column shows all reactions to the selected entry. **Liked** in the left column collects all entries you reacted to. The gallery view can sort by reactions, date or downloads.
- **Credits.** While a simulation from the browser is open, the right end of the menu bar shows its name, its author and a heart. Click the name to show the entry in the browser or the heart to give it a heart.
- **Credits.** While a simulation from the server is open, the right end of the menu bar shows its name, its author and a heart. Click the name to show the entry in the browser or the heart to give it a heart. A simulation from **My simulations** or **Autosaves** shows only its name there.

## Command line interface

Expand Down
2 changes: 1 addition & 1 deletion resources/docs/user-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This chapter describes the screen of ALIEN. The first sections cover everything

The screen consists of a few main parts:

- **Menu bar.** It runs along the top edge and gives access to most functions. The power button at its left end closes ALIEN. While a simulation from the browser is open, its name, its author and a heart appear at the right end.
- **Menu bar.** It runs along the top edge and gives access to most functions. The power button at its left end closes ALIEN. While a simulation from the server is open, its name, its author and a heart appear at the right end. A simulation from **My simulations** or **Autosaves** shows only its name.
- **Simulation view.** The world fills the whole screen behind all windows. Scrollbars at the right and bottom edges show which part of the world is visible.
- **Edit mode button.** The round button in the lower left corner switches between navigation mode and edit mode. In edit mode, a tool bar with editing tools appears next to the button.
- **Windows.** Windows float above the simulation view. You can move them by their title bar, resize them at their edges and collapse or close them with the buttons in the title bar. All windows can be opened again from the menus. The only exceptions are the separate parameter windows created with **Open in new window**, which are opened again from the **Simulation parameters** window.
Expand Down
3 changes: 2 additions & 1 deletion source/Gui/Impl/BrowserWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ void BrowserWindow::processIntern()
_lastServerWorkspaceType = workspaceType;
}

if (_resourceIdToShow.has_value() && !BrowserController::get().isRefreshing()) {
// The entries of this computer do not wait for the server
if (_resourceIdToShow.has_value() && (isLocalWorkspace(_data->getCurrentWorkspaceId().workspaceType) || !BrowserController::get().isRefreshing())) {
revealResource(*_resourceIdToShow);
_resourceIdToShow.reset();
}
Expand Down
17 changes: 16 additions & 1 deletion source/Gui/Impl/LocalLibraryController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ void LocalLibraryController::process()
}
_content.truncated = _content.truncated || autosaveContent.truncated;
}

// A folder may have been renamed to another spelling of its name, which the path of the running simulation follows
if (auto const& localFile = NewSimulationService::get().getLocalFile()) {
NewSimulationService::get().setLocalFile(service.normalize(*localFile));
}
_contentOutdated = false;
++_revision;
}
Expand Down Expand Up @@ -447,6 +452,9 @@ std::optional<std::string> LocalLibraryController::onDelete(std::vector<std::fil
if (nameOfRunningSimulation.has_value() && service.getSimulationName(_libraryFolder, simulationPath) == nameOfRunningSimulation) {
NewSimulationService::get().setNameInLibrary(std::nullopt);
}
if (auto const& localFile = NewSimulationService::get().getLocalFile(); localFile.has_value() && *localFile == service.normalize(simulationPath)) {
NewSimulationService::get().setLocalFile(std::nullopt);
}
service.deleteSimulation(getMainFolder(simulationPath), simulationPath);
}
_contentOutdated = true;
Expand Down Expand Up @@ -506,7 +514,8 @@ void LocalLibraryController::processPendingLoads()
auto name = service.getSimulationName(_libraryFolder, pendingLoad.simulationPath);
auto nameInLibrary = name.has_value() && service.isValidSimulationName(*name) ? name : std::nullopt;
auto data = _PersisterFacade::get()->fetchReadSimulationData(pendingLoad.requestId);
if (auto errorMessage = NewSimulationService::get().loadSimulation(data.simulationDesc, std::nullopt, nameInLibrary)) {
if (auto errorMessage =
NewSimulationService::get().loadSimulation(data.simulationDesc, std::nullopt, nameInLibrary, service.normalize(pendingLoad.simulationPath))) {
GenericMessageDialog::get().information("Error", *errorMessage);
continue;
}
Expand Down Expand Up @@ -611,6 +620,7 @@ void LocalLibraryController::onSaveFinished(PendingSave const& pendingSave, Save
// Another simulation may have been loaded or created in the meantime
if (pendingSave.sessionId == _SimulationFacade::get()->getSessionId()) {
NewSimulationService::get().setNameInLibrary(pendingSave.name);
NewSimulationService::get().setLocalFile(service.normalize(data.filename));
}
}
if (pendingSave.automatic && _saveMode == SaveMode_Limited) {
Expand All @@ -633,6 +643,8 @@ LocalLibraryController::rename(std::filesystem::path const& simulationPath, std:
auto isGenome = service.isGenomePath(simulationPath);
auto const& mainFolder = getMainFolder(simulationPath);
auto name = service.getSimulationName(_libraryFolder, simulationPath);
auto const& localFile = NewSimulationService::get().getLocalFile();
auto isLocalFile = localFile.has_value() && *localFile == service.normalize(simulationPath);
auto isNameTaken =
isGenome ? service.isGenomeNameTaken(mainFolder, newName, simulationPath) : service.isSimulationNameTaken(mainFolder, newName, simulationPath);
if (isNameTaken) {
Expand All @@ -650,6 +662,9 @@ LocalLibraryController::rename(std::filesystem::path const& simulationPath, std:
if (name.has_value() && name == NewSimulationService::get().getNameInLibrary()) {
NewSimulationService::get().setNameInLibrary(service.isValidSimulationName(newName) ? std::make_optional(newName) : std::nullopt);
}
if (isLocalFile) {
NewSimulationService::get().setLocalFile(service.normalize(newSimulationPath));
}
if (_pendingPicture.has_value() && _pendingPicture->simulationPath == simulationPath) {
_pendingPicture->simulationPath = newSimulationPath;
}
Expand Down
178 changes: 132 additions & 46 deletions source/Gui/Impl/MenuBarInfoWidget.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#include "MenuBarInfoWidget.h"

#include <algorithm>

#include <imgui.h>

#include <Fonts/IconsFontAwesome5.h>

#include <Base/StringHelper.h>

#include <Data/SimulationParameters.h>

#include <Engine/Interface/SimulationFacade.h>
Expand All @@ -15,6 +19,7 @@
#include "BrowserController.h"
#include "BrowserData.h"
#include "BrowserWindow.h"
#include "LocalLibraryController.h"
#include "NewSimulationService.h"
#include "StyleService.h"

Expand All @@ -23,6 +28,8 @@ namespace
auto constexpr MenuButtonRounding = 7.0f;
auto constexpr MenuButtonBorderSize = 2.0f;
auto constexpr TooltipValueWidth = 120.0f;
auto constexpr LocalTooltipValueWidth = 150.0f; // Leaves room for a date with time
auto constexpr TimestampLengthWithoutSeconds = 16; // e.g. 2026-11-13 14:02
}

MenuBarInfoWidget _MenuBarInfoWidget::create()
Expand Down Expand Up @@ -70,6 +77,29 @@ namespace
ImGui::PopStyleColor(3);
ImGui::PopStyleVar(2);
}

// Unlike the entries of the browser, the content of the library is also kept up to date while the browser is closed
LibraryFile const* findLocalFile()
{
auto const& localFile = NewSimulationService::get().getLocalFile();
if (!localFile.has_value()) {
return nullptr;
}
auto const& simulations = LocalLibraryController::get().getContent().simulations;
auto findResult = std::ranges::find_if(simulations, [&](LibraryFile const& simulation) { return simulation.path == *localFile; });
return findResult != simulations.end() ? &*findResult : nullptr;
}

bool alignRightIfFits(float width)
{
auto cursorX = ImGui::GetCursorPosX();
auto startX = cursorX + ImGui::GetContentRegionAvail().x - width;
if (startX < cursorX) {
return false;
}
ImGui::SetCursorPosX(startX);
return true;
}
}

void _MenuBarInfoWidget::process()
Expand All @@ -85,77 +115,133 @@ void _MenuBarInfoWidget::processCurrentSimulation()
if (BrowserWindow::get().isOn()) {
return;
}
auto const& originResourceId = NewSimulationService::get().getOriginResourceId();
if (!originResourceId.has_value()) {
return;

// A simulation of the server takes precedence. While the browser receives the entries of the server, at the start and at every refresh,
// a simulation of this computer is only shown if it has been shown before.
if (auto const& originResourceId = NewSimulationService::get().getOriginResourceId()) {
if (auto rawTO = BrowserController::get().getData()->findRawTO(*originResourceId)) {
_localSimulationShown = false;
processServerSimulation(rawTO);
return;
}
if (BrowserController::get().isRefreshing() && !_localSimulationShown) {
return;
}
}
auto rawTO = BrowserController::get().getData()->findRawTO(*originResourceId);
if (rawTO == nullptr) {
return;
auto file = findLocalFile();
_localSimulationShown = file != nullptr;
if (file != nullptr) {
processLocalSimulation(*file);
}
}

namespace
{
// The byline follows the name in a dimmed color. Returns true if the button has been clicked.
bool processNameButton(std::string const& nameText, std::string const& bylineText, float width)
{
auto pos = ImGui::GetCursorScreenPos();
pushMenuButtonStyle();
auto result = ImGui::Button("##currentSimulationName", {width, 0});
popMenuButtonStyle();

auto const& style = ImGui::GetStyle();
auto textPos = ImVec2{pos.x + style.FramePadding.x, pos.y + style.FramePadding.y};
auto drawList = ImGui::GetWindowDrawList();
drawList->AddText(textPos, ImGui::GetColorU32(ImGuiCol_Text), nameText.c_str());
drawList->AddText({textPos.x + ImGui::CalcTextSize(nameText.c_str()).x, textPos.y}, ImGui::GetColorU32(Const::TextDimColor.Value), bylineText.c_str());
return result;
}
}

void _MenuBarInfoWidget::processServerSimulation(NetworkResourceRawTO const& rawTO)
{
auto displayName = getDisplayName(rawTO);
auto nameText = getNameText(displayName);
auto userText = getUserText(rawTO);
auto const& style = ImGui::GetStyle();
auto nameWidth = ImGui::CalcTextSize(getNameText(displayName).c_str()).x + ImGui::CalcTextSize(getUserText(rawTO).c_str()).x + style.FramePadding.x * 2;
auto nameWidth = ImGui::CalcTextSize(nameText.c_str()).x + ImGui::CalcTextSize(userText.c_str()).x + style.FramePadding.x * 2;
auto heartWidth = ImGui::CalcTextSize(getHeartText(rawTO).c_str()).x + style.FramePadding.x * 2;
auto totalWidth = nameWidth + style.ItemSpacing.x + heartWidth;

auto cursorX = ImGui::GetCursorPosX();
auto startX = cursorX + ImGui::GetContentRegionAvail().x - totalWidth;
if (startX < cursorX) {
if (!alignRightIfFits(nameWidth + style.ItemSpacing.x + heartWidth)) {
return;
}
ImGui::SetCursorPosX(startX);

processNameButton(rawTO, displayName, nameWidth);
auto clicked = processNameButton(nameText, userText, nameWidth);
if (ImGui::IsItemHovered()) {
processServerTooltip(rawTO, displayName);
}
if (clicked) {
BrowserWindow::get().showResource(rawTO->resourceType, rawTO->workspaceType, rawTO->id);
}
processHeartButton(rawTO, displayName);
}

void _MenuBarInfoWidget::processLocalSimulation(LibraryFile const& file)
{
auto displayName = NetworkResourceService::get().removeFoldersFromName(file.name);
auto nameText = getNameText(displayName) + " ";
auto nameWidth = ImGui::CalcTextSize(nameText.c_str()).x + ImGui::GetStyle().FramePadding.x * 2;
if (!alignRightIfFits(nameWidth)) {
return;
}

auto clicked = processNameButton(nameText, std::string(), nameWidth);
if (ImGui::IsItemHovered()) {
processLocalTooltip(file, displayName);
}
if (clicked) {
auto workspaceType = file.kind == LibraryFileKind::Named ? WorkspaceType_Local : WorkspaceType_Autosave;
BrowserWindow::get().showResource(NetworkResourceType_Simulation, workspaceType, StringHelper::toUtf8(file.path));
}
}

namespace
{
void processTooltipRow(std::string const& label, std::string const& value)
void processTooltipRow(std::string const& label, std::string const& value, float valueWidth = TooltipValueWidth)
{
AlienGui::Text(value);
ImGui::SameLine(scale(TooltipValueWidth));
ImGui::SameLine(scale(valueWidth));
AlienGui::Text(AlienGui::TextParameters().text(label).style(AlienGui::TextStyle::Decent));
}
}

void _MenuBarInfoWidget::processNameButton(NetworkResourceRawTO const& rawTO, std::string const& displayName, float width)
void _MenuBarInfoWidget::processServerTooltip(NetworkResourceRawTO const& rawTO, std::string const& displayName)
{
auto pos = ImGui::GetCursorScreenPos();
pushMenuButtonStyle();
auto clicked = ImGui::Button("##currentSimulationName", {width, 0});
popMenuButtonStyle();

auto const& style = ImGui::GetStyle();
auto nameText = getNameText(displayName);
auto textPos = ImVec2{pos.x + style.FramePadding.x, pos.y + style.FramePadding.y};
auto drawList = ImGui::GetWindowDrawList();
drawList->AddText(textPos, ImGui::GetColorU32(ImGuiCol_Text), nameText.c_str());
drawList->AddText(
{textPos.x + ImGui::CalcTextSize(nameText.c_str()).x, textPos.y}, ImGui::GetColorU32(Const::TextDimColor.Value), getUserText(rawTO).c_str());
ImGui::BeginTooltip();
ImGui::PushStyleColor(ImGuiCol_Text, Const::TextTooltipColor.Value);
AlienGui::Text(AlienGui::TextParameters().text(displayName).style(AlienGui::TextStyle::Bold));
ImGui::PushStyleColor(ImGuiCol_Text, (ImU32)Const::BrowserLeafTextColor);
AlienGui::Text(rawTO->resourceName);
ImGui::PopStyleColor();
AlienGui::Separator();
processTooltipRow("User", rawTO->userName);
processTooltipRow("Uploaded", rawTO->timestamp.substr(0, 10));
processTooltipRow("Reactions", std::to_string(rawTO->getTotalLikes()));
processTooltipRow("Downloads", std::to_string(rawTO->numDownloads));
AlienGui::Separator();
AlienGui::Text("Click to show it in the browser.");
ImGui::PopStyleColor();
ImGui::EndTooltip();
}

if (ImGui::IsItemHovered()) {
ImGui::BeginTooltip();
ImGui::PushStyleColor(ImGuiCol_Text, Const::TextTooltipColor.Value);
AlienGui::Text(AlienGui::TextParameters().text(displayName).style(AlienGui::TextStyle::Bold));
void _MenuBarInfoWidget::processLocalTooltip(LibraryFile const& file, std::string const& displayName)
{
ImGui::BeginTooltip();
ImGui::PushStyleColor(ImGuiCol_Text, Const::TextTooltipColor.Value);
AlienGui::Text(AlienGui::TextParameters().text(displayName).style(AlienGui::TextStyle::Bold));
if (file.name != displayName) {
ImGui::PushStyleColor(ImGuiCol_Text, (ImU32)Const::BrowserLeafTextColor);
AlienGui::Text(rawTO->resourceName);
ImGui::PopStyleColor();
AlienGui::Separator();
processTooltipRow("User", rawTO->userName);
processTooltipRow("Uploaded", rawTO->timestamp.substr(0, 10));
processTooltipRow("Reactions", std::to_string(rawTO->getTotalLikes()));
processTooltipRow("Downloads", std::to_string(rawTO->numDownloads));
AlienGui::Separator();
AlienGui::Text("Click to show it in the browser.");
AlienGui::Text(file.name);
ImGui::PopStyleColor();
ImGui::EndTooltip();
}
if (clicked) {
BrowserWindow::get().showResource(rawTO->resourceType, rawTO->workspaceType, rawTO->id);
}
AlienGui::Separator();
auto timestamp = file.timestamp.substr(0, TimestampLengthWithoutSeconds);
processTooltipRow(file.kind == LibraryFileKind::Autosave ? "Autosaved" : "Saved", timestamp, LocalTooltipValueWidth);
processTooltipRow("File size", StringHelper::formatFileSize(file.fileSize), LocalTooltipValueWidth);
AlienGui::Separator();
AlienGui::Text("Click to show it in the browser.");
ImGui::PopStyleColor();
ImGui::EndTooltip();
}

void _MenuBarInfoWidget::processHeartButton(NetworkResourceRawTO const& rawTO, std::string const& displayName)
Expand Down
9 changes: 8 additions & 1 deletion source/Gui/Impl/MenuBarInfoWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include <Network/NetworkResourceRawTO.h>

#include <Persister/Interface/LocalLibrary.h>

#include "Definitions.h"

class _MenuBarInfoWidget
Expand All @@ -17,6 +19,11 @@ class _MenuBarInfoWidget
_MenuBarInfoWidget() = default;

void processCurrentSimulation();
void processNameButton(NetworkResourceRawTO const& rawTO, std::string const& displayName, float width);
void processServerSimulation(NetworkResourceRawTO const& rawTO);
void processLocalSimulation(LibraryFile const& file);
void processServerTooltip(NetworkResourceRawTO const& rawTO, std::string const& displayName);
void processLocalTooltip(LibraryFile const& file, std::string const& displayName);
void processHeartButton(NetworkResourceRawTO const& rawTO, std::string const& displayName);

bool _localSimulationShown = false;
};
Loading