Merge pull request #52 from GabrielRavier/improveDoConfig
Improve DoConfig
This commit is contained in:
commit
5fd6d3dd60
1 changed files with 116 additions and 112 deletions
|
@ -4,25 +4,26 @@
|
||||||
* To Public License, Version 2, as published by Sam Hocevar. See
|
* To Public License, Version 2, as published by Sam Hocevar. See
|
||||||
* http://sam.zoy.org/wtfpl/COPYING for more details. */
|
* http://sam.zoy.org/wtfpl/COPYING for more details. */
|
||||||
|
|
||||||
#include <cstdio>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <cstring>
|
|
||||||
#include <fstream>
|
|
||||||
#include "FL/Fl.H"
|
#include "FL/Fl.H"
|
||||||
#include "FL/Fl_Window.H"
|
|
||||||
#include "FL/Fl_Radio_Round_Button.H"
|
|
||||||
#include "FL/Fl_Choice.H"
|
|
||||||
#include "FL/Fl_Check_Button.H"
|
#include "FL/Fl_Check_Button.H"
|
||||||
|
#include "FL/Fl_Choice.H"
|
||||||
|
#include "FL/Fl_Radio_Round_Button.H"
|
||||||
|
#include "FL/Fl_Window.H"
|
||||||
|
#include <FL/Enumerations.H>
|
||||||
#include <FL/Fl_Button.H>
|
#include <FL/Fl_Button.H>
|
||||||
#include <FL/Fl_Group.H>
|
#include <FL/Fl_Group.H>
|
||||||
#include <FL/Fl_Menu_Item.H>
|
#include <FL/Fl_Menu_Item.H>
|
||||||
#include <FL/Fl_Round_Button.H>
|
#include <FL/Fl_Round_Button.H>
|
||||||
#include <FL/Enumerations.H>
|
#include <cstdio>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
#define MAGIC "DOUKUTSU20041206"
|
#define MAGIC "DOUKUTSU20041206"
|
||||||
#define FONT "Courier New"
|
#define FONT "Courier New"
|
||||||
|
|
||||||
struct data{
|
struct data
|
||||||
|
{
|
||||||
char magic[32];
|
char magic[32];
|
||||||
char font[64];
|
char font[64];
|
||||||
unsigned char move[4];
|
unsigned char move[4];
|
||||||
|
@ -33,15 +34,17 @@ struct data{
|
||||||
unsigned char buttons[8][4];
|
unsigned char buttons[8][4];
|
||||||
};
|
};
|
||||||
|
|
||||||
class RadioRow{
|
class RadioRow
|
||||||
public:
|
{
|
||||||
RadioRow(char offset);
|
public:
|
||||||
int value();
|
RadioRow(char offset);
|
||||||
void value(int input);
|
int value();
|
||||||
private:
|
void value(int input);
|
||||||
Fl_Group *group;
|
|
||||||
Fl_Radio_Round_Button *buttons[6];
|
private:
|
||||||
Fl_Group *label;
|
Fl_Group *group;
|
||||||
|
Fl_Radio_Round_Button *buttons[6];
|
||||||
|
Fl_Group *label;
|
||||||
};
|
};
|
||||||
|
|
||||||
static char config_path[FILENAME_MAX];
|
static char config_path[FILENAME_MAX];
|
||||||
|
@ -61,30 +64,30 @@ static void LongToChars(unsigned long long_var, unsigned char *chars)
|
||||||
chars[3] = (long_var >> 24) & 0xFF;
|
chars[3] = (long_var >> 24) & 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
RadioRow::RadioRow(char offset){
|
RadioRow::RadioRow(char offset)
|
||||||
|
{
|
||||||
char *temp = new char[2];
|
char *temp = new char[2];
|
||||||
*(temp) = (char)(49+offset); //Muhahahahahahah!
|
temp[0] = '1' + offset;
|
||||||
*(temp+1) = '\0';
|
temp[1] = '\0';
|
||||||
this->group = new Fl_Group(140+offset*30, 150, 30, 180);
|
this->group = new Fl_Group(140 + offset * 30, 150, 30, 180);
|
||||||
this->group->label(temp);
|
this->group->label(temp);
|
||||||
this->group->align(FL_ALIGN_TOP_LEFT);
|
this->group->align(FL_ALIGN_TOP_LEFT);
|
||||||
for(char i=0;i<6;i++){
|
for (char i = 0; i < 6; i++)
|
||||||
this->buttons[i] = new Fl_Radio_Round_Button(140+offset*30, 150+30*i, 30, 30);
|
this->buttons[i] = new Fl_Radio_Round_Button(140 + offset * 30, 150 + 30 * i, 30, 30);
|
||||||
}
|
|
||||||
this->group->end();
|
this->group->end();
|
||||||
}
|
}
|
||||||
|
|
||||||
int RadioRow::value(){
|
int RadioRow::value()
|
||||||
|
{
|
||||||
char i;
|
char i;
|
||||||
for(i=0;i<6;i++){
|
for (i = 0; i < 6; i++)
|
||||||
if(this->buttons[i]->value()){
|
if (this->buttons[i]->value())
|
||||||
return (int)i;
|
return (int)i;
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RadioRow::value(int input){
|
void RadioRow::value(int input)
|
||||||
|
{
|
||||||
this->buttons[input]->setonly();
|
this->buttons[input]->setonly();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,73 +106,71 @@ Fl_Check_Button *joychoice;
|
||||||
Fl_Group *joystuffcontainer;
|
Fl_Group *joystuffcontainer;
|
||||||
RadioRow *joyRows[8];
|
RadioRow *joyRows[8];
|
||||||
|
|
||||||
void quit(Fl_Widget*, void*){
|
void quit(Fl_Widget *, void *)
|
||||||
|
{
|
||||||
std::exit(0);
|
std::exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void activatejoy(Fl_Widget*, void*){
|
void activatejoy(Fl_Widget *, void *)
|
||||||
if(joystuffcontainer->active()){
|
{
|
||||||
|
if (joystuffcontainer->active())
|
||||||
joystuffcontainer->deactivate();
|
joystuffcontainer->deactivate();
|
||||||
} else {
|
else
|
||||||
joystuffcontainer->activate();
|
joystuffcontainer->activate();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void read_Config(){
|
void read_Config()
|
||||||
|
{
|
||||||
std::fstream fd;
|
std::fstream fd;
|
||||||
fd.open(config_path, std::ios::in | std::ios::binary);
|
fd.open(config_path, std::ios::in | std::ios::binary);
|
||||||
fd.read((char*)&config, sizeof(config));
|
fd.read((char *)&config, sizeof(config));
|
||||||
fd.close();
|
fd.close();
|
||||||
if (CharsToLong(config.move) == 0){
|
CharsToLong(config.move) ? movegt->setonly() : movear->setonly();
|
||||||
movear->setonly();
|
CharsToLong(config.attack) ? buttonzx->setonly() : buttonxz->setonly();
|
||||||
} else {
|
CharsToLong(config.okay) ? okayattack->setonly() : okayjump->setonly();
|
||||||
movegt->setonly();
|
|
||||||
}
|
|
||||||
if (CharsToLong(config.attack) == 0){
|
|
||||||
buttonxz->setonly();
|
|
||||||
} else {
|
|
||||||
buttonzx->setonly();
|
|
||||||
}
|
|
||||||
if (CharsToLong(config.okay) == 0){
|
|
||||||
okayjump->setonly();
|
|
||||||
}else{
|
|
||||||
okayattack->setonly();
|
|
||||||
}
|
|
||||||
displaychoice->value(CharsToLong(config.display));
|
displaychoice->value(CharsToLong(config.display));
|
||||||
joychoice->value(CharsToLong(config.useJoy));
|
joychoice->value(CharsToLong(config.useJoy));
|
||||||
if( !CharsToLong(config.useJoy) ){
|
|
||||||
|
if (!CharsToLong(config.useJoy))
|
||||||
joystuffcontainer->deactivate();
|
joystuffcontainer->deactivate();
|
||||||
}
|
|
||||||
for(char i=0;i<8;i++){
|
for (char i = 0; i < 8; i++)
|
||||||
|
{
|
||||||
const unsigned long button = CharsToLong(config.buttons[i]);
|
const unsigned long button = CharsToLong(config.buttons[i]);
|
||||||
if(button<9 && button>0){
|
if (button < 6 && button > 0)
|
||||||
|
{
|
||||||
const unsigned int button_lookup[6] = {0, 1, 2, 4, 5, 3};
|
const unsigned int button_lookup[6] = {0, 1, 2, 4, 5, 3};
|
||||||
joyRows[i]->value(button_lookup[button-1]);
|
joyRows[i]->value(button_lookup[button - 1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void write_Config(Fl_Widget*, void*){
|
void write_Config(Fl_Widget *, void *)
|
||||||
|
{
|
||||||
LongToChars(movegt->value(), config.move);
|
LongToChars(movegt->value(), config.move);
|
||||||
LongToChars(buttonzx->value(), config.attack);
|
LongToChars(buttonzx->value(), config.attack);
|
||||||
LongToChars(okayattack->value(), config.okay);
|
LongToChars(okayattack->value(), config.okay);
|
||||||
|
|
||||||
LongToChars(displaychoice->value(), config.display);
|
LongToChars(displaychoice->value(), config.display);
|
||||||
LongToChars(joychoice->value(), config.useJoy);
|
LongToChars(joychoice->value(), config.useJoy);
|
||||||
for(char i =0;i<8;i++){
|
for (char i = 0; i < 8; i++)
|
||||||
|
{
|
||||||
const unsigned int button_lookup[6] = {0, 1, 2, 5, 3, 4};
|
const unsigned int button_lookup[6] = {0, 1, 2, 5, 3, 4};
|
||||||
LongToChars(button_lookup[joyRows[i]->value()]+1, config.buttons[i]);
|
LongToChars(button_lookup[joyRows[i]->value()] + 1, config.buttons[i]);
|
||||||
}
|
}
|
||||||
std::fstream fd;
|
std::fstream fd;
|
||||||
fd.open(config_path, std::ios::out | std::ios::binary);
|
fd.open(config_path, std::ios::out | std::ios::binary);
|
||||||
fd.write((char*)&config, sizeof(config));
|
fd.write((char *)&config, sizeof(config));
|
||||||
fd.close();
|
fd.close();
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
int main(int argc, char* argv[]){
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
strcpy(config_path, argv[0]);
|
strcpy(config_path, argv[0]);
|
||||||
|
|
||||||
for (size_t i = strlen(config_path); ; --i)
|
for (size_t i = strlen(config_path);; --i)
|
||||||
{
|
{
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
{
|
{
|
||||||
|
@ -187,73 +188,76 @@ int main(int argc, char* argv[]){
|
||||||
Fl_Window *mainw = new Fl_Window(400, 380, "DoConfig - Doukutsu Monogatari Settings");
|
Fl_Window *mainw = new Fl_Window(400, 380, "DoConfig - Doukutsu Monogatari Settings");
|
||||||
|
|
||||||
Fl_Group *movegroup = new Fl_Group(10, 10, 185, 50);
|
Fl_Group *movegroup = new Fl_Group(10, 10, 185, 50);
|
||||||
movegroup->box(FL_THIN_DOWN_BOX);
|
movegroup->box(FL_THIN_DOWN_BOX);
|
||||||
movear = new Fl_Radio_Round_Button(10, 10, 185, 20, "Arrows for Movement");
|
movear = new Fl_Radio_Round_Button(10, 10, 185, 20, "Arrows for Movement");
|
||||||
movear->setonly();
|
movear->setonly();
|
||||||
movegt = new Fl_Radio_Round_Button(10, 40, 185, 20, "<>? for Movement");
|
movegt = new Fl_Radio_Round_Button(10, 40, 185, 20, "<>? for Movement");
|
||||||
movegroup->end();
|
movegroup->end();
|
||||||
|
|
||||||
Fl_Group *buttongroup = new Fl_Group(10, 70, 185, 50);
|
Fl_Group *buttongroup = new Fl_Group(10, 70, 185, 50);
|
||||||
buttongroup->box(FL_THIN_DOWN_BOX);
|
buttongroup->box(FL_THIN_DOWN_BOX);
|
||||||
buttonxz = new Fl_Radio_Round_Button(10, 70, 185, 20, "Z=Jump; X=Attack");
|
buttonxz = new Fl_Radio_Round_Button(10, 70, 185, 20, "Z=Jump; X=Attack");
|
||||||
buttonxz->setonly();
|
buttonxz->setonly();
|
||||||
buttonzx = new Fl_Radio_Round_Button(10, 100, 185, 20, "X=Jump; Z=Attack");
|
buttonzx = new Fl_Radio_Round_Button(10, 100, 185, 20, "X=Jump; Z=Attack");
|
||||||
buttongroup->end();
|
buttongroup->end();
|
||||||
|
|
||||||
Fl_Group *okaygroup = new Fl_Group(205, 10, 185, 50);
|
Fl_Group *okaygroup = new Fl_Group(205, 10, 185, 50);
|
||||||
okaygroup->box(FL_THIN_DOWN_BOX);
|
okaygroup->box(FL_THIN_DOWN_BOX);
|
||||||
okayjump = new Fl_Radio_Round_Button(205, 10, 185, 20, "Jump=Okay");
|
okayjump = new Fl_Radio_Round_Button(205, 10, 185, 20, "Jump=Okay");
|
||||||
okayjump->setonly();
|
okayjump->setonly();
|
||||||
okayattack = new Fl_Radio_Round_Button(205, 40, 185, 20, "Attack=Okay");
|
okayattack = new Fl_Radio_Round_Button(205, 40, 185, 20, "Attack=Okay");
|
||||||
okaygroup->end();
|
okaygroup->end();
|
||||||
|
|
||||||
displaychoice = new Fl_Choice(205, 70, 185, 20);
|
displaychoice = new Fl_Choice(205, 70, 185, 20);
|
||||||
Fl_Menu_Item screens[] = {
|
Fl_Menu_Item screens[] = {{"Fullscreen 16-bit"}, {"Windowed 320x240"}, {"Windowed 640x480"}, {"Fullscreen 24-bit"}, {"Fullscreen 32-bit"}, {0}};
|
||||||
{"Fullscreen 16-bit"},
|
|
||||||
{"Windowed 320x240"},
|
|
||||||
{"Windowed 640x480"},
|
|
||||||
{"Fullscreen 24-bit"},
|
|
||||||
{"Fullscreen 32-bit"},
|
|
||||||
{0}};
|
|
||||||
displaychoice->menu(screens);
|
displaychoice->menu(screens);
|
||||||
|
|
||||||
joychoice = new Fl_Check_Button(205, 100, 185, 20, "Use Joypad");
|
joychoice = new Fl_Check_Button(205, 100, 185, 20, "Use Joypad");
|
||||||
joychoice->callback(&activatejoy);
|
joychoice->callback(&activatejoy);
|
||||||
|
|
||||||
joystuffcontainer = new Fl_Group(10, 130, 380, 200);
|
joystuffcontainer = new Fl_Group(10, 130, 380, 200);
|
||||||
joystuffcontainer->box(FL_THIN_DOWN_BOX);
|
joystuffcontainer->box(FL_THIN_DOWN_BOX);
|
||||||
for(char i=0;i<8;i++){
|
for (char i = 0; i < 8; i++)
|
||||||
joyRows[i] = new RadioRow(i);
|
{
|
||||||
}
|
joyRows[i] = new RadioRow(i);
|
||||||
//There's no Label class alright? I'll switch it as soon as one is introduced.
|
}
|
||||||
Fl_Group *labeljump = new Fl_Group(10, 150, 10, 20);
|
|
||||||
labeljump->label("Jump:");
|
// There's no Label class alright? I'll switch it as soon as one is introduced.
|
||||||
labeljump->align(FL_ALIGN_RIGHT);
|
Fl_Group *labeljump = new Fl_Group(10, 150, 10, 20);
|
||||||
labeljump->end();
|
labeljump->label("Jump:");
|
||||||
Fl_Group *labelattack = new Fl_Group(10, 180, 10, 20);
|
labeljump->align(FL_ALIGN_RIGHT);
|
||||||
labelattack->label("Attack:");
|
labeljump->end();
|
||||||
labelattack->align(FL_ALIGN_RIGHT);
|
|
||||||
labelattack->end();
|
Fl_Group *labelattack = new Fl_Group(10, 180, 10, 20);
|
||||||
Fl_Group *labelweaponup = new Fl_Group(10, 210, 10, 20);
|
labelattack->label("Attack:");
|
||||||
labelweaponup->label("Weapon+:");
|
labelattack->align(FL_ALIGN_RIGHT);
|
||||||
labelweaponup->align(FL_ALIGN_RIGHT);
|
labelattack->end();
|
||||||
labelweaponup->end();
|
|
||||||
Fl_Group *labelweapondown = new Fl_Group(10, 240, 10, 20);
|
Fl_Group *labelweaponup = new Fl_Group(10, 210, 10, 20);
|
||||||
labelweapondown->label("Weapon-:");
|
labelweaponup->label("Weapon+:");
|
||||||
labelweapondown->align(FL_ALIGN_RIGHT);
|
labelweaponup->align(FL_ALIGN_RIGHT);
|
||||||
labelweapondown->end();
|
labelweaponup->end();
|
||||||
Fl_Group *labelitem = new Fl_Group(10, 270, 10, 20);
|
|
||||||
labelitem->label("Items:");
|
Fl_Group *labelweapondown = new Fl_Group(10, 240, 10, 20);
|
||||||
labelitem->align(FL_ALIGN_RIGHT);
|
labelweapondown->label("Weapon-:");
|
||||||
labelitem->end();
|
labelweapondown->align(FL_ALIGN_RIGHT);
|
||||||
Fl_Group *labelmap = new Fl_Group(10, 300, 10, 20);
|
labelweapondown->end();
|
||||||
labelmap->label("Map:");
|
|
||||||
labelmap->align(FL_ALIGN_RIGHT);
|
Fl_Group *labelitem = new Fl_Group(10, 270, 10, 20);
|
||||||
labelmap->end();
|
labelitem->label("Items:");
|
||||||
|
labelitem->align(FL_ALIGN_RIGHT);
|
||||||
|
labelitem->end();
|
||||||
|
|
||||||
|
Fl_Group *labelmap = new Fl_Group(10, 300, 10, 20);
|
||||||
|
labelmap->label("Map:");
|
||||||
|
labelmap->align(FL_ALIGN_RIGHT);
|
||||||
|
labelmap->end();
|
||||||
|
|
||||||
joystuffcontainer->end();
|
joystuffcontainer->end();
|
||||||
|
|
||||||
Fl_Button *okaybutton = new Fl_Button(10, 340, 185, 30, "Okay");
|
Fl_Button *okaybutton = new Fl_Button(10, 340, 185, 30, "Okay");
|
||||||
okaybutton->callback(&write_Config);
|
okaybutton->callback(&write_Config);
|
||||||
|
|
||||||
Fl_Button *cancelbutton = new Fl_Button(205, 340, 185, 30, "Cancel");
|
Fl_Button *cancelbutton = new Fl_Button(205, 340, 185, 30, "Cancel");
|
||||||
cancelbutton->callback(&quit);
|
cancelbutton->callback(&quit);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue