diff --git a/GlyphsJuke.vcxproj b/GlyphsJuke.vcxproj index 80bb1e2..614d801 100644 --- a/GlyphsJuke.vcxproj +++ b/GlyphsJuke.vcxproj @@ -152,6 +152,7 @@ + @@ -182,6 +183,7 @@ + diff --git a/GlyphsJuke.vcxproj.filters b/GlyphsJuke.vcxproj.filters index d9e576d..eb20bfd 100644 --- a/GlyphsJuke.vcxproj.filters +++ b/GlyphsJuke.vcxproj.filters @@ -42,6 +42,9 @@ Source Files + + Source Files + @@ -173,6 +176,9 @@ Header Files + + Header Files + diff --git a/src/InputWindowElement.h b/src/InputWindowElement.h index 45a5524..a960bc8 100644 --- a/src/InputWindowElement.h +++ b/src/InputWindowElement.h @@ -18,7 +18,7 @@ class InputWindowElement : public iElement { UniqPtr matcher; UniqPtr driver; - Scoreboard* scoreboard; + Scoreboard* scoreboard = nullptr; Period period; diff --git a/src/OffsetClock.h b/src/OffsetClock.h index 794870b..37c79e0 100644 --- a/src/OffsetClock.h +++ b/src/OffsetClock.h @@ -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_; diff --git a/src/PlayScene.cc b/src/PlayScene.cc index 326c0ca..83857ce 100644 --- a/src/PlayScene.cc +++ b/src/PlayScene.cc @@ -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; @@ -19,4 +23,14 @@ gj::PlayScene::PlayScene(Param&& p) : alloc_, &store_, map, "res/score/" + p.score + ".lua"); logger_->Print(L"PlayScene init"); +} + + +gj::UniqPtr gj::PlayScene::Update(Frame& f) { + if (store_.IsEmpty()) { + return alloc_->MakeUniq(alloc_, clock_.parent(), sb_); + } + + store_.Update(f); + return nullptr; } \ No newline at end of file diff --git a/src/PlayScene.h b/src/PlayScene.h index ad5815c..e4c7a11 100644 --- a/src/PlayScene.h +++ b/src/PlayScene.h @@ -35,13 +35,7 @@ class PlayScene : public iScene { PlayScene(Param&& p); - UniqPtr Update(Frame& f) override { - if (store_.IsEmpty()) { - /* TODO create and return next scene */ - } - store_.Update(f); - return nullptr; - } + UniqPtr Update(Frame& f) override; private: iAllocator* alloc_; diff --git a/src/ResultScene.cc b/src/ResultScene.cc new file mode 100644 index 0000000..bbc9951 --- /dev/null +++ b/src/ResultScene.cc @@ -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::ResultScene::Update(Frame& f) { + const int32_t w = static_cast(f.w); + const int32_t h = static_cast(f.h); + + const int32_t title_y = static_cast(h * .2); + const int32_t correct_y = static_cast(h * .35); + const int32_t line_y = static_cast(h * .45); + + title_.SetPosition((w-title_.width())/2, title_y); + f.Add(&title_); + + correct_label_.SetPosition( + static_cast(w*.2), correct_y); + f.Add(&correct_label_); + + correct_num_.SetPosition( + static_cast(w*.7 - correct_num_.width()), correct_y); + f.Add(&correct_num_); + + correct_den_.SetPosition( + static_cast(w*.8 - correct_den_.width()), correct_y); + f.Add(&correct_den_); + + line_label_.SetPosition( + static_cast(w*.2), line_y); + f.Add(&line_label_); + + line_num_.SetPosition( + static_cast(w*.7 - line_num_.width()), line_y); + f.Add(&line_num_); + + line_den_.SetPosition( + static_cast(w*.8 - line_den_.width()), line_y); + f.Add(&line_den_); + + guide_.SetPosition((w-guide_.width())/2, static_cast(h*.8)); + f.Add(&guide_); + + return nullptr; +} \ No newline at end of file diff --git a/src/ResultScene.h b/src/ResultScene.h new file mode 100644 index 0000000..14b6d52 --- /dev/null +++ b/src/ResultScene.h @@ -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 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_; +}; + + +} \ No newline at end of file diff --git a/src/Scoreboard.h b/src/Scoreboard.h index a99a355..d8fce75 100644 --- a/src/Scoreboard.h +++ b/src/Scoreboard.h @@ -8,6 +8,8 @@ namespace gj { struct Scoreboard { public: + std::wstring title; + size_t input = 0; size_t correct = 0; size_t miss = 0; diff --git a/src/Text.h b/src/Text.h index c6ae9a6..74c7f5a 100644 --- a/src/Text.h +++ b/src/Text.h @@ -3,6 +3,7 @@ #include #include +#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(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_; };