Skip to content

Commit

Permalink
Merge pull request #8 from JekiTheMonkey/v0.10-alpha
Browse files Browse the repository at this point in the history
v0.10 alpha
  • Loading branch information
Tonetfal authored Aug 11, 2021
2 parents aa24df1 + 592263e commit 7bfe834
Show file tree
Hide file tree
Showing 13 changed files with 172 additions and 75 deletions.
11 changes: 7 additions & 4 deletions Headers/ConfigHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@

namespace ConfigHelper
{

extern const std::string separationSign;

bool readConfig(
std::map<LogicalParameter::ID, std::shared_ptr<LogicalParameter>> &parameters,
std::map<ParameterLine::ID, std::shared_ptr<ParameterLine>> &parameterLines);
void fillParameters(std::map<LogicalParameter::ID, std::shared_ptr<LogicalParameter>> &parameters);
std::queue<LogKey> getLogKeys();
std::queue<LogKey> getLogButtons();
std::queue<LogKey> oldGetLogKeys();
std::queue<LogKey> oldGetLogButtons();
std::string readParameter(const std::string &par, bool &parameterFound, bool &parameterEmpty);
void writeParameter(LogicalParameter &par);
float readDigitParameter(const LogicalParameter &par, const std::string &valStr);
Expand All @@ -31,7 +34,8 @@ bool readBoolParameter(const LogicalParameter &par, const std::string &valStr);
void controlAssets(std::map<LogicalParameter::ID, std::shared_ptr<LogicalParameter>> &parameters);

std::queue<LogKey> readKeys(const std::string &keysStr, const std::string &visualKeysStr);
std::queue<LogKey> readButtons(const std::string &valStr, const std::string &visualValStr);
std::queue<LogKey> oldReadKeys(const std::string &keysStr, const std::string &visualKeysStr);
std::queue<LogKey> oldReadButtons(const std::string &valStr, const std::string &visualValStr);

void createDefaultConfig();
void saveConfig(
Expand All @@ -40,7 +44,6 @@ void saveConfig(
const std::vector<std::unique_ptr<Button>> *mKeys,
bool saveKeys);

std::string getKeysStr(const std::vector<std::unique_ptr<Button>> &mKeys, std::string str, bool readRealStr);
std::string getButtonStr(const std::vector<std::unique_ptr<Button>> &mKeys, std::string str, bool readRealStr);
std::string getKeysStr(const std::vector<std::unique_ptr<Button>> &mKeys, bool readRealStr);

} // !namespace ConfigHelper
3 changes: 2 additions & 1 deletion Headers/LogicalParameter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ struct LogicalParameter
KPSWndwTopPadding,
KPSWndwDistBtw,

ThemeDevMultpl,
OtherSaveStats,
OtherMultpl,

SaveStatMaxKPS,
SaveStatTotal,
Expand Down
7 changes: 4 additions & 3 deletions Headers/ParameterLine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,10 @@ class ParameterLine : public sf::Drawable, public sf::Transformable, public std:
KPSWndwDistBtw,
KPSWndwMty,

ThemeDevColl,
ThemeDevMultpl,
ThemeDevMty,
OtherColl,
OtherSaveStats,
OtherMultpl,
OtherMty,

SaveStatColl,
SaveStatMaxKPS,
Expand Down
3 changes: 2 additions & 1 deletion Headers/Settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ namespace Settings
extern unsigned KPSTextSize;
extern unsigned KPSNumberSize;

// [Theme developer]
// [Other]
extern bool SaveStats;
extern int ButtonPressMultiplier;

// Default assets
Expand Down
2 changes: 2 additions & 0 deletions Headers/StringHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ std::string keyToStr(sf::Keyboard::Key key, bool saveToCfg = false);
sf::Keyboard::Key strToKey(const std::string &str);
std::string btnToStr(sf::Mouse::Button button);
sf::Mouse::Button strToBtn(const std::string &str);
bool isKey(const std::string &str);
bool isButton(const std::string &str);
std::string logKeyToStr(const LogKey &logKey);
char enumKeyToStr(sf::Keyboard::Key key);
Binary file added Media/Preview-7k&4k-mania-Default-theme.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 10 additions & 2 deletions Source/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,19 +375,27 @@ void Application::buildStatistics()

void Application::buildButtons()
{
std::queue<LogKey> logKeyQueue = ConfigHelper::getLogKeys();
std::queue<LogKey> logKeyBtnsQueue = ConfigHelper::getLogButtons();
std::queue<LogKey> logKeyQueue = ConfigHelper::oldGetLogKeys();
std::queue<LogKey> logKeyBtnsQueue = ConfigHelper::oldGetLogButtons();
while (logKeyBtnsQueue.size())
{
logKeyQueue.push(logKeyBtnsQueue.front());
logKeyBtnsQueue.pop();
}
if (logKeyQueue.size() == 0)
logKeyQueue = ConfigHelper::getLogKeys();

for (unsigned i = 0; logKeyQueue.size(); ++i)
{
addButton(logKeyQueue.front());
logKeyQueue.pop();
}

if (mButtons.empty())
{
addButton(*new LogKey("Z", "Z", new sf::Keyboard::Key(sf::Keyboard::Z), nullptr));
addButton(*new LogKey("X", "X", new sf::Keyboard::Key(sf::Keyboard::X), nullptr));
}
}

bool Application::isPressPerformedOnButton(unsigned &btnIdx) const
Expand Down
15 changes: 11 additions & 4 deletions Source/Button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@ void Button::reset()
void Button::setTextStrings()
{
const bool lAlt = sf::Keyboard::isKeyPressed(sf::Keyboard::LAlt);
const bool advMode = Settings::ButtonTextPosAdvancedMode;
const bool advMode = Settings::ButtonTextSepPosAdvancedMode;

if (Settings::ButtonTextShowVisualKeys)
{
if (!lAlt == (!advMode || !Settings::ButtonTextShowTotal))
if ((!lAlt) || (lAlt && advMode && Settings::ButtonTextShowTotal))
mTexts[VisualKey]->setString(LogButton::mKey.visualStr);
else
else
mTexts[VisualKey]->setString(std::to_string(LogButton::mTotal));
}
if (Settings::ButtonTextShowTotal)
{
if (!lAlt == (!advMode || !Settings::ButtonTextShowVisualKeys))
if ((!lAlt) || (lAlt && advMode && Settings::ButtonTextShowVisualKeys))
mTexts[KeyCounter]->setString(std::to_string(LogButton::mTotal));
else
mTexts[KeyCounter]->setString(LogButton::mKey.visualStr);
Expand All @@ -70,6 +70,13 @@ void Button::setTextStrings()
{
mTexts[BeatsPerMinute]->setString(std::to_string(static_cast<unsigned>(LogButton::getLocalBeatsPerMinute())));
}

for (auto &text : mTexts)
{
text->setCharacterSize(Settings::ButtonTextCharacterSize);
GfxButton::keepInBounds(*text);
}
GfxButton::centerOrigins();
}

void Button::controlBounds()
Expand Down
146 changes: 101 additions & 45 deletions Source/ConfigHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ static std::ofstream ofErrLog;
namespace ConfigHelper
{

const std::string separationSign(" $SEPARATION$ ");

bool readConfig(
std::map<LogicalParameter::ID, std::shared_ptr<LogicalParameter>> &parameters,
std::map<ParameterLine::ID, std::shared_ptr<ParameterLine>> &parameterLines)
Expand Down Expand Up @@ -93,6 +95,23 @@ void fillParameters(std::map<LogicalParameter::ID, std::shared_ptr<LogicalParame
}

std::queue<LogKey> getLogKeys()
{
static const std::string parName1 = "Real keys";
static const std::string parName2 = "Visual keys";
bool parameterFound1 = false, parameterEmpty1 = false, nothing;

std::string keysStr = readParameter(parName1, parameterFound1, parameterEmpty1);
std::string visualKeysStr = readParameter(parName2, nothing, nothing);

if (!parameterFound1 || parameterEmpty1 || keysStr == "No" || keysStr == "no" || keysStr == "NO")
return { };

std::queue<LogKey> keyboardQueue = readKeys(keysStr, visualKeysStr);

return keyboardQueue;
}

std::queue<LogKey> oldGetLogKeys()
{
static const std::string parName1 = "Keyboard keys";
static const std::string parName2 = "Visual keys";
Expand All @@ -107,10 +126,10 @@ std::queue<LogKey> getLogKeys()
if (!parameterFound || parameterEmpty || keysStr == "No" || keysStr == "no" || keysStr == "NO")
return { };

return readKeys(keysStr, visualKeysStr);
return oldReadKeys(keysStr, visualKeysStr);
}

std::queue<LogKey> getLogButtons()
std::queue<LogKey> oldGetLogButtons()
{
static const std::string parName1 = "Mouse buttons";
static const std::string parName2 = "Visual buttons";
Expand All @@ -121,7 +140,7 @@ std::queue<LogKey> getLogButtons()
if (!parameterFound || parameterEmpty || buttonsStr == "No" || buttonsStr == "no" || buttonsStr == "NO")
return { };

return readButtons(buttonsStr, visualButtonsStr);
return oldReadButtons(buttonsStr, visualButtonsStr);
}

// Finds the parameter and returns everything after its name and ": ",
Expand Down Expand Up @@ -165,7 +184,7 @@ std::string readParameter(const std::string &parName, bool &parameterFound, bool
parameterFound = true;
parameterEmpty = false;
// Remove parameter name, ':' and space after it
return line.substr(parName.length() + 2, 81);
return std::string(line, parName.length() + 2);
}

void writeParameter(LogicalParameter &par)
Expand Down Expand Up @@ -372,6 +391,66 @@ void controlAssets(std::map<LogicalParameter::ID, std::shared_ptr<LogicalParamet
}

std::queue<LogKey> readKeys(const std::string &keysStr, const std::string &visualKeysStr)
{
std::queue<LogKey> logKeysQueue;
unsigned strIdx1 = 0, strIdx2 = 0;
const unsigned len = ConfigHelper::separationSign.length();

for (unsigned i = 0; strIdx1 < keysStr.size(); ++i)
{
std::string keyStr(keysStr, strIdx1, keysStr.substr(strIdx1).find(ConfigHelper::separationSign));
std::string visualKeyStr(visualKeysStr, strIdx2, visualKeysStr.substr(strIdx2).find(ConfigHelper::separationSign));
std::string checkStr;
sf::Keyboard::Key key;
sf::Mouse::Button button;

const bool isKeyB = isKey(keyStr);
const bool isButtonB = isButton(keyStr);
if (!isKeyB && !isButtonB)
{
// If there is no data to read - break
if (keysStr.find(ConfigHelper::separationSign, strIdx1) == std::string::npos)
break;

// Move index to the beggining of the next key
strIdx1 = keysStr.find(ConfigHelper::separationSign, strIdx1) + len;
strIdx2 = visualKeysStr.find(ConfigHelper::separationSign, strIdx2) + len;
}
else if (isKeyB)
{
key = strToKey(keyStr);
checkStr = keyToStr(key, true);
}
else
{
button = strToBtn(keyStr);
checkStr = btnToStr(button);
}

unsigned maxLength = 20;
if (visualKeyStr.size() > maxLength || visualKeyStr.size() == 0)
visualKeyStr = checkStr;

if (isKeyB)
logKeysQueue.emplace(*new LogKey(keyStr, visualKeyStr, new sf::Keyboard::Key(key), nullptr));
else
logKeysQueue.emplace(*new LogKey(keyStr, visualKeyStr, nullptr, new sf::Mouse::Button(button)));

logKeysQueue.back().realStr = checkStr == keyStr ? keyStr : checkStr;

// If there is no data to read - break
if (keysStr.find(ConfigHelper::separationSign, strIdx1) == std::string::npos)
break;

// Move index to the beggining of the next key
strIdx1 = keysStr.find(ConfigHelper::separationSign, strIdx1) + len;
strIdx2 = visualKeysStr.find(ConfigHelper::separationSign, strIdx2) + len;
}

return logKeysQueue;
}

std::queue<LogKey> oldReadKeys(const std::string &keysStr, const std::string &visualKeysStr)
{
std::queue<LogKey> logKeysQueue;
unsigned strIdx1 = 0, strIdx2 = 0;
Expand All @@ -383,6 +462,13 @@ std::queue<LogKey> readKeys(const std::string &keysStr, const std::string &visua
std::string checkStr;

sf::Keyboard::Key key = strToKey(keyStr);
if (key == sf::Keyboard::Unknown)
{
if (keysStr.find(',', strIdx1) == std::string::npos)
break;
strIdx1 = keysStr.find(',', strIdx1) + 1;
strIdx2 = visualKeysStr.find(',', strIdx2) + 1;
}

checkStr = keyToStr(key, true);
unsigned maxLength = 20;
Expand All @@ -404,7 +490,7 @@ std::queue<LogKey> readKeys(const std::string &keysStr, const std::string &visua
return logKeysQueue;
}

std::queue<LogKey> readButtons(const std::string &buttonsStr, const std::string &visualButtonsStr)
std::queue<LogKey> oldReadButtons(const std::string &buttonsStr, const std::string &visualButtonsStr)
{
std::queue<LogKey> logBtnQueue;
unsigned strIdx1 = 0, strIdx2 = 0;
Expand Down Expand Up @@ -450,17 +536,13 @@ void saveConfig(

if (saveKeys)
{
ofCfg << getKeysStr(*mKeys, "[Keyboard keys]\nKeyboard keys: ", true);
ofCfg << getKeysStr(*mKeys, "[Visual keys]\nVisual keys: ", false);
ofCfg << getButtonStr(*mKeys, "[Mouse buttons]\nMouse buttons: ", true);
ofCfg << getButtonStr(*mKeys, "[Visual buttons]\nVisual buttons: ", false);
ofCfg << "[Real keys]\nReal keys: " << getKeysStr(*mKeys, true);
ofCfg << "[Visual keys]\nVisual keys: " << getKeysStr(*mKeys, false);
}
else
{
ofCfg << "[Keyboard keys]\nKeyboard keys: Z,X\n";
ofCfg << "[nVisual keys]\nVisual keys: Z,X\n";
ofCfg << "[Mouse buttons]\nMouse buttons: No\n";
ofCfg << "[Visual buttons]\nVisual buttons: No\n";
ofCfg << "[Real keys]\nReal keys: Z,X\n";
ofCfg << "[Visual keys]\nVisual keys: Z,X\n";
}

bool commentsSection = false;
Expand Down Expand Up @@ -517,52 +599,26 @@ void saveConfig(
rename(tmpCfgPath.c_str(), cfgPath.c_str());
}

std::string getKeysStr(const std::vector<std::unique_ptr<Button>> &mKeys, std::string str, bool readRealStr)
std::string getKeysStr(const std::vector<std::unique_ptr<Button>> &mKeys, bool readRealStr)
{
std::string str;
auto it = mKeys.begin();

for (; it != mKeys.end(); ++it)
{
const LogKey *lKey = (*it)->getLogKey();
if (lKey->keyboardKey == nullptr)
break;
assert(lKey && (lKey->keyboardKey || lKey->mouseButton));

str += (readRealStr ? lKey->realStr : lKey->visualStr) + ",";
str += (readRealStr ? lKey->realStr : lKey->visualStr) + ConfigHelper::separationSign;
}
if (it != mKeys.begin())
str.erase(str.size() - 1);
str.erase(str.size() - ConfigHelper::separationSign.length());
else
str += "No";
str += "\n\n";

return str;
}

std::string getButtonStr(const std::vector<std::unique_ptr<Button>> &mKeys, std::string str, bool readRealStr)
{
auto it = mKeys.begin();
for (; it != mKeys.end(); ++it)
{
if ((*it)->getLogKey()->mouseButton)
break;
}

if (it == mKeys.end())
return str + "No\n\n";

for (; it != mKeys.end(); ++it)
{
const LogKey *lKey = (*it)->getLogKey();
if (lKey->mouseButton == nullptr)
break;

str += (readRealStr ? lKey->realStr : lKey->visualStr) + ",";
}
str.erase(str.size() - 1);
str += "\n\n";

return str;
}


} // !namespace ConfigHelper

Loading

0 comments on commit 7bfe834

Please sign in to comment.