示例#1
0
/** 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;
}
示例#2
0
int WMPImporter::PutAreas(DataStream *stream, WorldMap *wmap)
{
	char filling[128];
	ieDword tmpDword;

	memset (filling,0,sizeof(filling));
	for(unsigned i=0;i<wmap->AreaEntriesCount;i++) {
		WMPAreaEntry *ae = wmap->GetEntry(i);

		stream->WriteResRef( ae->AreaName );
		stream->WriteResRef( ae->AreaResRef );
		stream->Write( ae->AreaLongName, 32 );
		tmpDword = ae->GetAreaStatus();
		stream->WriteDword( &tmpDword );
		stream->WriteDword( &ae->IconSeq );
		stream->WriteDword( &ae->X );
		stream->WriteDword( &ae->Y );
		stream->WriteDword( &ae->LocCaptionName );
		stream->WriteDword( &ae->LocTooltipName );
		stream->WriteResRef( ae->LoadScreenResRef );

		for (unsigned int dir = 0; dir < 4; dir++) {
			stream->WriteDword( &ae->AreaLinksIndex[dir] );
			stream->WriteDword( &ae->AreaLinksCount[dir] );
		}
		stream->Write(filling,128);
	}
	return 0;
}
示例#3
0
//adds a temporary AreaEntry to the world map
//this entry has two links for each direction, leading to the two areas
//we were travelling between when using the supplied link
void WorldMap::SetEncounterArea(const ieResRef area, WMPAreaLink *link) {
	unsigned int i;
	if (GetArea(area, i)) {
		return;
	}

	//determine the area the link came from
	unsigned int j, cnt = GetLinkCount();
	for (j = 0; j < cnt; ++j) {
		if (link == area_links[j]) {
			break;
		}
	}

	i = WhoseLinkAmI(j);
	if (i == (unsigned int) -1) {
		Log(ERROR, "WorldMap", "Could not add encounter area");
		return;
	}

	WMPAreaEntry *ae = GetNewAreaEntry();
	ae->SetAreaStatus(WMP_ENTRY_VISIBLE|WMP_ENTRY_ACCESSIBLE|WMP_ENTRY_VISITED, BM_SET);
	CopyResRef(ae->AreaName, area);
	CopyResRef(ae->AreaResRef, area);
	ae->LocCaptionName = -1;
	ae->LocTooltipName = -1;
	ae->IconSeq = -1;
	CopyResRef(ae->LoadScreenResRef, "");

	WMPAreaEntry *src = area_entries[i];
	WMPAreaEntry *dest = area_entries[link->AreaIndex];
	ae->X = src->X + (int) (dest->X - src->X) / 2;
	ae->Y = src->Y + (int) (dest->Y - src->Y) / 2;

	//setup the area links
	WMPAreaLink *ldest = new WMPAreaLink();
	memcpy(ldest, link, sizeof(WMPAreaLink));
	ldest->DistanceScale /= 2;
	ldest->EncounterChance = 0;

	link = GetLink(dest->AreaName, src->AreaName);
	if (!link) {
		Log(ERROR, "WorldMap", "Could not find link from %s to %s",
			dest->AreaName, src->AreaName);
		delete ae;
		delete ldest;
		return;
	}

	WMPAreaLink *lsrc = new WMPAreaLink();
	memcpy(lsrc, link, sizeof(WMPAreaLink));
	lsrc->DistanceScale /= 2;
	lsrc->EncounterChance = 0;

	unsigned int idx = area_links.size();
	AddAreaLink(ldest);
	AddAreaLink(lsrc);

	for (i = 0; i < 4; ++i) {
		ae->AreaLinksCount[i] = 2;
		ae->AreaLinksIndex[i] = idx;
	}
	
	encounterArea = area_entries.size();
	AddAreaEntry(ae);
}
示例#4
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);
}