00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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 char *monthlist[] =
00033 {
00034 "December",
00035 "November",
00036 "October",
00037 "September",
00038 "August",
00039 "July",
00040 "June",
00041 "May",
00042 "April",
00043 "March",
00044 "February",
00045 "January",
00046 NULL
00047 };
00048
00049
00050 typedef struct {
00051 puDialogBox* dialog;
00052 puFrame* frame;
00053 puText* title;
00054 puInput* year;
00055 puSelectBox* month;
00056 puInput* date;
00057 puOneShot* dawn;
00058 puOneShot* day;
00059 puOneShot* dusk;
00060 puOneShot* night;
00061 puInput* hr;
00062 puInput* min;
00063 puText* tzLabel;
00064 puInput* tz;
00065 puOneShot* ok;
00066 puOneShot* cancel;
00067 } SDateTimeDialogData;
00068
00069 SDateTime datetime;
00070 float tz;
00071
00072 static SDateTimeDialogData *dt = NULL;
00073
00074
00075 void date_time_dlg_kill (void)
00076 {
00077 if (dt == NULL) return;
00078
00079
00080 delete dt->dialog;
00081
00082
00083 delete dt;
00084 dt = NULL;
00085 }
00086
00087 static void date_time_dlg_sync (void)
00088 {
00089 if (dt == NULL) return;
00090
00091
00092 if (datetime.date.year < 2000) datetime.date.year = 2000;
00093 if (datetime.date.year > 2099) datetime.date.year = 2099;
00094
00095
00096 unsigned int daysInMonth = CTimeManager::DaysInMonth (datetime.date.month, datetime.date.year);
00097 if (datetime.date.day < 1) datetime.date.day = 1;
00098 if (datetime.date.day > daysInMonth) datetime.date.day = daysInMonth;
00099
00100
00101 if (datetime.time.hour < 0) datetime.time.hour = 0;
00102 if (datetime.time.hour > 23) datetime.time.hour = 23;
00103
00104
00105 if (datetime.time.minute < 0) datetime.time.minute = 0;
00106 if (datetime.time.minute > 59) datetime.time.minute = 59;
00107
00108
00109 if (tz < -12) tz = -12;
00110 if (tz > 12) tz = 12;
00111
00112
00113
00114
00115 dt->year->setValue ((int)datetime.date.year);
00116 dt->date->setValue ((int)datetime.date.day);
00117 dt->hr->setValue ((int)datetime.time.hour);
00118 dt->min->setValue ((int)datetime.time.minute);
00119 dt->tz->setValue (tz);
00120
00121
00122 char debug[80];
00123 sprintf (debug, "Date/Time %04d/%02d%02d (%d) Time=%02d:%02d TZ=%3.1f",
00124 datetime.date.year, datetime.date.month, datetime.date.day, daysInMonth,
00125 datetime.time.hour, datetime.time.minute, tz);
00126 DrawNoticeToUser (debug, 2);
00127 }
00128
00129 static void date_time_ok_cb (puObject* obj)
00130 {
00131
00132 globals->timemgr->SetTimeZoneOffset (tz);
00133 globals->timemgr->SetLocalDateTime (datetime);
00134
00135
00136 date_time_dlg_kill ();
00137 }
00138
00139 static void date_time_cancel_cb (puObject* obj)
00140 {
00141
00142 date_time_dlg_kill ();
00143 }
00144
00145 static void date_time_btn_dawn_cb (puObject* obj)
00146 {
00147
00148 datetime.time.hour = 6;
00149 datetime.time.minute = 0;
00150
00151 date_time_dlg_sync ();
00152 }
00153
00154 static void date_time_btn_day_cb (puObject* obj)
00155 {
00156
00157 datetime.time.hour = 12;
00158 datetime.time.minute = 0;
00159
00160 date_time_dlg_sync ();
00161 }
00162
00163 static void date_time_btn_dusk_cb (puObject* obj)
00164 {
00165
00166 datetime.time.hour = 18;
00167 datetime.time.minute = 0;
00168
00169 date_time_dlg_sync ();
00170 }
00171
00172 static void date_time_btn_night_cb (puObject* obj)
00173 {
00174
00175 datetime.time.hour = 0;
00176 datetime.time.minute = 0;
00177
00178 date_time_dlg_sync ();
00179 }
00180
00181 static void date_time_year_cb (puObject* obj)
00182 {
00183 datetime.date.year = obj->getIntegerValue ();
00184
00185 date_time_dlg_sync ();
00186 }
00187
00188 static void date_time_month_cb (puObject* obj)
00189 {
00190 puSelectBox *sb = (puSelectBox*) obj;
00191
00192
00193 datetime.date.month = 12 - sb->getCurrentItem();
00194
00195 date_time_dlg_sync ();
00196 }
00197
00198 static void date_time_day_cb (puObject* obj)
00199 {
00200 datetime.date.day = obj->getIntegerValue();
00201
00202 date_time_dlg_sync ();
00203 }
00204
00205 static void date_time_hour_cb (puObject* obj)
00206 {
00207 datetime.time.hour = obj->getIntegerValue ();
00208
00209 date_time_dlg_sync ();
00210 }
00211
00212 static void date_time_minute_cb (puObject* obj)
00213 {
00214 datetime.time.minute = obj->getIntegerValue();
00215
00216 date_time_dlg_sync ();
00217 }
00218
00219 static void date_time_tz_cb (puObject* obj)
00220 {
00221 tz = obj->getFloatValue ();
00222
00223 date_time_dlg_sync ();
00224 }
00225
00226 void date_time_dlg_create (void)
00227 {
00228 if (dt != NULL) return;
00229
00230 datetime = globals->timemgr->GetLocalDateTime ();
00231 tz = globals->timemgr->GetTimeZoneOffset ();
00232
00233
00234 dt = new SDateTimeDialogData;
00235
00236
00237 dt->dialog = new puDialogBox (20, 300);
00238 {
00239
00240 dt->frame = new puFrame (0, 0, 400, 250);
00241
00242 dt->title = new puText (10, 210);
00243 dt->title->setLabel ("Select Date/Time:");
00244
00245
00246 dt->year = new puInput (100, 150, 170, 180);
00247 dt->year->setLabel ("Year");
00248 dt->year->setLabelPlace (PUPLACE_TOP_CENTERED);
00249 dt->year->setStyle (PUSTYLE_BOXED);
00250 dt->year->setCallback (date_time_year_cb);
00251
00252 dt->month = new puSelectBox (180, 150, 300, 180, monthlist);
00253 dt->month->setLabel ("Month");
00254 dt->month->setLabelPlace (PUPLACE_TOP_CENTERED);
00255 dt->month->setStyle (PUSTYLE_BOXED);
00256 dt->month->setCallback (date_time_month_cb);
00257
00258 dt->date = new puInput (310, 150, 380, 180);
00259 dt->date->setLabel ("Day");
00260 dt->date->setLabelPlace (PUPLACE_TOP_CENTERED);
00261 dt->date->setStyle (PUSTYLE_BOXED);
00262 dt->date->setCallback (date_time_day_cb);
00263
00264
00265 dt->dawn = new puOneShot (10, 110, 80, 130);
00266 dt->dawn->setLegend ("Dawn");
00267 dt->dawn->setStyle (PUSTYLE_SMALL_SHADED);
00268 dt->dawn->setCallback (date_time_btn_dawn_cb);
00269
00270 dt->day = new puOneShot (10, 90, 80, 110);
00271 dt->day->setLegend ("Day");
00272 dt->day->setStyle (PUSTYLE_SMALL_SHADED);
00273 dt->day->setCallback (date_time_btn_day_cb);
00274
00275 dt->dusk = new puOneShot (10, 70, 80, 90);
00276 dt->dusk->setLegend ("Dusk");
00277 dt->dusk->setStyle (PUSTYLE_SMALL_SHADED);
00278 dt->dusk->setCallback (date_time_btn_dusk_cb);
00279
00280 dt->night = new puOneShot (10, 50, 80, 70);
00281 dt->night->setLegend ("Night");
00282 dt->night->setStyle (PUSTYLE_SMALL_SHADED);
00283 dt->night->setCallback (date_time_btn_night_cb);
00284
00285 dt->hr = new puInput (100, 80, 160, 100);
00286 dt->hr->setLabel ("Hour");
00287 dt->hr->setLabelPlace (PUPLACE_TOP_CENTERED);
00288 dt->hr->setStyle (PUSTYLE_BOXED);
00289 dt->hr->setCallback (date_time_hour_cb);
00290
00291 dt->min = new puInput (170, 80, 230, 100);
00292 dt->min->setLabel ("Min");
00293 dt->min->setLabelPlace (PUPLACE_TOP_CENTERED);
00294 dt->min->setStyle (PUSTYLE_BOXED);
00295 dt->min->setCallback (date_time_minute_cb);
00296
00297 dt->tzLabel = new puText (280, 100);
00298 dt->tzLabel->setLabel ("TZ Offset");
00299
00300 dt->tz = new puInput (280, 80, 320, 100);
00301 dt->tz->setLabel ("Hrs");
00302 dt->tz->setLabelPlace (PUPLACE_RIGHT);
00303 dt->tz->setStyle (PUSTYLE_BOXED);
00304 dt->tz->setCallback (date_time_tz_cb);
00305
00306
00307 dt->ok = new puOneShot (250, 20, 310, 40);
00308 dt->ok->setLegend ("OK");
00309 dt->ok->makeReturnDefault (true);
00310 dt->ok->setStyle (PUSTYLE_SMALL_SHADED);
00311 dt->ok->setCallback (date_time_ok_cb);
00312
00313
00314 dt->cancel = new puOneShot (320, 20, 380, 40);
00315 dt->cancel->setLegend ("Cancel");
00316 dt->cancel->setCallback (date_time_cancel_cb);
00317 dt->cancel->setStyle (PUSTYLE_SMALL_SHADED);
00318
00319
00320 dt->month->setCurrentItem (12 - datetime.date.month);
00321 date_time_dlg_sync ();
00322 }
00323 dt->dialog->close ();
00324 dt->dialog->reveal ();
00325 }
00326