Advertisement
Guest User

DoConfig.cpp

a guest
Dec 14th, 2011
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.50 KB | None | 0 0
  1. /* This program is free software. It comes without any warranty, to
  2. * the extent permitted by applicable law. You can redistribute it
  3. * and/or modify it under the terms of the Do What The F*** You Want
  4. * To Public License, Version 2, as published by Sam Hocevar. See
  5. * http://sam.zoy.org/wtfpl/COPYING for more details. */
  6.  
  7. #include <cstdlib>
  8. #include <iostream>
  9. #include <fstream>
  10. #include <cstring>
  11. #include "FL/Fl.H"
  12. #include "FL/Fl_Window.H"
  13. #include "FL/Fl_Radio_Round_Button.H"
  14. #include "FL/Fl_Choice.H"
  15. #include "FL/Fl_Check_Button.H"
  16.  
  17. #define HEADER "DOUKUTSU20041206"
  18. #define TEXT "Courier New"
  19.  
  20. struct data{
  21. char header[32];
  22. char text[64];
  23. int move;
  24. int attack;
  25. int okay;
  26. int display;
  27. int useJoy;
  28. int buttons[8];
  29. };
  30.  
  31. class RadioRow{
  32. public:
  33. RadioRow(char offset);
  34. int value();
  35. void value(int input);
  36. private:
  37. Fl_Group *group;
  38. Fl_Radio_Round_Button *buttons[6];
  39. Fl_Group *label;
  40. };
  41.  
  42. RadioRow::RadioRow(char offset){
  43. char *temp = new char[2];
  44. *(temp) = (char)(49+offset); //Muhahahahahahah!
  45. *(temp+1) = '\0';
  46. this->group = new Fl_Group(140+offset*30, 150, 30, 180);
  47. this->group->label(temp);
  48. this->group->align(FL_ALIGN_TOP_LEFT);
  49. for(char i=0;i<6;i++){
  50. this->buttons[i] = new Fl_Radio_Round_Button(140+offset*30, 150+30*i, 30, 30);
  51. }
  52. this->group->end();
  53. }
  54.  
  55. int RadioRow::value(){
  56. char i;
  57. for(i=0;i<6;i++){
  58. if(this->buttons[i]->value()){
  59. return (int)i;
  60. }
  61. }
  62. return 0;
  63. }
  64.  
  65. void RadioRow::value(int input){
  66. this->buttons[input]->setonly();
  67. }
  68.  
  69. /**
  70. * Action code values are a bit mixed up - on the screen they don't follow in the same
  71. * way they are coded in Config.dat file.
  72. *
  73. * this is how hex dump of the last 4x8 bytes of the
  74. * Config.dat file looks when the controller settings
  75. * are saved in the following way:
  76. * 1=[0]Jump(1)
  77. * 2=[1]Attack(2)
  78. * 3=[2]Weapon+(3)
  79. * 4=[3]Weapon-(6)
  80. * 5=[4]Items(4)
  81. * 6=[5]Map(5)
  82. * 7=[0]Jump(1)
  83. * 8=[1]Attack(2)
  84. * 01 00 00 00 02 00 00 00 03 00 00 00
  85. * 06 00 00 00 04 00 00 00 05 00 00 00 01 00 00 00
  86. * 02 00 00 00
  87. */
  88. int screenIndexToFileIndex(int screenIndex) {
  89. int fileIndex;
  90. switch(screenIndex) {
  91. case 0: // Jump on screen
  92. fileIndex = 1; //Jump in file
  93. break;
  94. case 1: // Attack on screen
  95. fileIndex = 2; // Attack in file
  96. break;
  97. case 2: // Weapon+ on screen
  98. fileIndex = 3; // Weapon+ in file
  99. break;
  100. case 3: // Weapon- on screen
  101. fileIndex = 6; // Weapon- in file
  102. break;
  103. case 4: // Items on screen
  104. fileIndex = 4; // Items in file
  105. break;
  106. case 5: // Map on screen
  107. fileIndex = 5; // Map in file
  108. break;
  109. default:
  110. fileIndex = 0;
  111. }
  112. return fileIndex;
  113. }
  114.  
  115. /**
  116. * Action code values are a bit mixed up - on the screen they don't follow in the same
  117. * way they are coded in Config.dat file.
  118. *
  119. * this is how hex dump of the last 4x8 bytes of the
  120. * Config.dat file looks when the controller settings
  121. * are saved in the following way:
  122. * 1=[0]Jump(1)
  123. * 2=[1]Attack(2)
  124. * 3=[2]Weapon+(3)
  125. * 4=[3]Weapon-(6)
  126. * 5=[4]Items(4)
  127. * 6=[5]Map(5)
  128. * 7=[0]Jump(1)
  129. * 8=[1]Attack(2)
  130. * 01 00 00 00 02 00 00 00 03 00 00 00
  131. * 06 00 00 00 04 00 00 00 05 00 00 00 01 00 00 00
  132. * 02 00 00 00
  133. */
  134. int fileIndexToScreenIndex(int fileIndex) {
  135. int screenIndex;
  136. switch(fileIndex) {
  137. case 1: // Jump in file
  138. screenIndex = 0; //Jump on screen
  139. break;
  140. case 2: // Attack in file
  141. screenIndex = 1; // Attack on screen
  142. break;
  143. case 3: // Weapon+ in file
  144. screenIndex = 2; // Weapon+ on screen
  145. break;
  146. case 4: // Items in file
  147. screenIndex = 4; // Items on screen
  148. break;
  149. case 5: // Map in file
  150. screenIndex = 5; // Map on screen
  151. break;
  152. case 6: // Weapon- in file
  153. screenIndex = 3; // Weapon- on screen
  154. break;
  155. default:
  156. screenIndex = 0;
  157. }
  158. return screenIndex;
  159. }
  160.  
  161. Fl_Round_Button *movear;
  162. Fl_Round_Button *movegt;
  163.  
  164. Fl_Round_Button *buttonxz;
  165. Fl_Round_Button *buttonzx;
  166.  
  167. Fl_Round_Button *okayjump;
  168. Fl_Round_Button *okayattack;
  169.  
  170. Fl_Choice *displaychoice;
  171. Fl_Check_Button *joychoice;
  172.  
  173. Fl_Group *joystuffcontainer;
  174. RadioRow *joyRows[8];
  175.  
  176. void quit(Fl_Widget*, void*){
  177. std::exit(0);
  178. }
  179.  
  180. void activatejoy(Fl_Widget*, void*){
  181. if(joystuffcontainer->active()){
  182. joystuffcontainer->deactivate();
  183. } else {
  184. joystuffcontainer->activate();
  185. }
  186. }
  187. void read_Config(){
  188. std::fstream fd;
  189. data config;
  190. fd.open("Config.dat", std::ios::in | std::ios::binary);
  191. fd.read((char*)&config, 148);
  192. if (config.move == 0){
  193. movear->setonly();
  194. } else {
  195. movegt->setonly();
  196. }
  197. if (config.attack == 0){
  198. buttonxz->setonly();
  199. } else {
  200. buttonzx->setonly();
  201. }
  202. if (config.okay == 0){
  203. okayjump->setonly();
  204. }else{
  205. okayattack->setonly();
  206. }
  207. displaychoice->value(config.display);
  208. joychoice->value(config.useJoy);
  209. if( !config.useJoy ){
  210. joystuffcontainer->deactivate();
  211. }
  212.  
  213. for(char i=0;i<8;i++){
  214. joyRows[i]->value(fileIndexToScreenIndex(config.buttons[i]));
  215. }
  216. fd.close();
  217. }
  218.  
  219. void write_Config(Fl_Widget*, void*){
  220. std::fstream fd;
  221. data config;
  222. std::memset(config.header, '\0', 32);
  223. std::memset(config.text, '\0', 64);
  224. std::strcpy(config.header, HEADER);
  225. std::strcpy(config.text, TEXT);
  226. fd.open("Config.dat", std::ios::out | std::ios::binary);
  227.  
  228. config.move = movegt->value();
  229. config.attack = buttonzx->value();
  230. config.okay = okayattack->value();
  231.  
  232. config.display = displaychoice->value();
  233. config.useJoy = joychoice->value();
  234. for(char i =0;i<8;i++){
  235. config.buttons[i] = screenIndexToFileIndex(joyRows[i]->value());
  236. }
  237. fd.write((char*)&config, 148);
  238. fd.close();
  239. exit(0);
  240. }
  241. int main(int argc, char* argv[]){
  242. Fl_Window *mainw = new Fl_Window(400, 380, "DoConfigure - Doukutsu Monotagari Settings");
  243.  
  244. Fl_Group *movegroup = new Fl_Group(10, 10, 185, 50);
  245. movegroup->box(FL_THIN_DOWN_BOX);
  246. movear = new Fl_Radio_Round_Button(10, 10, 185, 20, "Arrows for Movement");
  247. movear->setonly();
  248. movegt = new Fl_Radio_Round_Button(10, 40, 185, 20, "<>? for Movement");
  249. movegroup->end();
  250.  
  251. Fl_Group *buttongroup = new Fl_Group(10, 70, 185, 50);
  252. buttongroup->box(FL_THIN_DOWN_BOX);
  253. buttonxz = new Fl_Radio_Round_Button(10, 70, 185, 20, "Z=Jump; X=Attack");
  254. buttonxz->setonly();
  255. buttonzx = new Fl_Radio_Round_Button(10, 100, 185, 20, "X=Jump; Z=Attack");
  256. buttongroup->end();
  257.  
  258. Fl_Group *okaygroup = new Fl_Group(205, 10, 185, 50);
  259. okaygroup->box(FL_THIN_DOWN_BOX);
  260. okayjump = new Fl_Radio_Round_Button(205, 10, 185, 20, "Jump=Okay");
  261. okayjump->setonly();
  262. okayattack = new Fl_Radio_Round_Button(205, 40, 185, 20, "Attack=Okay");
  263. okaygroup->end();
  264.  
  265. displaychoice = new Fl_Choice(205, 70, 185, 20);
  266. Fl_Menu_Item screens[] = {
  267. {"Fullscreen 16-bit"},
  268. {"Windowed 320x240"},
  269. {"Windowed 640x480"},
  270. {"Fullscreen 24-bit"},
  271. {"Fullscreen 32-bit"},
  272. {0}};
  273. displaychoice->menu(screens);
  274. joychoice = new Fl_Check_Button(205, 100, 185, 20, "Use Joypad");
  275. joychoice->callback(&activatejoy);
  276.  
  277. joystuffcontainer = new Fl_Group(10, 130, 380, 200);
  278. joystuffcontainer->box(FL_THIN_DOWN_BOX);
  279. for(char i=0;i<8;i++){
  280. joyRows[i] = new RadioRow(i);
  281. }
  282. //There's no Label class alright? I'll switch it as soon as one is introduced.
  283. Fl_Group *labeljump = new Fl_Group(10, 150, 10, 20);
  284. labeljump->label("Jump:");
  285. labeljump->align(FL_ALIGN_RIGHT);
  286. labeljump->end();
  287. Fl_Group *labelattack = new Fl_Group(10, 180, 10, 20);
  288. labelattack->label("Attack:");
  289. labelattack->align(FL_ALIGN_RIGHT);
  290. labelattack->end();
  291. Fl_Group *labelweaponup = new Fl_Group(10, 210, 10, 20);
  292. labelweaponup->label("Weapon+:");
  293. labelweaponup->align(FL_ALIGN_RIGHT);
  294. labelweaponup->end();
  295. Fl_Group *labelweapondown = new Fl_Group(10, 240, 10, 20);
  296. labelweapondown->label("Weapon-:");
  297. labelweapondown->align(FL_ALIGN_RIGHT);
  298. labelweapondown->end();
  299. Fl_Group *labelitem = new Fl_Group(10, 270, 10, 20);
  300. labelitem->label("Items:");
  301. labelitem->align(FL_ALIGN_RIGHT);
  302. labelitem->end();
  303. Fl_Group *labelmap = new Fl_Group(10, 300, 10, 20);
  304. labelmap->label("Map:");
  305. labelmap->align(FL_ALIGN_RIGHT);
  306. labelmap->end();
  307.  
  308. joystuffcontainer->end();
  309.  
  310. Fl_Button *okaybutton = new Fl_Button(10, 340, 185, 30, "Okay");
  311. okaybutton->callback(&write_Config);
  312. Fl_Button *cancelbutton = new Fl_Button(205, 340, 185, 30, "Cancel");
  313. cancelbutton->callback(&quit);
  314.  
  315. mainw->end();
  316. mainw->show(argc, argv);
  317.  
  318. read_Config();
  319. Fl::option(Fl::OPTION_VISIBLE_FOCUS, false);
  320. return Fl::run();
  321. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement