Skip to content

Commit

Permalink
Cleanup (delete ResourceData and ComponentSet)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob1 committed Dec 17, 2024
1 parent 125be6e commit 0bb9980
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 103 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ screenshot_*
/.kdev4

# Other IDEs / misc
/.idea
.vscode/
.vs/
*.sublime-*
Expand Down
34 changes: 0 additions & 34 deletions src/gui/credits/ComponentSet.cpp

This file was deleted.

24 changes: 0 additions & 24 deletions src/gui/credits/ComponentSet.h

This file was deleted.

35 changes: 18 additions & 17 deletions src/gui/credits/Credits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ Credits::Credits():
{
Json::Value root;
Json::Reader reader;
if (bool parsed = reader.parse((const char*)credits_json, (const char*)credits_json + credits_json_size, root, false); !parsed) {
auto credits = credits_json.AsCharSpan();
if (bool parsed = reader.parse(credits.data(), credits.data() + credits.size(), root, false); !parsed) {
// Failure. Shouldn't ever happen.
return;
}
Expand All @@ -30,14 +31,20 @@ Credits::Credits():
int xPos = 0, yPos = 0, row = 0;
int nextY = 0;

// Organize blocks of components of equal width into rows
auto organizeComponents = [&xPos, &yPos, &nextY, &row](ui::ComponentSet components, const int panelWidth) {
auto blockSize = components.Size();
// Organize blocks of components of equal width into rows, and add them to the scroll panel
auto organizeComponents = [&xPos, &yPos, &nextY, &row, &scrollPanel](const auto& components, const int panelWidth) {
ui::Point blockSize = { 0, 0 };
for (const auto &component : components)
{
blockSize.X = std::max(blockSize.X, component->Position.X + component->Size.X);
blockSize.Y = std::max(blockSize.Y, component->Position.Y + component->Size.Y);
}

// New row, offset x position to ensure entire row is centered
if (xPos == 0)
xPos = (panelWidth % blockSize.X) / 2;
components.AddOffset({ xPos, yPos });
for (const auto &component : components)
component->Position += ui::Point({ xPos, yPos });

xPos += blockSize.X;
nextY = std::max(nextY, yPos + blockSize.Y);
Expand All @@ -47,6 +54,9 @@ Credits::Credits():
yPos = nextY + 8;
row++;
}

for (const auto &component : components)
scrollPanel->AddChild(component);
};

// Add header and separator for each section of credits
Expand Down Expand Up @@ -79,9 +89,8 @@ Credits::Credits():
for (auto &item : GitHub)
{
ByteString username = item.asString();
auto components = AddCredit(username.FromUtf8(), "", Small, GetGithubCommitsUri(username), false, grayscale);
auto components = AddCredit(username.FromUtf8(), "", Small, "", false, grayscale);
organizeComponents(components, scrollPanel->Size.X);
components.AddToPanel(scrollPanel);
if (grayscale > 180)
grayscale--;
}
Expand All @@ -99,7 +108,6 @@ Credits::Credits():
{
auto components = AddCredit(username.FromUtf8(), "", Large, GetProfileUri(username), true);
organizeComponents(components, scrollPanel->Size.X);
components.AddToPanel(scrollPanel);
}
}

Expand All @@ -115,7 +123,6 @@ Credits::Credits():
{
auto components = AddCredit(username.FromUtf8(), "", Small, "", true);
organizeComponents(components, scrollPanel->Size.X);
components.AddToPanel(scrollPanel);
}
}

Expand All @@ -131,7 +138,6 @@ Credits::Credits():

auto components = AddCredit(realname.FromUtf8(), message.FromUtf8(), row == 0 ? Half : Small, "");
organizeComponents(components, scrollPanel->Size.X);
components.AddToPanel(scrollPanel);
}


Expand All @@ -145,7 +151,7 @@ Credits::Credits():
AddComponent(closeButton);
}

ui::ComponentSet Credits::AddCredit(const String &name, const String &subheader, const CreditSize size,
std::vector<ui::Component *> Credits::AddCredit(const String &name, const String &subheader, const CreditSize size,
const ByteString &uri, const bool includeAvatar, const int grayscale)
{
std::vector<ui::Component *> components;
Expand Down Expand Up @@ -190,19 +196,14 @@ ui::ComponentSet Credits::AddCredit(const String &name, const String &subheader,
components.push_back(subheaderLabel);
}

return ui::ComponentSet(components);
return components;
}

ByteString Credits::GetProfileUri(const ByteString &username)
{
return "https://powdertoy.co.uk/User.html?Name=" + username;
}

ByteString Credits::GetGithubCommitsUri(const ByteString &username)
{
return "https://github.com/The-Powder-Toy/The-Powder-Toy/commits?author=" + username;
}

String Credits::GetRichLabelText(const ByteString &uri, const String &message)
{
StringBuilder builder;
Expand Down
6 changes: 2 additions & 4 deletions src/gui/credits/Credits.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once
#include "ComponentSet.h"
#include "ResourceData.h"
#include <vector>
#include "gui/interface/Window.h"

class Credits : public ui::Window
Expand All @@ -12,10 +11,9 @@ class Credits : public ui::Window
Half,
};

static ui::ComponentSet AddCredit(const String &name, const String &subheader, CreditSize size,
static std::vector<ui::Component *> AddCredit(const String &name, const String &subheader, CreditSize size,
const ByteString &uri, bool includeAvatar = false, int grayscale = 255);
static ByteString GetProfileUri(const ByteString &username);
static ByteString GetGithubCommitsUri(const ByteString &username);
static ByteString GetTptLabelText(const ByteString &tpt, const ByteString &github);
static String GetRichLabelText(const ByteString &uri, const String &message);
public:
Expand Down
23 changes: 0 additions & 23 deletions src/gui/credits/ResourceData.h

This file was deleted.

1 change: 0 additions & 1 deletion src/gui/credits/meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
powder_files += files(
'Credits.cpp',
'ComponentSet.cpp',
)

0 comments on commit 0bb9980

Please sign in to comment.