GUI: don't sort note keys in settings
until Apply or OK are clicked issue #2345
This commit is contained in:
parent
3464dd17f5
commit
b95f9885a4
|
@ -1602,6 +1602,15 @@ struct PendingDrawOsc {
|
|||
lineSize(0.0f) {}
|
||||
};
|
||||
|
||||
struct MappedInput {
|
||||
int scan;
|
||||
int val;
|
||||
MappedInput():
|
||||
scan(SDL_SCANCODE_UNKNOWN), val(0) {}
|
||||
MappedInput(int s, int v):
|
||||
scan(s), val(v) {}
|
||||
};
|
||||
|
||||
struct FurnaceCV;
|
||||
|
||||
class FurnaceGUI {
|
||||
|
@ -2450,6 +2459,7 @@ class FurnaceGUI {
|
|||
|
||||
// SDL_Scancode,int
|
||||
std::map<int,int> noteKeys;
|
||||
std::vector<MappedInput> noteKeysRaw;
|
||||
// SDL_Keycode,int
|
||||
std::map<int,int> valueKeys;
|
||||
|
||||
|
@ -3037,6 +3047,8 @@ class FurnaceGUI {
|
|||
bool parseSysEx(unsigned char* data, size_t len);
|
||||
|
||||
void applyUISettings(bool updateFonts=true);
|
||||
void decompileNoteKeys();
|
||||
void compileNoteKeys();
|
||||
void initSystemPresets();
|
||||
|
||||
void initRandomDemoSong();
|
||||
|
|
|
@ -535,15 +535,6 @@ void FurnaceGUI::promptKey(int which, int bindIdx) {
|
|||
}
|
||||
}
|
||||
|
||||
struct MappedInput {
|
||||
int scan;
|
||||
int val;
|
||||
MappedInput():
|
||||
scan(SDL_SCANCODE_UNKNOWN), val(0) {}
|
||||
MappedInput(int s, int v):
|
||||
scan(s), val(v) {}
|
||||
};
|
||||
|
||||
void FurnaceGUI::drawSettings() {
|
||||
if (nextWindow==GUI_WINDOW_SETTINGS) {
|
||||
settingsOpen=true;
|
||||
|
@ -2288,18 +2279,7 @@ void FurnaceGUI::drawSettings() {
|
|||
ImGui::TreePop();
|
||||
}
|
||||
if (ImGui::TreeNode(_("Note input"))) {
|
||||
std::vector<MappedInput> sorted;
|
||||
if (ImGui::BeginTable("keysNoteInput",4)) {
|
||||
for (std::map<int,int>::value_type& i: noteKeys) {
|
||||
std::vector<MappedInput>::iterator j;
|
||||
for (j=sorted.begin(); j!=sorted.end(); j++) {
|
||||
if (j->val>i.second) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
sorted.insert(j,MappedInput(i.first,i.second));
|
||||
}
|
||||
|
||||
static char id[4096];
|
||||
|
||||
ImGui::TableNextRow(ImGuiTableRowFlags_Headers);
|
||||
|
@ -2312,7 +2292,8 @@ void FurnaceGUI::drawSettings() {
|
|||
ImGui::TableNextColumn();
|
||||
ImGui::Text(_("Remove"));
|
||||
|
||||
for (MappedInput& i: sorted) {
|
||||
for (size_t _i=0; _i<noteKeysRaw.size(); _i++) {
|
||||
MappedInput& i=noteKeysRaw[_i];
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%s",SDL_GetScancodeName((SDL_Scancode)i.scan));
|
||||
|
@ -2320,22 +2301,22 @@ void FurnaceGUI::drawSettings() {
|
|||
if (i.val==102) {
|
||||
snprintf(id,4095,_("Macro release##SNType_%d"),i.scan);
|
||||
if (ImGui::Button(id)) {
|
||||
noteKeys[i.scan]=0;
|
||||
i.val=0;
|
||||
}
|
||||
} else if (i.val==101) {
|
||||
snprintf(id,4095,_("Note release##SNType_%d"),i.scan);
|
||||
if (ImGui::Button(id)) {
|
||||
noteKeys[i.scan]=102;
|
||||
i.val=102;
|
||||
}
|
||||
} else if (i.val==100) {
|
||||
snprintf(id,4095,_("Note off##SNType_%d"),i.scan);
|
||||
if (ImGui::Button(id)) {
|
||||
noteKeys[i.scan]=101;
|
||||
i.val=101;
|
||||
}
|
||||
} else {
|
||||
snprintf(id,4095,_("Note##SNType_%d"),i.scan);
|
||||
if (ImGui::Button(id)) {
|
||||
noteKeys[i.scan]=100;
|
||||
i.val=100;
|
||||
}
|
||||
}
|
||||
ImGui::TableNextColumn();
|
||||
|
@ -2344,14 +2325,14 @@ void FurnaceGUI::drawSettings() {
|
|||
if (ImGui::InputInt(id,&i.val,1,12)) {
|
||||
if (i.val<0) i.val=0;
|
||||
if (i.val>96) i.val=96;
|
||||
noteKeys[i.scan]=i.val;
|
||||
settingsChanged=true;
|
||||
}
|
||||
}
|
||||
ImGui::TableNextColumn();
|
||||
snprintf(id,4095,ICON_FA_TIMES "##SNRemove_%d",i.scan);
|
||||
if (ImGui::Button(id)) {
|
||||
noteKeys.erase(i.scan);
|
||||
noteKeysRaw.erase(noteKeysRaw.begin()+_i);
|
||||
_i--;
|
||||
settingsChanged=true;
|
||||
}
|
||||
}
|
||||
|
@ -2364,8 +2345,19 @@ void FurnaceGUI::drawSettings() {
|
|||
if (sName[0]==0) continue;
|
||||
snprintf(id,4095,"%s##SNNewKey_%d",sName,i);
|
||||
if (ImGui::Selectable(id)) {
|
||||
noteKeys[(SDL_Scancode)i]=0;
|
||||
settingsChanged=true;
|
||||
bool alreadyThere=false;
|
||||
for (MappedInput& j: noteKeysRaw) {
|
||||
if (j.scan==i) {
|
||||
alreadyThere=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (alreadyThere) {
|
||||
showError(_("that key is bound already!"));
|
||||
} else {
|
||||
noteKeysRaw.push_back(MappedInput(i,0));
|
||||
settingsChanged=true;
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
|
@ -4947,6 +4939,7 @@ void FurnaceGUI::readConfig(DivConfig& conf, FurnaceGUISettingGroups groups) {
|
|||
}
|
||||
|
||||
decodeKeyMap(noteKeys,conf.getString("noteKeys",DEFAULT_NOTE_KEYS));
|
||||
decompileNoteKeys();
|
||||
}
|
||||
|
||||
if (groups&GUI_SETTINGS_BEHAVIOR) {
|
||||
|
@ -5542,6 +5535,7 @@ void FurnaceGUI::writeConfig(DivConfig& conf, FurnaceGUISettingGroups groups) {
|
|||
conf.set(String("keybind_GUI_ACTION_")+String(guiActions[i].name),actionKeys[i]);
|
||||
}
|
||||
|
||||
compileNoteKeys();
|
||||
conf.set("noteKeys",encodeKeyMap(noteKeys));
|
||||
}
|
||||
|
||||
|
@ -6118,6 +6112,7 @@ void FurnaceGUI::resetKeybinds() {
|
|||
actionKeys[i]=guiActions[i].defaultBind;
|
||||
}
|
||||
decodeKeyMap(noteKeys,DEFAULT_NOTE_KEYS);
|
||||
decompileNoteKeys();
|
||||
parseKeybinds();
|
||||
}
|
||||
|
||||
|
@ -6296,6 +6291,27 @@ void setupLabel(const char* lStr, char* label, int len) {
|
|||
}
|
||||
}
|
||||
|
||||
void FurnaceGUI::decompileNoteKeys() {
|
||||
noteKeysRaw.clear();
|
||||
for (std::map<int,int>::value_type& i: noteKeys) {
|
||||
std::vector<MappedInput>::iterator j;
|
||||
for (j=noteKeysRaw.begin(); j!=noteKeysRaw.end(); j++) {
|
||||
if (j->val>i.second) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
noteKeysRaw.insert(j,MappedInput(i.first,i.second));
|
||||
}
|
||||
}
|
||||
|
||||
void FurnaceGUI::compileNoteKeys() {
|
||||
noteKeys.clear();
|
||||
for (MappedInput& i: noteKeysRaw) {
|
||||
noteKeys[i.scan]=i.val;
|
||||
}
|
||||
decompileNoteKeys();
|
||||
}
|
||||
|
||||
void FurnaceGUI::applyUISettings(bool updateFonts) {
|
||||
ImGuiStyle sty;
|
||||
if (settings.guiColorsBase) {
|
||||
|
|
Loading…
Reference in a new issue