Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

DialogSceneryOptions.cpp

Go to the documentation of this file.
00001 /*
00002  * DialogSceneryOptions.cpp
00003  *
00004  * Part of Fly! Legacy project
00005  *
00006  * Copyright 2003 Chris Wallace
00007  *
00008  * Fly! Legacy is free software; you can redistribute it and/or modify
00009  *   it under the terms of the GNU General Public License as published by
00010  *   the Free Software Foundation; either version 2 of the License, or
00011  *   (at your option) any later version.
00012  *
00013  * Fly! Legacy is distributed in the hope that it will be useful,
00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  *   GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  *   along with Fly! Legacy; if not, write to the Free Software
00020  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  */
00023 
00024 
00025 #include "../Include/FlyLegacy.h"
00026 #include "../Include/Globals.h"
00027 #include "../Include/Ui.h"
00028 #include "../Include/TimeManager.h"
00029 #include "../Include/Situation.h"
00030 
00031 
00032 static char *detaillist[] =
00033   {
00034     "No Scenery",
00035     "Sparse",
00036     "Normal",
00037     "Complex",
00038     NULL
00039   };
00040 
00041 static char *shadowlist[] =
00042   {
00043     "None",
00044     "Aircraft Only",
00045     "Aircraft and Buildings",
00046     NULL
00047   };
00048 
00049 
00050 typedef struct {
00051   puDialogBox*  dialog;
00052   puFrame*    frame;
00053   puText*     title;
00054   puComboBox*   detail;
00055   puComboBox*   shadows;
00056   puButton*   envmap;
00057   puButton*   watereffects;
00058   puButton*   nightlight;
00059   puSlider*   visibility;
00060   puSlider*   highres;
00061   puSlider*   medres;
00062   puSlider*   aiaircraft;
00063   puOneShot*    apply;
00064   puOneShot*    ok;
00065   puOneShot*    cancel;
00066 
00067   float     maxvisibility;    // Maximu visibility derived from slider position
00068   char      vislegend[8];   // Legend text for max vis slider
00069   char      highlegend[8];    // Legend text for high detail slider
00070   char      medlegend[8];   // Legend text for medium detail slider
00071 } SSceneryOptionsDialogData;
00072 
00073 
00074 static SSceneryOptionsDialogData* data = NULL;
00075 
00076 
00077 void scenery_options_dlg_kill (void)
00078 {
00079   if (data == NULL) return;
00080 
00081   // Deleting the PUI dialog will delete all child widgets as well
00082   delete data->dialog;
00083 
00084   // Delete dialog data structure
00085   delete data;
00086   data = NULL;
00087 }
00088 
00089 
00090 static float vis_to_slider (float f)
00091 {
00092   float rc;
00093 
00094   if (f <= 5.0) {
00095     // 0.25 mile increments up to 5 miles
00096     rc = f * 4.0;
00097   } else if (f <= 10.0) {
00098     // 0.5 mile increments between 5 and 10 miles
00099     rc = 20.0 + ((f - 5.0) * 2.0);
00100   } else {
00101     // 1.0 mile increments up to 60 miles
00102     rc = 30.0 + (f - 10.0);
00103   }
00104 
00105   return rc;
00106 
00107 }
00108 
00109 
00110 //
00111 // Convert the value of the max visibility slider (range 0..80) to
00112 //   the actual max visibility in miles.
00113 //
00114 // Visibility can be set in 0.25 mile increments for the first five miles,
00115 //   then 0.5 mile increments for the next 10 miles, and 1.0 mile
00116 //   increments up to maximum of 60.0
00117 //
00118 static float slider_to_vis (float f)
00119 {
00120   float rc = 60.0;
00121 
00122   if (f <= 20.0) {
00123     // 0.25 mile increments up to 5 miles
00124     rc = f / 4.0;
00125   } else if (f <= 30.0) {
00126     // 0.5 mile increments between 5 and 10 miles
00127     rc = 5.0 + ((f - 20.0) / 2.0);
00128   } else {
00129     // 1.0 mile increments up to 60 miles
00130     rc = 10.0 + (f - 30.0);
00131   }
00132 
00133   return rc;
00134 }
00135 
00136 static void scenery_options_visibility_cb (puObject *obj)
00137 {
00138   float value;
00139   obj->getValue (&value);
00140   data->maxvisibility = slider_to_vis (value);
00141 
00142   sprintf (data->vislegend, "%4.2f", data->maxvisibility);
00143   obj->setLegend (data->vislegend);
00144 }
00145 
00146 
00147 static void scenery_options_highres_cb (puObject *obj)
00148 {
00149   float value;
00150   obj->getValue (&value);
00151 
00152   sprintf (data->highlegend, "%3.1f", value);
00153   obj->setLegend (data->highlegend);
00154 }
00155 
00156 
00157 static void scenery_options_medres_cb (puObject *obj)
00158 {
00159   float value;
00160   obj->getValue (&value);
00161 
00162   sprintf (data->medlegend, "%3.1f", value);
00163   obj->setLegend (data->medlegend);
00164 }
00165 
00166 
00167 static void apply (void)
00168 {
00169   // Update INI settings with new scenery option values
00170   SetIniFloat ("Graphics", "maxUserVisibility", data->maxvisibility);
00171   SetIniFloat ("Graphics", "medDetailRadius", data->medres->getValue ());
00172   SetIniFloat ("Graphics", "highDetailRadius", data->highres->getValue ());
00173   SaveIniSettings ();
00174   
00175   // Update terrain manager with new values
00176   globals->terrainmgr->UpdateMaxVisibility ();
00177   globals->terrainmgr->UpdateHighDetailRange ();
00178   globals->terrainmgr->UpdateMediumDetailRange ();
00179 }
00180 
00181 static void scenery_options_apply_cb (puObject* obj)
00182 {
00183   // Apply new values without closing dialog box
00184   apply ();
00185 }
00186 
00187 static void scenery_options_ok_cb (puObject* obj)
00188 {
00189   // Apply new values and close dialog box
00190   apply ();
00191   scenery_options_dlg_kill ();
00192 }
00193 
00194 
00195 static void scenery_options_cancel_cb (puObject* obj)
00196 {
00197   // Close dialog box without applying new date/time
00198   scenery_options_dlg_kill ();
00199 }
00200 
00201 
00202 void scenery_options_dlg_create (void)
00203 {
00204   if (data != NULL) return;
00205 
00206   // Instantiate data structure for dialog contents
00207   data = new SSceneryOptionsDialogData;
00208 
00209   // Create dialog box
00210   data->dialog = new puDialogBox (20, 300);
00211   {
00212     // Frame
00213     data->frame = new puFrame (0, 0, 440, 260);
00214 
00215     // Title
00216     data->title = new puText (10, 230);
00217     data->title->setLabel ("Scenery Options:");
00218 
00219     // Scenery detail
00220     data->detail = new puComboBox (20, 190, 180, 210, detaillist);
00221     data->detail->setLabel ("Detail Level");
00222     data->detail->setLabelPlace (PUPLACE_TOP_LEFT);
00223     data->detail->greyOut ();
00224 
00225     // Shadow detail
00226     data->shadows = new puComboBox (20, 150, 180, 170, shadowlist);
00227     data->shadows->setLabel ("Shadows");
00228     data->shadows->setLabelPlace (PUPLACE_TOP_LEFT);
00229     data->shadows->greyOut ();
00230 
00231     // Environment mapping
00232     data->envmap = new puButton (20, 120, 40, 140);
00233     data->envmap->setStyle (PUSTYLE_RADIO);
00234     data->envmap->setLabel ("Environment Mapping");
00235     data->envmap->setLabelPlace (PUPLACE_CENTERED_RIGHT);
00236     data->envmap->greyOut ();
00237 
00238     // Water effects
00239     data->watereffects = new puButton (20, 90, 40, 110);
00240     data->watereffects->setStyle (PUSTYLE_RADIO);
00241     data->watereffects->setLabel ("Water Effects");
00242     data->watereffects->setLabelPlace (PUPLACE_CENTERED_RIGHT);
00243     data->watereffects->greyOut ();
00244 
00245     // Night lighting
00246     data->nightlight = new puButton (20, 60, 40, 80);
00247     data->nightlight->setStyle (PUSTYLE_RADIO);
00248     data->nightlight->setLabel ("Night Lighting");
00249     data->nightlight->setLabelPlace (PUPLACE_CENTERED_RIGHT);
00250     data->nightlight->greyOut ();
00251 
00252     // Maximum visibility
00253     data->visibility = new puSlider (220, 180, 180, false, 20);
00254     data->visibility->setLabel ("Maximum Visibility");
00255     data->visibility->setLabelPlace (PUPLACE_TOP_LEFT);
00256     data->visibility->setMinValue (0.0);
00257     data->visibility->setMaxValue (80.0);
00258     data->visibility->setStepSize (1.0);
00259     data->visibility->setCallback (scenery_options_visibility_cb);
00260 
00261     // High-resolution texture radius
00262     data->highres = new puSlider (220, 140, 180, false, 20);
00263     data->highres->setLabel ("High Resolution Radius");
00264     data->highres->setLabelPlace (PUPLACE_TOP_LEFT);
00265     data->highres->setMinValue (0.0);
00266     data->highres->setMaxValue (6.0);
00267     data->highres->setStepSize (0.5);
00268     data->highres->setCallback (scenery_options_highres_cb);
00269 
00270     // Medium-resolution texture radius
00271     data->medres = new puSlider (220, 100, 180, false, 20);
00272     data->medres->setLabel ("Medium Resolution Radius");
00273     data->medres->setLabelPlace (PUPLACE_TOP_LEFT);
00274     data->medres->setMinValue (0.0);
00275     data->medres->setMaxValue (20.0);
00276     data->medres->setStepSize (0.5);
00277     data->medres->setCallback (scenery_options_medres_cb);
00278 
00279     // AI (Dynamic Scenery) Aircraft
00280     data->aiaircraft = new puSlider (220, 60, 180, false, 20);
00281     data->aiaircraft->setLabel ("Dynamic Scenery Aircraft");
00282     data->aiaircraft->setLabelPlace (PUPLACE_TOP_LEFT);
00283     data->aiaircraft->setMinValue (0.0);
00284     data->aiaircraft->setMaxValue (20.0);
00285     data->aiaircraft->setStepSize (1.0);
00286     data->aiaircraft->greyOut ();
00287 
00288     // apply button
00289     data->apply = new puOneShot (20, 20, 80, 40);
00290     data->apply->setLegend ("Apply");
00291     data->apply->makeReturnDefault (true);
00292     data->apply->setStyle (PUSTYLE_SMALL_SHADED);
00293     data->apply->setCallback (scenery_options_apply_cb);
00294 
00295     // OK button
00296     data->ok = new puOneShot (290, 20, 350, 40);
00297     data->ok->setLegend ("OK");
00298     data->ok->makeReturnDefault (true);
00299     data->ok->setStyle (PUSTYLE_SMALL_SHADED);
00300     data->ok->setCallback (scenery_options_ok_cb);
00301 
00302     // Cancel button
00303     data->cancel = new puOneShot (360, 20, 420, 40);
00304     data->cancel->setLegend ("Cancel");
00305     data->cancel->setStyle (PUSTYLE_SMALL_SHADED);
00306     data->cancel->setCallback (scenery_options_cancel_cb);
00307   }
00308   data->dialog->close ();
00309   data->dialog->reveal ();
00310 
00311   // Initialize max visibility slider
00312   float f = vis_to_slider (globals->terrainmgr->GetMaxVisibility ());
00313   data->visibility->setValue (f);
00314   scenery_options_visibility_cb (data->visibility);
00315 
00316   // Initialize high res range slider
00317   data->highres->setValue (globals->terrainmgr->GetHighDetailRange ());
00318   scenery_options_highres_cb (data->highres);
00319 
00320   data->medres->setValue (globals->terrainmgr->GetMediumDetailRange ());
00321   scenery_options_medres_cb (data->medres);
00322 }
00323 
SourceForge.net Logo Documentation generated by doxygen