Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. #include <stdio.h>
  2. #include "options.h"
  3. #include "PHL.h"
  4. #include "game.h"
  5. #include "ini.h"
  6. #include "text.h"
  7.  
  8. char page = 0;
  9. int optCursor = 0;
  10. int lastOption = -1;
  11. #ifdef _SDL
  12. int musicType = 1;
  13.  
  14. int getMusicType()
  15. {
  16.         return musicType;
  17. }
  18. void setMusicType(int t)
  19. {
  20. #ifndef _KOLIBRI
  21.         if(t!=musicType)
  22.         {
  23.                 musicType = t;
  24.                 // restart music...
  25.         }
  26. #else
  27.         musicType = 1;  /* MIDI NOT WORK! */
  28. #endif
  29. }
  30. #endif
  31.  
  32. #ifdef EMSCRIPTEN
  33. static char tempDark;
  34. static int emOnly;
  35. void optionsSetup(int only)
  36. {
  37.         tempDark = roomDarkness;
  38.         roomDarkness = 0;
  39.         emOnly = only;
  40.         page = only?1:0;
  41. }
  42.  
  43. int optionsEMStep()
  44. {
  45.         int loop = 1;
  46.         PHL_MainLoop();
  47.  
  48.         PHL_StartDrawing();
  49.        
  50.         optionsDraw();
  51.        
  52.         PHL_ScanInput();       
  53.         int result = optionsStep();
  54.        
  55.         PHL_EndDrawing();
  56.        
  57.         if (page == 0 && result != -1 && result != 2) {
  58.                 loop = 0;
  59.         }
  60.         if (emOnly && page==0) {
  61.                 loop = 0;
  62.         }
  63.  
  64.         if(!loop) roomDarkness = tempDark;
  65.        
  66.         return (!loop)?result:-1;
  67. }
  68. #else
  69.  
  70. int options(int only)
  71. {
  72.         char tempDark = roomDarkness;
  73.         roomDarkness = 0;
  74.        
  75.         int result = -1;
  76.         char loop = 1;
  77.  
  78.         if(only) page=1;
  79.        
  80.         while (PHL_MainLoop() && loop == 1)
  81.         {
  82.                 PHL_StartDrawing();
  83.                
  84.                 optionsDraw();
  85.                
  86.                 PHL_ScanInput();       
  87.                 result = optionsStep();
  88.                
  89.                 PHL_EndDrawing();
  90.                
  91.                 if (page == 0 && result != -1 && result != 2) {
  92.                         loop = 0;
  93.                 }
  94.                 if (only && page==0) {
  95.                         loop = 0;
  96.                 }
  97.         }
  98.        
  99.         roomDarkness = tempDark;
  100.        
  101.         return result;
  102. }
  103. #endif
  104. int optionsStep()
  105. {              
  106.         int result = -1;
  107.        
  108.         secretCountdown();
  109.        
  110.         //input
  111.         if (btnDown.pressed == 1) {
  112.                 optCursor += 1;
  113.                 PHL_PlaySound(sounds[sndPi01], CHN_SOUND);
  114.                
  115.         }else if (btnUp.pressed == 1) {
  116.                 optCursor -= 1;
  117.                 PHL_PlaySound(sounds[sndPi01], CHN_SOUND);
  118.         }
  119.        
  120.         //First screen (continue/reset/exit)
  121.         if (page == 0) {
  122.                 //Limit cursor
  123.                 if (optCursor >= 4) {
  124.                         optCursor = 0;
  125.                 }
  126.                
  127.                 if (optCursor < 0) {
  128.                         optCursor = 3;
  129.                 }
  130.                
  131.                 if (btnAccept.pressed == 1 || btnStart.pressed == 1) {
  132.                         result = optCursor;
  133.                         if (result == 1) {
  134.                                 PHL_StopMusic();
  135.                         }
  136.                         if (result == 2) {
  137.                                 page = 1;
  138.                                 optCursor = 0;
  139.                         }
  140.                        
  141.                         //No blip on game exit
  142.                         if (optCursor != 3) {
  143.                                 PHL_PlaySound(sounds[sndOk], CHN_SOUND);
  144.                         }
  145.                 }
  146.                
  147.                 if (btnSelect.pressed == 1) {
  148.                         result = 0;
  149.                         PHL_PlaySound(sounds[sndOk], CHN_SOUND);
  150.                 }
  151.         }
  152.         //Actual options screen
  153.         else if (page == 1) {
  154.                 //Limit cursor
  155.                 if (optCursor > lastOption) {
  156.                         optCursor = 0;
  157.                 }
  158.                
  159.                 if (optCursor < 0) {
  160.                         optCursor = lastOption;
  161.                 }
  162.                
  163.                 if (btnAccept.pressed == 1 || btnStart.pressed == 1) {
  164.                         //Universal settings
  165.                         //Language
  166.                         if (optCursor == 0) {
  167.                                 if (getLanguage() == JAPANESE) {
  168.                                         setLanguage(ENGLISH);
  169.                                 }else{
  170.                                         setLanguage(JAPANESE);
  171.                                 }
  172.                         }
  173.                        
  174.                         //Autosave
  175.                         if (optCursor == 1) {
  176.                                 if (getAutoSave() == 0) {
  177.                                         setAutoSave(1);
  178.                                 }else{
  179.                                         setAutoSave(0);
  180.                                 }
  181.                         }
  182.                        
  183.                         #ifdef _3DS
  184.                                 if (optCursor == 2) {
  185.                                         if (activeScreen->screen == GFX_TOP) {
  186.                                                 swapScreen(GFX_BOTTOM, GFX_LEFT);
  187.                                         }else{
  188.                                                 swapScreen(GFX_TOP, GFX_LEFT);
  189.                                         }
  190.                                 }                              
  191.                         #endif
  192.                        
  193.                         #ifdef _PSP
  194.                                 if (optCursor == 2) {
  195.                                         if (getScreenSize() == 0) {
  196.                                                 setScreenSize(1);
  197.                                         }else if (getScreenSize() == 1) {
  198.                                                 setScreenSize(2);
  199.                                         }else{
  200.                                                 setScreenSize(0);
  201.                                         }
  202.                                 }
  203.                                
  204.                                 //Blur
  205.                                 if (optCursor == 3) {
  206.                                         if (getBlur() == 0) {
  207.                                                 setBlur(1);
  208.                                         }else{
  209.                                                 setBlur(0);
  210.                                         }
  211.                                 }
  212.                         #endif
  213.  
  214.                         #ifdef _SDL
  215.                                 // Music type
  216.                                 if(optCursor == 2) {
  217.                                         if(getMusicType()  == 0)
  218.                                                 setMusicType(1);
  219.                                         else
  220.                                                 setMusicType(0);
  221.                                 }
  222.                                 // Music volume
  223.                                 if(optCursor == 3) {
  224.                                         music_volume = (music_volume+1)%5;
  225.                                         PHL_MusicVolume(0.25f * music_volume);
  226.                                 }
  227.                                 // xBRZ
  228.                                 if (optCursor == 4) {
  229.                                         if (getXBRZ() == 0) {
  230.                                                 setXBRZ(1);
  231.                                         }else{
  232.                                                 setXBRZ(0);
  233.                                         }
  234.                                 }
  235.                         #endif
  236.                        
  237.                         //Back
  238.                         if (optCursor == lastOption) {
  239.                                 page = 0;
  240.                         }
  241.                 }              
  242.                 else if (btnDecline.pressed == 1) {
  243.                         page = 0;                      
  244.                 }
  245.                
  246.                 if (page == 0) {
  247.                         saveSettings();
  248.                 }
  249.         }
  250.        
  251.         return result;
  252. }
  253.  
  254. void optionsDraw()
  255. {      
  256.         PHL_DrawRect(0, 0, 640, 480, PHL_NewRGB(0, 0, 0));
  257.        
  258.         if (page == 0)
  259.         {
  260.                 PHL_DrawTextBold("CONTINUE", 254, 144, YELLOW);
  261.                 PHL_DrawTextBold("RESET", 278, 176, YELLOW);
  262.                 PHL_DrawTextBold("OPTIONS", 262, 208, YELLOW);
  263.                 PHL_DrawTextBold("EXIT", 286, 240, YELLOW);
  264.                
  265.                 PHL_DrawTextBold("<", 232, 144 + (32 * optCursor), RED);
  266.                 PHL_DrawTextBold(">", 390, 144 + (32 * optCursor), RED);
  267.         }
  268.         else if (page == 1)
  269.         {
  270.                 int xleft = 216;
  271.                 int xright = xleft + 160;
  272.                
  273.                 int ydrawstart = 144;
  274.                 int ydraw = ydrawstart;
  275.                 int ystep = 32;
  276.                 int optioncount = 0;
  277.                
  278.                 //Language
  279.                 PHL_DrawTextBold("LANGUAGE", xleft, ydraw, YELLOW);
  280.                 if (getLanguage() == 1) {
  281.                         PHL_DrawTextBold("EN", xright, ydraw, YELLOW);
  282.                 }
  283.                 if (getLanguage() == 0) {
  284.                         PHL_DrawTextBold("JP", xright, ydraw, YELLOW);
  285.                 }
  286.                
  287.                 ydraw += ystep;
  288.                 optioncount++;
  289.                
  290.                 //AutoSave
  291.                 PHL_DrawTextBold("SAFE SAVE", xleft, ydraw, YELLOW);
  292.                 if (getAutoSave() == 1) {
  293.                         PHL_DrawTextBold("ON", xright, ydraw, YELLOW);
  294.                 }else{
  295.                         PHL_DrawTextBold("OFF", xright, ydraw, YELLOW);
  296.                 }              
  297.                
  298.                 ydraw += ystep;
  299.                 optioncount++;
  300.                
  301.                 #ifdef _3DS
  302.                         //Screen
  303.                         PHL_DrawTextBold("SCREEN", xleft, ydraw, YELLOW);
  304.                         if (activeScreen->screen == GFX_TOP) {
  305.                                 PHL_DrawTextBold("TOP", xright, ydraw, YELLOW);
  306.                         }else{
  307.                                 PHL_DrawTextBold("BOTTOM", xright, ydraw, YELLOW);
  308.                         }
  309.  
  310.                         ydraw += ystep;
  311.                         optioncount++;                 
  312.                 #endif
  313.                
  314.                 #ifdef _PSP                    
  315.                         //Screen Size
  316.                         PHL_DrawTextBold("SCREEN", xleft, ydraw, YELLOW);
  317.                         if (getScreenSize() == 0) {
  318.                                 PHL_DrawTextBold("1:1", xright, ydraw, YELLOW);
  319.                         }
  320.                         else if (getScreenSize() == 1) {
  321.                                 PHL_DrawTextBold("FILL", xright, ydraw, YELLOW);
  322.                         }
  323.                         else if (getScreenSize() == 2) {
  324.                                 PHL_DrawTextBold("FULL", xright, ydraw, YELLOW);
  325.                         }
  326.                        
  327.                         ydraw += ystep;
  328.                         optioncount++;
  329.                        
  330.                         //Blur
  331.                         PHL_DrawTextBold("BLUR", xleft, ydraw, YELLOW);
  332.                         if (getBlur() == 1) {
  333.                                 PHL_DrawTextBold("ON", xright, ydraw, YELLOW);
  334.                         }
  335.                         else{
  336.                                 PHL_DrawTextBold("OFF", xright, ydraw, YELLOW);
  337.                         }
  338.                        
  339.                         ydraw += ystep;
  340.                         optioncount++;
  341.                 #endif
  342.  
  343.                 #ifdef _SDL
  344.                         // Music type
  345.                         PHL_DrawTextBold("MUSIC", xleft, ydraw, YELLOW);
  346.                         if (getMusicType() == 1) {
  347.                                 PHL_DrawTextBold("OGG", xright, ydraw, YELLOW);
  348.                         }
  349.                         else{
  350.                                 PHL_DrawTextBold("MIDI", xright, ydraw, YELLOW);
  351.                         }
  352.                         ydraw += ystep;
  353.                         optioncount++;
  354.                         // Music volume
  355.                         PHL_DrawTextBold("MUSIC", xleft, ydraw, YELLOW);
  356.                         char buff[50];
  357.                         sprintf(buff, "%d%%", music_volume*25);
  358.                         PHL_DrawTextBold(buff, xright, ydraw, YELLOW);
  359.                         ydraw += ystep;
  360.                         optioncount++;
  361.                         // xBRZ scaling
  362.                         PHL_DrawTextBold("XBRZ", xleft, ydraw, YELLOW);
  363.                         if (getXBRZ() == 1) {
  364.                                 PHL_DrawTextBold("ON", xright, ydraw, YELLOW);
  365.                         }
  366.                         else{
  367.                                 PHL_DrawTextBold("OFF", xright, ydraw, YELLOW);
  368.                         }
  369.                         ydraw += ystep;
  370.                         optioncount++;
  371.                 #endif
  372.                
  373.                 PHL_DrawTextBold("BACK", xleft, ydraw, YELLOW);
  374.                
  375.                 if (lastOption == -1) {
  376.                         lastOption = optioncount;
  377.                 }
  378.                
  379.                 PHL_DrawTextBold(">", xleft - 32, ydrawstart + (ystep * optCursor), RED);
  380.         }
  381. }
  382.