-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
277 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
#include "QuestPinnedRenderer.h" | ||
|
||
#include "Akagoria.h" | ||
#include "QuestData.h" | ||
|
||
namespace akgr { | ||
|
||
namespace { | ||
|
||
gf::RichTextStyle compute_quest_style() | ||
{ | ||
gf::RichTextStyle style; | ||
style.set_style("title", { 1.2f, gf::White, gf::FontStyle::Bold }); | ||
style.set_style("history", { 1.0f, gf::Yellow, gf::FontStyle::Bold }); | ||
style.set_style("current", { 1.0f, gf::White, gf::FontStyle::Italic }); | ||
style.set_style("progress", { 1.0f, gf::White, gf::None }); | ||
return style; | ||
} | ||
|
||
} | ||
|
||
QuestPinnedRenderer::QuestPinnedRenderer(Akagoria* game, const WorldResources& resources) | ||
: m_game(game) | ||
, m_atlas({ 1024, 1024 }, game->render_manager()) | ||
, m_style(compute_quest_style()) | ||
, m_quest_texts({ initial_text(resources), initial_text(resources), initial_text(resources), initial_text(resources), initial_text(resources) }) | ||
{ | ||
} | ||
|
||
void QuestPinnedRenderer::update(gf::Time time) | ||
{ | ||
std::vector<QuestState*> visible_quests; | ||
|
||
for (auto& quest : m_game->world_state()->hero.quests) { | ||
if (quest.status != QuestStatus::Visible) { | ||
continue; | ||
} | ||
|
||
visible_quests.push_back(&quest); | ||
} | ||
|
||
if (visible_quests.empty()) { | ||
return; | ||
} | ||
|
||
std::sort(visible_quests.begin(), visible_quests.end(), [](const QuestState* lhs, const QuestState* rhs) { | ||
if (lhs->data->scope == QuestScope::History) { | ||
return true; | ||
} | ||
|
||
if (rhs->data->scope == QuestScope::History) { | ||
return false; | ||
} | ||
|
||
return lhs->last_update > rhs->last_update; | ||
}); | ||
|
||
if (visible_quests.size() > PinnedQuestCount) { | ||
visible_quests.resize(PinnedQuestCount); | ||
} | ||
|
||
m_quest_count = visible_quests.size(); | ||
|
||
for (std::size_t i = 0; i < m_quest_count; ++i) { | ||
auto& quest = visible_quests[i]; | ||
const std::size_t step_index = quest->current_step; | ||
|
||
gf::TextData data = m_default_text_data; | ||
|
||
if (quest->data->scope == QuestScope::History) { | ||
data.content = fmt::format("<style=title><style=history>{}</></>", quest->data->title); | ||
} else { | ||
data.content = fmt::format("<style=title>{}</>", quest->data->title); | ||
} | ||
|
||
switch (quest->type()) { | ||
case QuestType::None: | ||
break; | ||
case QuestType::Hunt: | ||
{ | ||
data.content += '\n'; | ||
|
||
const auto& quest_state = std::get<HuntQuestState>(quest->features); | ||
const auto& quest_data = std::get<HuntQuestData>(quest->data->steps[step_index].features); | ||
|
||
data.content += fmt::format("→ <style=current>{}</> <style=progress>{}/{}</>", quest->data->steps[step_index].description, quest_state.amount, quest_data.count); | ||
} | ||
break; | ||
case QuestType::Talk: | ||
{ | ||
data.content += '\n'; | ||
data.content += fmt::format("→ <style=current>{}</>", quest->data->steps[step_index].description); | ||
} | ||
break; | ||
case QuestType::Farm: | ||
{ | ||
data.content += '\n'; | ||
|
||
const auto& quest_state = std::get<FarmQuestState>(quest->features); | ||
const auto& quest_data = std::get<FarmQuestData>(quest->data->steps[step_index].features); | ||
|
||
data.content += fmt::format("→ <style=current>{}</> <style=progress>{}/{}</>", quest->data->steps[step_index].description, quest_state.amount, quest_data.count); | ||
} | ||
break; | ||
case QuestType::Explore: | ||
{ | ||
data.content += '\n'; | ||
data.content += fmt::format("→ {}", quest->data->steps[step_index].description); | ||
} | ||
break; | ||
} | ||
|
||
m_quest_texts[i].text().update(data, m_game->render_manager()); // NOLINT | ||
m_quest_texts[i].set_location({ 1300, 200 }); // NOLINT | ||
} | ||
|
||
} | ||
|
||
void QuestPinnedRenderer::render(gf::RenderRecorder& recorder) | ||
{ | ||
for (std::size_t i = 0; i < m_quest_count; ++i) { | ||
m_quest_texts[i].render(recorder); // NOLINT | ||
} | ||
} | ||
|
||
gf::RichTextEntity QuestPinnedRenderer::initial_text(const WorldResources& resources) | ||
{ | ||
return { &m_atlas, &m_style, resources.pinned_quest_text, m_game->render_manager(), m_game->resource_manager() }; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#ifndef AKGR_QUEST_RENDERER_H | ||
#define AKGR_QUEST_RENDERER_H | ||
|
||
#include <array> | ||
|
||
#include <gf2/graphics/Entity.h> | ||
#include <gf2/graphics/TextEntity.h> | ||
|
||
#include "WorldResources.h" | ||
|
||
namespace akgr { | ||
|
||
class Akagoria; | ||
|
||
class QuestPinnedRenderer : public gf::Entity { | ||
public: | ||
QuestPinnedRenderer(Akagoria* game, const WorldResources& resources); | ||
|
||
void update(gf::Time time) override; | ||
void render(gf::RenderRecorder& recorder) override; | ||
|
||
private: | ||
gf::RichTextEntity initial_text(const WorldResources& resources); | ||
|
||
static constexpr std::size_t PinnedQuestCount = 5; | ||
|
||
Akagoria* m_game = nullptr; | ||
gf::FontAtlas m_atlas; | ||
gf::RichTextStyle m_style; | ||
|
||
gf::TextData m_default_text_data; | ||
|
||
std::size_t m_quest_count = 0; | ||
std::array<gf::RichTextEntity, PinnedQuestCount> m_quest_texts; | ||
}; | ||
|
||
} | ||
|
||
#endif // AKGR_QUEST_RENDERER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,48 @@ | ||
#include "QuestState.h" | ||
|
||
#include <cassert> | ||
|
||
namespace akgr { | ||
|
||
void QuestState::reset_features() | ||
{ | ||
assert(current_step < data->steps.size()); | ||
const QuestStepData& step = data->steps[current_step]; | ||
|
||
switch (step.type()) { | ||
case QuestType::None: | ||
{ | ||
features = {}; | ||
} | ||
break; | ||
case QuestType::Hunt: | ||
{ | ||
HuntQuestState state = {}; | ||
state.amount = 0; | ||
features = state; | ||
} | ||
break; | ||
case QuestType::Talk: | ||
{ | ||
TalkQuestState state = {}; | ||
features = state; | ||
} | ||
break; | ||
case QuestType::Farm: | ||
{ | ||
FarmQuestState state = {}; | ||
state.amount = 0; | ||
features = state; | ||
} | ||
break; | ||
case QuestType::Explore: | ||
{ | ||
ExploreQuestState state = {}; | ||
features = state; | ||
} | ||
break; | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.