DoConfig portability improvements and bugfixes
This commit is contained in:
parent
c533a8084a
commit
89ace4b737
1 changed files with 47 additions and 35 deletions
|
@ -14,18 +14,18 @@
|
||||||
#include "FL/Fl_Choice.H"
|
#include "FL/Fl_Choice.H"
|
||||||
#include "FL/Fl_Check_Button.H"
|
#include "FL/Fl_Check_Button.H"
|
||||||
|
|
||||||
#define HEADER "DOUKUTSU20041206"
|
#define MAGIC "DOUKUTSU20041206"
|
||||||
#define TEXT "Courier New"
|
#define FONT "Courier New"
|
||||||
|
|
||||||
struct data{
|
struct data{
|
||||||
char header[32];
|
char magic[32];
|
||||||
char text[64];
|
char font[64];
|
||||||
int move;
|
unsigned char move[4];
|
||||||
int attack;
|
unsigned char attack[4];
|
||||||
int okay;
|
unsigned char okay[4];
|
||||||
int display;
|
unsigned char display[4];
|
||||||
int useJoy;
|
unsigned char useJoy[4];
|
||||||
int buttons[8];
|
unsigned char buttons[8][4];
|
||||||
};
|
};
|
||||||
|
|
||||||
class RadioRow{
|
class RadioRow{
|
||||||
|
@ -39,6 +39,19 @@ class RadioRow{
|
||||||
Fl_Group *label;
|
Fl_Group *label;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static unsigned long CharsToLong(unsigned char *chars)
|
||||||
|
{
|
||||||
|
return (chars[3] << 24) | (chars[2] << 16) | (chars[1] << 8) | chars[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
static void LongToChars(unsigned long long_var, unsigned char *chars)
|
||||||
|
{
|
||||||
|
chars[0] = long_var & 0xFF;
|
||||||
|
chars[1] = (long_var >> 8) & 0xFF;
|
||||||
|
chars[2] = (long_var >> 16) & 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) = (char)(49+offset); //Muhahahahahahah!
|
||||||
|
@ -94,61 +107,60 @@ void activatejoy(Fl_Widget*, void*){
|
||||||
}
|
}
|
||||||
void read_Config(){
|
void read_Config(){
|
||||||
std::fstream fd;
|
std::fstream fd;
|
||||||
data config;
|
data config = {0};
|
||||||
fd.open("Config.dat", std::ios::in | std::ios::binary);
|
fd.open("Config.dat", std::ios::in | std::ios::binary);
|
||||||
fd.read((char*)&config, 148);
|
fd.read((char*)&config, sizeof(config));
|
||||||
if (config.move == 0){
|
fd.close();
|
||||||
|
if (CharsToLong(config.move) == 0){
|
||||||
movear->setonly();
|
movear->setonly();
|
||||||
} else {
|
} else {
|
||||||
movegt->setonly();
|
movegt->setonly();
|
||||||
}
|
}
|
||||||
if (config.attack == 0){
|
if (CharsToLong(config.attack) == 0){
|
||||||
buttonxz->setonly();
|
buttonxz->setonly();
|
||||||
} else {
|
} else {
|
||||||
buttonzx->setonly();
|
buttonzx->setonly();
|
||||||
}
|
}
|
||||||
if (config.okay == 0){
|
if (CharsToLong(config.okay) == 0){
|
||||||
okayjump->setonly();
|
okayjump->setonly();
|
||||||
}else{
|
}else{
|
||||||
okayattack->setonly();
|
okayattack->setonly();
|
||||||
}
|
}
|
||||||
displaychoice->value(config.display);
|
displaychoice->value(CharsToLong(config.display));
|
||||||
joychoice->value(config.useJoy);
|
joychoice->value(CharsToLong(config.useJoy));
|
||||||
if( !config.useJoy ){
|
if( !CharsToLong(config.useJoy) ){
|
||||||
joystuffcontainer->deactivate();
|
joystuffcontainer->deactivate();
|
||||||
}
|
}
|
||||||
for(char i=0;i<8;i++){
|
for(char i=0;i<8;i++){
|
||||||
if(config.buttons[i]<9 && config.buttons[i]>0){
|
const unsigned long button = CharsToLong(config.buttons[i]);
|
||||||
joyRows[i]->value(config.buttons[i] -1);
|
if(button<9 && button>0){
|
||||||
|
joyRows[i]->value(button -1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fd.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void write_Config(Fl_Widget*, void*){
|
void write_Config(Fl_Widget*, void*){
|
||||||
std::fstream fd;
|
std::fstream fd;
|
||||||
data config;
|
data config = {0};
|
||||||
std::memset(config.header, '\0', 32);
|
std::strcpy(config.magic, MAGIC);
|
||||||
std::memset(config.text, '\0', 64);
|
std::strcpy(config.font, FONT);
|
||||||
std::strcpy(config.header, HEADER);
|
|
||||||
std::strcpy(config.text, TEXT);
|
|
||||||
fd.open("Config.dat", std::ios::out | std::ios::binary);
|
|
||||||
|
|
||||||
config.move = movegt->value();
|
LongToChars(movegt->value(), config.move);
|
||||||
config.attack = buttonzx->value();
|
LongToChars(buttonzx->value(), config.attack);
|
||||||
config.okay = okayattack->value();
|
LongToChars(okayattack->value(), config.okay);
|
||||||
|
|
||||||
config.display = displaychoice->value();
|
LongToChars(displaychoice->value(), config.display);
|
||||||
config.useJoy = joychoice->value();
|
LongToChars(joychoice->value(), config.useJoy);
|
||||||
for(char i =0;i<8;i++){
|
for(char i =0;i<8;i++){
|
||||||
config.buttons[i] = joyRows[i]->value();
|
LongToChars(joyRows[i]->value(), config.buttons[i]);
|
||||||
}
|
}
|
||||||
fd.write((char*)&config, 148);
|
fd.open("Config.dat", std::ios::out | std::ios::binary);
|
||||||
|
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[]){
|
||||||
Fl_Window *mainw = new Fl_Window(400, 380, "DoConfigure - Doukutsu Monotagari 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);
|
||||||
|
|
Loading…
Add table
Reference in a new issue