00001
00009 #define ALLOW_ACCESS_TO_INTERNALS_OF_WINDOWS
00010 #include <PalmOS.h>
00011 #include <Window.h>
00012 #include <Rect.h>
00013 #include <Progress.h>
00014 #include <simcity.h>
00015 #include <simcity_resconsts.h>
00016 #include <locking.h>
00017 #include <logging.h>
00018 #include <ui.h>
00019 #include <map.h>
00020 #include <globals.h>
00021 #include <drawing.h>
00022 #include <resCompat.h>
00023 #include <palmutils.h>
00024 #include <sections.h>
00025
00027 typedef enum e_map_type {
00028 mt_fullpaint = 1,
00029 mt_overlay
00030 } map_type;
00031
00033 typedef enum e_map_entries {
00034 me_basemap = 0,
00035 me_end
00036 } map_entry;
00037
00039 typedef struct scr_map {
00040 WinHandle handle;
00041 map_type type;
00042 } scr_map_t;
00043
00044 static void DrawMap(void) MAP_SECTION;
00045 static void RenderMaps(void) MAP_SECTION;
00046 static void freemaps(void) MAP_SECTION;
00047 static void AddMap(WinHandle handle, map_type type, map_entry code) MAP_SECTION;
00048
00050 map_entry currmap;
00052 scr_map_t *themaps;
00053
00054 static const int StartX = 1;
00055 static const int StartY = 17;
00056
00063 static void
00064 AddMap(WinHandle handle, map_type type, map_entry code)
00065 {
00066 if (themaps == NULL) {
00067 themaps = (scr_map_t *)MemPtrNew((int)me_end *
00068 sizeof(scr_map_t));
00069 }
00070 themaps[code].handle = handle;
00071 themaps[code].type = type;
00072 }
00073
00075 static void
00076 freemaps(void)
00077 {
00078 map_entry entry = me_basemap;
00079
00080 if (themaps == NULL) return;
00081 while (entry != me_end) {
00082 WinDeleteWindow(themaps[entry].handle, false);
00083 entry++;
00084 }
00085 MemPtrFree(themaps);
00086 themaps = NULL;
00087 }
00088
00092 Boolean
00093 hMap(EventPtr event)
00094 {
00095 FormPtr form;
00096 Boolean handled = false;
00097
00098 switch (event->eType) {
00099 case penDownEvent:
00100 if (event->screenX >= StartX &&
00101 event->screenX <= (getMapWidth() + StartX) &&
00102 event->screenY >= StartY &&
00103 event->screenY <= (getMapHeight() + StartY)) {
00104 UInt16 x = (UInt16)(event->screenX - StartX);
00105 UInt16 y = (UInt16)(event->screenY - StartY);
00106 Goto(x, y, true);
00107 FrmGotoForm(formID_pocketCity);
00108 handled = true;
00109 }
00110
00111 break;
00112 case frmOpenEvent:
00113 PauseGame();
00114 WriteLog("map opened\n");
00115 form = FrmGetActiveForm();
00116 SetSilkResizable(form, true);
00117 collapseMove(form, CM_DEFAULT, NULL, NULL);
00118 FrmDrawForm(form);
00119 RenderMaps();
00120 DrawMap();
00121 handled = true;
00122 break;
00123 case frmCloseEvent:
00124 freemaps();
00125 SetSilkResizable(NULL, false);
00126 WriteLog("map closed\n");
00127 break;
00128 case keyDownEvent:
00129 switch (event->data.keyDown.chr) {
00130 case vchrFind:
00131 case vchrLaunch:
00132 FrmGotoForm(formID_pocketCity);
00133 handled = true;
00134 break;
00135 }
00136 break;
00137 case menuEvent:
00138 switch (event->data.menu.itemID) {
00139 case menuitemID_MapBack:
00140 FrmGotoForm(formID_pocketCity);
00141 handled = true;
00142 break;
00143 }
00144 break;
00145 case popSelectEvent:
00146 if (event->data.popSelect.controlID == listID_shifter_popup) {
00147 UIGotoForm(event->data.popSelect.selection);
00148 handled = true;
00149 }
00150 break;
00151 #if defined(HRSUPPORT)
00152 case winDisplayChangedEvent:
00153 #if defined(SONY_CLIE)
00154 case vchrSilkResize:
00155 #endif
00156 form = FrmGetActiveForm();
00157 if (collapseMove(form, CM_DEFAULT, NULL, NULL)) {
00158 FrmDrawForm(form);
00159 DrawMap();
00160 }
00161 handled = true;
00162 break;
00163 #endif
00164 default:
00165 break;
00166 }
00167
00168 return (handled);
00169 }
00170
00174 static void
00175 DrawMap(void)
00176 {
00177 const RectangleType rect = {
00178 { StartX, StartY }, { getMapWidth(), getMapHeight() }
00179 };
00180 const RectangleType grect = {
00181 { 0, 0 }, { getMapWidth(), getMapHeight() }
00182 };
00183
00184 map_entry entry = currmap;
00185 WinHandle swh = WinGetDrawWindow();
00186
00187 WinDrawRectangleFrame(1, &rect);
00188
00189 while(themaps[entry].type != mt_fullpaint) {
00190 entry--;
00191 }
00192 WinCopyRectangle(themaps[entry].handle, swh,
00193 (RectangleType *)&grect, StartX, StartY, winPaint);
00194 if (entry != currmap) {
00195
00196 WinCopyRectangle(themaps[currmap].handle, swh,
00197 (RectangleType *)&grect, StartX, StartY, winErase);
00198 WinCopyRectangle(themaps[currmap].handle, swh,
00199 (RectangleType *)&grect, StartX, StartY, winInvert);
00200 }
00201 }
00202
00206 static void
00207 RenderMaps(void)
00208 {
00209 PointType posits = { 0, 0 };
00210 static IndexedColorType entries[5] = { 0, 1, 2, 3, 4 };
00211 static int inited = 0;
00212 IndexedColorType cc = 1;
00213 WinHandle wh;
00214 WinHandle swh;
00215 Err e;
00216 UInt8 *addr = NULL;
00217 int shift = 0;
00218 UInt32 depth;
00219 char mapRenderString[80];
00220 char perc[5];
00221
00222 currmap = me_basemap;
00223
00224 ResGetString(si_maprender, mapRenderString, 79);
00225
00226 WinPaintChars(mapRenderString, (Int16)StrLen(mapRenderString), 20, 20);
00227 StrPrintF(perc, "%d%%", 0);
00228 WinPaintChars(perc, (Int16)StrLen(perc), 20, 40);
00229
00230 wh = WinCreateOffscreenWindow(getMapWidth(), getMapHeight(),
00231 screenFormat, &e);
00232 if (e != errNone) {
00233 return;
00234 }
00235
00236 LockZone(lz_world);
00237
00238 swh = WinSetDrawWindow(wh);
00239 WinSetDrawWindow(swh);
00240
00241
00242
00243 if (!Is35ROM()) {
00244
00245 addr = (UInt8 *)wh->displayAddrV20;
00246 }
00247 depth = getDepth();
00248
00249
00250
00251
00252 if (inited == 0) {
00253 inited++;
00254 if (depth >= 4) {
00255
00256 RGBColorType rg = { 0, 0, 0, 255 };
00257 entries[0] = WinRGBToIndex(&rg);
00258
00259 rg.g = 255; rg.b = 0;
00260 entries[1] = WinRGBToIndex(&rg);
00261
00262 rg.g = 102; rg.b = 102;
00263 entries[2] = WinRGBToIndex(&rg);
00264
00265 rg.r = 242; rg.g = 103; rg.b = 57;
00266 entries[3] = WinRGBToIndex(&rg);
00267
00268
00269 rg.r = 99; rg.g = 43; rg.b = 170;
00270 entries[4] = WinRGBToIndex(&rg);
00271 inited++;
00272 }
00273 }
00274
00275 for (posits.y = 0; posits.y < getMapHeight(); posits.y++) {
00276 if (Is35ROM() && (posits.y & 0xF) == 0xF) {
00277 int prc = (int)(( (long)posits.y * 100 ) /
00278 getMapHeight());
00279 StrPrintF(perc, "%d%%", prc);
00280 WinPaintChars(perc, (Int16)StrLen(perc), 20, 40);
00281 }
00282 for (posits.x = 0; posits.x < getMapWidth(); posits.x++) {
00283 int wt = getWorld(WORLDPOS(posits.x, posits.y));
00284 if (inited >= 1) {
00285 switch (wt) {
00286 case Z_DIRT:
00287 cc = 0;
00288 break;
00289 case Z_FAKEWATER:
00290 case Z_REALWATER:
00291 cc = entries[0];
00292 break;
00293 case Z_RESIDENTIAL_SLUM:
00294 cc = entries[1];
00295 break;
00296 case Z_COMMERCIAL_SLUM:
00297 cc = entries[2];
00298 break;
00299 case Z_INDUSTRIAL_SLUM:
00300 cc = entries[3];
00301 break;
00302 default:
00303 cc = entries[4];
00304 break;
00305 }
00306 }
00307
00308 if (addr != NULL) {
00309 switch (depth) {
00310 case 1:
00311 if (wt == Z_DIRT) {
00312 *addr &=
00313 (UInt8)~(1U << shift);
00314 } else {
00315 *addr |=
00316 (UInt8)(1U << shift);
00317 }
00318 shift++;
00319 if ((shift > 8)) {
00320 shift = 0;
00321 addr++;
00322 }
00323 break;
00324 case 4:
00325 if (posits.x & 0x1) {
00326 *addr &= (UInt8)0xf0;
00327 *addr |= cc;
00328 addr++;
00329 } else {
00330 *addr &= (UInt8)0x0f;
00331 *addr |= (UInt8)(cc << 4);
00332 }
00333 break;
00334 default:
00335 *addr++ = (UInt8)cc;
00336 break;
00337 }
00338 } else {
00339 IndexedColorType color;
00340 swh = WinSetDrawWindow(wh);
00341 color = WinSetForeColor(cc);
00342 WinDrawPixel(posits.x, posits.y);
00343 WinSetForeColor(color);
00344 WinSetDrawWindow(swh);
00345 }
00346 }
00347 }
00348 AddMap(wh, mt_fullpaint, me_basemap);
00349 UnlockZone(lz_world);
00350 }
00351
00352 void
00353 UIUpdateMap(UInt16 xpos __attribute__((unused)),
00354 UInt16 ypos __attribute__((unused)))
00355 {
00356 }
00357
00358 void
00359 UIMapResize(void)
00360 {
00361
00362 }
00363
00364 void
00365 UIPaintMapStatus(UInt16 xpos __attribute__((unused)),
00366 UInt16 ypos __attribute__((unused)),
00367 welem_t world __attribute__((unused)),
00368 selem_t status __attribute__((unused)))
00369 {
00370
00371 }
00372
00373 void
00374 UIPaintMapField(UInt16 xpos __attribute__((unused)),
00375 UInt16 ypos __attribute__((unused)),
00376 welem_t world __attribute__((unused)))
00377 {
00378
00379 }
00380
00381