Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(WIP, DO NOT MERGE) Replay drag n drop #286

Merged
merged 25 commits into from
Sep 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .gitignore
Binary file not shown.
1 change: 0 additions & 1 deletion _RELEASE/Packs/experimental/Scripts/Levels/cw.lua
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ end
function onUnload()
end

-- TODO: move to utils
-- From: https://stackoverflow.com/questions/12394841/
function ArrayRemove(t, fnRemove)
local j, n = 1, #t;
Expand Down
3 changes: 2 additions & 1 deletion _RELEASE/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@
"no_music" : false,
"no_rotation" : false,
"no_sound" : false,
"official" : false,
"official" : true,
"online" : true,
"pixel_multiplier" : 1,
"player_focus_speed" : 4.6250,
"player_size" : 7.300000190734863,
"player_speed" : 9.449999809265137,
"pulse_enabled" : true,
"rotate_to_start" : true,
"save_local_best_replay_to_file" : true,
"server_local" : true,
"server_verbose" : true,
"show_fps" : true,
Expand Down
2 changes: 1 addition & 1 deletion build/cmake_mingw_debug.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
cmake .. -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE=DEBUG
cmake .. -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE=DEBUG -DCMAKE_CXX_FLAGS="-O0 -fno-omit-frame-pointer"
2 changes: 1 addition & 1 deletion extlibs/SSVMenuSystem
255 changes: 14 additions & 241 deletions include/SSVOpenHexagon/Core/BindControl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

#include <string>


namespace hg
{

Expand All @@ -24,20 +23,10 @@ class BindControlBase : public ssvms::ItemBase

public:
BindControlBase(ssvms::Menu& mMenu, ssvms::Category& mCategory,
const std::string& mName, const int mID)
: ssvms::ItemBase(mMenu, mCategory, mName), ID{mID}
{
}

[[nodiscard]] virtual bool erase()
{
return false;
}
const std::string& mName, const int mID);

[[nodiscard]] virtual bool isWaitingForBind()
{
return false;
}
[[nodiscard]] virtual bool erase();
[[nodiscard]] virtual bool isWaitingForBind();
};

class KeyboardBindControl final : public BindControlBase
Expand All @@ -58,19 +47,7 @@ class KeyboardBindControl final : public BindControlBase
Callback callback;

[[nodiscard]] int getRealSize(
const std::vector<ssvs::Input::Combo>& combos) const
{
decltype(combos.size()) i = 0;
for(; i < combos.size(); ++i)
{
if(combos[i].isUnbound())
{
break;
}
}

return i;
}
const std::vector<ssvs::Input::Combo>& combos) const;

public:
template <typename TFuncGet, typename TFuncSet, typename TFuncClear,
Expand All @@ -91,132 +68,15 @@ class KeyboardBindControl final : public BindControlBase
{
}

void exec() override
{
waitingForBind = !waitingForBind;
}

[[nodiscard]] bool isWaitingForBind() override
{
return waitingForBind;
}

[[nodiscard]] bool erase() override
{
const int size = sizeGetter();
if(!size)
{
return false;
}
void exec() override;

clearBind();
callback(triggerGetter(), ID);
return true;
}
[[nodiscard]] bool isWaitingForBind() override;
[[nodiscard]] bool erase() override;

void newKeyboardBind(
const ssvs::KKey key, const ssvs::MBtn btn = ssvs::MBtn::Left)
{
// stop if the pressed key is already assigned to this bind
const std::vector<ssvs::Input::Combo>& Combos =
triggerGetter().getCombos();

const int size = sizeGetter();
if(key > ssvs::KKey::Unknown)
{
for(int i = 0; i < size; ++i)
{
if(Combos[i].getKeys()[int(key) + 1])
{
waitingForBind = false;
return;
}
}
}
else
{
for(int i = 0; i < size; ++i)
{
if(Combos[i].getBtns()[int(btn) + 1])
{
waitingForBind = false;
return;
}
}
}

// assign the pressed key to the config value
auto [unboundID, trig] = addBind(key, btn);

// key was assigned to another function and was unbound.
// This trigger must be refreshed as well
if(unboundID > -1)
{
callback(trig, unboundID);
}

// apply the new bind in game
callback(triggerGetter(), ID);

// finalize
waitingForBind = false;
}

std::string getName() const override
{
const std::vector<ssvs::Input::Combo>& combos =
triggerGetter().getCombos();

const int size = sizeGetter();
std::string bindNames;

// get binds in the order they have been entered
for(int i = 0; i < size; ++i)
{
const auto keyBind = combos[i].getKeys();
for(int j = 0; j <= ssvs::KKey::KeyCount; ++j)
{
if(!keyBind[j])
{
continue;
}
const ssvs::KKey key, const ssvs::MBtn btn = ssvs::MBtn::Left);

if(!bindNames.empty())
{
bindNames += ", ";
}

// names are shifted compared to the Key enum
bindNames += ssvs::getKKeyName(ssvs::KKey(j - 1));
break;
}

const auto btnBinds = combos[i].getBtns();
for(int j = 0; j <= ssvs::MBtn::ButtonCount; ++j)
{
if(!btnBinds[j])
{
continue;
}

if(!bindNames.empty())
{
bindNames += ", ";
}

// same as with keys
bindNames += ssvs::getMBtnName(ssvs::MBtn(j - 1));
break;
}
}

if(waitingForBind)
{
bindNames += "_";
}

return name + ": " + bindNames;
}
[[nodiscard]] std::string getName() const override;
};

class JoystickBindControl final : public BindControlBase
Expand All @@ -230,11 +90,6 @@ class JoystickBindControl final : public BindControlBase
ValueSetter setButton;
Callback callback;

const std::string buttonsNames[12][2] = {{"A", "SQUARE"}, {"B", "CROSS"},
{"X", "CIRCLE"}, {"Y", "TRIANGLE"}, {"LB", "L1"}, {"RB", "R1"},
{"BACK", "L2"}, {"START", "R2"}, {"LEFT STICK", "SELECT"},
{"RIGHT STICK", "START"}, {"LT", "LEFT STICK"}, {"RT", "RIGHT STICK"}};

public:
template <typename TFuncGet, typename TFuncSet, typename TFuncCallback>
JoystickBindControl(ssvms::Menu& mMenu, ssvms::Category& mCategory,
Expand All @@ -245,96 +100,14 @@ class JoystickBindControl final : public BindControlBase
{
}

void exec() override
{
waitingForBind = !waitingForBind;
}

[[nodiscard]] bool isWaitingForBind() override
{
return waitingForBind;
}

[[nodiscard]] bool erase() override
{
if(valueGetter() == 33)
{
return false;
}

// clear both the config and the in game input
setButton(33);
callback(33, ID);
return true;
}

void newJoystickBind(const int joy)
{
// stop if the pressed button is already assigned to this bind
if(joy == valueGetter())
{
waitingForBind = false;
return;
}

// save the new key in config
int unboundID = setButton(joy);

// if the key was bound to another function and it was reassigned
// make sure we also update the unbound joystick button
if(unboundID > -1)
{
callback(33, unboundID);
}
void exec() override;

// update the bind we customized
callback(joy, ID);
[[nodiscard]] bool isWaitingForBind() override;
[[nodiscard]] bool erase() override;

// finalize
waitingForBind = false;
}
void newJoystickBind(const int joy);

[[nodiscard]] std::string getName() const override
{
std::string bindNames;
const unsigned int value = valueGetter();

if(value == 33)
{
bindNames = "";
}
else
{
#define MS_VENDOR_ID 0x045E
#define SONY_VENDOR_ID 0x54C

const unsigned int vendorId =
sf::Joystick::isConnected(0)
? sf::Joystick::getIdentification(0).vendorId
: 0;

switch(vendorId)
{
case MS_VENDOR_ID:
bindNames = value >= 12 ? "" : buttonsNames[value][0];
break;
case SONY_VENDOR_ID:
bindNames = value >= 12 ? "" : buttonsNames[value][1];
break;
default: bindNames = ssvu::toStr(value); break;
}

#undef MS_VENDOR_ID
#undef SONY_VENDOR_ID
}

if(waitingForBind)
{
bindNames += "_";
}

return name + ": " + bindNames;
}
[[nodiscard]] std::string getName() const override;
};

} // namespace hg
2 changes: 0 additions & 2 deletions include/SSVOpenHexagon/Core/Discord.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#pragma once

#include "SSVOpenHexagon/Global/Common.hpp"

#include "discord/discord.h"

#include <string_view>
Expand Down
Loading