command palette: "add chip" menu

This commit is contained in:
YohananDiamond 2023-08-27 14:19:26 -03:00
parent 4f83fc2e93
commit 7e9edb59f7
5 changed files with 47 additions and 1 deletions

View file

@ -62,6 +62,9 @@ void FurnaceGUI::drawPalette() {
case CMDPAL_TYPE_INSTRUMENT_CHANGE:
hint="Search instruments (to change to)...";
break;
case CMDPAL_TYPE_ADD_CHIP:
hint="Search chip (to add)...";
break;
}
if (ImGui::InputTextWithHint("##CommandPaletteSearch",hint,&paletteQuery) || paletteFirstFrame) {
@ -99,13 +102,22 @@ void FurnaceGUI::drawPalette() {
case CMDPAL_TYPE_SAMPLES:
for (int i=0; i<e->song.sampleLen; i++) {
logD("ins #%x: %s", i, e->song.sample[i]->name.c_str());
if (matchFuzzy(e->song.sample[i]->name.c_str(),paletteQuery.c_str())) {
paletteSearchResults.push_back(i);
}
}
break;
case CMDPAL_TYPE_ADD_CHIP:
for (int i=0; availableSystems[i]; i++) {
int ds=availableSystems[i];
const char* sysname=getSystemName((DivSystem)ds);
if (matchFuzzy(sysname,paletteQuery.c_str())) {
paletteSearchResults.push_back(ds);
}
}
break;
default:
logE("invalid command palette type");
ImGui::CloseCurrentPopup();
@ -127,6 +139,15 @@ void FurnaceGUI::drawPalette() {
navigated=true;
}
if (paletteSearchResults.size()>0 && curPaletteChoice<0) {
curPaletteChoice=0;
navigated=true;
}
if (curPaletteChoice>=(int)paletteSearchResults.size()) {
curPaletteChoice=paletteSearchResults.size()-1;
navigated=true;
}
for (int i=0; i<(int)paletteSearchResults.size(); i++) {
bool current=(i==curPaletteChoice);
int id=paletteSearchResults[i];
@ -150,6 +171,9 @@ void FurnaceGUI::drawPalette() {
case CMDPAL_TYPE_SAMPLES:
s=e->song.sample[id]->name.c_str();
break;
case CMDPAL_TYPE_ADD_CHIP:
s=getSystemName((DivSystem)id);
break;
default:
logE("invalid command palette type");
break;
@ -203,6 +227,21 @@ void FurnaceGUI::drawPalette() {
doChangeIns(i-1);
break;
case CMDPAL_TYPE_ADD_CHIP:
if (i!=DIV_SYSTEM_NULL) {
if (!e->addSystem((DivSystem)i)) {
showError("cannot add chip! ("+e->getLastError()+")");
} else {
MARK_MODIFIED;
}
ImGui::CloseCurrentPopup();
if (e->song.autoSystem) {
autoDetectSystem();
}
updateWindowTitle();
}
break;
default:
logE("invalid command palette type");
break;

View file

@ -23,6 +23,7 @@ enum CommandPaletteType {
CMDPAL_TYPE_INSTRUMENTS,
CMDPAL_TYPE_SAMPLES,
CMDPAL_TYPE_INSTRUMENT_CHANGE,
CMDPAL_TYPE_ADD_CHIP,
// a menu to select wavetables is beyond scope (they can't be put as strings)
// TODO: are there more?

View file

@ -206,6 +206,10 @@ void FurnaceGUI::doAction(int what) {
displayPalette=true;
curPaletteType=CMDPAL_TYPE_INSTRUMENT_CHANGE;
break;
case GUI_ACTION_CMDPAL_ADD_CHIP:
displayPalette=true;
curPaletteType=CMDPAL_TYPE_ADD_CHIP;
break;
case GUI_ACTION_WINDOW_EDIT_CONTROLS:
nextWindow=GUI_WINDOW_EDIT_CONTROLS;
break;

View file

@ -520,6 +520,7 @@ enum FurnaceGUIActions {
GUI_ACTION_CMDPAL_INSTRUMENTS,
GUI_ACTION_CMDPAL_SAMPLES,
GUI_ACTION_CMDPAL_INSTRUMENT_CHANGE,
GUI_ACTION_CMDPAL_ADD_CHIP,
GUI_ACTION_CMDPAL_MAX,
GUI_ACTION_WINDOW_EDIT_CONTROLS,

View file

@ -567,6 +567,7 @@ const FurnaceGUIActionDef guiActions[GUI_ACTION_MAX]={
D("CMDPAL_INSTRUMENTS", "Instruments (Palette)", 0),
D("CMDPAL_SAMPLES", "Samples (Palette)", 0),
D("CMDPAL_INSTRUMENT_CHANGE", "Change instrument (Palette)", 0),
D("CMDPAL_ADD_CHIP", "Add chip (Palette)", 0),
D("CMDPAL_MAX", "", NOT_AN_ACTION),
D("WINDOW_EDIT_CONTROLS", "Edit Controls", 0),