基于RapidXml的StringEngine不好用(在VS和GCC下表现不同),因此只好再写一个

This commit is contained in:
Kirigaya Kazuto 2017-05-18 14:36:21 +08:00
parent 6ded19818a
commit 7e850436b1
8 changed files with 93 additions and 28 deletions

View File

@ -155,6 +155,10 @@
<ClInclude Include="MapEditor.h" />
<ClInclude Include="MiniEngine\MiniEngine.h" />
<ClInclude Include="MiniEngine\MiniEngine_Event.h" />
<ClInclude Include="MiniEngine\rapidxml\rapidxml.hpp" />
<ClInclude Include="MiniEngine\rapidxml\rapidxml_iterators.hpp" />
<ClInclude Include="MiniEngine\rapidxml\rapidxml_print.hpp" />
<ClInclude Include="MiniEngine\rapidxml\rapidxml_utils.hpp" />
<ClInclude Include="Scene.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />

View File

@ -51,6 +51,18 @@
<ClInclude Include="UnitInit.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="MiniEngine\rapidxml\rapidxml.hpp">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="MiniEngine\rapidxml\rapidxml_iterators.hpp">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="MiniEngine\rapidxml\rapidxml_print.hpp">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="MiniEngine\rapidxml\rapidxml_utils.hpp">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">

View File

@ -8,6 +8,5 @@ struct Env
MiniEngine::Renderer* rnd;
MiniEngine::Font* font;
Frame* frame;
MiniEngine::StringEngine* strEngine;
};

View File

@ -9,25 +9,47 @@ using namespace MiniEngine;
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iterator>
#include <vector>
using namespace std;
vector<pair<string, string>> 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 <MiniEngine/rapidxml/rapidxml.hpp>
#include <MiniEngine/rapidxml/rapidxml_print.hpp>
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());
}

View File

@ -1,3 +1,4 @@
#pragma once
#include "MiniEngine/MiniEngine.h"
void GameMain();
std::string GetString(const std::string& Tag);

View File

@ -1,6 +1,9 @@
#include "MapEditor.h"
#include "Button.h"
#include "Game.h"
using namespace MiniEngine;
#include <memory>
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<MapEditorMapSizeConfigureSceneReturnButton> 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();
}

View File

@ -1,8 +0,0 @@
<zh_CN>
<INPUT_SIZE>输入尺寸</INPUT_SIZE>
<BACK>返回</BACK>
<CREATE_MAP>创建地图</CREATE_MAP>
<SAVE>保存</SAVE>
<SAVE_MAP>保存地图</SAVE_MAP>
<EXIT_EDITOR>退出编辑器</EXIT_EDITOR>
</zh_CN>

View File

@ -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