mirror of
https://github.com/ApfelTeeSaft/PlanetFleet.git
synced 2026-08-27 03:43:30 +00:00
83 lines
2.4 KiB
C++
83 lines
2.4 KiB
C++
#include <algorithm>
|
|
#include <sstream>
|
|
#include <iostream>
|
|
#include <iomanip>
|
|
#include <util.h>
|
|
|
|
#include "abstractAppState.h"
|
|
#include "defConfigs.h"
|
|
|
|
using namespace game::core;
|
|
using namespace vb01;
|
|
using namespace std;
|
|
|
|
namespace game{
|
|
namespace core{
|
|
void AbstractAppState::onAttachment() {
|
|
const int stateId=(int)type,numBinds=core::numBinds[stateId];
|
|
int firstLine=0,lastLine;
|
|
|
|
for(int i=0;i<stateId;i++)
|
|
firstLine+=core::numConfBinds[i];
|
|
|
|
// firstLine++;
|
|
lastLine=firstLine+core::numConfBinds[stateId];
|
|
std::vector<string> lines;
|
|
readFile(PATH_STR + "../options.cfg", lines, firstLine,lastLine);
|
|
|
|
for(int i=0;i<numBinds;i++){
|
|
int trigger=core::triggers[stateId][i];
|
|
|
|
if(i<core::numConfBinds[stateId]&&stateId!=(int)AppStateTypes::GUI_STATE){
|
|
int xId=-1;
|
|
|
|
for(int i2=0;i2<lines[i].size()&&xId==-1;i2++)
|
|
if(lines[i].c_str()[i2]=='x')
|
|
xId=i2;
|
|
|
|
char ch[2];
|
|
|
|
for(int i2=0;i2<2;i2++)
|
|
ch[i2]=(char)lines[i].substr(xId+1,2).c_str()[i2];
|
|
|
|
stringstream ss;
|
|
ss<<ch;
|
|
ss>>std::hex>>trigger;
|
|
}
|
|
|
|
Mapping::Bind bind=binds[stateId][i];
|
|
Mapping::BindType type = (stateId > 0 ? Mapping::KEYBOARD : Mapping::MOUSE_KEY);
|
|
bool isAnalog = core::isAnalog[stateId][i];
|
|
|
|
Mapping *m = new Mapping;
|
|
m->bind = bind;
|
|
m->trigger = trigger;
|
|
m->type = type;
|
|
m->action = !isAnalog;
|
|
attachedKeys.push_back(m);
|
|
}
|
|
|
|
attached = true;
|
|
}
|
|
|
|
void AbstractAppState::onDetachment() {
|
|
attached = false;
|
|
}
|
|
|
|
void AbstractAppState::detachKey(Mapping *key) {
|
|
for (int i = 0; i < attachedKeys.size(); i++)
|
|
if (key == attachedKeys[i]) {
|
|
delete key;
|
|
attachedKeys.erase(attachedKeys.begin() + i);
|
|
}
|
|
}
|
|
|
|
void AbstractAppState::detachAllKeys() {
|
|
while (attachedKeys.size() > 0) {
|
|
delete attachedKeys[attachedKeys.size() - 1];
|
|
attachedKeys.pop_back();
|
|
}
|
|
}
|
|
}
|
|
}
|