Adds ResultScene.
This commit is contained in:
parent
7b5bc58246
commit
7a13e62bf1
@ -152,6 +152,7 @@
|
|||||||
<ClCompile Include="src\Lua.cc" />
|
<ClCompile Include="src\Lua.cc" />
|
||||||
<ClCompile Include="src\main.cc" />
|
<ClCompile Include="src\main.cc" />
|
||||||
<ClCompile Include="src\PlayScene.cc" />
|
<ClCompile Include="src\PlayScene.cc" />
|
||||||
|
<ClCompile Include="src\ResultScene.cc" />
|
||||||
<ClCompile Include="src\Texture.cc" />
|
<ClCompile Include="src\Texture.cc" />
|
||||||
<ClCompile Include="src\Win32Console.cc" />
|
<ClCompile Include="src\Win32Console.cc" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@ -182,6 +183,7 @@
|
|||||||
<ClInclude Include="src\iAllocator.h" />
|
<ClInclude Include="src\iAllocator.h" />
|
||||||
<ClInclude Include="src\LinearAllocator.h" />
|
<ClInclude Include="src\LinearAllocator.h" />
|
||||||
<ClInclude Include="src\Frame.h" />
|
<ClInclude Include="src\Frame.h" />
|
||||||
|
<ClInclude Include="src\ResultScene.h" />
|
||||||
<ClInclude Include="src\Scoreboard.h" />
|
<ClInclude Include="src\Scoreboard.h" />
|
||||||
<ClInclude Include="src\StackAllocator.h" />
|
<ClInclude Include="src\StackAllocator.h" />
|
||||||
<ClInclude Include="src\SystemClock.h" />
|
<ClInclude Include="src\SystemClock.h" />
|
||||||
|
@ -42,6 +42,9 @@
|
|||||||
<ClCompile Include="src\HiraganaMatcher.cc">
|
<ClCompile Include="src\HiraganaMatcher.cc">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\ResultScene.cc">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="src\iConsole.h">
|
<ClInclude Include="src\iConsole.h">
|
||||||
@ -173,6 +176,9 @@
|
|||||||
<ClInclude Include="src\Scoreboard.h">
|
<ClInclude Include="src\Scoreboard.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="src\ResultScene.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Library Include="thirdparty\lua5.1.lib" />
|
<Library Include="thirdparty\lua5.1.lib" />
|
||||||
|
@ -18,7 +18,7 @@ class InputWindowElement : public iElement {
|
|||||||
UniqPtr<iInputMatcher> matcher;
|
UniqPtr<iInputMatcher> matcher;
|
||||||
UniqPtr<iElementDriver> driver;
|
UniqPtr<iElementDriver> driver;
|
||||||
|
|
||||||
Scoreboard* scoreboard;
|
Scoreboard* scoreboard = nullptr;
|
||||||
|
|
||||||
Period period;
|
Period period;
|
||||||
|
|
||||||
|
@ -28,6 +28,9 @@ class OffsetClock : public iClock {
|
|||||||
uint64_t now() const override {
|
uint64_t now() const override {
|
||||||
return parent_->now() - offset_;
|
return parent_->now() - offset_;
|
||||||
}
|
}
|
||||||
|
const iClock* parent() const {
|
||||||
|
return parent_;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const iClock* parent_;
|
const iClock* parent_;
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
#include "PlayScene.h"
|
#include "PlayScene.h"
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
#include "GlyphElementFactory.h"
|
#include "GlyphElementFactory.h"
|
||||||
#include "InputWindowElementFactory.h"
|
#include "InputWindowElementFactory.h"
|
||||||
|
#include "ResultScene.h"
|
||||||
|
|
||||||
|
|
||||||
gj::PlayScene::PlayScene(Param&& p) :
|
gj::PlayScene::PlayScene(Param&& p) :
|
||||||
@ -11,6 +13,8 @@ gj::PlayScene::PlayScene(Param&& p) :
|
|||||||
GlyphElementFactory glyph(alloc_);
|
GlyphElementFactory glyph(alloc_);
|
||||||
InputWindowElementFactory inputWin(alloc_, &sb_);
|
InputWindowElementFactory inputWin(alloc_, &sb_);
|
||||||
|
|
||||||
|
sb_.title = ConvertStrToWstr(p.score);
|
||||||
|
|
||||||
Lua::FactoryMap map;
|
Lua::FactoryMap map;
|
||||||
map["Glyph"] = &glyph;
|
map["Glyph"] = &glyph;
|
||||||
map["InputWin"] = &inputWin;
|
map["InputWin"] = &inputWin;
|
||||||
@ -19,4 +23,14 @@ gj::PlayScene::PlayScene(Param&& p) :
|
|||||||
alloc_, &store_, map, "res/score/" + p.score + ".lua");
|
alloc_, &store_, map, "res/score/" + p.score + ".lua");
|
||||||
|
|
||||||
logger_->Print(L"PlayScene init");
|
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);
|
PlayScene(Param&& p);
|
||||||
|
|
||||||
UniqPtr<iScene> Update(Frame& f) override {
|
UniqPtr<iScene> Update(Frame& f) override;
|
||||||
if (store_.IsEmpty()) {
|
|
||||||
/* TODO create and return next scene */
|
|
||||||
}
|
|
||||||
store_.Update(f);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
iAllocator* alloc_;
|
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 {
|
struct Scoreboard {
|
||||||
public:
|
public:
|
||||||
|
std::wstring title;
|
||||||
|
|
||||||
size_t input = 0;
|
size_t input = 0;
|
||||||
size_t correct = 0;
|
size_t correct = 0;
|
||||||
size_t miss = 0;
|
size_t miss = 0;
|
||||||
|
12
src/Text.h
12
src/Text.h
@ -3,6 +3,7 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "common.h"
|
||||||
#include "iWritable.h"
|
#include "iWritable.h"
|
||||||
|
|
||||||
namespace gj {
|
namespace gj {
|
||||||
@ -17,7 +18,8 @@ class Text : public WritableBase {
|
|||||||
Text& operator=(const Text&) = default;
|
Text& operator=(const Text&) = default;
|
||||||
|
|
||||||
Text(const std::wstring& str, uint32_t x = 0, uint32_t y = 0) :
|
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 {
|
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:
|
private:
|
||||||
std::wstring entity_;
|
std::wstring entity_;
|
||||||
|
uint32_t w_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user