Functional save/load

This commit is contained in:
y4my4my4m 2021-11-09 01:03:37 -05:00
parent 85801e2b87
commit febf6bfae4
6 changed files with 75 additions and 52 deletions
src
Home/PaletteEditor
System/Gr

View file

@ -139,7 +139,7 @@ U0 DrawCtrlSlider(CDC *dc,CCtrl *c)
// buttons
//I64 l1 = StrLen("LOAD");
//I64 l1 = StrLen("LOAD");
//GrPrint(dc, 100,30,"$$CM+CX,%d,4$$$$BT,\"%s\",LE=%d$$\n", -l1 / 2, "LOAD", 1);
//DocPrint(dc, "$$CM+CX,%d,4$$$$BT,\"%s\",LE=%d$$\n", -l1 / 2, "LOAD", 1);
@ -148,42 +148,63 @@ U0 DrawCtrlSlider(CDC *dc,CCtrl *c)
}
U0 PELoad(Bool prompt)
{
// "TODO: Load A Palette\n";
U8 file = PopUpPickFile("::/Home/PaletteEditor/Palettes");
"file:%s\n",file;
// #include file;
U8 file_path = PopUpPickFile("::/Home/PaletteEditor/Palettes");
//"%s",file;
// gr_palette = "gr_palette_%s",file;
// PaletteSetTemp;
//FileExtRemove(file_path);
//StrLastRemove(file_path, "/", file_name);
//StrFirstRemove(file_name+1, StrLen(file_name), without_first_ch);
//ToUpper(*upper_case);
U8 file = FileRead(file_path);
I64 temp_file;
I64 i;
// StrPrintHex might be better?..
for (i = 0; i < COLORS_NUM; i++)
{
StrFirstRemove(file,",", temp_file);
gr_palette[i] = Str2I64(temp_file,16);
}
LFBFlush;
// PaletteSetTemp;
}
U0 PESave(Bool prompt)
U0 PESave(Bool prompt, CCtrl *c)
{
//U8 old_draw_it = Fs->draw_it;
//U8 old_draw_it = c->draw_it;
CDoc *doc = DocNew;
I64 i;
U8 tmp_name= doc->filename.name;
U8 name;
//StrLastRemove(tmp_name,".", name);
//StrFirstRemove(tmp_name,"/", name);
// U8 tmp_name= doc->filename.name;
// I64 file_name;
// FileExtRemove(tmp_name);
// StrLastRemove(tmp_name, "/", file_name);
DocPrint(doc, "public CBGR24 gr_palette_%s[COLORS_NUM] = {\n ", name);
// DocPrint(doc, "public CBGR24 gr_palette_%s[COLORS_NUM] = {\n ", file_name);
for (i = 0; i < 16; i++)
for (i = 0; i < COLORS_NUM; i++)
{
if (i == 15) DocPrint(doc, "0x%X", gr_palette[i]);
if (i == COLORS_NUM-1) DocPrint(doc, "0x%X", gr_palette[i]);
else DocPrint(doc, "0x%X, ", gr_palette[i]);
if (i == 7) {
DocPrint(doc, "\n ");
}
// if (i == 7) {
// DocPrint(doc, "\n ");
// }
}
DocPrint(doc,"\n};
\n\npublic U0 PaletteSet%s(Bool persistent=TRUE)\n{\n\tGrPaletteSet(gr_palette_%s);\n\tLFBFlush;\n\tif (persistent)\n\t\tfp_set_std_palette = &PaletteSet%s\n}",name,name,name);
// StrCopy
// StrFirstRemove(file_name+1, StrLen(file_name));
// DocPrint(doc,"\n};
// \n\npublic U0 PaletteSet%s(Bool persistent=TRUE)\n{\n\tGrPaletteSet(gr_palette_%s);\n\tLFBFlush;\n\tif (persistent)\n\t\tfp_set_std_palette = &PaletteSet%s\n}",
// file_name,file_name,file_name);
// TODO: supposed to make draw_it null and put it back to blank the window when saving...
DocWrite(doc, prompt);
DocDel(doc);
}
@ -321,12 +342,13 @@ public U0 PaletteEditor()
original_right = c->win_task->win_right;
original_top = c->win_task->win_top;
original_bottom = c->win_task->win_bottom;
//PopUp(c);
// PopUp(c);
// windowed
c->win_task->win_left = (GR_WIDTH/20);
c->win_task->win_right = (GR_WIDTH/14);
// c->win_task->win_right = c->win_task->win_width - 85;
// c->win_task->win_right = c->win_task->win_width - 85;
c->win_task->win_top = 20;
c->win_task->win_bottom = GR_HEIGHT/14;//c->win_task->win_height;
@ -364,9 +386,9 @@ public U0 PaletteEditor()
case 'r': SelectColor(15,c);break;
//case 's': PalettePrint; break;
case CH_CTRLO: PELoad(TRUE);break;
case CH_CTRLA: PESave(TRUE);break;
case CH_CTRLA: PESave(TRUE,c);break;
//case CH_CTRLT: LFBFlush; break;
case CH_ESC:
case CH_ESC: // should make it keep palette on ESC and discard on SHIFT_ESC
case CH_SHIFT_ESC:
LFBFlush;
DocClear;

View file

@ -1,12 +1 @@
public CBGR24 gr_palette_green[COLORS_NUM] = {
0xEEFCD7, 0x79824F, 0x336019, 0x297582, 0xB34F4B, 0x8F49, 0xA24D1B, 0x444444,
0x6D6D6D, 0x94BFDE, 0xA1CE97, 0x6DB4BE, 0xE88E88, 0xCA94E8, 0xD4B475, 0x142223
};
public U0 PaletteSetGreen(Bool persistent=TRUE)
{
GrPaletteSet(gr_palette_green);
LFBFlush;
if (persistent)
fp_set_std_palette = &PaletteSetGreen;
}
0xEEFCD7, 0x79824F, 0x336019, 0x297582, 0xB34F4B, 0x8F49, 0xA24D1B, 0x444444, 0x6D6D6D, 0x94BFDE, 0xA1CE97, 0x6DB4BE, 0xE88E88, 0xCA94E8, 0xD4B475, 0x142223

View file

@ -1,12 +1,2 @@
public CBGR24 gr_palette_marine[COLORS_NUM] = {
0xE2E8EB, 0x5BD2D4, 0x47515D, 0xB46D29, 0xB34F4B, 0xCB711F, 0xFFEF2F, 0x3D272F,
0xA161C, 0xE24594, 0xA1CE97, 0x6DB4BE, 0xFF575B, 0xB1AA9E, 0xD4B475, 0xE2331
};
public U0 PaletteSetMarine(Bool persistent=TRUE)
{
GrPaletteSet(gr_palette_marine);
LFBFlush;
if (persistent)
fp_set_std_palette = &PaletteSetMarine;
}
0xE2E8EB, 0x5BD2D4, 0x47515D, 0xB46D29, 0xB34F4B, 0xCB711F, 0xFFEF2F, 0x3D272F, 0xA161C, 0xE24594, 0xA1CE97, 0x6DB4BE, 0xFF575B, 0xB1AA9E, 0xD4B475, 0xE2331


View file

@ -0,0 +1 @@
0xE3E3E3, 0x4F84A6, 0x73A255, 0x297582, 0xB34F4B, 0x8A52C3, 0xB7822F, 0x444444,0x6D6D6D, 0x94BFDE, 0xA1CE97, 0x6DB4BE, 0xE88E88, 0xCA94E8, 0xD4B475, 0x1F1F1F

View file

@ -1,2 +1,2 @@
#include "Load.CC";
PaletteEditor;
#include "~/PaletteEditor/Load.CC";
PaletteEditor;

View file

@ -90,3 +90,24 @@ public U0 PaletteSetCommander(Bool persistent=TRUE)
if (persistent)
fp_set_std_palette = &PaletteSetCommander;
}
public U0 PaletteSet(U8 *palette_name="Slate", Bool persistent=TRUE)
{//Pass filename (without ext) as string to load palette
U8 *dir = "~/PaletteEditor/Palettes/";
U8 path = MStrPrint("%Q%Q%Q",dir,palette_name,".CC");
I64 temp_file, i;
U8 file = FileRead(path);
for (i = 0; i < COLORS_NUM; i++)
{
StrFirstRemove(file,",", temp_file);
gr_palette[i] = Str2I64(temp_file,16);
}
LFBFlush;
//this doesn't work yet...
// if (persistent)
// fp_set_std_palette = &PaletteSet;
}