/** Mouse Over Event */ void WorldMapControl::OnMouseOver(unsigned short x, unsigned short y) { WorldMap* worldmap = core->GetWorldMap(); lastCursor = IE_CURSOR_GRAB; if (MouseIsDown) { AdjustScrolling(lastMouseX-x, lastMouseY-y); } lastMouseX = x; lastMouseY = y; if (Value!=(ieDword) -1) { x =(ieWord) (x + ScrollX); y =(ieWord) (y + ScrollY); WMPAreaEntry *oldArea = Area; Area = NULL; unsigned int i; unsigned int ec = worldmap->GetEntryCount(); for (i=0;i<ec;i++) { WMPAreaEntry *ae = worldmap->GetEntry(i); if ( (ae->GetAreaStatus() & WMP_ENTRY_WALKABLE)!=WMP_ENTRY_WALKABLE) { continue; //invisible or inaccessible } Sprite2D *icon=ae->GetMapIcon(worldmap->bam); int h=0, w=0, iconx=0, icony=0; if (icon) { h=icon->Height; w=icon->Width; iconx = icon->XPos; icony = icon->YPos; core->GetVideoDriver()->FreeSprite( icon ); } if (ftext && ae->GetCaption()) { int tw = ftext->CalcStringWidth( (unsigned char*)ae->GetCaption() ) + 5; int th = ftext->maxHeight; if(h<th) h=th; if(w<tw) w=tw; } if (ae->X - iconx > x) continue; if (ae->X - iconx + w < x) continue; if (ae->Y - icony > y) continue; if (ae->Y - icony + h < y) continue; lastCursor = IE_CURSOR_NORMAL; Area=ae; if(oldArea!=ae) { RunEventHandler(WorldMapControlOnEnter); } break; } } Owner->Cursor = lastCursor; }
int WMPImporter::GetStoredFileSize(WorldMapArray *wmap, unsigned int index) { assert(!index || !wmap->IsSingle()); int headersize = 16; int WorldMapsOffset; WorldMapsCount = wmap->GetMapCount(); if (index>WorldMapsCount || index>1) return 0; WorldMapsOffset = headersize; if (index) { WorldMapsCount2 = 0; } else { WorldMapsCount1 = 0; } for (unsigned int i=index;i<WorldMapsCount; i++) { if (index) { WorldMapsCount2++; } else { WorldMapsCount1++; } headersize += 184; WorldMap *map = wmap->GetWorldMap(i); //Update the links and entries counts now, in case the worldmap has changed map->AreaEntriesCount = map->GetEntryCount(); headersize += map->AreaEntriesCount * 240; map->AreaLinksCount = map->GetLinkCount(); headersize += map->AreaLinksCount * 216; //put the first array into the first map //the rest into the second map if not single if (!wmap->IsSingle() && !index) { break; } } if (index) { WorldMapsOffset2 = WorldMapsOffset; } else { WorldMapsOffset1 = WorldMapsOffset; } return headersize; }
int WMPImporter::PutMap(DataStream *stream, WorldMapArray *wmap, unsigned int index) { unsigned int i; unsigned int WorldMapsOffset; unsigned int count; int ret; char filling[128]; assert(!index || !wmap->IsSingle()); if (index) { WorldMapsOffset = WorldMapsOffset2; count = WorldMapsCount2; } else { WorldMapsOffset = WorldMapsOffset1; count = WorldMapsCount1; } memset (filling,0,sizeof(filling)); ieDword AreaEntriesOffset = WorldMapsOffset + count * 184; ieDword AreaLinksOffset = AreaEntriesOffset; for (i=index;i<WorldMapsCount; i++) { WorldMap *map = wmap->GetWorldMap(i); AreaLinksOffset += map->GetEntryCount() * 240; if (!wmap->IsSingle() && !index) { break; } } //map headers for (i=index;i<WorldMapsCount; i++) { ieDword AreaEntriesCount, AreaLinksCount; WorldMap *map = wmap->GetWorldMap(i); AreaLinksCount = map->GetLinkCount(); AreaEntriesCount = map->GetEntryCount(); stream->WriteResRef( map->MapResRef ); stream->WriteDword( &map->Width ); stream->WriteDword( &map->Height ); stream->WriteDword( &map->MapNumber ); stream->WriteDword( &map->AreaName ); stream->WriteDword( &map->unknown1 ); stream->WriteDword( &map->unknown2 ); //??? stream->WriteDword( &AreaEntriesCount ); stream->WriteDword( &AreaEntriesOffset ); stream->WriteDword( &AreaLinksOffset ); stream->WriteDword( &AreaLinksCount ); stream->WriteResRef( map->MapIconResRef ); AreaEntriesOffset += AreaEntriesCount * 240; AreaLinksOffset += AreaLinksCount * 216; stream->Write( filling, 128); if (!wmap->IsSingle() && !index) { break; } } //area entries for (i=index;i<WorldMapsCount; i++) { WorldMap *map = wmap->GetWorldMap(i); ret = PutAreas( stream, map); if (ret) { return ret; } if (!wmap->IsSingle() && !index) { break; } } //links for (i=index;i<WorldMapsCount; i++) { WorldMap *map = wmap->GetWorldMap(i); ret = PutLinks( stream, map); if (ret) { return ret; } if (!wmap->IsSingle() && !index) { break; } } return 0; }
/** Draws the Control on the Output Display */ void WorldMapControl::Draw(unsigned short XWin, unsigned short YWin) { WorldMap* worldmap = core->GetWorldMap(); if (!Width || !Height) { return; } if(!Changed) return; Changed = false; Video* video = core->GetVideoDriver(); Region r( XWin+XPos, YWin+YPos, Width, Height ); Region clipbackup; video->GetClipRect(clipbackup); video->SetClipRect(&r); video->BlitSprite( worldmap->GetMapMOS(), MAP_TO_SCREENX(0), MAP_TO_SCREENY(0), true, &r ); unsigned int i; unsigned int ec = worldmap->GetEntryCount(); for(i=0;i<ec;i++) { WMPAreaEntry *m = worldmap->GetEntry(i); if (! (m->GetAreaStatus() & WMP_ENTRY_VISIBLE)) continue; int xOffs = MAP_TO_SCREENX(m->X); int yOffs = MAP_TO_SCREENY(m->Y); Sprite2D* icon = m->GetMapIcon(worldmap->bam); if( icon ) { if (m == Area) { Palette *pal = icon->GetPalette(); icon->SetPalette(pal_selected); video->BlitSprite( icon, xOffs, yOffs, true, &r ); icon->SetPalette(pal); pal->Release(); } else { video->BlitSprite( icon, xOffs, yOffs, true, &r ); } video->FreeSprite( icon ); } if (AnimPicture && !strnicmp(m->AreaResRef, currentArea, 8) ) { video->BlitSprite( AnimPicture, xOffs, yOffs, true, &r ); } } // Draw WMP entry labels if (ftext==NULL) { video->SetClipRect(&clipbackup); return; } for(i=0;i<ec;i++) { WMPAreaEntry *m = worldmap->GetEntry(i); if (! (m->GetAreaStatus() & WMP_ENTRY_VISIBLE)) continue; Sprite2D *icon=m->GetMapIcon(worldmap->bam); int h=0,w=0,xpos=0,ypos=0; if (icon) { h=icon->Height; w=icon->Width; xpos=icon->XPos; ypos=icon->YPos; video->FreeSprite( icon ); } Region r2 = Region( MAP_TO_SCREENX(m->X-xpos), MAP_TO_SCREENY(m->Y-ypos), w, h ); if (!m->GetCaption()) continue; int tw = ftext->CalcStringWidth( (unsigned char*)m->GetCaption() ) + 5; int th = ftext->maxHeight; Palette* text_pal = pal_normal; if (Area == m) { text_pal = pal_selected; } else { if (! (m->GetAreaStatus() & WMP_ENTRY_VISITED)) { text_pal = pal_notvisited; } } ftext->Print( Region( r2.x + (r2.w - tw)/2, r2.y + r2.h, tw, th ), ( const unsigned char * ) m->GetCaption(), text_pal, 0, true ); } video->SetClipRect(&clipbackup); }