Layout changes only (to be in STK coding style).
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2217 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
796b0b9848
commit
82d817a7ec
@ -69,7 +69,7 @@ UserConfig::UserConfig(const std::string& filename)
|
||||
// -----------------------------------------------------------------------------
|
||||
UserConfig::~UserConfig()
|
||||
{
|
||||
}
|
||||
} // ~UserConfig
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/**
|
||||
@ -134,78 +134,78 @@ void UserConfig::setDefaults()
|
||||
for(int i=0; i<4; i++)
|
||||
{
|
||||
m_player[i].setName(m_username);
|
||||
m_player[i].setLastKartId(0);
|
||||
m_player[i].setLastKartId(0);
|
||||
}
|
||||
|
||||
// Clear every entry.
|
||||
memset(inputMap, 0, sizeof(inputMap));
|
||||
|
||||
/* general game input settings */
|
||||
set(GA_ENTER,
|
||||
Input(IT_KEYBOARD, SDLK_RETURN),
|
||||
Input(IT_KEYBOARD, SDLK_SPACE),
|
||||
Input(IT_STICKBUTTON, 0, 0),
|
||||
Input(IT_MOUSEBUTTON, 1));
|
||||
set(GA_LEAVE,
|
||||
Input(IT_KEYBOARD, SDLK_ESCAPE),
|
||||
Input(IT_STICKBUTTON, 0, 1),
|
||||
Input(IT_MOUSEBUTTON, 2),
|
||||
Input(IT_MOUSEBUTTON, 3));
|
||||
set(GA_CURSOR_UP,
|
||||
Input(IT_KEYBOARD, SDLK_UP),
|
||||
Input(IT_MOUSEBUTTON, 4),
|
||||
Input(IT_STICKMOTION, 0, 1, AD_NEGATIVE));
|
||||
|
||||
set(GA_CURSOR_DOWN,
|
||||
Input(IT_KEYBOARD, SDLK_DOWN),
|
||||
Input(IT_MOUSEBUTTON, 5),
|
||||
Input(IT_STICKMOTION, 0, 1, AD_POSITIVE));
|
||||
// Clear every entry.
|
||||
memset(inputMap, 0, sizeof(inputMap));
|
||||
|
||||
set(GA_CURSOR_LEFT,
|
||||
Input(IT_KEYBOARD, SDLK_LEFT),
|
||||
Input(IT_STICKMOTION, 0, 0, AD_NEGATIVE));
|
||||
/* general game input settings */
|
||||
set(GA_ENTER,
|
||||
Input(IT_KEYBOARD, SDLK_RETURN),
|
||||
Input(IT_KEYBOARD, SDLK_SPACE),
|
||||
Input(IT_STICKBUTTON, 0, 0),
|
||||
Input(IT_MOUSEBUTTON, 1));
|
||||
set(GA_LEAVE,
|
||||
Input(IT_KEYBOARD, SDLK_ESCAPE),
|
||||
Input(IT_STICKBUTTON, 0, 1),
|
||||
Input(IT_MOUSEBUTTON, 2),
|
||||
Input(IT_MOUSEBUTTON, 3));
|
||||
set(GA_CURSOR_UP,
|
||||
Input(IT_KEYBOARD, SDLK_UP),
|
||||
Input(IT_MOUSEBUTTON, 4),
|
||||
Input(IT_STICKMOTION, 0, 1, AD_NEGATIVE));
|
||||
|
||||
set(GA_CURSOR_RIGHT,
|
||||
Input(IT_KEYBOARD, SDLK_RIGHT),
|
||||
Input(IT_STICKMOTION, 0, 0, AD_POSITIVE));
|
||||
set(GA_CURSOR_DOWN,
|
||||
Input(IT_KEYBOARD, SDLK_DOWN),
|
||||
Input(IT_MOUSEBUTTON, 5),
|
||||
Input(IT_STICKMOTION, 0, 1, AD_POSITIVE));
|
||||
|
||||
set(GA_CLEAR_MAPPING,
|
||||
Input(IT_KEYBOARD, SDLK_BACKSPACE),
|
||||
Input(IT_STICKBUTTON, 0, 2));
|
||||
set(GA_CURSOR_LEFT,
|
||||
Input(IT_KEYBOARD, SDLK_LEFT),
|
||||
Input(IT_STICKMOTION, 0, 0, AD_NEGATIVE));
|
||||
|
||||
set(GA_INC_SCROLL_SPEED,
|
||||
Input(IT_KEYBOARD, SDLK_PLUS));
|
||||
set(GA_INC_SCROLL_SPEED_FAST,
|
||||
Input(IT_KEYBOARD, SDLK_PAGEDOWN));
|
||||
set(GA_CURSOR_RIGHT,
|
||||
Input(IT_KEYBOARD, SDLK_RIGHT),
|
||||
Input(IT_STICKMOTION, 0, 0, AD_POSITIVE));
|
||||
|
||||
set(GA_DEC_SCROLL_SPEED,
|
||||
Input(IT_KEYBOARD, SDLK_MINUS));
|
||||
set(GA_DEC_SCROLL_SPEED_FAST,
|
||||
Input(IT_KEYBOARD, SDLK_PAGEUP));
|
||||
set(GA_CLEAR_MAPPING,
|
||||
Input(IT_KEYBOARD, SDLK_BACKSPACE),
|
||||
Input(IT_STICKBUTTON, 0, 2));
|
||||
|
||||
set(GA_TOGGLE_FULLSCREEN,
|
||||
Input(IT_KEYBOARD, SDLK_F9));
|
||||
set(GA_LEAVE_RACE,
|
||||
Input(IT_KEYBOARD, SDLK_ESCAPE));
|
||||
set(GA_INC_SCROLL_SPEED,
|
||||
Input(IT_KEYBOARD, SDLK_PLUS));
|
||||
set(GA_INC_SCROLL_SPEED_FAST,
|
||||
Input(IT_KEYBOARD, SDLK_PAGEDOWN));
|
||||
|
||||
set(GA_DEC_SCROLL_SPEED,
|
||||
Input(IT_KEYBOARD, SDLK_MINUS));
|
||||
set(GA_DEC_SCROLL_SPEED_FAST,
|
||||
Input(IT_KEYBOARD, SDLK_PAGEUP));
|
||||
|
||||
set(GA_TOGGLE_FULLSCREEN,
|
||||
Input(IT_KEYBOARD, SDLK_F9));
|
||||
set(GA_LEAVE_RACE,
|
||||
Input(IT_KEYBOARD, SDLK_ESCAPE));
|
||||
#ifdef DEBUG
|
||||
set(GA_DEBUG_ADD_BOWLING,
|
||||
Input(IT_KEYBOARD, SDLK_F1));
|
||||
set(GA_DEBUG_ADD_MISSILE,
|
||||
Input(IT_KEYBOARD, SDLK_F2));
|
||||
set(GA_DEBUG_ADD_HOMING,
|
||||
Input(IT_KEYBOARD, SDLK_F3));
|
||||
set(GA_DEBUG_ADD_BOWLING,
|
||||
Input(IT_KEYBOARD, SDLK_F1));
|
||||
set(GA_DEBUG_ADD_MISSILE,
|
||||
Input(IT_KEYBOARD, SDLK_F2));
|
||||
set(GA_DEBUG_ADD_HOMING,
|
||||
Input(IT_KEYBOARD, SDLK_F3));
|
||||
#endif
|
||||
set(GA_DEBUG_TOGGLE_FPS,
|
||||
Input(IT_KEYBOARD, SDLK_F12));
|
||||
set(GA_DEBUG_TOGGLE_WIREFRAME,
|
||||
Input(IT_KEYBOARD, SDLK_F11));
|
||||
set(GA_DEBUG_HISTORY,
|
||||
Input(IT_KEYBOARD, SDLK_F10));
|
||||
|
||||
// TODO: The following should become a static
|
||||
// array. This allows:
|
||||
// a) resetting to default values
|
||||
// b) prevent loading those defaults if config file contains any bindings
|
||||
set(GA_DEBUG_TOGGLE_FPS,
|
||||
Input(IT_KEYBOARD, SDLK_F12));
|
||||
set(GA_DEBUG_TOGGLE_WIREFRAME,
|
||||
Input(IT_KEYBOARD, SDLK_F11));
|
||||
set(GA_DEBUG_HISTORY,
|
||||
Input(IT_KEYBOARD, SDLK_F10));
|
||||
|
||||
// TODO: The following should become a static
|
||||
// array. This allows:
|
||||
// a) resetting to default values
|
||||
// b) prevent loading those defaults if config file contains any bindings
|
||||
|
||||
/* Player 1 default input settings */
|
||||
set(GA_P1_LEFT,
|
||||
@ -442,10 +442,10 @@ void UserConfig::loadConfig(const std::string& filename)
|
||||
|
||||
//get whether to log errors to file
|
||||
lisp->get("log-errors", m_log_errors);
|
||||
lisp->get("kart-group", m_kart_group);
|
||||
lisp->get("kart-group", m_kart_group);
|
||||
lisp->get("track-group", m_track_group);
|
||||
// Handle loading the stick config in it own method.
|
||||
readStickConfigs(lisp);
|
||||
readStickConfigs(lisp);
|
||||
|
||||
// Unlock information:
|
||||
const lisp::Lisp* unlock_info = lisp->getLisp("unlock-info");
|
||||
@ -520,58 +520,55 @@ void UserConfig::loadConfig(const std::string& filename)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void
|
||||
UserConfig::readStickConfigs(const lisp::Lisp *r)
|
||||
void UserConfig::readStickConfigs(const lisp::Lisp *r)
|
||||
{
|
||||
string temp;
|
||||
int count = 0;
|
||||
|
||||
const lisp::Lisp *scsreader = r->getLisp("stick-configs");
|
||||
if (scsreader)
|
||||
string temp;
|
||||
int count = 0;
|
||||
|
||||
const lisp::Lisp *scsreader = r->getLisp("stick-configs");
|
||||
if (scsreader)
|
||||
{
|
||||
scsreader->get("count", count);
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
scsreader->get("count", count);
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
temp = "stick-";
|
||||
temp += (i + '1');
|
||||
const lisp::Lisp *screader = scsreader->getLisp(temp);
|
||||
if (screader)
|
||||
{
|
||||
string *id = new string();
|
||||
screader->get("id", *id);
|
||||
|
||||
StickConfig *sc = new StickConfig(*id);
|
||||
|
||||
screader->get("preferredIndex", sc->preferredIndex);
|
||||
screader->get("deadzone", sc->deadzone);
|
||||
|
||||
m_stickconfigs.push_back(sc);
|
||||
}
|
||||
}
|
||||
|
||||
temp = "stick-";
|
||||
temp += (i + '1');
|
||||
const lisp::Lisp *screader = scsreader->getLisp(temp);
|
||||
if (screader)
|
||||
{
|
||||
string *id = new string();
|
||||
screader->get("id", *id);
|
||||
|
||||
StickConfig *sc = new StickConfig(*id);
|
||||
|
||||
screader->get("preferredIndex", sc->preferredIndex);
|
||||
screader->get("deadzone", sc->deadzone);
|
||||
|
||||
m_stickconfigs.push_back(sc);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} // readStickConfigs
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void
|
||||
UserConfig::readPlayerInput(const lisp::Lisp *r, const char *node,
|
||||
KartAction ka, int playerIndex)
|
||||
void UserConfig::readPlayerInput(const lisp::Lisp *r, const char *node,
|
||||
KartAction ka, int playerIndex)
|
||||
{
|
||||
readInput(r, node, (GameAction) (playerIndex * KC_COUNT + ka + GA_P1_LEFT));
|
||||
}
|
||||
readInput(r, node, (GameAction) (playerIndex * KC_COUNT + ka + GA_P1_LEFT));
|
||||
} // readPlayerInput
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void
|
||||
UserConfig::readInput(const lisp::Lisp* r,
|
||||
const char *node,
|
||||
GameAction action)
|
||||
void UserConfig::readInput(const lisp::Lisp* r, const char *node,
|
||||
GameAction action)
|
||||
{
|
||||
string inputTypeName;
|
||||
|
||||
const Lisp* nodeReader = r->getLisp(node);
|
||||
if (!nodeReader)
|
||||
return;
|
||||
return;
|
||||
|
||||
// Every unused id variable *must* be set to
|
||||
// something different than -1. Otherwise
|
||||
@ -619,11 +616,11 @@ UserConfig::readInput(const lisp::Lisp* r,
|
||||
}
|
||||
|
||||
if (input.id0 != -1 && input.id1 != -1 && input.id2 != -1)
|
||||
{
|
||||
{
|
||||
setInput(action, input);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // readInput
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** Call saveConfig with the default filename for this platform. */
|
||||
@ -694,7 +691,7 @@ void UserConfig::saveConfig(const std::string& filename)
|
||||
writer->write("kart-group", m_kart_group);
|
||||
writer->writeComment("Last selected track group");
|
||||
writer->write("track-group", m_track_group);
|
||||
writeStickConfigs(writer);
|
||||
writeStickConfigs(writer);
|
||||
|
||||
// Write unlock information back
|
||||
writer->beginList("unlock-info");
|
||||
@ -744,99 +741,97 @@ void UserConfig::saveConfig(const std::string& filename)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void
|
||||
UserConfig::writeStickConfigs(lisp::Writer *writer)
|
||||
void UserConfig::writeStickConfigs(lisp::Writer *writer)
|
||||
{
|
||||
int count = 0;
|
||||
string temp;
|
||||
|
||||
writer->beginList("stick-configs");
|
||||
|
||||
count = (int)m_stickconfigs.size();
|
||||
writer->write("count", count);
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
StickConfig *sc = m_stickconfigs[i];
|
||||
temp = "stick-";
|
||||
temp += i + '1';
|
||||
|
||||
writer->beginList(temp);
|
||||
|
||||
writer->write("id", sc->id);
|
||||
writer->write("preferredIndex", sc->preferredIndex);
|
||||
writer->writeComment("0 means that the default deadzone value is used.");
|
||||
writer->write("deadzone", sc->deadzone);
|
||||
|
||||
writer->endList(temp);
|
||||
}
|
||||
|
||||
writer->endList("stick-configs");
|
||||
}
|
||||
int count = 0;
|
||||
string temp;
|
||||
|
||||
writer->beginList("stick-configs");
|
||||
|
||||
count = (int)m_stickconfigs.size();
|
||||
writer->write("count", count);
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
StickConfig *sc = m_stickconfigs[i];
|
||||
temp = "stick-";
|
||||
temp += i + '1';
|
||||
|
||||
writer->beginList(temp);
|
||||
|
||||
writer->write("id", sc->id);
|
||||
writer->write("preferredIndex", sc->preferredIndex);
|
||||
writer->writeComment("0 means that the default deadzone value is used.");
|
||||
writer->write("deadzone", sc->deadzone);
|
||||
|
||||
writer->endList(temp);
|
||||
}
|
||||
|
||||
writer->endList("stick-configs");
|
||||
} // writeStickConfigs
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void
|
||||
UserConfig::writePlayerInput(lisp::Writer *writer, const char *node,
|
||||
KartAction ka, int playerIndex)
|
||||
void UserConfig::writePlayerInput(lisp::Writer *writer, const char *node,
|
||||
KartAction ka, int playerIndex)
|
||||
{
|
||||
writeInput(writer, node, (GameAction) (playerIndex * KC_COUNT + ka + GA_P1_LEFT));
|
||||
}
|
||||
writeInput(writer, node, (GameAction) (playerIndex * KC_COUNT + ka + GA_P1_LEFT));
|
||||
} // writePlayerInput
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void
|
||||
UserConfig::writeInput(lisp::Writer *writer,
|
||||
const char *node,
|
||||
GameAction action)
|
||||
void UserConfig::writeInput(lisp::Writer *writer, const char *node,
|
||||
GameAction action)
|
||||
{
|
||||
writer->beginList(node);
|
||||
|
||||
if (inputMap[action].count)
|
||||
{
|
||||
|
||||
const Input input = inputMap[action].inputs[0];
|
||||
|
||||
if (input.type != IT_NONE)
|
||||
if (inputMap[action].count)
|
||||
{
|
||||
switch (input.type)
|
||||
{
|
||||
case IT_NONE:
|
||||
break;
|
||||
case IT_KEYBOARD:
|
||||
writer->write("type", "keyboard");
|
||||
writer->write("key", input.id0);
|
||||
break;
|
||||
case IT_STICKMOTION:
|
||||
writer->write("type", "stickaxis");
|
||||
writer->write("stick", input.id0);
|
||||
writer->write("axis", input.id1);
|
||||
writer->writeComment("0 is negative/left/up, 1 is positive/right/down");
|
||||
writer->write("direction", input.id2);
|
||||
break;
|
||||
case IT_STICKBUTTON:
|
||||
writer->write("type", "stickbutton");
|
||||
writer->write("stick", input.id0);
|
||||
writer->write("button", input.id1);
|
||||
break;
|
||||
case IT_STICKHAT:
|
||||
// TODO: Implement me
|
||||
break;
|
||||
case IT_MOUSEMOTION:
|
||||
writer->write("type", "mouseaxis");
|
||||
writer->write("axis", input.id0);
|
||||
writer->writeComment("0 is negative/left/up, 1 is positive/right/down");
|
||||
writer->write("direction", input.id1);
|
||||
break;
|
||||
case IT_MOUSEBUTTON:
|
||||
writer->write("type", "mousebutton");
|
||||
writer->writeComment("0 is left, 1 is middle, 2 is right, 3 is wheel up, 4 is wheel down");
|
||||
writer->writeComment("other values denote auxillary buttons");
|
||||
writer->write("button", input.id0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const Input input = inputMap[action].inputs[0];
|
||||
|
||||
if (input.type != IT_NONE)
|
||||
{
|
||||
switch (input.type)
|
||||
{
|
||||
case IT_NONE:
|
||||
break;
|
||||
case IT_KEYBOARD:
|
||||
writer->write("type", "keyboard");
|
||||
writer->write("key", input.id0);
|
||||
break;
|
||||
case IT_STICKMOTION:
|
||||
writer->write("type", "stickaxis");
|
||||
writer->write("stick", input.id0);
|
||||
writer->write("axis", input.id1);
|
||||
writer->writeComment("0 is negative/left/up, 1 is positive/right/down");
|
||||
writer->write("direction", input.id2);
|
||||
break;
|
||||
case IT_STICKBUTTON:
|
||||
writer->write("type", "stickbutton");
|
||||
writer->write("stick", input.id0);
|
||||
writer->write("button", input.id1);
|
||||
break;
|
||||
case IT_STICKHAT:
|
||||
// TODO: Implement me
|
||||
break;
|
||||
case IT_MOUSEMOTION:
|
||||
writer->write("type", "mouseaxis");
|
||||
writer->write("axis", input.id0);
|
||||
writer->writeComment("0 is negative/left/up, 1 is positive/right/down");
|
||||
writer->write("direction", input.id1);
|
||||
break;
|
||||
case IT_MOUSEBUTTON:
|
||||
writer->write("type", "mousebutton");
|
||||
writer->writeComment("0 is left, 1 is middle, 2 is right, 3 is wheel up, 4 is wheel down");
|
||||
writer->writeComment("other values denote auxillary buttons");
|
||||
writer->write("button", input.id0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
writer->endList(node);
|
||||
}
|
||||
} // writeInput
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
std::string UserConfig::getInputAsString(Input &input)
|
||||
{
|
||||
@ -878,216 +873,208 @@ std::string UserConfig::getInputAsString(Input &input)
|
||||
} // GetKeyAsString
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
string
|
||||
UserConfig::getMappingAsString(GameAction ga)
|
||||
string UserConfig::getMappingAsString(GameAction ga)
|
||||
{
|
||||
if (inputMap[ga].count
|
||||
&& inputMap[ga].inputs[0].type)
|
||||
{
|
||||
stringstream s;
|
||||
s << getInputAsString(inputMap[ga].inputs[0]);
|
||||
if (inputMap[ga].count &&
|
||||
inputMap[ga].inputs[0].type)
|
||||
{
|
||||
stringstream s;
|
||||
s << getInputAsString(inputMap[ga].inputs[0]);
|
||||
|
||||
return s.str();
|
||||
}
|
||||
else
|
||||
{
|
||||
return string(_("not set"));
|
||||
}
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
string
|
||||
UserConfig::getMappingAsString(int playerIndex, KartAction ka)
|
||||
{
|
||||
return getMappingAsString((GameAction) (GA_FIRST_KARTACTION
|
||||
+ playerIndex * KC_COUNT + ka));
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void
|
||||
UserConfig::unsetDuplicates (GameAction ga, Input &i)
|
||||
{
|
||||
for (int cga = GA_FIRST_KARTACTION; cga <= GA_LAST_KARTACTION; cga++)
|
||||
{
|
||||
if (cga != ga)
|
||||
{
|
||||
// If the input occurs in any other mapping
|
||||
// delete it properly from there.
|
||||
|
||||
if (inputMap[cga].count
|
||||
&& inputMap[cga].inputs[0].type == i.type
|
||||
&& inputMap[cga].inputs[0].id0 == i.id0
|
||||
&& inputMap[cga].inputs[0].id1 == i.id1
|
||||
&& inputMap[cga].inputs[0].id2 == i.id2)
|
||||
{
|
||||
// Delete it.
|
||||
inputMap[cga].inputs[0].type = IT_NONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
void
|
||||
UserConfig::set(GameAction ga, Input i)
|
||||
{
|
||||
inputMap[ga].count = 1;
|
||||
inputMap[ga].inputs = new Input[1];
|
||||
inputMap[ga].inputs[0] = i;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
void
|
||||
UserConfig::set(GameAction ga, Input i0, Input i1)
|
||||
{
|
||||
inputMap[ga].count = 2;
|
||||
inputMap[ga].inputs = new Input[2];
|
||||
inputMap[ga].inputs[0] = i0;
|
||||
inputMap[ga].inputs[1] = i1;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
void
|
||||
UserConfig::set(GameAction ga, Input i0, Input i1, Input i2)
|
||||
{
|
||||
inputMap[ga].count = 3;
|
||||
inputMap[ga].inputs = new Input[3];
|
||||
inputMap[ga].inputs[0] = i0;
|
||||
inputMap[ga].inputs[1] = i1;
|
||||
inputMap[ga].inputs[2] = i2;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
void
|
||||
UserConfig::set(GameAction ga, Input i0, Input i1, Input i2, Input i3)
|
||||
{
|
||||
inputMap[ga].count = 4;
|
||||
inputMap[ga].inputs = new Input[4];
|
||||
inputMap[ga].inputs[0] = i0;
|
||||
inputMap[ga].inputs[1] = i1;
|
||||
inputMap[ga].inputs[2] = i2;
|
||||
inputMap[ga].inputs[3] = i3;
|
||||
}
|
||||
else
|
||||
{
|
||||
return string(_("not set"));
|
||||
}
|
||||
} // getMappingAsString
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void
|
||||
UserConfig::setInput(GameAction ga, Input &input)
|
||||
string UserConfig::getMappingAsString(int playerIndex, KartAction ka)
|
||||
{
|
||||
// Removes the input from all mappings where it occurs.
|
||||
unsetDuplicates(ga, input);
|
||||
return getMappingAsString((GameAction) (GA_FIRST_KARTACTION
|
||||
+ playerIndex * KC_COUNT + ka) );
|
||||
} // getMappingAsString
|
||||
|
||||
set(ga, input);
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
void
|
||||
UserConfig::setInput(int playerIndex, KartAction ka, Input &input)
|
||||
void UserConfig::unsetDuplicates(GameAction ga, Input &i)
|
||||
{
|
||||
setInput((GameAction) (GA_FIRST_KARTACTION
|
||||
+ playerIndex * KC_COUNT + ka),
|
||||
input);
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
void
|
||||
UserConfig::clearInput(int playerIndex, KartAction ka)
|
||||
{
|
||||
inputMap[(GameAction) (GA_FIRST_KARTACTION + playerIndex * KC_COUNT + ka)]
|
||||
.count = 0;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
ActionMap *
|
||||
UserConfig::newActionMap(const int from, const int to)
|
||||
{
|
||||
ActionMap *am = new ActionMap();
|
||||
|
||||
for (int i = from; i <= to; i++)
|
||||
for (int cga = GA_FIRST_KARTACTION; cga <= GA_LAST_KARTACTION; cga++)
|
||||
{
|
||||
if (cga != ga)
|
||||
{
|
||||
const int count = inputMap[i].count;
|
||||
for (int j = 0;j < count; j++)
|
||||
am->putEntry(inputMap[i].inputs[j], (GameAction) i);
|
||||
// If the input occurs in any other mapping
|
||||
// delete it properly from there.
|
||||
|
||||
if (inputMap[cga].count
|
||||
&& inputMap[cga].inputs[0].type == i.type
|
||||
&& inputMap[cga].inputs[0].id0 == i.id0
|
||||
&& inputMap[cga].inputs[0].id1 == i.id1
|
||||
&& inputMap[cga].inputs[0].id2 == i.id2)
|
||||
{
|
||||
// Delete it.
|
||||
inputMap[cga].inputs[0].type = IT_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
return am;
|
||||
}
|
||||
}
|
||||
} // unsetDuplicates
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
ActionMap *
|
||||
UserConfig::newMenuActionMap()
|
||||
void UserConfig::set(GameAction ga, Input i)
|
||||
{
|
||||
return newActionMap(GA_FIRST_MENU, GA_LAST_MENU);
|
||||
}
|
||||
inputMap[ga].count = 1;
|
||||
inputMap[ga].inputs = new Input[1];
|
||||
inputMap[ga].inputs[0] = i;
|
||||
} // set(1 input)
|
||||
// -----------------------------------------------------------------------------
|
||||
ActionMap *
|
||||
UserConfig::newIngameActionMap()
|
||||
void UserConfig::set(GameAction ga, Input i0, Input i1)
|
||||
{
|
||||
// This is rather unfriendly hack but work quite effective:
|
||||
// In order to prevent the input driver from handling input mappings
|
||||
// for human players which are not in the current game we select a subset
|
||||
// of the game actions by looking at the amount of players. The
|
||||
// race_manager instance is assumed to be available at this time because
|
||||
// this method is called immediately before the RaceGUI instance is created
|
||||
// (in MenuManager) and RaceGUI needs race_manager, too.
|
||||
inputMap[ga].count = 2;
|
||||
inputMap[ga].inputs = new Input[2];
|
||||
inputMap[ga].inputs[0] = i0;
|
||||
inputMap[ga].inputs[1] = i1;
|
||||
} // set(2 inputs)
|
||||
// -----------------------------------------------------------------------------
|
||||
void UserConfig::set(GameAction ga, Input i0, Input i1, Input i2)
|
||||
{
|
||||
inputMap[ga].count = 3;
|
||||
inputMap[ga].inputs = new Input[3];
|
||||
inputMap[ga].inputs[0] = i0;
|
||||
inputMap[ga].inputs[1] = i1;
|
||||
inputMap[ga].inputs[2] = i2;
|
||||
} //set(3 inputs)
|
||||
// -----------------------------------------------------------------------------
|
||||
void UserConfig::set(GameAction ga, Input i0, Input i1, Input i2, Input i3)
|
||||
{
|
||||
inputMap[ga].count = 4;
|
||||
inputMap[ga].inputs = new Input[4];
|
||||
inputMap[ga].inputs[0] = i0;
|
||||
inputMap[ga].inputs[1] = i1;
|
||||
inputMap[ga].inputs[2] = i2;
|
||||
inputMap[ga].inputs[3] = i3;
|
||||
} // set(4 inputs)
|
||||
|
||||
// TODO: Reorder ingame GameAction values so that they start with
|
||||
// the fixed ones. This would allow simpler looking code here.
|
||||
// -----------------------------------------------------------------------------
|
||||
void UserConfig::setInput(GameAction ga, Input &input)
|
||||
{
|
||||
// Removes the input from all mappings where it occurs.
|
||||
unsetDuplicates(ga, input);
|
||||
|
||||
GameAction gaEnd = GA_NULL;
|
||||
|
||||
switch (race_manager->getNumPlayers())
|
||||
{
|
||||
case 1:
|
||||
gaEnd = GA_P1_LOOK_BACK; break;
|
||||
case 2:
|
||||
gaEnd = GA_P2_LOOK_BACK; break;
|
||||
case 3:
|
||||
gaEnd = GA_P3_LOOK_BACK; break;
|
||||
case 4:
|
||||
gaEnd = GA_P4_LOOK_BACK; break;
|
||||
}
|
||||
|
||||
ActionMap *am = newActionMap(GA_FIRST_INGAME, gaEnd);
|
||||
set(ga, input);
|
||||
} // setInput
|
||||
|
||||
for (int i = GA_FIRST_INGAME_FIXED; i <= GA_LAST_INGAME_FIXED; i++)
|
||||
{
|
||||
const int count = inputMap[i].count;
|
||||
for (int j = 0;j < count; j++)
|
||||
am->putEntry(inputMap[i].inputs[j], (GameAction) i);
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
void UserConfig::setInput(int playerIndex, KartAction ka, Input &input)
|
||||
{
|
||||
setInput((GameAction) (GA_FIRST_KARTACTION
|
||||
+ playerIndex * KC_COUNT + ka),
|
||||
input);
|
||||
} // setInput
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
void UserConfig::clearInput(int playerIndex, KartAction ka)
|
||||
{
|
||||
inputMap[(GameAction) (GA_FIRST_KARTACTION + playerIndex * KC_COUNT + ka)]
|
||||
.count = 0;
|
||||
} // clearInput
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
ActionMap *UserConfig::newActionMap(const int from, const int to)
|
||||
{
|
||||
ActionMap *am = new ActionMap();
|
||||
|
||||
for (int i = from; i <= to; i++)
|
||||
{
|
||||
const int count = inputMap[i].count;
|
||||
for (int j = 0;j < count; j++)
|
||||
am->putEntry(inputMap[i].inputs[j], (GameAction) i);
|
||||
}
|
||||
|
||||
return am;
|
||||
} // newActionMap
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
ActionMap *UserConfig::newMenuActionMap()
|
||||
{
|
||||
return newActionMap(GA_FIRST_MENU, GA_LAST_MENU);
|
||||
} // newMenuActionMap
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
ActionMap *UserConfig::newIngameActionMap()
|
||||
{
|
||||
// This is rather unfriendly hack but work quite effective:
|
||||
// In order to prevent the input driver from handling input mappings
|
||||
// for human players which are not in the current game we select a subset
|
||||
// of the game actions by looking at the amount of players. The
|
||||
// race_manager instance is assumed to be available at this time because
|
||||
// this method is called immediately before the RaceGUI instance is created
|
||||
// (in MenuManager) and RaceGUI needs race_manager, too.
|
||||
|
||||
// TODO: Reorder ingame GameAction values so that they start with
|
||||
// the fixed ones. This would allow simpler looking code here.
|
||||
|
||||
GameAction gaEnd = GA_NULL;
|
||||
|
||||
switch (race_manager->getNumPlayers())
|
||||
{
|
||||
case 1:
|
||||
gaEnd = GA_P1_LOOK_BACK; break;
|
||||
case 2:
|
||||
gaEnd = GA_P2_LOOK_BACK; break;
|
||||
case 3:
|
||||
gaEnd = GA_P3_LOOK_BACK; break;
|
||||
case 4:
|
||||
gaEnd = GA_P4_LOOK_BACK; break;
|
||||
}
|
||||
|
||||
ActionMap *am = newActionMap(GA_FIRST_INGAME, gaEnd);
|
||||
|
||||
for (int i = GA_FIRST_INGAME_FIXED; i <= GA_LAST_INGAME_FIXED; i++)
|
||||
{
|
||||
const int count = inputMap[i].count;
|
||||
for (int j = 0;j < count; j++)
|
||||
am->putEntry(inputMap[i].inputs[j], (GameAction) i);
|
||||
}
|
||||
|
||||
return am;
|
||||
} // newIngameActionMap
|
||||
|
||||
return am;
|
||||
}
|
||||
// -----------------------------------------------------------------------------
|
||||
/** Determines whether the given Input is used in a mapping where it is marked
|
||||
* as fixed. This allows the input driver to discard the mapping and not
|
||||
* allow the user to use it.
|
||||
*/
|
||||
bool
|
||||
UserConfig::isFixedInput(InputType type, int id0, int id1, int id2)
|
||||
bool UserConfig::isFixedInput(InputType type, int id0, int id1, int id2)
|
||||
{
|
||||
for (int i = GA_FIRST_INGAME_FIXED; i <= GA_LAST_INGAME_FIXED; i++)
|
||||
{
|
||||
const int count = inputMap[i].count;
|
||||
for (int j = 0;j < count; j++)
|
||||
if (inputMap[i].inputs[j].type == type
|
||||
&& inputMap[i].inputs[j].id0 == id0
|
||||
&& inputMap[i].inputs[j].id1 == id1
|
||||
&& inputMap[i].inputs[j].id2 == id2)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
for (int i = GA_FIRST_INGAME_FIXED; i <= GA_LAST_INGAME_FIXED; i++)
|
||||
{
|
||||
const int count = inputMap[i].count;
|
||||
for (int j = 0;j < count; j++)
|
||||
if (inputMap[i].inputs[j].type == type
|
||||
&& inputMap[i].inputs[j].id0 == id0
|
||||
&& inputMap[i].inputs[j].id1 == id1
|
||||
&& inputMap[i].inputs[j].id2 == id2)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
} // isFixedInput
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void
|
||||
UserConfig::addStickConfig(StickConfig *sc)
|
||||
void UserConfig::addStickConfig(StickConfig *sc)
|
||||
{
|
||||
m_stickconfigs.push_back(sc);
|
||||
}
|
||||
m_stickconfigs.push_back(sc);
|
||||
} // addStickConfig
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
const std::vector<UserConfig::StickConfig *> *
|
||||
UserConfig::getStickConfigs() const
|
||||
const std::vector<UserConfig::StickConfig *> *UserConfig::getStickConfigs() const
|
||||
{
|
||||
return &m_stickconfigs;
|
||||
}
|
||||
return &m_stickconfigs;
|
||||
} // getStickConfigs
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
UserConfig::StickConfig::StickConfig(string &newId)
|
||||
: id(newId)
|
||||
: id(newId)
|
||||
{
|
||||
// Nothing else to do.
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user