-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCampaignLevelState.cpp
161 lines (133 loc) · 3.84 KB
/
CampaignLevelState.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include "CampaignLevelState.h"
#include <Windows.h>
#include <direct.h>
#include <tchar.h>
#include <string>
#include <algorithm>
#include "CameraManager.h"
#include "MainMenuState.h"
#include "PlayState.h"
#include "Menu.h"
#include "TestState.h"
class Menu;
extern CameraManager* gCameraManager;
CampaignLevelState CampaignLevelState::mCampaignLevelState;
void CampaignLevelState::init(Game* game)
{
// important!
setGame(game);
// create the menu
//mCampaignLevelMenu = new Menu("CustemLevelMenu", MOUSE, true, 4, 4);
mCampaignLevelMenu = new Menu("CustemLevelMenu", MOUSE, VER, 2, true, 4, 4);
mCampaignLevelMenu->setMenuBackground("none", 700, 450, 256, 350); // mCampaignLevelMenu->setMenuBackground("misc\\textures\\menu_bkgd.bmp", 700, 450, 256, 350);
// get the files in the map folder
std::vector<string> levelList = getLevels();
// load the campaign progress
mProgress.loadProgress("levels\\campaign\\campaign_progress.txt");
// add menu items, each level
for(int i = 0; i < levelList.size(); i++)
{
// remove .txt
if(levelList[i].find(".txt") != string::npos || levelList[i].find(".TXT") != string::npos)
levelList[i].erase(levelList[i].end()-4,levelList[i].end());
if(mProgress.getProgress(levelList[i]).playable == 0) {
mCampaignLevelMenu->addMenuItem(levelList[i], (char*)GRAY_BUTTON_NORMAL_SOURCE.c_str(), (char*)GRAY_BUTTON_HOOVER_SOURCE.c_str());
mCampaignLevelMenu->setPressable(levelList[i], false);
}
else
mCampaignLevelMenu->addMenuItem(levelList[i], "misc\\textures\\level_menu_normal.bmp", "misc\\textures\\level_menu_hoover.bmp");
}
// build the menu
mCampaignLevelMenu->buildMenu2();
mCampaignLevelMenu->connect(&CampaignLevelState::menuHandler, this);
mBackgroundTexture = gGraphics->loadTexture("misc\\textures\\epic_bkgd.bmp");
}
void CampaignLevelState::cleanup()
{
delete mCampaignLevelMenu;
ReleaseCOM(mBackgroundTexture);
}
void CampaignLevelState::pause()
{
// don't know how to to yet
}
void CampaignLevelState::resume()
{
// don't know how to to yet
}
void CampaignLevelState::handleEvents(UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_KEYDOWN:
if( wParam == VK_ESCAPE ) {
changeState(MainMenuState::Instance());
}
break;
}
}
void CampaignLevelState::update(double dt)
{
// call menuHandler() when a item is pressed
// state changing takes place there
updateMenu();
}
// just so CampaignEditorState can reach this
void CampaignLevelState::updateMenu(void)
{
// consider to combine this with the menuHandler()
mCampaignLevelMenu->update(gDInput->getCursorX(), gDInput->getCursorY());
}
void CampaignLevelState::drawMain(void)
{
gGraphics->BlitTexture(mBackgroundTexture, 0, 0, 1200, 900);
mCampaignLevelMenu->draw();
}
void CampaignLevelState::drawGui(void)
{
// the green side
gGraphics->BlitRect(1300, 450, 200, 900, D3DCOLOR_ARGB( 155, 155, 200, 000));
}
std::vector<string> CampaignLevelState::getLevels(void)
{
int size;
int counter = 0;
bool working(true);
string test;
char buffer[256] = "";
std::vector<string> levelList;
WIN32_FIND_DATA findData;
HANDLE myHandle = FindFirstFile("levels\\campaign\\*",&findData); // C:\\hlserver\\*
if (myHandle == INVALID_HANDLE_VALUE)
{
MessageBox(0, "Error loading the first file", 0, 0);
}
else
{
do
{
test = string(findData.cFileName);
if (test != "." && test != ".." && test != "campaign_progress.txt")
{
// remove spaces
for(int j = 0; j < test.length()-1; j++) {
if(test[j] == ' ')
test.erase(j);
}
levelList.push_back(test);
counter++;
}
} while (FindNextFile(myHandle, &findData));
}
return levelList;
}
bool CampaignLevelState::menuHandler(std::string name)
{
//add levels\\ and .txt
string tmp = "levels\\campaign\\";
tmp.append(name);
tmp.append(".txt");
changeState(PlayState::Instance());
PlayState::Instance()->setLevel(tmp);
return false;
}