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

Esc handling #220

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 4 additions & 16 deletions src/core/Config.cpp
Expand Up @@ -346,29 +346,17 @@ void Config::setActionKey(ControlAction actionId, size_t index, InputKeyId key)
return;
}

ActionKey & action = actions[actionId];
action.key[index] = key;

int otherIndex = 1 - index;

if(action.key[otherIndex] == key) {
action.key[otherIndex] = ActionKey::UNUSED;
}

// remove double key assignments
// remove existing key assignments
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be merged with the previous commit.

for(size_t i = 0; i < NUM_ACTION_KEY; i++) {

if(i == (size_t)actionId) {
continue;
}

for(int k = 0; k < 2; k++) {
if(actions[i].key[k] == key) {
actions[i].key[k] = ActionKey::UNUSED;
}
}

}

ActionKey & action = actions[actionId];
action.key[index] = key;
}

void Config::setOutputFile(const fs::path & _file) {
Expand Down
22 changes: 18 additions & 4 deletions src/gui/MenuWidgets.cpp
Expand Up @@ -445,7 +445,9 @@ MENUSTATE CWindowMenu::Render() {

if(g_debugInfo == InfoPanelGuiDebug)
page->drawDebug();


if(eMS == NOP)
eMS = page->checkShortcuts();
break;
}
}}
Expand All @@ -465,6 +467,7 @@ MenuPage::MenuPage(const Vec2f & pos, const Vec2f & size, MENUSTATE _eMenuState)
, m_selected(NULL)
, bEdit(false)
, bMouseAttack(false)
, m_disableShortcuts(false)
, m_blinkTime(PlatformDuration_ZERO)
, m_blink(true)
{
Expand Down Expand Up @@ -778,22 +781,29 @@ MENUSTATE MenuPage::Update(Vec2f pos) {
}
}

//check les shortcuts
return NOP;
}

MENUSTATE MenuPage::checkShortcuts() {

if(!bEdit) {

{Widget * w; BOOST_FOREACH(w, m_children.m_widgets) {
arx_assert(w);

if(w->m_shortcut != -1) {
if(w->m_shortcut != ActionKey::UNUSED) {
if(GInput->isKeyPressedNowUnPressed(w->m_shortcut)) {
if(m_disableShortcuts) {
m_disableShortcuts = false;
break;
}
bEdit = w->OnMouseClick();
m_selected = w;
return w->m_targetMenu;
}
}
}}
}

return NOP;
}

Expand Down Expand Up @@ -883,6 +893,10 @@ void MenuPage::Render() {
if(widget) {
if(!bEdit) {
if(widget->m_isKeybind) {
if(inputKeyId == Keyboard::Key_Escape) {
inputKeyId = ActionKey::UNUSED;
m_disableShortcuts = true;
}
config.setActionKey(widget->m_keybindAction, widget->m_keybindIndex, inputKeyId);
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/gui/MenuWidgets.h
Expand Up @@ -75,6 +75,7 @@ class MenuPage {

TextWidget *GetTouch(bool keyTouched, int keyId, InputKeyId* pInputKeyId, bool _bValidateTest);
void ReInitActionKey();
MENUSTATE checkShortcuts();

Vec2f m_pos;
Vec2f m_oldPos;
Expand All @@ -90,12 +91,11 @@ class MenuPage {
private:
void updateTextRect(TextWidget * widget);
void UpdateText();

Widget * m_selected;
bool bEdit;

bool bMouseAttack;


Widget * m_selected;
bool bEdit;
bool bMouseAttack;
bool m_disableShortcuts;
PlatformDuration m_blinkTime;
bool m_blink;
};
Expand Down
2 changes: 1 addition & 1 deletion src/gui/widget/Widget.cpp
Expand Up @@ -35,7 +35,7 @@ Widget::Widget()
ePlace=NOCENTER;
eState=TNOP;
m_targetMenu = NOP;
m_shortcut = -1;
m_shortcut = ActionKey::UNUSED;
}

extern TextWidget * pMenuElementApply;
Expand Down
3 changes: 2 additions & 1 deletion src/gui/widget/Widget.h
Expand Up @@ -23,6 +23,7 @@
#include <boost/noncopyable.hpp>

#include "core/SaveGame.h"
#include "input/InputKey.h"
#include "math/Rectangle.h"
#include "util/HandleType.h"

Expand Down Expand Up @@ -101,7 +102,7 @@ class Widget : private boost::noncopyable {
ELEMPOS ePlace; //placement de la zone
ELEMSTATE eState; //etat de l'element en cours
MENUSTATE m_targetMenu; //etat de retour de l'element
int m_shortcut;
InputKeyId m_shortcut;

public:
explicit Widget();
Expand Down