-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathApp.cpp
134 lines (116 loc) · 3.22 KB
/
App.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/***************************************************************
* Name: App.cpp
* Purpose: Code for Application Class
* Author:
* Created:
* Copyright:
* License:
**************************************************************/
#ifdef WX_PRECOMP
#include "wx_pch.h"
#endif
#ifdef __BORLANDC__
#pragma hdrstop
#endif //__BORLANDC__
#include "App.h"
#include "MapTool.h"
#include <wx/image.h>
#include <wx/regex.h>
#include "wx/stdpaths.h"
#include <wx/utils.h>
#include "wx/propgrid/propgrid.h"
IMPLEMENT_APP(wxWidgets_templateApp);
std::map<int, LevelDetial> *g_NpcLevelList = NULL;
void LoadNpcLevelList();
bool wxWidgets_templateApp::OnInit()
{
bool wxsOK = true;
wxInitAllImageHandlers();
wxPropertyGridInterface::RegisterAdditionalEditors();
//Tmx settings
TmxReaderSetting::LoadConfing();
m_mapTool = new MapTool(NULL);
//Start tmx map file reader help server
wxString exepath;
exepath = wxStandardPaths::Get().GetExecutablePath();
exepath = wxFileName::FileName(exepath).GetPath(wxPATH_GET_VOLUME);
wxExecute(exepath+"/resource/TmxReadHelper/TmxReadHelper.exe");
LoadNpcLevelList();
m_mapTool->Show(true);
return wxsOK;
}
int wxWidgets_templateApp::OnExit()
{
if(g_NpcLevelList != NULL) delete g_NpcLevelList;
Settings::TheSetting.SaveSetting();
return 0;
}
//int wxWidgets_templateApp::FilterEvent(wxEvent& event)
//{
// wxEventType type = event.GetEventType();
// if(type == wxEVT_KEY_UP ||
// type == wxEVT_KEY_DOWN)
// {
// wxKeyEvent *kEvent = (wxKeyEvent*)&event;
// if(kEvent->GetKeyCode() == WXK_CONTROL)
// {
// m_mapTool->RedrawMapView();
// }
// }
// return Event_Skip;
//}
void LoadNpcLevelList()
{
g_NpcLevelList = new std::map<int, LevelDetial>;
wxString filePath = wxStandardPaths::Get().GetExecutablePath();
filePath = wxFileName::FileName(filePath).GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
filePath += wxT("ini\\level\\level-npc.ini");
wxRegEx regex;
if(wxFileName::FileExists(filePath))
{
wxTextFile file(filePath);
file.Open();
if(file.IsOpened())
{
long level, value;
wxString name;
size_t count = file.GetLineCount();
size_t i;
for(i = 0; i < count;)
{
LevelDetial detail;
regex.Compile(wxT("\\[Level([0-9]+)\\]"));
if(regex.Matches(file[i]) &&
!regex.GetMatch(file[i]).IsEmpty())
{
regex.GetMatch(file[i], 1).ToLong(&level);
regex.Compile(wxT("(.*)=([0-9]+)"));
i++;
while(i < count &&
regex.Matches(file[i]) &&
!regex.GetMatch(file[i]).IsEmpty())
{
name = regex.GetMatch(file[i], 1);
regex.GetMatch(file[i], 2).ToLong(&value);
if(name == wxT("Life"))
detail.Life = value;
else if(name == wxT("Attack"))
detail.Attack = value;
else if(name == wxT("Attack2"))
detail.Attack2 = value;
else if(name == wxT("Defend"))
detail.Defend = value;
else if(name == wxT("Defend2"))
detail.Defend2 = value;
else if(name == wxT("Evade"))
detail.Evade = value;
i++;
}
(*g_NpcLevelList)[level] = detail;
}
i++;
}
file.Close();
}
}
}