Skip to content

Commit

Permalink
Commit all 1.0 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Cruel committed Feb 29, 2016
1 parent 81b9136 commit 972d08b
Show file tree
Hide file tree
Showing 15 changed files with 711 additions and 209 deletions.
45 changes: 4 additions & 41 deletions src/AppItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,17 @@
#include "AssetManager.hpp"
#include "AppItem.hpp"

namespace {

cpp3ds::Texture& getMissingIconTexture()
{
static cpp3ds::Texture texture;
if (texture.getSize().x == 0)
texture.loadFromFile("images/missing-icon.png");
return texture;
}

}


namespace BrewMan
{

// Static members
cpp3ds::Texture AppItem::m_backgroundTexture;
cpp3ds::Texture AppItem::m_backgroundSelectedTexture;

AppItem::AppItem()
: m_progress(0.f)
, m_installed(false)
: m_installed(false)
{
if (m_backgroundTexture.getSize().x == 0)
m_backgroundTexture.loadFromFile("images/itembg.9.png");
if (m_backgroundSelectedTexture.getSize().x == 0)
m_backgroundSelectedTexture.loadFromFile("images/itembg-selected.9.png");

deselect();

m_icon.setSize(cpp3ds::Vector2f(48.f, 48.f));
m_icon.setTexture(&getMissingIconTexture(), true);
m_icon.setTexture(&AssetManager<cpp3ds::Texture>::get("images/missing-icon.png"), true);
m_icon.setPosition(4.f, 4.f);
m_icon.setOutlineThickness(1.f);
m_icon.setFillColor(cpp3ds::Color(180,180,180));
Expand Down Expand Up @@ -78,19 +56,15 @@ void AppItem::draw(cpp3ds::RenderTarget &target, cpp3ds::RenderStates states) co
target.draw(m_titleText, states);
target.draw(m_filesizeText, states);
target.draw(m_authorText, states);
if (m_progress > 0.f)
target.draw(m_progressBar, states);
}

void AppItem::setSize(float width, float height)
{
m_size.x = width;
m_size.y = height;

// m_background.setPadding(3.f, 3.f, 3.f, 3.f);
m_background.setContentSize(m_size.x + m_background.getPadding().width - m_background.getTexture()->getSize().x + 2.f,
m_size.y + m_background.getPadding().height - m_background.getTexture()->getSize().y + 2.f);
setProgress(m_progress); // Resize progress bar
}

const cpp3ds::Vector2f& AppItem::getSize() const
Expand Down Expand Up @@ -231,29 +205,18 @@ void AppItem::loadFromYAML(const std::string &filename)

void AppItem::select()
{
m_background.setTexture(&m_backgroundSelectedTexture);
m_background.setTexture(&AssetManager<cpp3ds::Texture>::get("images/itembg-selected.9.png"));
m_background.setColor(cpp3ds::Color(255, 255, 255, 200));
m_icon.setOutlineThickness(2.f);
}

void AppItem::deselect()
{
m_background.setTexture(&m_backgroundTexture);
m_background.setTexture(&AssetManager<cpp3ds::Texture>::get("images/itembg.9.png"));
m_background.setColor(cpp3ds::Color(255, 255, 255, 80));
m_icon.setOutlineThickness(1.f);
}

void AppItem::setProgress(float progress)
{
m_progress = progress;
m_progressBar.setSize(cpp3ds::Vector2f(m_progress * m_size.x, m_size.y));
}

float AppItem::getProgress() const
{
return m_progress;
}

void AppItem::setInstalled(bool installed)
{
m_installed = installed;
Expand Down
6 changes: 0 additions & 6 deletions src/AppItem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ class AppItem : public cpp3ds::Drawable, public util3ds::TweenTransformable<cpp3
void setScreenshots(const std::vector<std::string> &screenshots);
const std::vector<std::string>& getScreenshots() const;

void setProgress(float progress);
float getProgress() const;

void setInstalled(bool installed);
bool isInstalled() const;

Expand All @@ -69,8 +66,6 @@ class AppItem : public cpp3ds::Drawable, public util3ds::TweenTransformable<cpp3
virtual void draw(cpp3ds::RenderTarget &target, cpp3ds::RenderStates states) const;

private:
static cpp3ds::Texture m_backgroundTexture;
static cpp3ds::Texture m_backgroundSelectedTexture;
gui3ds::NinePatch m_background;

cpp3ds::RectangleShape m_icon;
Expand All @@ -82,7 +77,6 @@ class AppItem : public cpp3ds::Drawable, public util3ds::TweenTransformable<cpp3
cpp3ds::Text m_filesizeText;

cpp3ds::Vector2f m_size;
float m_progress;

std::string m_title;
std::string m_directory;
Expand Down
18 changes: 7 additions & 11 deletions src/AppList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,8 @@
#include <functional>
#include <iostream>
#include "AppList.hpp"
#include "Util.hpp"

namespace {

static bool fileExists(const char *filename)
{
struct stat buffer;
return stat(cpp3ds::FileSystem::getFilePath(filename).c_str(), &buffer) == 0;
}

}

namespace BrewMan {

Expand Down Expand Up @@ -53,11 +45,11 @@ void AppList::refresh()
snprintf(configNameBuf, sizeof(configNameBuf), "%s%s/config.yml", m_directory.c_str(), entry->d_name);
snprintf(iconNameBuf, sizeof(iconNameBuf), "%s%s/icon.png", m_directory.c_str(), entry->d_name);

if (fileExists(configNameBuf))
if (pathExists(configNameBuf))
{
AppItem item;

if (fileExists(iconNameBuf))
if (pathExists(iconNameBuf))
{
cpp3ds::Texture* icon = new cpp3ds::Texture();
if (icon->loadFromFile(iconNameBuf))
Expand All @@ -71,6 +63,10 @@ void AppList::refresh()

item.loadFromYAML(cpp3ds::FileSystem::getFilePath(configNameBuf));
item.setDirectory(entry->d_name);

snprintf(configNameBuf, sizeof(configNameBuf), "sdmc:/3ds/BrewMan/installed/%s.list", entry->d_name);
item.setInstalled(pathExists(configNameBuf));

m_list.push_back(item);
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/BrewMan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ BrewMan::BrewMan()
m_stateStack.registerState<SyncState>(States::Sync);
m_stateStack.registerState<BrowseState>(States::Browse);
// m_stateStack.pushState(States::Browse);
m_stateStack.pushState(States::Loading);
m_stateStack.pushState(States::Sync);
m_stateStack.pushState(States::Title);
m_stateStack.pushState(States::Loading);

textFPS.setFillColor(cpp3ds::Color::Red);
textFPS.setCharacterSize(20);
Expand All @@ -42,11 +42,13 @@ void BrewMan::update(float delta)

Notification::update(delta);

#ifndef NDEBUG
static int i;
if (i++ % 10 == 0) {
textFPS.setString(_("%.1f fps", 1.f / delta));
textFPS.setPosition(395 - textFPS.getGlobalBounds().width, 2.f);
}
#endif
}

void BrewMan::processEvent(Event& event)
Expand All @@ -58,10 +60,12 @@ void BrewMan::renderTopScreen(Window& window)
{
window.clear(Color::White);
m_stateStack.renderTopScreen(window);
window.setView(window.getDefaultView());
for (auto& notification : Notification::notifications)
window.draw(*notification);

#ifndef NDEBUG
window.draw(textFPS);
#endif
}

void BrewMan::renderBottomScreen(Window& window)
Expand Down
147 changes: 145 additions & 2 deletions src/Download.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,57 @@
#include <iostream>
#include <cpp3ds/System/FileSystem.hpp>
#include "Download.hpp"
#include "AssetManager.hpp"

namespace BrewMan {


Download::Download(const std::string &url, const std::string &destination)
: m_thread(&Download::run, this)
, m_destination(destination)
, m_progress(0.f)
, m_markedForDelete(false)
, m_cancelFlag(false)
{
setUrl(url);

setProgressMessage("Queued");

m_icon.setSize(cpp3ds::Vector2f(48.f, 48.f));
m_icon.setTexture(&AssetManager<cpp3ds::Texture>::get("images/missing-icon.png"), true);
m_icon.setPosition(4.f, 4.f);
m_icon.setScale(0.5f, 0.5f);
m_icon.setOutlineThickness(1.f);
m_icon.setFillColor(cpp3ds::Color(180,180,180));
m_icon.setOutlineColor(cpp3ds::Color(0, 0, 0, 50));

m_textCancel.setFont(AssetManager<cpp3ds::Font>::get("fonts/fontawesome.ttf"));
m_textCancel.setString(L"\uf00d");
m_textCancel.setCharacterSize(18);
m_textCancel.setFillColor(cpp3ds::Color::White);
m_textCancel.setOutlineColor(cpp3ds::Color(0, 0, 0, 200));
m_textCancel.setOutlineThickness(1.f);
m_textCancel.setPosition(294.f, 4.f);

m_textTitle.setCharacterSize(10);
m_textTitle.setPosition(35.f, 2.f);
m_textTitle.setFillColor(cpp3ds::Color::Black);

m_textProgress = m_textTitle;
m_textProgress.setFillColor(cpp3ds::Color(130, 130, 130, 255));
m_textProgress.setPosition(35.f, 16.f);

m_background.setTexture(&AssetManager<cpp3ds::Texture>::get("images/itembg.9.png"));
m_background.setColor(cpp3ds::Color(255, 255, 255, 80));
m_progressBar.setFillColor(cpp3ds::Color(0, 0, 0, 50));

setSize(314.f, 32.f);
}


Download::~Download()
{
cancel();
}


Expand All @@ -37,7 +78,6 @@ void Download::start(cpp3ds::Http::RequestCallback onData, DownloadFinishCallbac
if (m_destination.empty())
return;

m_cancelFlag = false;
m_buffer.clear();

m_onData = onData;
Expand All @@ -52,6 +92,8 @@ void Download::run()

m_file = fopen(cpp3ds::FileSystem::getFilePath(m_destination).c_str(), "w");

m_cancelFlag = false;

cpp3ds::Http::RequestCallback dataCallback = [&](const void* data, size_t len, size_t processed, const cpp3ds::Http::Response& response)
{
if (response.getStatus() == 200)
Expand Down Expand Up @@ -87,8 +129,109 @@ void Download::run()
fclose(m_file);

if (m_onFinish)
m_onFinish();
m_onFinish(m_cancelFlag);

if (m_cancelFlag)
m_markedForDelete = true;
}


void Download::cancel(bool wait)
{
m_cancelFlag = true;
if (wait)
m_thread.wait();
}


bool Download::isCanceled()
{
return m_cancelFlag;
}


void Download::setProgress(float progress)
{
m_progress = progress;
m_progressBar.setSize(cpp3ds::Vector2f(m_progress * m_size.x, m_size.y));
}


float Download::getProgress() const
{
return m_progress;
}


void Download::setProgressMessage(const std::string &message)
{
m_progressMessage = message;
m_textProgress.setString(message);
}


const std::string &Download::getProgressMessage() const
{
return m_progressMessage;
}


void Download::draw(cpp3ds::RenderTarget &target, cpp3ds::RenderStates states) const
{
states.transform *= getTransform();

target.draw(m_background, states);
target.draw(m_icon, states);
target.draw(m_textTitle, states);
target.draw(m_textProgress, states);
target.draw(m_textCancel, states);
if (m_progress > 0.f && m_progress < 1.f)
target.draw(m_progressBar, states);
}


void Download::setSize(float width, float height)
{
m_size.x = width;
m_size.y = height;

m_background.setContentSize(m_size.x + m_background.getPadding().width - m_background.getTexture()->getSize().x + 2.f,
m_size.y + m_background.getPadding().height - m_background.getTexture()->getSize().y + 2.f);
setProgress(m_progress); // Resize progress bar
}


void Download::fillFromAppItem(AppItem *app)
{
m_icon.setTexture(app->getIcon(), true);
m_textTitle.setString(app->getTitle());
}


void Download::processEvent(const cpp3ds::Event &event)
{
if (event.type == cpp3ds::Event::TouchBegan)
{
cpp3ds::FloatRect cancelBounds = m_textCancel.getGlobalBounds();
cancelBounds.left += getPosition().x;
cancelBounds.top += getPosition().y;
if (cancelBounds.contains(event.touch.x, event.touch.y))
{
// If download is already finished, just mark it for deletion
if (m_progress == 1.f)
m_markedForDelete = true;
else
{
setProgressMessage("Canceling...");
cancel(false);
}
}
}
}

bool Download::markedForDelete()
{
return m_markedForDelete;
}

} // namespace BrewMan
Loading

0 comments on commit 972d08b

Please sign in to comment.