GUI: implement search in "Choose a System!"
This commit is contained in:
		
							parent
							
								
									73f88c7635
								
							
						
					
					
						commit
						efd5cc0dac
					
				| 
						 | 
					@ -969,7 +969,7 @@ class FurnaceGUI {
 | 
				
			||||||
  int sampleTexW, sampleTexH;
 | 
					  int sampleTexW, sampleTexH;
 | 
				
			||||||
  bool updateSampleTex;
 | 
					  bool updateSampleTex;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  String workingDir, fileName, clipboard, warnString, errorString, lastError, curFileName, nextFile, sysSearchQuery;
 | 
					  String workingDir, fileName, clipboard, warnString, errorString, lastError, curFileName, nextFile, sysSearchQuery, newSongQuery;
 | 
				
			||||||
  String workingDirSong, workingDirIns, workingDirWave, workingDirSample, workingDirAudioExport;
 | 
					  String workingDirSong, workingDirIns, workingDirWave, workingDirSample, workingDirAudioExport;
 | 
				
			||||||
  String workingDirVGMExport, workingDirROMExport, workingDirFont, workingDirColors, workingDirKeybinds;
 | 
					  String workingDirVGMExport, workingDirROMExport, workingDirFont, workingDirColors, workingDirKeybinds;
 | 
				
			||||||
  String workingDirLayout, workingDirROM, workingDirTest;
 | 
					  String workingDirLayout, workingDirROM, workingDirTest;
 | 
				
			||||||
| 
						 | 
					@ -977,6 +977,7 @@ class FurnaceGUI {
 | 
				
			||||||
  String mmlStringW;
 | 
					  String mmlStringW;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  std::vector<DivSystem> sysSearchResults;
 | 
					  std::vector<DivSystem> sysSearchResults;
 | 
				
			||||||
 | 
					  std::vector<FurnaceGUISysDef> newSongSearchResults;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  bool quit, warnQuit, willCommit, edit, modified, displayError, displayExporting, vgmExportLoop, vgmExportPatternHints;
 | 
					  bool quit, warnQuit, willCommit, edit, modified, displayError, displayExporting, vgmExportLoop, vgmExportPatternHints;
 | 
				
			||||||
  bool wantCaptureKeyboard, oldWantCaptureKeyboard, displayMacroMenu;
 | 
					  bool wantCaptureKeyboard, oldWantCaptureKeyboard, displayMacroMenu;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -18,7 +18,8 @@
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "gui.h"
 | 
					#include "gui.h"
 | 
				
			||||||
#include <imgui.h>
 | 
					#include "misc/cpp/imgui_stdlib.h"
 | 
				
			||||||
 | 
					#include <algorithm>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void FurnaceGUI::drawNewSong() {
 | 
					void FurnaceGUI::drawNewSong() {
 | 
				
			||||||
  bool accepted=false;
 | 
					  bool accepted=false;
 | 
				
			||||||
| 
						 | 
					@ -32,35 +33,76 @@ void FurnaceGUI::drawNewSong() {
 | 
				
			||||||
  avail.y-=ImGui::GetFrameHeightWithSpacing();
 | 
					  avail.y-=ImGui::GetFrameHeightWithSpacing();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (ImGui::BeginChild("sysPickerC",avail,false,ImGuiWindowFlags_NoScrollWithMouse|ImGuiWindowFlags_NoScrollbar)) {
 | 
					  if (ImGui::BeginChild("sysPickerC",avail,false,ImGuiWindowFlags_NoScrollWithMouse|ImGuiWindowFlags_NoScrollbar)) {
 | 
				
			||||||
    if (ImGui::BeginTable("sysPicker",2,ImGuiTableFlags_BordersInnerV)) {
 | 
					    ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
 | 
				
			||||||
      ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthFixed,0.0f);
 | 
					    if (ImGui::InputTextWithHint("##SysSearch","Search...",&newSongQuery)) {
 | 
				
			||||||
 | 
					      String lowerCase=newSongQuery;
 | 
				
			||||||
 | 
					      for (char& i: lowerCase) {
 | 
				
			||||||
 | 
					        if (i>='A' && i<='Z') i+='a'-'A';
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      auto lastItem=std::remove_if(lowerCase.begin(),lowerCase.end(),[](char c) {
 | 
				
			||||||
 | 
					        return (c==' ' || c=='_' || c=='-');
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					      lowerCase.erase(lastItem,lowerCase.end());
 | 
				
			||||||
 | 
					      newSongSearchResults.clear();
 | 
				
			||||||
 | 
					      for (FurnaceGUISysCategory& i: sysCategories) {
 | 
				
			||||||
 | 
					        for (FurnaceGUISysDef& j: i.systems) {
 | 
				
			||||||
 | 
					          String lowerCase1=j.name;
 | 
				
			||||||
 | 
					          for (char& i: lowerCase1) {
 | 
				
			||||||
 | 
					            if (i>='A' && i<='Z') i+='a'-'A';
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					          auto lastItem=std::remove_if(lowerCase1.begin(),lowerCase1.end(),[](char c) {
 | 
				
			||||||
 | 
					            return (c==' ' || c=='_' || c=='-');
 | 
				
			||||||
 | 
					          });
 | 
				
			||||||
 | 
					          lowerCase1.erase(lastItem,lowerCase1.end());
 | 
				
			||||||
 | 
					          if (lowerCase1.find(lowerCase)!=String::npos) {
 | 
				
			||||||
 | 
					            newSongSearchResults.push_back(j);
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        std::sort(newSongSearchResults.begin(),newSongSearchResults.end(),[](const FurnaceGUISysDef& a, const FurnaceGUISysDef& b) {
 | 
				
			||||||
 | 
					          return strcmp(a.name,b.name)<0;
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					        auto lastItem=std::unique(newSongSearchResults.begin(),newSongSearchResults.end(),[](const FurnaceGUISysDef& a, const FurnaceGUISysDef& b) {
 | 
				
			||||||
 | 
					          return strcmp(a.name,b.name)==0;
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					        newSongSearchResults.erase(lastItem,newSongSearchResults.end());
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if (ImGui::BeginTable("sysPicker",newSongQuery.empty()?2:1,ImGuiTableFlags_BordersInnerV)) {
 | 
				
			||||||
 | 
					      if (newSongQuery.empty()) {
 | 
				
			||||||
 | 
					        ImGui::TableSetupColumn("c0",ImGuiTableColumnFlags_WidthFixed,0.0f);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
      ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthStretch,0.0f);
 | 
					      ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthStretch,0.0f);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      ImGui::TableNextRow(ImGuiTableRowFlags_Headers);
 | 
					      if (newSongQuery.empty()) {
 | 
				
			||||||
      ImGui::TableNextColumn();
 | 
					        ImGui::TableNextRow(ImGuiTableRowFlags_Headers);
 | 
				
			||||||
      ImGui::Text("Categories");
 | 
					        ImGui::TableNextColumn();
 | 
				
			||||||
      ImGui::TableNextColumn();
 | 
					        ImGui::Text("Categories");
 | 
				
			||||||
      ImGui::Text("Systems");
 | 
					        ImGui::TableNextColumn();
 | 
				
			||||||
 | 
					        ImGui::Text("Systems");
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      ImGui::TableNextRow();
 | 
					      ImGui::TableNextRow();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // CATEGORIES
 | 
					      // CATEGORIES
 | 
				
			||||||
      ImGui::TableNextColumn();
 | 
					      if (newSongQuery.empty()) {
 | 
				
			||||||
      int index=0;
 | 
					        ImGui::TableNextColumn();
 | 
				
			||||||
      for (FurnaceGUISysCategory& i: sysCategories) {
 | 
					        int index=0;
 | 
				
			||||||
        if (ImGui::Selectable(i.name,newSongCategory==index,ImGuiSelectableFlags_DontClosePopups)) { \
 | 
					        for (FurnaceGUISysCategory& i: sysCategories) {
 | 
				
			||||||
          newSongCategory=index;
 | 
					          if (ImGui::Selectable(i.name,newSongCategory==index,ImGuiSelectableFlags_DontClosePopups)) { \
 | 
				
			||||||
 | 
					            newSongCategory=index;
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					          if (ImGui::IsItemHovered()) {
 | 
				
			||||||
 | 
					            ImGui::SetTooltip("%s",i.description);
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					          index++;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if (ImGui::IsItemHovered()) {
 | 
					 | 
				
			||||||
          ImGui::SetTooltip("%s",i.description);
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        index++;
 | 
					 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // SYSTEMS
 | 
					      // SYSTEMS
 | 
				
			||||||
      ImGui::TableNextColumn();
 | 
					      ImGui::TableNextColumn();
 | 
				
			||||||
      if (ImGui::BeginTable("Systems",1,ImGuiTableFlags_BordersInnerV|ImGuiTableFlags_ScrollY)) {
 | 
					      if (ImGui::BeginTable("Systems",1,ImGuiTableFlags_BordersInnerV|ImGuiTableFlags_ScrollY)) {
 | 
				
			||||||
        for (FurnaceGUISysDef& i: sysCategories[newSongCategory].systems) {
 | 
					        std::vector<FurnaceGUISysDef>& category=(newSongQuery.empty())?(sysCategories[newSongCategory].systems):(newSongSearchResults);
 | 
				
			||||||
 | 
					        for (FurnaceGUISysDef& i: category) {
 | 
				
			||||||
          ImGui::TableNextRow();
 | 
					          ImGui::TableNextRow();
 | 
				
			||||||
          ImGui::TableNextColumn();
 | 
					          ImGui::TableNextColumn();
 | 
				
			||||||
          if (ImGui::Selectable(i.name,false,ImGuiSelectableFlags_DontClosePopups)) {
 | 
					          if (ImGui::Selectable(i.name,false,ImGuiSelectableFlags_DontClosePopups)) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue