2014-06-25 16:29:58 +00:00
|
|
|
#include "components/AsyncReqComponent.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
|
|
|
|
#include "HttpReq.h"
|
2014-06-25 16:29:58 +00:00
|
|
|
#include "Renderer.h"
|
|
|
|
|
|
|
|
AsyncReqComponent::AsyncReqComponent(Window* window, std::shared_ptr<HttpReq> req, std::function<void(std::shared_ptr<HttpReq>)> onSuccess, std::function<void()> onCancel)
|
|
|
|
: GuiComponent(window),
|
|
|
|
mSuccessFunc(onSuccess), mCancelFunc(onCancel), mTime(0), mRequest(req)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AsyncReqComponent::input(InputConfig* config, Input input)
|
|
|
|
{
|
|
|
|
if(input.value != 0 && config->isMappedTo("b", input))
|
|
|
|
{
|
|
|
|
if(mCancelFunc)
|
|
|
|
mCancelFunc();
|
|
|
|
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AsyncReqComponent::update(int deltaTime)
|
|
|
|
{
|
|
|
|
if(mRequest->status() != HttpReq::REQ_IN_PROGRESS)
|
|
|
|
{
|
|
|
|
mSuccessFunc(mRequest);
|
|
|
|
delete this;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mTime += deltaTime;
|
|
|
|
}
|
|
|
|
|
2017-10-28 20:24:35 +00:00
|
|
|
void AsyncReqComponent::render(const Transform4x4f& parentTrans)
|
2014-06-25 16:29:58 +00:00
|
|
|
{
|
2017-10-28 20:24:35 +00:00
|
|
|
Transform4x4f trans = Transform4x4f::Identity();
|
|
|
|
trans = trans.translate(Vector3f(Renderer::getScreenWidth() / 2.0f, Renderer::getScreenHeight() / 2.0f, 0));
|
2014-06-25 16:29:58 +00:00
|
|
|
Renderer::setMatrix(trans);
|
|
|
|
|
2017-10-28 20:24:35 +00:00
|
|
|
Vector3f point(cos(mTime * 0.01f) * 12, sin(mTime * 0.01f) * 12, 0);
|
2014-06-25 16:29:58 +00:00
|
|
|
Renderer::drawRect((int)point.x(), (int)point.y(), 8, 8, 0x0000FFFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<HelpPrompt> AsyncReqComponent::getHelpPrompts()
|
|
|
|
{
|
|
|
|
std::vector<HelpPrompt> prompts;
|
|
|
|
prompts.push_back(HelpPrompt("b", "cancel"));
|
|
|
|
return prompts;
|
|
|
|
}
|