2022-03-21 22:34:43 +00:00
|
|
|
/**
|
|
|
|
* Furnace Tracker - multi-system chiptune tracker
|
2023-01-20 00:18:40 +00:00
|
|
|
* Copyright (C) 2021-2023 tildearrow and contributors
|
2022-03-21 22:34:43 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gui.h"
|
2022-08-27 05:14:17 +00:00
|
|
|
#include "misc/cpp/imgui_stdlib.h"
|
2022-09-30 05:26:54 +00:00
|
|
|
#include <fmt/printf.h>
|
2022-08-27 05:14:17 +00:00
|
|
|
#include <algorithm>
|
2022-03-21 22:34:43 +00:00
|
|
|
|
|
|
|
void FurnaceGUI::drawNewSong() {
|
|
|
|
bool accepted=false;
|
|
|
|
|
|
|
|
ImGui::PushFont(bigFont);
|
|
|
|
ImGui::SetCursorPosX((ImGui::GetContentRegionAvail().x-ImGui::CalcTextSize("Choose a System!").x)*0.5);
|
|
|
|
ImGui::Text("Choose a System!");
|
|
|
|
ImGui::PopFont();
|
|
|
|
|
2022-05-14 09:05:29 +00:00
|
|
|
ImVec2 avail=ImGui::GetContentRegionAvail();
|
|
|
|
avail.y-=ImGui::GetFrameHeightWithSpacing();
|
2022-03-21 22:34:43 +00:00
|
|
|
|
2022-05-14 09:05:29 +00:00
|
|
|
if (ImGui::BeginChild("sysPickerC",avail,false,ImGuiWindowFlags_NoScrollWithMouse|ImGuiWindowFlags_NoScrollbar)) {
|
2023-04-03 14:11:26 +00:00
|
|
|
if (newSongFirstFrame)
|
2023-04-03 03:05:25 +00:00
|
|
|
ImGui::SetKeyboardFocusHere();
|
2022-08-27 05:14:17 +00:00
|
|
|
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
|
|
|
|
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);
|
|
|
|
}
|
2022-05-14 09:05:29 +00:00
|
|
|
ImGui::TableSetupColumn("c1",ImGuiTableColumnFlags_WidthStretch,0.0f);
|
2022-03-21 22:34:43 +00:00
|
|
|
|
2022-08-27 05:14:17 +00:00
|
|
|
if (newSongQuery.empty()) {
|
|
|
|
ImGui::TableNextRow(ImGuiTableRowFlags_Headers);
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
ImGui::Text("Categories");
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
ImGui::Text("Systems");
|
|
|
|
}
|
2022-03-21 22:34:43 +00:00
|
|
|
|
2022-05-14 09:05:29 +00:00
|
|
|
ImGui::TableNextRow();
|
|
|
|
|
|
|
|
// CATEGORIES
|
2022-08-27 05:14:17 +00:00
|
|
|
if (newSongQuery.empty()) {
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
int index=0;
|
|
|
|
for (FurnaceGUISysCategory& i: sysCategories) {
|
|
|
|
if (ImGui::Selectable(i.name,newSongCategory==index,ImGuiSelectableFlags_DontClosePopups)) { \
|
|
|
|
newSongCategory=index;
|
|
|
|
}
|
|
|
|
if (ImGui::IsItemHovered()) {
|
|
|
|
ImGui::SetTooltip("%s",i.description);
|
|
|
|
}
|
|
|
|
index++;
|
2022-05-14 09:05:29 +00:00
|
|
|
}
|
2022-03-21 22:34:43 +00:00
|
|
|
}
|
|
|
|
|
2022-05-14 09:05:29 +00:00
|
|
|
// SYSTEMS
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
if (ImGui::BeginTable("Systems",1,ImGuiTableFlags_BordersInnerV|ImGuiTableFlags_ScrollY)) {
|
2022-08-27 05:14:17 +00:00
|
|
|
std::vector<FurnaceGUISysDef>& category=(newSongQuery.empty())?(sysCategories[newSongCategory].systems):(newSongSearchResults);
|
|
|
|
for (FurnaceGUISysDef& i: category) {
|
2022-05-14 09:05:29 +00:00
|
|
|
ImGui::TableNextRow();
|
|
|
|
ImGui::TableNextColumn();
|
|
|
|
if (ImGui::Selectable(i.name,false,ImGuiSelectableFlags_DontClosePopups)) {
|
2022-11-13 20:41:40 +00:00
|
|
|
nextDesc=i.definition;
|
2022-07-23 22:02:03 +00:00
|
|
|
nextDescName=i.name;
|
2022-05-14 09:05:29 +00:00
|
|
|
accepted=true;
|
|
|
|
}
|
2023-07-15 23:23:52 +00:00
|
|
|
if (ImGui::IsItemHovered()) {
|
|
|
|
if (ImGui::BeginTooltip()) {
|
2023-07-15 23:49:28 +00:00
|
|
|
std::map<DivSystem,int> chipCounts;
|
2023-07-15 23:23:52 +00:00
|
|
|
std::vector<DivSystem> chips;
|
|
|
|
for (FurnaceGUISysDefChip chip: i.orig) {
|
2023-07-15 23:49:28 +00:00
|
|
|
if (chipCounts.find(chip.sys)==chipCounts.end()) {
|
|
|
|
chipCounts[chip.sys]=1;
|
2023-07-15 23:23:52 +00:00
|
|
|
chips.push_back(chip.sys);
|
2023-07-15 23:49:28 +00:00
|
|
|
} else {
|
|
|
|
chipCounts[chip.sys]+=1;
|
2023-07-15 23:23:52 +00:00
|
|
|
}
|
|
|
|
}
|
2023-07-15 23:49:28 +00:00
|
|
|
for (size_t chipIndex=0; chipIndex<chips.size(); chipIndex++) {
|
|
|
|
DivSystem chip=chips[chipIndex];
|
|
|
|
const DivSysDef* sysDef=e->getSystemDef(chip);
|
2023-07-18 20:07:48 +00:00
|
|
|
ImGui::PushTextWrapPos(MIN(scrW*dpiScale,400.0f*dpiScale));
|
2023-07-15 23:49:28 +00:00
|
|
|
ImGui::Text("%s (x%d): ",sysDef->name,chipCounts[chip]);
|
2023-07-18 20:07:48 +00:00
|
|
|
ImGui::Text("%s",sysDef->description);
|
|
|
|
ImGui::PopTextWrapPos();
|
2023-07-15 23:49:28 +00:00
|
|
|
if (chipIndex+1<chips.size()) {
|
2023-07-15 23:23:52 +00:00
|
|
|
ImGui::Separator();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::EndTooltip();
|
|
|
|
}
|
|
|
|
}
|
2022-03-21 22:34:43 +00:00
|
|
|
}
|
2023-07-15 23:23:52 +00:00
|
|
|
|
2022-05-14 09:05:29 +00:00
|
|
|
ImGui::EndTable();
|
2022-03-21 22:34:43 +00:00
|
|
|
}
|
2022-05-14 09:05:29 +00:00
|
|
|
|
2022-03-21 22:34:43 +00:00
|
|
|
ImGui::EndTable();
|
|
|
|
}
|
|
|
|
}
|
2022-05-14 09:05:29 +00:00
|
|
|
ImGui::EndChild();
|
2022-03-21 22:34:43 +00:00
|
|
|
|
2022-04-29 09:42:18 +00:00
|
|
|
if (ImGui::Button("I'm feeling lucky")) {
|
|
|
|
if (sysCategories.size()==0) {
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
} else {
|
|
|
|
FurnaceGUISysCategory* newSystemCat=&sysCategories[rand()%sysCategories.size()];
|
|
|
|
if (newSystemCat->systems.size()==0) {
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
} else {
|
2022-10-31 02:57:52 +00:00
|
|
|
unsigned int selection=rand()%newSystemCat->systems.size();
|
2022-11-13 20:41:40 +00:00
|
|
|
nextDesc=newSystemCat->systems[selection].definition;
|
2022-10-31 02:57:52 +00:00
|
|
|
nextDescName=newSystemCat->systems[selection].name;
|
2022-04-29 09:42:18 +00:00
|
|
|
accepted=true;
|
|
|
|
}
|
|
|
|
}
|
2022-03-21 22:34:43 +00:00
|
|
|
}
|
|
|
|
|
2022-04-29 08:54:10 +00:00
|
|
|
ImGui::SameLine();
|
|
|
|
|
2023-07-04 01:32:54 +00:00
|
|
|
if (ImGui::Button("Cancel") || ImGui::IsKeyPressed(ImGuiKey_Escape)) {
|
2022-04-29 09:42:18 +00:00
|
|
|
ImGui::CloseCurrentPopup();
|
2022-04-29 08:54:10 +00:00
|
|
|
}
|
|
|
|
|
2022-03-21 22:34:43 +00:00
|
|
|
if (accepted) {
|
2022-11-13 21:57:47 +00:00
|
|
|
e->createNew(nextDesc.c_str(),nextDescName,false);
|
2022-03-21 22:34:43 +00:00
|
|
|
undoHist.clear();
|
|
|
|
redoHist.clear();
|
|
|
|
curFileName="";
|
|
|
|
modified=false;
|
|
|
|
curNibble=false;
|
|
|
|
orderNibble=false;
|
|
|
|
orderCursor=-1;
|
|
|
|
samplePos=0;
|
|
|
|
updateSampleTex=true;
|
|
|
|
selStart=SelectionPoint();
|
|
|
|
selEnd=SelectionPoint();
|
|
|
|
cursor=SelectionPoint();
|
|
|
|
updateWindowTitle();
|
|
|
|
ImGui::CloseCurrentPopup();
|
|
|
|
}
|
2023-04-03 14:11:26 +00:00
|
|
|
|
|
|
|
newSongFirstFrame=false;
|
2022-04-29 09:42:18 +00:00
|
|
|
}
|