Modernized some code.

This commit is contained in:
Leon Styhre 2022-09-10 11:35:55 +02:00
parent f0fd5346c6
commit 74d3e1f063
2 changed files with 47 additions and 34 deletions

View file

@ -470,33 +470,41 @@ void GamelistView::legacyUpdateView(const CursorState& state)
// the game counter. // the game counter.
for (auto& gamelistInfo : mGamelistInfoComponents) { for (auto& gamelistInfo : mGamelistInfoComponents) {
std::string gamelistInfoString; std::string gamelistInfoString;
Alignment infoAlign = gamelistInfo->getHorizontalAlignment(); Alignment infoAlign {gamelistInfo->getHorizontalAlignment()};
if (mIsFolder && infoAlign == ALIGN_RIGHT) if (mIsFolder && infoAlign == ALIGN_RIGHT)
gamelistInfoString = ViewController::FOLDER_CHAR + " "; gamelistInfoString = ViewController::FOLDER_CHAR + " ";
if (mIsFiltered) { if (mIsFiltered) {
if (mFilteredGameCountAll == mFilteredGameCount) if (mFilteredGameCountAll == mFilteredGameCount)
gamelistInfoString += ViewController::FILTER_CHAR + " " + gamelistInfoString.append(ViewController::FILTER_CHAR)
std::to_string(mFilteredGameCount) + " / " + .append(" ")
std::to_string(mGameCount); .append(std::to_string(mFilteredGameCount))
.append(" / ")
.append(std::to_string(mGameCount));
else else
gamelistInfoString += gamelistInfoString.append(ViewController::FILTER_CHAR)
ViewController::FILTER_CHAR + " " + std::to_string(mFilteredGameCount) + .append(" ")
" + " + std::to_string(mFilteredGameCountAll - mFilteredGameCount) + " / " + .append(std::to_string(mFilteredGameCount))
std::to_string(mGameCount); .append(" + ")
.append(std::to_string(mFilteredGameCountAll - mFilteredGameCount))
.append(" / ")
.append(std::to_string(mGameCount));
} }
else { else {
gamelistInfoString += gamelistInfoString.append(ViewController::CONTROLLER_CHAR)
ViewController::CONTROLLER_CHAR + " " + std::to_string(mGameCount); .append(" ")
.append(std::to_string(mGameCount));
if (!(file->getSystem()->isCollection() && if (!(file->getSystem()->isCollection() &&
file->getSystem()->getFullName() == "favorites")) file->getSystem()->getFullName() == "favorites"))
gamelistInfoString += " " + ViewController::FAVORITE_CHAR + " " + gamelistInfoString.append(" ")
std::to_string(mFavoritesGameCount); .append(ViewController::FAVORITE_CHAR)
.append(" ")
.append(std::to_string(mFavoritesGameCount));
} }
if (mIsFolder && infoAlign != ALIGN_RIGHT) if (mIsFolder && infoAlign != ALIGN_RIGHT)
gamelistInfoString += " " + ViewController::FOLDER_CHAR; gamelistInfoString.append(" ").append(ViewController::FOLDER_CHAR);
gamelistInfo->setValue(gamelistInfoString); gamelistInfo->setValue(gamelistInfoString);
} }
@ -668,8 +676,8 @@ void GamelistView::legacyInitMDLabels()
const float rowPadding {0.01f * mSize.y}; const float rowPadding {0.01f * mSize.y};
for (unsigned int i = 0; i < components.size(); ++i) { for (unsigned int i = 0; i < components.size(); ++i) {
const unsigned int row = i % rowCount; const unsigned int row {i % rowCount};
glm::vec3 pos {}; glm::vec3 pos {0.0f, 0.0f, 0.0f};
if (row == 0) { if (row == 0) {
pos = start + glm::vec3 {colSize * (i / rowCount), 0.0f, 0.0f}; pos = start + glm::vec3 {colSize * (i / rowCount), 0.0f, 0.0f};
} }
@ -681,7 +689,6 @@ void GamelistView::legacyInitMDLabels()
components[i]->setFont(Font::get(FONT_SIZE_SMALL)); components[i]->setFont(Font::get(FONT_SIZE_SMALL));
components[i]->setPosition(pos); components[i]->setPosition(pos);
// components[i]->setColor(0xFFFFFFFF);
components[i]->setDefaultZIndex(40.0f); components[i]->setDefaultZIndex(40.0f);
} }
} }
@ -716,12 +723,12 @@ void GamelistView::legacyInitMDValues()
float bottom {0.0f}; float bottom {0.0f};
const float colSize {(mSize.x * 0.48f) / 2.0f}; const float colSize {(mSize.x * 0.48f) / 2.0f};
for (unsigned int i = 0; i < labels.size(); ++i) { for (unsigned int i = 0; i < labels.size(); ++i) {
const float heightDiff = (labels[i]->getSize().y - values[i]->getSize().y) / 2.0f; const float heightDiff {(labels[i]->getSize().y - values[i]->getSize().y) / 2.0f};
values[i]->setPosition(mSize.x + glm::vec3 {labels[i]->getSize().x, heightDiff, 0.0f}); values[i]->setPosition(mSize.x + glm::vec3 {labels[i]->getSize().x, heightDiff, 0.0f});
values[i]->setSize(colSize - labels[i]->getSize().x, values[i]->getSize().y); values[i]->setSize(colSize - labels[i]->getSize().x, values[i]->getSize().y);
values[i]->setDefaultZIndex(40.0f); values[i]->setDefaultZIndex(40.0f);
float testBot = values[i]->getPosition().y + values[i]->getSize().y; float testBot {values[i]->getPosition().y + values[i]->getSize().y};
if (testBot > bottom) if (testBot > bottom)
bottom = testBot; bottom = testBot;

View file

@ -615,38 +615,45 @@ void GamelistView::updateView(const CursorState& state)
// the game counter. // the game counter.
for (auto& gamelistInfo : mGamelistInfoComponents) { for (auto& gamelistInfo : mGamelistInfoComponents) {
std::string gamelistInfoString; std::string gamelistInfoString;
Alignment infoAlign = gamelistInfo->getHorizontalAlignment(); Alignment infoAlign {gamelistInfo->getHorizontalAlignment()};
if (mIsFolder && infoAlign == ALIGN_RIGHT) if (mIsFolder && infoAlign == ALIGN_RIGHT)
gamelistInfoString = ViewController::FOLDER_CHAR + " "; gamelistInfoString = ViewController::FOLDER_CHAR + " ";
if (mIsFiltered) { if (mIsFiltered) {
if (mFilteredGameCountAll == mFilteredGameCount) if (mFilteredGameCountAll == mFilteredGameCount)
gamelistInfoString += ViewController::FILTER_CHAR + " " + gamelistInfoString.append(ViewController::FILTER_CHAR)
std::to_string(mFilteredGameCount) + " / " + .append(" ")
std::to_string(mGameCount); .append(std::to_string(mFilteredGameCount))
.append(" / ")
.append(std::to_string(mGameCount));
else else
gamelistInfoString += gamelistInfoString.append(ViewController::FILTER_CHAR)
ViewController::FILTER_CHAR + " " + std::to_string(mFilteredGameCount) + .append(" ")
" + " + std::to_string(mFilteredGameCountAll - mFilteredGameCount) + " / " + .append(std::to_string(mFilteredGameCount))
std::to_string(mGameCount); .append(" + ")
.append(std::to_string(mFilteredGameCountAll - mFilteredGameCount))
.append(" / ")
.append(std::to_string(mGameCount));
} }
else { else {
gamelistInfoString += gamelistInfoString.append(ViewController::CONTROLLER_CHAR)
ViewController::CONTROLLER_CHAR + " " + std::to_string(mGameCount); .append(" ")
.append(std::to_string(mGameCount));
if (!(file->getSystem()->isCollection() && if (!(file->getSystem()->isCollection() &&
file->getSystem()->getFullName() == "favorites")) file->getSystem()->getFullName() == "favorites"))
gamelistInfoString += " " + ViewController::FAVORITE_CHAR + " " + gamelistInfoString.append(" ")
std::to_string(mFavoritesGameCount); .append(ViewController::FAVORITE_CHAR)
.append(" ")
.append(std::to_string(mFavoritesGameCount));
} }
if (mIsFolder && infoAlign != ALIGN_RIGHT) if (mIsFolder && infoAlign != ALIGN_RIGHT)
gamelistInfoString += " " + ViewController::FOLDER_CHAR; gamelistInfoString.append(" ").append(ViewController::FOLDER_CHAR);
gamelistInfo->setValue(gamelistInfoString); gamelistInfo->setValue(gamelistInfoString);
} }
// Fade in the game image.
for (auto& image : mImageComponents) { for (auto& image : mImageComponents) {
if (image->getScrollFadeIn()) { if (image->getScrollFadeIn()) {
auto func = [&image](float t) { auto func = [&image](float t) {
@ -656,7 +663,6 @@ void GamelistView::updateView(const CursorState& state)
} }
} }
// Fade in the static image.
for (auto& video : mVideoComponents) { for (auto& video : mVideoComponents) {
if (video->getScrollFadeIn()) { if (video->getScrollFadeIn()) {
auto func = [&video](float t) { auto func = [&video](float t) {
@ -807,7 +813,7 @@ void GamelistView::updateView(const CursorState& state)
} }
for (auto& date : mDateTimeComponents) { for (auto& date : mDateTimeComponents) {
std::string metadata = date->getThemeMetadata(); std::string metadata {date->getThemeMetadata()};
if (metadata == "") if (metadata == "")
continue; continue;