mirror of
https://github.com/tildearrow/furnace.git
synced 2024-11-02 02:52:40 +00:00
GUI: import/export colors/keybinds/layout
untested
This commit is contained in:
parent
9d653b58b3
commit
eb8f99dafe
3 changed files with 357 additions and 3 deletions
102
src/gui/gui.cpp
102
src/gui/gui.cpp
|
@ -1442,6 +1442,66 @@ void FurnaceGUI::openFileDialog(FurnaceGUIFileDialogs type) {
|
|||
dpiScale
|
||||
);
|
||||
break;
|
||||
case GUI_FILE_IMPORT_COLORS:
|
||||
if (!dirExists(workingDirColors)) workingDirColors=getHomeDir();
|
||||
hasOpened=fileDialog->openLoad(
|
||||
"Select Color File",
|
||||
{"configuration files", "*.cfg"},
|
||||
"configuration files{.cfg}",
|
||||
workingDirColors,
|
||||
dpiScale
|
||||
);
|
||||
break;
|
||||
case GUI_FILE_IMPORT_KEYBINDS:
|
||||
if (!dirExists(workingDirKeybinds)) workingDirKeybinds=getHomeDir();
|
||||
hasOpened=fileDialog->openLoad(
|
||||
"Select Keybind File",
|
||||
{"configuration files", "*.cfg"},
|
||||
"configuration files{.cfg}",
|
||||
workingDirKeybinds,
|
||||
dpiScale
|
||||
);
|
||||
break;
|
||||
case GUI_FILE_IMPORT_LAYOUT:
|
||||
if (!dirExists(workingDirKeybinds)) workingDirKeybinds=getHomeDir();
|
||||
hasOpened=fileDialog->openLoad(
|
||||
"Select Layout File",
|
||||
{".ini files", "*.ini"},
|
||||
".ini files{.ini}",
|
||||
workingDirKeybinds,
|
||||
dpiScale
|
||||
);
|
||||
break;
|
||||
case GUI_FILE_EXPORT_COLORS:
|
||||
if (!dirExists(workingDirColors)) workingDirColors=getHomeDir();
|
||||
hasOpened=fileDialog->openSave(
|
||||
"Export Colors",
|
||||
{"configuration files", "*.cfg"},
|
||||
"configuration files{.cfg}",
|
||||
workingDirColors,
|
||||
dpiScale
|
||||
);
|
||||
break;
|
||||
case GUI_FILE_EXPORT_KEYBINDS:
|
||||
if (!dirExists(workingDirKeybinds)) workingDirKeybinds=getHomeDir();
|
||||
hasOpened=fileDialog->openSave(
|
||||
"Export Keybinds",
|
||||
{"configuration files", "*.cfg"},
|
||||
"configuration files{.cfg}",
|
||||
workingDirKeybinds,
|
||||
dpiScale
|
||||
);
|
||||
break;
|
||||
case GUI_FILE_EXPORT_LAYOUT:
|
||||
if (!dirExists(workingDirKeybinds)) workingDirKeybinds=getHomeDir();
|
||||
hasOpened=fileDialog->openSave(
|
||||
"Export Layout",
|
||||
{".ini files", "*.ini"},
|
||||
".ini files{.ini}",
|
||||
workingDirKeybinds,
|
||||
dpiScale
|
||||
);
|
||||
break;
|
||||
}
|
||||
if (hasOpened) curFileDialog=type;
|
||||
//ImGui::GetIO().ConfigFlags|=ImGuiConfigFlags_NavEnableKeyboard;
|
||||
|
@ -2588,6 +2648,18 @@ bool FurnaceGUI::loop() {
|
|||
case GUI_FILE_LOAD_PAT_FONT:
|
||||
workingDirFont=fileDialog->getPath()+DIR_SEPARATOR_STR;
|
||||
break;
|
||||
case GUI_FILE_IMPORT_COLORS:
|
||||
case GUI_FILE_EXPORT_COLORS:
|
||||
workingDirColors=fileDialog->getPath()+DIR_SEPARATOR_STR;
|
||||
break;
|
||||
case GUI_FILE_IMPORT_KEYBINDS:
|
||||
case GUI_FILE_EXPORT_KEYBINDS:
|
||||
workingDirKeybinds=fileDialog->getPath()+DIR_SEPARATOR_STR;
|
||||
break;
|
||||
case GUI_FILE_IMPORT_LAYOUT:
|
||||
case GUI_FILE_EXPORT_LAYOUT:
|
||||
workingDirLayout=fileDialog->getPath()+DIR_SEPARATOR_STR;
|
||||
break;
|
||||
}
|
||||
if (fileDialog->accepted()) {
|
||||
fileName=fileDialog->getFileName();
|
||||
|
@ -2723,6 +2795,24 @@ bool FurnaceGUI::loop() {
|
|||
case GUI_FILE_LOAD_PAT_FONT:
|
||||
settings.patFontPath=copyOfName;
|
||||
break;
|
||||
case GUI_FILE_IMPORT_COLORS:
|
||||
importColors(copyOfName);
|
||||
break;
|
||||
case GUI_FILE_IMPORT_KEYBINDS:
|
||||
importKeybinds(copyOfName);
|
||||
break;
|
||||
case GUI_FILE_IMPORT_LAYOUT:
|
||||
importLayout(copyOfName);
|
||||
break;
|
||||
case GUI_FILE_EXPORT_COLORS:
|
||||
exportColors(copyOfName);
|
||||
break;
|
||||
case GUI_FILE_EXPORT_KEYBINDS:
|
||||
exportKeybinds(copyOfName);
|
||||
break;
|
||||
case GUI_FILE_EXPORT_LAYOUT:
|
||||
exportLayout(copyOfName);
|
||||
break;
|
||||
}
|
||||
curFileDialog=GUI_FILE_OPEN;
|
||||
}
|
||||
|
@ -2813,6 +2903,12 @@ bool FurnaceGUI::loop() {
|
|||
ImGui::LoadIniSettingsFromMemory(defaultLayout);
|
||||
ImGui::SaveIniSettingsToDisk(finalLayoutPath);
|
||||
break;
|
||||
case GUI_WARN_RESET_KEYBINDS:
|
||||
resetKeybinds();
|
||||
break;
|
||||
case GUI_WARN_RESET_COLORS:
|
||||
resetColors();
|
||||
break;
|
||||
case GUI_WARN_GENERIC:
|
||||
break;
|
||||
}
|
||||
|
@ -2899,6 +2995,9 @@ bool FurnaceGUI::init() {
|
|||
workingDirAudioExport=e->getConfString("lastDirAudioExport",workingDir);
|
||||
workingDirVGMExport=e->getConfString("lastDirVGMExport",workingDir);
|
||||
workingDirFont=e->getConfString("lastDirFont",workingDir);
|
||||
workingDirColors=e->getConfString("lastDirColors",workingDir);
|
||||
workingDirKeybinds=e->getConfString("lastDirKeybinds",workingDir);
|
||||
workingDirLayout=e->getConfString("lastDirLayout",workingDir);
|
||||
|
||||
editControlsOpen=e->getConfBool("editControlsOpen",true);
|
||||
ordersOpen=e->getConfBool("ordersOpen",true);
|
||||
|
@ -3057,6 +3156,9 @@ bool FurnaceGUI::finish() {
|
|||
e->setConf("lastDirAudioExport",workingDirAudioExport);
|
||||
e->setConf("lastDirVGMExport",workingDirVGMExport);
|
||||
e->setConf("lastDirFont",workingDirFont);
|
||||
e->setConf("lastDirColors",workingDirColors);
|
||||
e->setConf("lastDirKeybinds",workingDirKeybinds);
|
||||
e->setConf("lastDirLayout",workingDirLayout);
|
||||
|
||||
// commit last open windows
|
||||
e->setConf("editControlsOpen",editControlsOpen);
|
||||
|
|
|
@ -198,7 +198,13 @@ enum FurnaceGUIFileDialogs {
|
|||
GUI_FILE_EXPORT_VGM,
|
||||
GUI_FILE_EXPORT_ROM,
|
||||
GUI_FILE_LOAD_MAIN_FONT,
|
||||
GUI_FILE_LOAD_PAT_FONT
|
||||
GUI_FILE_LOAD_PAT_FONT,
|
||||
GUI_FILE_IMPORT_COLORS,
|
||||
GUI_FILE_IMPORT_KEYBINDS,
|
||||
GUI_FILE_IMPORT_LAYOUT,
|
||||
GUI_FILE_EXPORT_COLORS,
|
||||
GUI_FILE_EXPORT_KEYBINDS,
|
||||
GUI_FILE_EXPORT_LAYOUT
|
||||
};
|
||||
|
||||
enum FurnaceGUIWarnings {
|
||||
|
@ -208,6 +214,8 @@ enum FurnaceGUIWarnings {
|
|||
GUI_WARN_OPEN_BACKUP,
|
||||
GUI_WARN_OPEN_DROP,
|
||||
GUI_WARN_RESET_LAYOUT,
|
||||
GUI_WARN_RESET_COLORS,
|
||||
GUI_WARN_RESET_KEYBINDS,
|
||||
GUI_WARN_GENERIC
|
||||
};
|
||||
|
||||
|
@ -648,7 +656,7 @@ class FurnaceGUI {
|
|||
bool updateSampleTex;
|
||||
|
||||
String workingDir, fileName, clipboard, warnString, errorString, lastError, curFileName, nextFile;
|
||||
String workingDirSong, workingDirIns, workingDirWave, workingDirSample, workingDirAudioExport, workingDirVGMExport, workingDirFont;
|
||||
String workingDirSong, workingDirIns, workingDirWave, workingDirSample, workingDirAudioExport, workingDirVGMExport, workingDirFont, workingDirColors, workingDirKeybinds, workingDirLayout;
|
||||
String mmlString[13];
|
||||
String mmlStringW;
|
||||
|
||||
|
@ -1015,6 +1023,16 @@ class FurnaceGUI {
|
|||
void promptKey(int which);
|
||||
void doAction(int what);
|
||||
|
||||
bool importColors(String path);
|
||||
bool exportColors(String path);
|
||||
bool importKeybinds(String path);
|
||||
bool exportKeybinds(String path);
|
||||
bool importLayout(String path);
|
||||
bool exportLayout(String path);
|
||||
|
||||
void resetColors();
|
||||
void resetKeybinds();
|
||||
|
||||
void syncSettings();
|
||||
void commitSettings();
|
||||
void processDrags(int dragX, int dragY);
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "gui.h"
|
||||
#include "fonts.h"
|
||||
#include "../ta-log.h"
|
||||
#include "../fileutils.h"
|
||||
#include "util.h"
|
||||
#include "guiConst.h"
|
||||
#include "ImGuiFileDialog.h"
|
||||
|
@ -870,6 +871,17 @@ void FurnaceGUI::drawSettings() {
|
|||
ImGui::Separator();
|
||||
|
||||
if (ImGui::TreeNode("Color scheme")) {
|
||||
if (ImGui::Button("Import")) {
|
||||
openFileDialog(GUI_FILE_IMPORT_COLORS);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Export")) {
|
||||
openFileDialog(GUI_FILE_EXPORT_COLORS);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Reset defaults")) {
|
||||
showWarning("Are you sure you want to reset the color scheme?",GUI_WARN_RESET_COLORS);
|
||||
}
|
||||
if (ImGui::TreeNode("General")) {
|
||||
ImGui::Text("Color scheme type:");
|
||||
if (ImGui::RadioButton("Dark##gcb0",settings.guiColorsBase==0)) {
|
||||
|
@ -1005,6 +1017,17 @@ void FurnaceGUI::drawSettings() {
|
|||
ImGui::EndTabItem();
|
||||
}
|
||||
if (ImGui::BeginTabItem("Keyboard")) {
|
||||
if (ImGui::Button("Import")) {
|
||||
openFileDialog(GUI_FILE_IMPORT_KEYBINDS);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Export")) {
|
||||
openFileDialog(GUI_FILE_EXPORT_KEYBINDS);
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Reset defaults")) {
|
||||
showWarning("Are you sure you want to reset the keyboard settings?",GUI_WARN_RESET_KEYBINDS);
|
||||
}
|
||||
if (ImGui::TreeNode("Global hotkeys")) {
|
||||
KEYBIND_CONFIG_BEGIN("keysGlobal");
|
||||
|
||||
|
@ -1537,7 +1560,7 @@ void FurnaceGUI::commitSettings() {
|
|||
|
||||
// colors
|
||||
for (int i=0; i<GUI_COLOR_MAX; i++) {
|
||||
e->setConf(guiColors[i].name,(int)ImGui::GetColorU32(uiColors[i]));
|
||||
e->setConf(guiColors[i].name,(int)ImGui::ColorConvertFloat4ToU32(uiColors[i]));
|
||||
}
|
||||
|
||||
// keybinds
|
||||
|
@ -1577,6 +1600,217 @@ void FurnaceGUI::commitSettings() {
|
|||
}
|
||||
}
|
||||
|
||||
bool FurnaceGUI::importColors(String path) {
|
||||
FILE* f=ps_fopen(path.c_str(),"rb");
|
||||
if (f==NULL) {
|
||||
logW("error while opening color file for import: %s\n",strerror(errno));
|
||||
return false;
|
||||
}
|
||||
resetColors();
|
||||
char line[4096];
|
||||
while (!feof(f)) {
|
||||
String key="";
|
||||
String value="";
|
||||
bool keyOrValue=false;
|
||||
if (fgets(line,4095,f)==NULL) {
|
||||
break;
|
||||
}
|
||||
for (char* i=line; *i; i++) {
|
||||
if (*i=='\n') continue;
|
||||
if (keyOrValue) {
|
||||
value+=*i;
|
||||
} else {
|
||||
if (*i=='=') {
|
||||
keyOrValue=true;
|
||||
} else {
|
||||
key+=*i;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (keyOrValue) {
|
||||
// unoptimal
|
||||
const char* cs=key.c_str();
|
||||
bool found=false;
|
||||
for (int i=0; i<GUI_COLOR_MAX; i++) {
|
||||
try {
|
||||
if (strcmp(cs,guiColors[i].name)==0) {
|
||||
uiColors[i]=ImGui::ColorConvertU32ToFloat4(std::stoi(value));
|
||||
found=true;
|
||||
break;
|
||||
}
|
||||
} catch (std::out_of_range& e) {
|
||||
break;
|
||||
} catch (std::invalid_argument& e) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) logW("line invalid: %s\n",line);
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FurnaceGUI::exportColors(String path) {
|
||||
FILE* f=ps_fopen(path.c_str(),"wb");
|
||||
if (f==NULL) {
|
||||
logW("error while opening color file for export: %s\n",strerror(errno));
|
||||
return false;
|
||||
}
|
||||
for (int i=0; i<GUI_COLOR_MAX; i++) {
|
||||
if (fprintf(f,"%s=%d\n",guiColors[i].name,ImGui::ColorConvertFloat4ToU32(uiColors[i]))<0) {
|
||||
logW("error while exporting colors: %s\n",strerror(errno));
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FurnaceGUI::importKeybinds(String path) {
|
||||
FILE* f=ps_fopen(path.c_str(),"rb");
|
||||
if (f==NULL) {
|
||||
logW("error while opening keybind file for import: %s\n",strerror(errno));
|
||||
return false;
|
||||
}
|
||||
resetKeybinds();
|
||||
char line[4096];
|
||||
while (!feof(f)) {
|
||||
String key="";
|
||||
String value="";
|
||||
bool keyOrValue=false;
|
||||
if (fgets(line,4095,f)==NULL) {
|
||||
break;
|
||||
}
|
||||
for (char* i=line; *i; i++) {
|
||||
if (*i=='\n') continue;
|
||||
if (keyOrValue) {
|
||||
value+=*i;
|
||||
} else {
|
||||
if (*i=='=') {
|
||||
keyOrValue=true;
|
||||
} else {
|
||||
key+=*i;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (keyOrValue) {
|
||||
// unoptimal
|
||||
const char* cs=key.c_str();
|
||||
bool found=false;
|
||||
for (int i=0; i<GUI_ACTION_MAX; i++) {
|
||||
try {
|
||||
if (strcmp(cs,guiActions[i].name)==0) {
|
||||
actionKeys[i]=std::stoi(value);
|
||||
found=true;
|
||||
break;
|
||||
}
|
||||
} catch (std::out_of_range& e) {
|
||||
break;
|
||||
} catch (std::invalid_argument& e) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) logW("line invalid: %s\n",line);
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FurnaceGUI::exportKeybinds(String path) {
|
||||
FILE* f=ps_fopen(path.c_str(),"wb");
|
||||
if (f==NULL) {
|
||||
logW("error while opening keybind file for export: %s\n",strerror(errno));
|
||||
return false;
|
||||
}
|
||||
for (int i=0; i<GUI_ACTION_MAX; i++) {
|
||||
if (guiActions[i].defaultBind==-1) continue;
|
||||
if (fprintf(f,"%s=%d\n",guiActions[i].name,actionKeys[i])<0) {
|
||||
logW("error while exporting keybinds: %s\n",strerror(errno));
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FurnaceGUI::importLayout(String path) {
|
||||
FILE* f=ps_fopen(path.c_str(),"rb");
|
||||
if (f==NULL) {
|
||||
logW("error while opening keybind file for import: %s\n",strerror(errno));
|
||||
return false;
|
||||
}
|
||||
if (fseek(f,0,SEEK_END)<0) {
|
||||
fclose(f);
|
||||
return false;
|
||||
}
|
||||
ssize_t len=ftell(f);
|
||||
if (len==(SIZE_MAX>>1)) {
|
||||
fclose(f);
|
||||
return false;
|
||||
}
|
||||
if (len<1) {
|
||||
if (len==0) {
|
||||
logE("that file is empty!\n");
|
||||
lastError="file is empty";
|
||||
} else {
|
||||
perror("tell error");
|
||||
}
|
||||
fclose(f);
|
||||
return false;
|
||||
}
|
||||
unsigned char* file=new unsigned char[len];
|
||||
if (fseek(f,0,SEEK_SET)<0) {
|
||||
perror("size error");
|
||||
lastError=fmt::sprintf("on get size: %s",strerror(errno));
|
||||
fclose(f);
|
||||
delete[] file;
|
||||
return false;
|
||||
}
|
||||
if (fread(file,1,(size_t)len,f)!=(size_t)len) {
|
||||
perror("read error");
|
||||
lastError=fmt::sprintf("on read: %s",strerror(errno));
|
||||
fclose(f);
|
||||
delete[] file;
|
||||
return false;
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
ImGui::LoadIniSettingsFromMemory((const char*)file,len);
|
||||
delete[] file;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FurnaceGUI::exportLayout(String path) {
|
||||
FILE* f=ps_fopen(path.c_str(),"wb");
|
||||
if (f==NULL) {
|
||||
logW("error while opening layout file for export: %s\n",strerror(errno));
|
||||
return false;
|
||||
}
|
||||
size_t dataSize=0;
|
||||
const char* data=ImGui::SaveIniSettingsToMemory(&dataSize);
|
||||
if (fwrite(data,1,dataSize,f)!=dataSize) {
|
||||
logW("error while exporting layout: %s\n",strerror(errno));
|
||||
}
|
||||
fclose(f);
|
||||
return true;
|
||||
}
|
||||
|
||||
void FurnaceGUI::resetColors() {
|
||||
for (int i=0; i<GUI_COLOR_MAX; i++) {
|
||||
uiColors[i]=ImGui::ColorConvertU32ToFloat4(guiColors[i].defaultColor);
|
||||
}
|
||||
}
|
||||
|
||||
void FurnaceGUI::resetKeybinds() {
|
||||
for (int i=0; i<GUI_COLOR_MAX; i++) {
|
||||
if (guiActions[i].defaultBind==-1) continue;
|
||||
actionKeys[i]=guiActions[i].defaultBind;
|
||||
}
|
||||
parseKeybinds();
|
||||
}
|
||||
|
||||
void FurnaceGUI::parseKeybinds() {
|
||||
actionMapGlobal.clear();
|
||||
actionMapPat.clear();
|
||||
|
|
Loading…
Reference in a new issue