1 #include "script/MyEnvironment.hpp"
2 #include <boost/tuple/tuple.hpp>
3 #include <boost/format.hpp>
4 #include <boost/lexical_cast.hpp>
5 #include <boost/algorithm/string.hpp>
6 #include <mof/script/ObjectData.hpp>
8 #include <mof/streams.hpp>
9 #include "widget/createMenuView.hpp"
10 #include "widget/createFrame.hpp"
11 #include <mof/Font.hpp>
12 #include <mof/widgets.hpp>
13 #include <mof/utilities.hpp>
14 #include <configure.hpp>
15 #include <mof/utilities.hpp>
16 #include <mof/widget/GridLayout.hpp>
17 #include "sqlite_wrapper.hpp"
18 #include "resource.hpp"
24 struct MyEnvironment::Impl
26 ::sqlite_wrapper sqlite_;
35 MyEnvironment::MyEnvironment(std::shared_ptr<mof::InputReceiver> input)
36 : mof::script::Environment(input), impl_(new Impl())
41 MyEnvironment::~MyEnvironment()
45 //{{{ create_message_data
46 std::unique_ptr<mof::script::MessageData> MyEnvironment::create_message_data
48 const mof::tstring& title, const mof::script::GameData::entry_t& style
51 using namespace mof::widget;
52 using namespace boost;
54 auto compiler = std::make_shared<TextCompiler>
56 mof::Font(FONT_NAME_UME, FONT_SIZE_STANDARD),
57 [] (const mof::tstring& path) { return ::getTextureResourceManager(::SYSTEM)->getResource(path);}
61 // set behavior for page updated
62 mof::KeyFrameAnimation<mof::Color4f>::KeyFrame keyFrames[] =
64 mof::makeKeyFrame(0, mof::Color4f(0, 1, 1, 1)),
65 mof::makeKeyFrame(15, mof::Color4f(0, 1, 1, 1)),
66 mof::makeKeyFrame(45, mof::Color4f(1, 1, 1, 1)),
68 compiler->setBehaviorOnColor
70 TextCompiler::PAGE_OPEN,
71 mof::makeKeyFrameAnimationHandler(keyFrames[0], mof::lastOf(keyFrames)),
77 // set behavior for page updated
78 compiler->setBehaviorOnColor
80 TextCompiler::PAGE_CLOSE,
81 mof::makeKeyFrameAnimationHandler(0, mof::Color4f(1, 1, 1, 1), 15, mof::Color4f(0, 1, 1, 1)),
86 std::unique_ptr<mof::script::MessageData> result(new mof::script::MessageData);
89 result->message_ = std::make_shared<Message>(mof::Vector2D(550, 125), compiler);
92 std::shared_ptr<Frame>
97 _T("image/frame0.png"),
98 _T("image/frame3.png"),
99 result->message_->getView()
109 //{{{ create_menu_data
110 std::unique_ptr<mof::script::MenuData> MyEnvironment::create_menu_data
112 const mof::tstring& title,
113 const std::vector<mof::tstring>& items,
114 const mof::script::GameData::entry_t& style
117 using namespace mof::widget;
118 using namespace mof::script;
119 using namespace boost;
121 GridLayout::Direction direction = GridLayout::VERTICAL;
122 std::vector<int> disable_items;
124 //
\83X
\83^
\83C
\83\8b\82Ì
\89ð
\90Í
125 foreach (const auto& p, style) {
126 if (p.first == "direction") {
127 if (p.second == "vertical") direction = GridLayout::VERTICAL;
128 else if (p.second == "horizontal") direction = GridLayout::HORIZONTAL;
129 else throw std::invalid_argument("invalid direction value:" + p.second);
131 else if (p.first == "disable") {
132 //
\96³
\8cø
\89»
\82·
\82é
\8d\80\96Ú
\82Ì
\89ð
\90Í
133 std::vector<mof::tstring> splited_list;
134 split(splited_list, p.second, is_any_of(","));
135 foreach (auto& item, splited_list) {
136 disable_items.push_back(lexical_cast<int>(item));
139 else throw std::invalid_argument("invalid key:" + p.first);
142 std::unique_ptr<MenuData> result(new MenuData);
145 std::vector<MenuItem> menu_items;
146 for (int i = 0; i < items.size(); ++i) {
147 bool disable = find(disable_items.begin(), disable_items.end(), i) != disable_items.end();// disable_items
\82æ
\82è
\96³
\8cø
\82È
\8d\80\96Ú
\82©
\94»
\92f
148 menu_items.push_back(MenuItem(createMenuView(items[i], disable)));
150 result->menu_ = std::make_shared<Menu>
152 menu_items.front(), menu_items.back(),
153 mof::makeFactoryMethod<GridLayout>(direction, 0)
157 std::shared_ptr<Frame>
162 _T("image/frame0.png") ,
163 _T("image/frame3.png") ,
164 result->menu_->getView()
174 mof::script::GameData::ptr MyEnvironment::get_game_data(const mof::tstring& resource_path)
176 using namespace mof::script;
177 using namespace boost;
179 DEBUG_PRINT("load_game_data(" << resource_path << ")");
181 if (resource_path == "gamedata.item_profile") {
182 return impl_->sqlite_.query_item_profile();
184 else if (resource_path == "gamedata.relic_profile") {
185 return impl_->sqlite_.query_relic_profile();
187 else if (resource_path == "gamedata.ideal_profile") {
188 return impl_->sqlite_.query_ideal_profile();
190 else if (resource_path == "system.client_region") {
191 mof::Rectangle<int> rect = mof::GraphicsDevice::getClientRegion();
192 mof::script::GameData::ptr p = std::make_shared<mof::script::GameData>();
193 mof::script::GameData::entry_t entry;
194 entry["width"] = boost::lexical_cast<mof::tstring>(rect.getWidth());
195 entry["height"] = boost::lexical_cast<mof::tstring>(rect.getHeight());
196 p->data_.push_back(entry);
200 DEBUG_PRINT("unknown resource path:" << resource_path);
201 return std::make_shared<GameData>();