1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-07-03 06:24:32 +00:00

Various improvements and fixes

This commit is contained in:
fgenesis 2016-07-17 05:54:09 +02:00
parent 411f8950e5
commit 77e4bfd292
9 changed files with 167 additions and 32 deletions

View file

@ -4574,3 +4574,27 @@ bool DSQ::isMiniMapCursorOkay()
return ((inputMode != INPUT_MOUSE) || (!game->miniMapRender || !game->miniMapRender->isCursorIn()));
}
void DSQ::onJoystickAdded(int deviceID)
{
Core::onJoystickAdded(deviceID);
fixupJoysticks();
}
void DSQ::onJoystickRemoved(int instanceID)
{
Core::onJoystickRemoved(instanceID);
fixupJoysticks();
}
void DSQ::fixupJoysticks()
{
for(int i = 0; i < getNumJoysticks(); ++i)
if(Joystick *j = getJoystick(i))
j->setEnabled(false);
for(size_t i = 0; i < user.control.actionSets.size(); ++i)
{
ActionSet& as = user.control.actionSets[i];
as.updateJoystick();
}
}

View file

@ -553,6 +553,10 @@ protected:
void onRender();
void modifyDt(float &dt);
void fixupJoysticks();
virtual void onJoystickAdded(int deviceID);
virtual void onJoystickRemoved(int instanceID);
};
extern DSQ *dsq;

View file

@ -1980,6 +1980,30 @@ void InGameMenu::create()
const float offx = 140 - keyConfigBg->position.x;
const float yi = 20;
TTFText *joystickLabel = new TTFText(&dsq->fontArialSmall);
joystickLabel->position = Vector(offx, offy + 390);
joystickLabel->setText(SB(2140));
keyConfigBg->addChild(joystickLabel, PM_POINTER);
AquariaMenuItem *nextJoystickBtn = new AquariaMenuItem;
nextJoystickBtn->event.set(MakeFunctionEvent(InGameMenu, nextJoystick));
nextJoystickBtn->useQuad("gui/sort");
nextJoystickBtn->useGlow("particles/glow", 40, 40);
nextJoystickBtn->position = Vector(offx + 100, offy + 390);
keyConfigBg->addChild(nextJoystickBtn, PM_POINTER);
joystickNameText = new TTFText(&dsq->fontArialSmallest);
joystickNameText->position = Vector(offx + 100 + 32, offy + 390);
keyConfigBg->addChild(joystickNameText, PM_POINTER);
joystickGUIDText = new TTFText(&dsq->fontArialSmallest);
joystickGUIDText->position = Vector(offx + 100 + 32, offy + 390 + 15);
joystickGUIDText->color = Vector(0.5f, 0.5f, 0.5f);
keyConfigBg->addChild(joystickGUIDText, PM_POINTER);
updateJoystickText();
{
float x = offx;
TTFText *header_actionset = new TTFText(&dsq->fontArialSmall);
@ -2075,7 +2099,6 @@ void InGameMenu::create()
addKeyConfigLine(kk, SB(2114), "Revert", offx, y+=yi);
addKeyConfigLine(kk, SB(2115), "WorldMap", offx, y+=yi);
addKeyConfigLine(kk, SB(2127), "Look", offx, y+=yi);
addKeyConfigLine(kk, SB(2132), "Screenshot", offx, y+=yi);
y+=yi+yi/2;
AquariaKeyConfig* s1x = addAxesConfigLine(kk, SB(2117), "s1ax", offx, y);
@ -2103,6 +2126,8 @@ void InGameMenu::create()
int y = offy;
addKeyConfigLine(kk, SB(2116), "Escape", offx, y+=yi, true);
addKeyConfigLine(kk, SB(2128), "ToggleHelp", offx, y+=yi);
addKeyConfigLine(kk, SB(2135), "MenuUp", offx, y+=yi);
addKeyConfigLine(kk, SB(2136), "MenuDown", offx, y+=yi);
addKeyConfigLine(kk, SB(2137), "MenuLeft", offx, y+=yi);
@ -2113,7 +2138,6 @@ void InGameMenu::create()
addKeyConfigLine(kk, SB(2124), "FoodLeft", offx, y+=yi);
addKeyConfigLine(kk, SB(2125), "FoodRight", offx, y+=yi);
addKeyConfigLine(kk, SB(2126), "FoodDrop", offx, y+=yi);
addKeyConfigLine(kk, SB(2128), "ToggleHelp", offx, y+=yi);
}
// PART 2
@ -2131,6 +2155,7 @@ void InGameMenu::create()
osac << "SongSlot" << i;
addKeyConfigLine(kk, osname.str(), osac.str(), offx, y+=yi);
}
addKeyConfigLine(kk, SB(2132), "Screenshot", offx, y+=yi);
}
actionSetBox->moveToFront();
@ -3951,12 +3976,14 @@ void InGameMenu::updateKeyConfigMenu(float dt)
for(size_t i = 0; i < keyCategoryButtons.size(); ++i)
keyCategoryButtons[i]->alpha = a;
dsq->user.control.actionSets[selectedActionSetIdx].enabled
= actionSetCheck->getValue();
const int curAS = actionSetBox->getSelectedItem();
if(selectedActionSetIdx != curAS)
switchToActionSet(curAS);
dsq->user.control.actionSets[selectedActionSetIdx].enabled
= actionSetCheck->getValue();
updateJoystickText();
}
void InGameMenu::updateOptionsMenu(float dt)
@ -4183,3 +4210,52 @@ void InGameMenu::updateActionSetComboBox()
actionSetBox->addItem(os.str());
}
}
void InGameMenu::nextJoystick()
{
ActionSet& as = dsq->user.control.actionSets[selectedActionSetIdx];
int i = as.joystickID;
Joystick *j = NULL;
const int N = core->getNumJoysticks();
bool looped = false;
do
{
++i;
if(i >= N)
{
i = -1;
break;
}
j = core->getJoystick(i);
}
while (!j);
as.assignJoystickIdx(i, true);
if(as.joystickID < 0)
as.joystickName = "NONE";
updateJoystickText();
}
void InGameMenu::updateJoystickText()
{
ActionSet& as = dsq->user.control.actionSets[selectedActionSetIdx];
Joystick *j = core->getJoystick(as.joystickID);
if(j)
joystickNameText->setText(j->getName());
else if(as.joystickID == ACTIONSET_REASSIGN_JOYSTICK)
{
std::string s = "(";
s += dsq->continuity.stringBank.get(2141);
s += " ";
s += as.joystickName;
s += ")";
joystickNameText->setText(s);
}
else
joystickNameText->setText(dsq->continuity.stringBank.get(2139));
if(j && as.joystickID >= 0)
joystickGUIDText->setText(as.joystickGUID);
else
joystickGUIDText->setText("");
}

View file

@ -23,6 +23,7 @@ class RecipeMenuEntry;
class Recipe;
class RoundedRect;
class DebugButton;
class TTFText;
enum MenuPage
@ -214,8 +215,11 @@ private:
AquariaComboBox *actionSetBox;
AquariaCheckBox *actionSetCheck;
int selectedActionSetIdx;
TTFText *joystickNameText, *joystickGUIDText;
void updateActionSetComboBox();
void switchToActionSet(int idx);
void nextJoystick();
void updateJoystickText();
void onExitCheckNo();
void onExitCheckYes();

View file

@ -582,7 +582,6 @@ void UserSettings::apply()
dsq->loops.updateVolume();
// FIXME: This should be per-joystick
for(size_t i = 0; i < control.actionSets.size(); ++i)
{
ActionSet& as = control.actionSets[i];

View file

@ -34,7 +34,7 @@ JoystickConfig::JoystickConfig()
ActionSet::ActionSet()
{
enabled = true;
joystickID = 0;
joystickID = ACTIONSET_REASSIGN_JOYSTICK;
}
void ActionSet::clearActions()
@ -42,35 +42,45 @@ void ActionSet::clearActions()
inputSet.clear();
}
int ActionSet::assignJoystickByName()
int ActionSet::assignJoystickByName(bool force)
{
int idx = _whichJoystickForName();
if(idx >= 0)
assignJoystickIdx(idx);
if(idx >= 0 || force)
assignJoystickIdx(idx, false);
return idx;
}
void ActionSet::assignJoystickIdx(int idx)
void ActionSet::assignJoystickIdx(int idx, bool updateValues)
{
if(idx < 0)
{
joystickID = -1;
if(updateValues && idx != ACTIONSET_REASSIGN_JOYSTICK)
{
joystickName.clear();
joystickGUID.clear();
}
}
else if(idx < (int)core->getNumJoysticks())
{
if(Joystick *j = core->getJoystick(idx))
{
if(updateValues)
{
joystickGUID = j->getGUID();
joystickName = j->getName();
}
}
else
idx = -1;
}
joystickID = idx;
}
}
}
int ActionSet::_whichJoystickForName()
{
if(joystickName == "NONE")
return -1;
if(joystickGUID.length() && joystickName.length())
for(size_t i = 0; i < core->getNumJoysticks(); ++i)
if(Joystick *j = core->getJoystick(i))
@ -89,11 +99,29 @@ int ActionSet::_whichJoystickForName()
if(joystickName == j->getName())
return int(i);
return -1;
// first attached
if(!joystickGUID.length() && !joystickName.length())
for(size_t i = 0; i < core->getNumJoysticks(); ++i)
if(Joystick *j = core->getJoystick(i))
return i;
return ACTIONSET_REASSIGN_JOYSTICK;
}
void ActionSet::updateJoystick()
{
bool reassign = joystickID == ACTIONSET_REASSIGN_JOYSTICK;
if(joystickID >= 0)
{
Joystick *j = core->getJoystick(joystickID);
if(!j)
reassign = true;
}
if(reassign)
assignJoystickByName(true);
Joystick *j = core->getJoystick(joystickID);
if(j)
j->setEnabled(enabled);
@ -111,8 +139,6 @@ ActionInput *ActionSet::getActionInputByName(const std::string &name)
return 0;
}
void ActionSet::importAction(ActionMapper *mapper, const std::string &name, int actionID, int sourceID) const
{
if (!enabled) return;

View file

@ -32,6 +32,8 @@ typedef std::vector<ActionInput> ActionInputSet;
class ActionMapper;
class Event;
const int ACTIONSET_REASSIGN_JOYSTICK = -2;
struct JoystickConfig
{
JoystickConfig();
@ -48,14 +50,14 @@ public:
void importAction(ActionMapper *mapper, const std::string &name, Event *event, int state) const;
void importAction(ActionMapper *mapper, const std::string &name, int actionID, int sourceID) const;
void clearActions();
int assignJoystickByName(); // -1 if no such joystick found
void assignJoystickIdx(int idx);
int assignJoystickByName(bool force); // -1 if no such joystick found
void assignJoystickIdx(int idx, bool updateValues);
void updateJoystick();
ActionInput *addActionInput(const std::string &name);
ActionInput *getActionInputByName(const std::string &name);
int joystickID;
int joystickID; // >= 0: use that, -1 = no joystick, or ACTIONSET_REASSIGN_JOYSTICK
// --- Saved in config ---
ActionInputSet inputSet;

View file

@ -3019,20 +3019,20 @@ void Core::onJoystickAdded(int deviceID)
}
joysticks.push_back(j);
done:
; // TODO: fixup ActionMapper?
;
}
void Core::onJoystickRemoved(int instanceID)
{
debugLog("Joystick removed");
for(size_t i = 0; i < joysticks.size(); ++i)
if(joysticks[i]->getInstanceID() == instanceID)
if(Joystick *j = joysticks[i])
if(j->getInstanceID() == instanceID)
{
joysticks[i]->shutdown();
delete joysticks[i];
j->shutdown();
delete j;
joysticks[i] = NULL;
}
// TODO: fixup ActionMapper?
}
Joystick *Core::getJoystick(int idx)

View file

@ -52,7 +52,7 @@ Joystick::Joystick()
s2ax = 4;
s2ay = 3;
enabled = true;
enabled = false;
}
const char *Joystick::getName() const