From 7e850436b1f6b8e4a359a8c6013c7d313ffa3108 Mon Sep 17 00:00:00 2001 From: kiritow <1362050620@qq.com> Date: Thu, 18 May 2017 14:36:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E4=BA=8ERapidXml=E7=9A=84StringEngine?= =?UTF-8?q?=E4=B8=8D=E5=A5=BD=E7=94=A8=EF=BC=88=E5=9C=A8VS=E5=92=8CGCC?= =?UTF-8?q?=E4=B8=8B=E8=A1=A8=E7=8E=B0=E4=B8=8D=E5=90=8C=EF=BC=89=EF=BC=8C?= =?UTF-8?q?=E5=9B=A0=E6=AD=A4=E5=8F=AA=E5=A5=BD=E5=86=8D=E5=86=99=E4=B8=80?= =?UTF-8?q?=E4=B8=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BattleGame/BattleGame.vcxproj | 4 +++ BattleGame/BattleGame.vcxproj.filters | 12 +++++++ BattleGame/Env.h | 1 - BattleGame/Game.cpp | 52 +++++++++++++++++++++------ BattleGame/Game.h | 1 + BattleGame/MapEditor.cpp | 42 +++++++++++++++++----- BattleGame/Strings.xml | 8 ----- BattleGame/global.h | 1 - 8 files changed, 93 insertions(+), 28 deletions(-) delete mode 100644 BattleGame/Strings.xml diff --git a/BattleGame/BattleGame.vcxproj b/BattleGame/BattleGame.vcxproj index f56224d..763a93c 100644 --- a/BattleGame/BattleGame.vcxproj +++ b/BattleGame/BattleGame.vcxproj @@ -155,6 +155,10 @@ + + + + diff --git a/BattleGame/BattleGame.vcxproj.filters b/BattleGame/BattleGame.vcxproj.filters index 0a38a31..ca61f1a 100644 --- a/BattleGame/BattleGame.vcxproj.filters +++ b/BattleGame/BattleGame.vcxproj.filters @@ -51,6 +51,18 @@ 头文件 + + 头文件 + + + 头文件 + + + 头文件 + + + 头文件 + diff --git a/BattleGame/Env.h b/BattleGame/Env.h index 56d548e..cfe19ce 100644 --- a/BattleGame/Env.h +++ b/BattleGame/Env.h @@ -8,6 +8,5 @@ struct Env MiniEngine::Renderer* rnd; MiniEngine::Font* font; Frame* frame; - MiniEngine::StringEngine* strEngine; }; diff --git a/BattleGame/Game.cpp b/BattleGame/Game.cpp index 5cc66a3..0c4dc7e 100644 --- a/BattleGame/Game.cpp +++ b/BattleGame/Game.cpp @@ -9,25 +9,47 @@ using namespace MiniEngine; #include #include #include +#include +#include +using namespace std; +vector> strvec; void InitStringEngine() { - StringEngine* _str_engine=new StringEngine("Strings.xml","zh_CN"); - if(_str_engine==nullptr||(!_str_engine->ready())) - { - printf("[Error] String Engine is not ready. \n"); - abort(); - } - global.strEngine = _str_engine; + FILE* fp = fopen("Strings.txt", "r"); + char tagbuff[256]; + memset(tagbuff, 0, 256); + char content[1024]; + memset(content, 0, 1024); + while (fscanf(fp, "%s%*c", tagbuff) == 1) + { + fgets(content, 1024, fp); + strvec.push_back(make_pair(tagbuff, content)); + } + fclose(fp); +} + +string GetString(const string & Tag) +{ + for (auto iter = strvec.begin();iter != strvec.end();++iter) + { + if (iter->first == Tag) + { + return iter->second; + } + } + + return "STRING_NOT_FOUND"; } void QuitStringEngine() { - delete global.strEngine; - global.strEngine = nullptr; + } - +#include +#include +using namespace rapidxml; void GameMain() { @@ -38,4 +60,14 @@ void GameMain() InitUnitData(); global.frame->run(new MapEditorScene); + + xml_document<> doc; + xml_node<>* rootnode = doc.allocate_node(node_type::node_element, "en_US"); + doc.append_node(rootnode); + rootnode->append_node(doc.allocate_node(node_type::node_element, "Fuck", "Fuck XML")); + std::string s; + print(std::back_inserter(s), doc); + printf("%s\n", s.c_str()); } + + diff --git a/BattleGame/Game.h b/BattleGame/Game.h index e4f7a97..83bb354 100644 --- a/BattleGame/Game.h +++ b/BattleGame/Game.h @@ -1,3 +1,4 @@ #pragma once #include "MiniEngine/MiniEngine.h" void GameMain(); +std::string GetString(const std::string& Tag); \ No newline at end of file diff --git a/BattleGame/MapEditor.cpp b/BattleGame/MapEditor.cpp index cc19ead..c3980de 100644 --- a/BattleGame/MapEditor.cpp +++ b/BattleGame/MapEditor.cpp @@ -1,6 +1,9 @@ #include "MapEditor.h" #include "Button.h" +#include "Game.h" using namespace MiniEngine; + +#include using namespace std; struct SizePack @@ -14,26 +17,49 @@ void MapEditorScene::start(void* ptr) SizePack* ppack=(SizePack*)global.frame->run(new MapEditorMapSizeConfigureScene,new SizePack); } -class MapEditorMapSizeConfigureSceneReturnButton : public StaticButtonBase +class FramedStaticButtonBase : public StaticButtonBase { public: + virtual void draw() override + { + global.rnd->copyTo(text, pos); + RGBA c = global.rnd->getColor(); + global.rnd->setColor(RGBA(255, 255, 255, 255)); + global.rnd->drawRect(pos); + global.rnd->setColor(c); + } +}; +class MapEditorMapSizeConfigureSceneReturnButton : public FramedStaticButtonBase +{ +public: + virtual void onMouseDown(Looper& lp, Event& ev) override + { + /// If return is pressed, stop the looper. + lp.stop(); + } }; //virtual void MapEditorMapSizeConfigureScene::start(void* ptr) { - Rect winSize=global.wnd->getSize(); + Rect winSize = global.wnd->getSize(); - Texture text_a1 = global.font->renderUTF8(*(global.rnd),global.strEngine->getString("INPUT_SIZE"), RGBA(255, 255, 255, 255)); - Texture text_a2 = global.font->renderUTF8(*(global.rnd),global.strEngine->getString("BACK"), RGBA(255, 255, 255, 255)); - Texture text_a3 = global.font->renderUTF8(*(global.rnd),global.strEngine->getString("CREATE_MAP"), RGBA(255, 255, 255, 255)); - Texture text_b1 = global.font->renderUTF8(*(global.rnd),global.strEngine->getString("W:"), RGBA(255, 255, 255, 255)); - Texture text_b2 = global.font->renderUTF8(*(global.rnd),global.strEngine->getString("H:"), RGBA(255, 255, 255, 255)); - Texture text_c1 = global.font->renderUTF8(*(global.rnd),global.strEngine->getString("999"), RGBA(255, 255, 255, 255)); + Texture text_a1 = global.font->renderUTF8(*(global.rnd),GetString("FUCK"), RGBA(255, 255, 255, 255)); + Texture text_a2 = global.font->renderUTF8(*(global.rnd),GetString("BACK"), RGBA(255, 255, 255, 255)); + Texture text_a3 = global.font->renderUTF8(*(global.rnd),GetString("CREATE_MAP"), RGBA(255, 255, 255, 255)); + Texture text_b1 = global.font->renderUTF8(*(global.rnd),"W:", RGBA(255, 255, 255, 255)); + Texture text_b2 = global.font->renderUTF8(*(global.rnd),"H:", RGBA(255, 255, 255, 255)); + Texture text_c1 = global.font->renderUTF8(*(global.rnd),"999", RGBA(255, 255, 255, 255)); Looper lp; LooperAdapter lpa(lp); ButtonAdapter btna(lpa); + shared_ptr pReturnButton(new MapEditorMapSizeConfigureSceneReturnButton); + pReturnButton->text = text_a2; + pReturnButton->pos = Rect(winSize.w / 2 - text_a1.getw()/2, winSize.h / 2 + 20, text_a1.getw(), 20); + btna.addButton(pReturnButton.get()); + + lp.run(); } diff --git a/BattleGame/Strings.xml b/BattleGame/Strings.xml deleted file mode 100644 index 7fd565e..0000000 --- a/BattleGame/Strings.xml +++ /dev/null @@ -1,8 +0,0 @@ - -输入尺寸 -返回 -创建地图 -保存 -保存地图 -退出编辑器 - \ No newline at end of file diff --git a/BattleGame/global.h b/BattleGame/global.h index 29fb1d5..d4c4c23 100644 --- a/BattleGame/global.h +++ b/BattleGame/global.h @@ -14,4 +14,3 @@ extern MiniEngine::Texture textstr_hp;/// HP extern MiniEngine::Texture textstr_enemy;/// Enemy extern MiniEngine::Texture textstr_player;/// Player extern MiniEngine::Texture textstr_cooling;/// Cooling -