Adds ResultScene.
This commit is contained in:
parent
7b5bc58246
commit
7a13e62bf1
@ -152,6 +152,7 @@
|
||||
<ClCompile Include="src\Lua.cc" />
|
||||
<ClCompile Include="src\main.cc" />
|
||||
<ClCompile Include="src\PlayScene.cc" />
|
||||
<ClCompile Include="src\ResultScene.cc" />
|
||||
<ClCompile Include="src\Texture.cc" />
|
||||
<ClCompile Include="src\Win32Console.cc" />
|
||||
</ItemGroup>
|
||||
@ -182,6 +183,7 @@
|
||||
<ClInclude Include="src\iAllocator.h" />
|
||||
<ClInclude Include="src\LinearAllocator.h" />
|
||||
<ClInclude Include="src\Frame.h" />
|
||||
<ClInclude Include="src\ResultScene.h" />
|
||||
<ClInclude Include="src\Scoreboard.h" />
|
||||
<ClInclude Include="src\StackAllocator.h" />
|
||||
<ClInclude Include="src\SystemClock.h" />
|
||||
|
@ -42,6 +42,9 @@
|
||||
<ClCompile Include="src\HiraganaMatcher.cc">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\ResultScene.cc">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\iConsole.h">
|
||||
@ -173,6 +176,9 @@
|
||||
<ClInclude Include="src\Scoreboard.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\ResultScene.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Library Include="thirdparty\lua5.1.lib" />
|
||||
|
@ -18,7 +18,7 @@ class InputWindowElement : public iElement {
|
||||
UniqPtr<iInputMatcher> matcher;
|
||||
UniqPtr<iElementDriver> driver;
|
||||
|
||||
Scoreboard* scoreboard;
|
||||
Scoreboard* scoreboard = nullptr;
|
||||
|
||||
Period period;
|
||||
|
||||
|
@ -28,6 +28,9 @@ class OffsetClock : public iClock {
|
||||
uint64_t now() const override {
|
||||
return parent_->now() - offset_;
|
||||
}
|
||||
const iClock* parent() const {
|
||||
return parent_;
|
||||
}
|
||||
|
||||
private:
|
||||
const iClock* parent_;
|
||||
|
@ -1,7 +1,9 @@
|
||||
#include "PlayScene.h"
|
||||
|
||||
#include "common.h"
|
||||
#include "GlyphElementFactory.h"
|
||||
#include "InputWindowElementFactory.h"
|
||||
#include "ResultScene.h"
|
||||
|
||||
|
||||
gj::PlayScene::PlayScene(Param&& p) :
|
||||
@ -11,6 +13,8 @@ gj::PlayScene::PlayScene(Param&& p) :
|
||||
GlyphElementFactory glyph(alloc_);
|
||||
InputWindowElementFactory inputWin(alloc_, &sb_);
|
||||
|
||||
sb_.title = ConvertStrToWstr(p.score);
|
||||
|
||||
Lua::FactoryMap map;
|
||||
map["Glyph"] = &glyph;
|
||||
map["InputWin"] = &inputWin;
|
||||
@ -20,3 +24,13 @@ gj::PlayScene::PlayScene(Param&& p) :
|
||||
|
||||
logger_->Print(L"PlayScene init");
|
||||
}
|
||||
|
||||
|
||||
gj::UniqPtr<gj::iScene> gj::PlayScene::Update(Frame& f) {
|
||||
if (store_.IsEmpty()) {
|
||||
return alloc_->MakeUniq<iScene, ResultScene>(alloc_, clock_.parent(), sb_);
|
||||
}
|
||||
|
||||
store_.Update(f);
|
||||
return nullptr;
|
||||
}
|
@ -35,13 +35,7 @@ class PlayScene : public iScene {
|
||||
|
||||
PlayScene(Param&& p);
|
||||
|
||||
UniqPtr<iScene> Update(Frame& f) override {
|
||||
if (store_.IsEmpty()) {
|
||||
/* TODO create and return next scene */
|
||||
}
|
||||
store_.Update(f);
|
||||
return nullptr;
|
||||
}
|
||||
UniqPtr<iScene> Update(Frame& f) override;
|
||||
|
||||
private:
|
||||
iAllocator* alloc_;
|
||||
|
55
src/ResultScene.cc
Normal file
55
src/ResultScene.cc
Normal file
@ -0,0 +1,55 @@
|
||||
#include "ResultScene.h"
|
||||
|
||||
|
||||
gj::ResultScene::ResultScene(iAllocator* alloc, const iClock* clock, const Scoreboard& sb) :
|
||||
alloc_(alloc), clock_(clock), sb_(sb),
|
||||
title_(sb.title),
|
||||
correct_label_(L"CORRECT TYPES"),
|
||||
correct_num_(std::to_wstring(sb.correct)),
|
||||
correct_den_(std::to_wstring(sb.input)),
|
||||
line_label_(L"COMPLETE LINES"),
|
||||
line_num_(std::to_wstring(sb.completeLines)),
|
||||
line_den_(std::to_wstring(sb.lines)),
|
||||
guide_(L"~ PRESS ENTER ~") {
|
||||
}
|
||||
|
||||
gj::UniqPtr<gj::iScene> gj::ResultScene::Update(Frame& f) {
|
||||
const int32_t w = static_cast<int32_t>(f.w);
|
||||
const int32_t h = static_cast<int32_t>(f.h);
|
||||
|
||||
const int32_t title_y = static_cast<int32_t>(h * .2);
|
||||
const int32_t correct_y = static_cast<int32_t>(h * .35);
|
||||
const int32_t line_y = static_cast<int32_t>(h * .45);
|
||||
|
||||
title_.SetPosition((w-title_.width())/2, title_y);
|
||||
f.Add(&title_);
|
||||
|
||||
correct_label_.SetPosition(
|
||||
static_cast<int32_t>(w*.2), correct_y);
|
||||
f.Add(&correct_label_);
|
||||
|
||||
correct_num_.SetPosition(
|
||||
static_cast<int32_t>(w*.7 - correct_num_.width()), correct_y);
|
||||
f.Add(&correct_num_);
|
||||
|
||||
correct_den_.SetPosition(
|
||||
static_cast<int32_t>(w*.8 - correct_den_.width()), correct_y);
|
||||
f.Add(&correct_den_);
|
||||
|
||||
line_label_.SetPosition(
|
||||
static_cast<int32_t>(w*.2), line_y);
|
||||
f.Add(&line_label_);
|
||||
|
||||
line_num_.SetPosition(
|
||||
static_cast<int32_t>(w*.7 - line_num_.width()), line_y);
|
||||
f.Add(&line_num_);
|
||||
|
||||
line_den_.SetPosition(
|
||||
static_cast<int32_t>(w*.8 - line_den_.width()), line_y);
|
||||
f.Add(&line_den_);
|
||||
|
||||
guide_.SetPosition((w-guide_.width())/2, static_cast<int32_t>(h*.8));
|
||||
f.Add(&guide_);
|
||||
|
||||
return nullptr;
|
||||
}
|
47
src/ResultScene.h
Normal file
47
src/ResultScene.h
Normal file
@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#include "ElementStore.h"
|
||||
#include "Frame.h"
|
||||
#include "iAllocator.h"
|
||||
#include "iScene.h"
|
||||
#include "OffsetClock.h"
|
||||
#include "Scoreboard.h"
|
||||
#include "Text.h"
|
||||
|
||||
|
||||
namespace gj {
|
||||
|
||||
|
||||
class ResultScene : public iScene {
|
||||
public:
|
||||
ResultScene() = delete;
|
||||
ResultScene(ResultScene&&) = delete;
|
||||
ResultScene(const ResultScene&) = delete;
|
||||
|
||||
ResultScene& operator=(ResultScene&&) = delete;
|
||||
ResultScene& operator=(const ResultScene&) = delete;
|
||||
|
||||
ResultScene(iAllocator* alloc, const iClock* clock, const Scoreboard& sb);
|
||||
|
||||
UniqPtr<iScene> Update(Frame& f) override;
|
||||
|
||||
private:
|
||||
iAllocator* alloc_;
|
||||
OffsetClock clock_;
|
||||
Scoreboard sb_;
|
||||
|
||||
Text title_;
|
||||
|
||||
Text correct_label_;
|
||||
Text correct_num_;
|
||||
Text correct_den_;
|
||||
|
||||
Text line_label_;
|
||||
Text line_num_;
|
||||
Text line_den_;
|
||||
|
||||
Text guide_;
|
||||
};
|
||||
|
||||
|
||||
}
|
@ -8,6 +8,8 @@ namespace gj {
|
||||
|
||||
struct Scoreboard {
|
||||
public:
|
||||
std::wstring title;
|
||||
|
||||
size_t input = 0;
|
||||
size_t correct = 0;
|
||||
size_t miss = 0;
|
||||
|
12
src/Text.h
12
src/Text.h
@ -3,6 +3,7 @@
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#include "common.h"
|
||||
#include "iWritable.h"
|
||||
|
||||
namespace gj {
|
||||
@ -17,7 +18,8 @@ class Text : public WritableBase {
|
||||
Text& operator=(const Text&) = default;
|
||||
|
||||
Text(const std::wstring& str, uint32_t x = 0, uint32_t y = 0) :
|
||||
WritableBase(x, y), entity_(str) {
|
||||
WritableBase(x, y), entity_(str),
|
||||
w_(static_cast<uint32_t>(CountWstrBytes(str))) {
|
||||
}
|
||||
|
||||
void Write(Textbuffer& fb) const override {
|
||||
@ -39,8 +41,16 @@ class Text : public WritableBase {
|
||||
}
|
||||
}
|
||||
|
||||
const std::wstring& entity() const {
|
||||
return entity_;
|
||||
}
|
||||
uint32_t width() const {
|
||||
return w_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::wstring entity_;
|
||||
uint32_t w_;
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user