Skip to content

Commit

Permalink
Added greek and hebrew glyphs, improved controls remap
Browse files Browse the repository at this point in the history
  • Loading branch information
deathkiller committed Dec 28, 2024
1 parent d745186 commit aaabc06
Show file tree
Hide file tree
Showing 11 changed files with 214 additions and 179 deletions.
Binary file modified Content/Animations/UI/font_small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Content/Animations/UI/font_small.png.font
Binary file not shown.
2 changes: 1 addition & 1 deletion Sources/Jazz2/LevelHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ namespace Jazz2
_pressedKeys.set((std::size_t)event.sym);

if (_pauseMenu != nullptr) {
_pauseMenu->OnKeyReleased(event);
_pauseMenu->OnKeyPressed(event);
} else if (_console->IsVisible()) {
_console->OnKeyPressed(event);
}
Expand Down
214 changes: 57 additions & 157 deletions Sources/Jazz2/UI/Menu/RemapControlsSection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ using namespace Jazz2::UI::Menu::Resources;
namespace Jazz2::UI::Menu
{
RemapControlsSection::RemapControlsSection(std::int32_t playerIndex)
: _selectedColumn(0), _playerIndex(playerIndex), _isDirty(false), _waitForInput(false), _timeout(0.0f),
_hintAnimation(0.0f), _keysPressedLast(ValueInit, (std::size_t)Keys::Count)
: _selectedColumn(0), _playerIndex(playerIndex), _isDirty(false), _waitForInput(false), _waitForInputPrev(false),
_timeout(0.0f), _hintAnimation(0.0f)
{
// TRANSLATORS: Menu item in Options > Controls > Remap Controls section
_items.emplace_back(RemapControlsItem { PlayerActions::Left, _("Left") });
Expand Down Expand Up @@ -60,17 +60,16 @@ namespace Jazz2::UI::Menu
}

if (waitingForInput) {
auto& input = theApplication().GetInputManager();
auto& keyState = input.keyboardState();

if (keyState.isKeyDown(Keys::Escape) || _timeout <= 0.0f) {
if (_timeout <= 0.0f) {
_root->PlaySfx("MenuSelect"_s, 0.5f);
_waitForInput = false;
_waitForInputPrev = true;
return;
}

_timeout -= timeMult;

auto& input = theApplication().GetInputManager();
MappingTarget newTarget;
const JoyMappedState* joyStates[UI::ControlScheme::MaxConnectedGamepads];
std::int32_t joyStatesCount = 0;
Expand All @@ -92,6 +91,7 @@ namespace Jazz2::UI::Menu
// Button has collision, but it's the same as it's already assigned
_root->PlaySfx("MenuSelect"_s, 0.5f);
_waitForInput = false;
_waitForInputPrev = true;
return;
}
}
Expand All @@ -111,6 +111,7 @@ namespace Jazz2::UI::Menu
// Axis has collision, but it's the same as it's already assigned
_root->PlaySfx("MenuSelect"_s, 0.5f);
_waitForInput = false;
_waitForInputPrev = true;
return;
}
}
Expand All @@ -121,25 +122,6 @@ namespace Jazz2::UI::Menu
}
}

for (std::int32_t key = 0; key < (std::int32_t)Keys::Count && waitingForInput; key++) {
bool isPressed = keyState.isKeyDown((Keys)key);
if (isPressed != _keysPressedLast[key]) {
_keysPressedLast.set(key, isPressed);
if (isPressed) {
newTarget = ControlScheme::CreateTarget((Keys)key);
std::int32_t collidingAction, collidingAssignment;
if (!HasCollision(newTarget, collidingAction, collidingAssignment)) {
waitingForInput = false;
} else if (collidingAction == (std::int32_t)_items[_selectedIndex].Item.Type && collidingAssignment == _selectedColumn) {
// Key has collision, but it's the same as it's already assigned
_root->PlaySfx("MenuSelect"_s, 0.5f);
_waitForInput = false;
return;
}
}
}
}

if (!waitingForInput) {
auto& mapping = ControlScheme::GetMappings(_playerIndex)[(std::int32_t)_items[_selectedIndex].Item.Type];
if (_selectedColumn < mapping.Targets.size()) {
Expand All @@ -150,10 +132,14 @@ namespace Jazz2::UI::Menu

_isDirty = true;
_waitForInput = false;
_waitForInputPrev = true;
_root->PlaySfx("MenuSelect"_s, 0.5f);
_root->ApplyPreferencesChanges(ChangedPreferencesType::ControlScheme);
return;
}
}

_waitForInputPrev = false;
}

void RemapControlsSection::OnDraw(Canvas* canvas)
Expand Down Expand Up @@ -278,7 +264,7 @@ namespace Jazz2::UI::Menu
}
} else {
Keys key = (Keys)(data & ControlScheme::ButtonMask);
value = KeyToName(key);
value = theApplication().GetInputManager().getKeyName(key);
}

if (!value.empty()) {
Expand Down Expand Up @@ -311,9 +297,50 @@ namespace Jazz2::UI::Menu
}
}

void RemapControlsSection::OnKeyPressed(const KeyboardEvent& event)
{
bool waitingForInput = _waitForInput;

if (waitingForInput) {
if (event.sym == Keys::Escape) {
_root->PlaySfx("MenuSelect"_s, 0.5f);
_waitForInput = false;
_waitForInputPrev = true;
return;
}

MappingTarget newTarget = ControlScheme::CreateTarget(event.sym);
std::int32_t collidingAction, collidingAssignment;
if (!HasCollision(newTarget, collidingAction, collidingAssignment)) {
waitingForInput = false;
} else if (collidingAction == (std::int32_t)_items[_selectedIndex].Item.Type && collidingAssignment == _selectedColumn) {
// Key has collision, but it's the same as it's already assigned
_root->PlaySfx("MenuSelect"_s, 0.5f);
_waitForInput = false;
_waitForInputPrev = true;
return;
}

if (!waitingForInput) {
auto& mapping = ControlScheme::GetMappings(_playerIndex)[(std::int32_t)_items[_selectedIndex].Item.Type];
if (_selectedColumn < mapping.Targets.size()) {
mapping.Targets[_selectedColumn] = newTarget;
} else {
mapping.Targets.push_back(newTarget);
}

_isDirty = true;
_waitForInput = false;
_waitForInputPrev = true;
_root->PlaySfx("MenuSelect"_s, 0.5f);
_root->ApplyPreferencesChanges(ChangedPreferencesType::ControlScheme);
}
}
}

void RemapControlsSection::OnHandleInput()
{
if (_waitForInput) {
if (_waitForInput || _waitForInputPrev) {
return;
}

Expand Down Expand Up @@ -396,6 +423,7 @@ namespace Jazz2::UI::Menu
if (_waitForInput) {
// If we are already waiting for input, delete the target instead
_waitForInput = false;
_waitForInputPrev = true;

if (_selectedIndex == (int32_t)PlayerActions::Menu && _selectedColumn == 0) {
return;
Expand All @@ -414,6 +442,7 @@ namespace Jazz2::UI::Menu
} else {
_root->PlaySfx("MenuSelect"_s, 0.5f);
_waitForInput = false;
_waitForInputPrev = true;
_animation = 0.0f;
_selectedIndex = newIndex;
_selectedColumn = newColumn;
Expand All @@ -429,6 +458,7 @@ namespace Jazz2::UI::Menu
if (_waitForInput) {
_root->PlaySfx("MenuSelect"_s, 0.5f);
_waitForInput = false;
_waitForInputPrev = true;
return;
}

Expand All @@ -453,15 +483,6 @@ namespace Jazz2::UI::Menu
void RemapControlsSection::RefreshPreviousState()
{
auto& input = theApplication().GetInputManager();
auto& keyState = input.keyboardState();

_keysPressedLast.resetAll();

for (std::int32_t key = 0; key < (int32_t)Keys::Count; key++) {
if (keyState.isKeyDown((Keys)key)) {
_keysPressedLast.set(key);
}
}

const JoyMappedState* joyStates[UI::ControlScheme::MaxConnectedGamepads];
std::int32_t joyStatesCount = 0;
Expand All @@ -488,125 +509,4 @@ namespace Jazz2::UI::Menu

return false;
}

StringView RemapControlsSection::KeyToName(Keys key)
{
switch (key) {
case Keys::Backspace: return "Backspace"_s;
case Keys::Tab: return "Tab"_s;
case Keys::Return: return "Enter"_s;
case Keys::Escape: return "Escape"_s;
case Keys::Space: return "Space"_s;
case Keys::Quote: return "'"_s;
case Keys::Plus: return "+"_s;
case Keys::Comma: return ","_s;
case Keys::Minus: return "-"_s;
case Keys::Period: return "."_s;
case Keys::Slash: return "/"_s;
case Keys::D0: return "0"_s;
case Keys::D1: return "1"_s;
case Keys::D2: return "2"_s;
case Keys::D3: return "3"_s;
case Keys::D4: return "4"_s;
case Keys::D5: return "5"_s;
case Keys::D6: return "6"_s;
case Keys::D7: return "7"_s;
case Keys::D8: return "8"_s;
case Keys::D9: return "9"_s;
case Keys::Semicolon: return ";"_s;
case Keys::LeftBracket: return "["_s;
case Keys::Backslash: return "\\"_s;
case Keys::RightBracket: return "]"_s;
case Keys::Backquote: return "`"_s;

case Keys::A: return "A"_s;
case Keys::B: return "B"_s;
case Keys::C: return "C"_s;
case Keys::D: return "D"_s;
case Keys::E: return "E"_s;
case Keys::F: return "F"_s;
case Keys::G: return "G"_s;
case Keys::H: return "H"_s;
case Keys::I: return "I"_s;
case Keys::J: return "J"_s;
case Keys::K: return "K"_s;
case Keys::L: return "L"_s;
case Keys::M: return "M"_s;
case Keys::N: return "N"_s;
case Keys::O: return "O"_s;
case Keys::P: return "P"_s;
case Keys::Q: return "Q"_s;
case Keys::R: return "R"_s;
case Keys::S: return "S"_s;
case Keys::T: return "T"_s;
case Keys::U: return "U"_s;
case Keys::V: return "V"_s;
case Keys::W: return "W"_s;
case Keys::X: return "X"_s;
case Keys::Y: return "Y"_s;
case Keys::Z: return "Z"_s;
case Keys::Delete: return "Del"_s;

case Keys::NumPad0: return "0 (N)"_s;
case Keys::NumPad1: return "1 (N)"_s;
case Keys::NumPad2: return "2 (N)"_s;
case Keys::NumPad3: return "3 (N)"_s;
case Keys::NumPad4: return "4 (N)"_s;
case Keys::NumPad5: return "5 (N)"_s;
case Keys::NumPad6: return "6 (N)"_s;
case Keys::NumPad7: return "7 (N)"_s;
case Keys::NumPad8: return "8 (N)"_s;
case Keys::NumPad9: return "9 (N)"_s;
case Keys::NumPadPeriod: return ". [N]"_s;
case Keys::NumPadDivide: return "/ [N]"_s;
case Keys::NumPadMultiply: return "* [N]"_s;
case Keys::NumPadMinus: return "- [N]"_s;
case Keys::NumPadPlus: return "+ [N]"_s;
case Keys::NumPadEnter: return "Enter [N]"_s;
case Keys::NumPadEquals: return "= [N]"_s;

case Keys::Up: return "Up"_s;
case Keys::Down: return "Down"_s;
case Keys::Right: return "Right"_s;
case Keys::Left: return "Left"_s;
case Keys::Insert: return "Ins"_s;
case Keys::Home: return "Home"_s;
case Keys::End: return "End"_s;
case Keys::PageUp: return "PgUp"_s;
case Keys::PageDown: return "PgDn"_s;

case Keys::F1: return "F1"_s;
case Keys::F2: return "F2"_s;
case Keys::F3: return "F3"_s;
case Keys::F4: return "F4"_s;
case Keys::F5: return "F5"_s;
case Keys::F6: return "F6"_s;
case Keys::F7: return "F7"_s;
case Keys::F8: return "F8"_s;
case Keys::F9: return "F9"_s;
case Keys::F10: return "F10"_s;
case Keys::F11: return "F11"_s;
case Keys::F12: return "F12"_s;
case Keys::F13: return "F13"_s;
case Keys::F14: return "F14"_s;
case Keys::F15: return "F15"_s;

case Keys::NumLock: return "Num Lock"_s;
case Keys::CapsLock: return "Caps Lock"_s;
case Keys::ScrollLock: return "Scroll Lock"_s;
case Keys::RShift: return "R. Shift"_s;
case Keys::LShift: return "Shift"_s;
case Keys::RCtrl: return "R. Ctrl"_s;
case Keys::LCtrl: return "Ctrl"_s;
case Keys::RAlt: return "R. Alt"_s;
case Keys::LAlt: return "Alt"_s;
//case Keys::RSuper: return "R. Super"_s;
//case Keys::LSuper: return "Super"_s;
//case Keys::PrintScreen: return "PrtSc"_s;
case Keys::Pause: return "Pause"_s;
case Keys::Menu: return "Menu"_s;

default: return {};
}
}
}
6 changes: 3 additions & 3 deletions Sources/Jazz2/UI/Menu/RemapControlsSection.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@ namespace Jazz2::UI::Menu
void OnUpdate(float timeMult) override;
void OnDraw(Canvas* canvas) override;

private:
protected:
std::int32_t _selectedColumn;
std::int32_t _playerIndex;
float _timeout;
float _hintAnimation;
BitArray _keysPressedLast;
JoyMappedState _joyStatesLast[ControlScheme::MaxConnectedGamepads];
bool _isDirty;
bool _waitForInput;
bool _waitForInputPrev;

void OnLayoutItem(Canvas* canvas, ListViewItem& item) override;
void OnDrawItem(Canvas* canvas, ListViewItem& item, std::int32_t& charOffset, bool isSelected) override;
void OnKeyPressed(const KeyboardEvent& event) override;
void OnHandleInput() override;
void OnExecuteSelected() override;
void OnTouchUp(std::int32_t newIndex, const Vector2i& viewSize, const Vector2i& touchPos) override;
void OnBackPressed() override;

void RefreshPreviousState();
bool HasCollision(MappingTarget target, std::int32_t& collidingAction, std::int32_t& collidingAssignment);
static StringView KeyToName(Keys key);
};
}
3 changes: 2 additions & 1 deletion Sources/Shared/Cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ extern "C" {
}
#endif

/**
/** @file
@brief Compile-time and runtime CPU instruction set detection and dispatch
This namespace provides *tags* for x86, ARM and WebAssembly instruction sets,
Expand Down Expand Up @@ -300,6 +300,7 @@ extern "C" {
function declaration to make it possible to unify them under a single wrapper
macro in case a practical use case needs to handle more than one variant.
*/

namespace Death { namespace Cpu {
//###==##====#=====--==~--~=~- --- -- - - - -

Expand Down
7 changes: 7 additions & 0 deletions Sources/nCine/Backends/SdlInputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ namespace nCine
}
}

StringView SdlInputManager::getKeyName(Keys key) const
{
// TODO
//return SDL_GetKeyName(SdlKeys::enumToKeysValue(key));
return IInputManager::getKeyName(key);
}

bool SdlInputManager::isJoyPresent(int joyId) const
{
ASSERT(joyId >= 0);
Expand Down
Loading

0 comments on commit aaabc06

Please sign in to comment.