2012-03-19 11:44:39 +00:00
|
|
|
// * This file is part of the COLOBOT source code
|
2012-03-09 16:08:05 +00:00
|
|
|
// * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
|
|
|
|
// *
|
|
|
|
// * This program is free software: you can redistribute it and/or modify
|
|
|
|
// * it under the terms of the GNU General Public License as published by
|
|
|
|
// * the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// * (at your option) any later version.
|
|
|
|
// *
|
|
|
|
// * This program is distributed in the hope that it will be useful,
|
|
|
|
// * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// * GNU General Public License for more details.
|
|
|
|
// *
|
|
|
|
// * You should have received a copy of the GNU General Public License
|
2012-03-22 19:34:46 +00:00
|
|
|
// * along with this program. If not, see http://www.gnu.org/licenses/.
|
|
|
|
|
|
|
|
// mainmap.cpp
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
#define STRICT
|
|
|
|
#define D3D_OVERLOADS
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <d3d.h>
|
|
|
|
|
2012-06-09 22:18:08 +00:00
|
|
|
#include "common/struct.h"
|
|
|
|
#include "graphics/d3d/d3dengine.h"
|
|
|
|
#include "math/old/d3dmath.h"
|
|
|
|
#include "common/global.h"
|
|
|
|
#include "common/event.h"
|
|
|
|
#include "common/iman.h"
|
|
|
|
#include "ui/interface.h"
|
|
|
|
#include "ui/map.h"
|
|
|
|
#include "ui/image.h"
|
|
|
|
#include "ui/group.h"
|
|
|
|
#include "ui/slider.h"
|
|
|
|
#include "ui/scroll.h"
|
|
|
|
#include "ui/window.h"
|
|
|
|
#include "ui/mainmap.h"
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2012-06-11 15:28:27 +00:00
|
|
|
const float ZOOM_MIN = 1.0f;
|
|
|
|
const float ZOOM_MAX = 16.0f;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2012-03-22 19:34:46 +00:00
|
|
|
// Constructor of the application card.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
CMainMap::CMainMap(CInstanceManager* iMan)
|
|
|
|
{
|
|
|
|
m_iMan = iMan;
|
|
|
|
m_iMan->AddInstance(CLASS_MAP, this);
|
|
|
|
|
|
|
|
m_interface = (CInterface*)m_iMan->SearchInstance(CLASS_INTERFACE);
|
|
|
|
m_event = (CEvent*)m_iMan->SearchInstance(CLASS_EVENT);
|
|
|
|
m_engine = (CD3DEngine*)m_iMan->SearchInstance(CLASS_ENGINE);
|
|
|
|
|
|
|
|
m_mapMode = 1;
|
2012-06-10 13:28:12 +00:00
|
|
|
m_bFixImage = false;
|
2012-03-08 18:32:05 +00:00
|
|
|
}
|
|
|
|
|
2012-03-22 19:34:46 +00:00
|
|
|
// Destructor of the application card.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
CMainMap::~CMainMap()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-22 19:34:46 +00:00
|
|
|
// Created the mini-map and the corresponding buttons.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
void CMainMap::CreateMap()
|
|
|
|
{
|
|
|
|
CWindow* pw;
|
|
|
|
FPOINT pos, dim;
|
|
|
|
|
|
|
|
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW1);
|
|
|
|
if ( pw == 0 )
|
|
|
|
{
|
|
|
|
pos.x = 0.0f;
|
|
|
|
pos.y = 0.0f;
|
|
|
|
dim.x = 0.0f;
|
|
|
|
dim.y = 0.0f;
|
|
|
|
pw = m_interface->CreateWindows(pos, dim, 10, EVENT_WINDOW1);
|
|
|
|
}
|
|
|
|
|
|
|
|
dim.x = 10.0f/640.0f;
|
|
|
|
dim.y = 10.0f/480.0f;
|
|
|
|
pos.x = 10.0f/640.0f;
|
|
|
|
pos.y = 10.0f/480.0f;
|
|
|
|
pw->CreateMap (pos, dim, 2, EVENT_OBJECT_MAP);
|
|
|
|
pw->CreateSlider(pos, dim, 0, EVENT_OBJECT_MAPZOOM);
|
|
|
|
|
|
|
|
DimMap();
|
|
|
|
}
|
|
|
|
|
2012-03-22 19:34:46 +00:00
|
|
|
// Indicates whether the mini-map should display a still image.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
void CMainMap::SetFixImage(char *filename)
|
|
|
|
{
|
|
|
|
CWindow* pw;
|
|
|
|
CMap* pm;
|
|
|
|
|
|
|
|
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW1);
|
|
|
|
if ( pw == 0 ) return;
|
|
|
|
|
|
|
|
pm = (CMap*)pw->SearchControl(EVENT_OBJECT_MAP);
|
|
|
|
if ( pm == 0 ) return;
|
|
|
|
|
|
|
|
pw->DeleteControl(EVENT_OBJECT_MAPZOOM);
|
2012-06-10 13:28:12 +00:00
|
|
|
m_bFixImage = true;
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
pm->SetFixImage(filename);
|
|
|
|
}
|
|
|
|
|
2012-03-22 19:34:46 +00:00
|
|
|
// Choosing colors of soil and water for the mini-map.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
void CMainMap::FloorColorMap(D3DCOLORVALUE floor, D3DCOLORVALUE water)
|
|
|
|
{
|
|
|
|
CWindow* pw;
|
|
|
|
CMap* pm;
|
|
|
|
|
|
|
|
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW1);
|
|
|
|
if ( pw == 0 ) return;
|
|
|
|
|
|
|
|
pm = (CMap*)pw->SearchControl(EVENT_OBJECT_MAP);
|
|
|
|
if ( pm != 0 )
|
|
|
|
{
|
|
|
|
pm->SetFloorColor(floor);
|
|
|
|
pm->SetWaterColor(water);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-22 19:34:46 +00:00
|
|
|
// Shows or hides the minimap.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
void CMainMap::ShowMap(bool bShow)
|
2012-03-08 18:32:05 +00:00
|
|
|
{
|
|
|
|
CWindow* pw;
|
|
|
|
CMap* pm;
|
|
|
|
CSlider* ps;
|
|
|
|
|
|
|
|
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW1);
|
|
|
|
if ( pw == 0 ) return;
|
|
|
|
|
|
|
|
if ( bShow )
|
|
|
|
{
|
|
|
|
DimMap();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pm = (CMap*)pw->SearchControl(EVENT_OBJECT_MAP);
|
|
|
|
if ( pm != 0 )
|
|
|
|
{
|
|
|
|
pm->ClearState(STATE_VISIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
ps = (CSlider*)pw->SearchControl(EVENT_OBJECT_MAPZOOM);
|
|
|
|
if ( ps != 0 )
|
|
|
|
{
|
|
|
|
ps->ClearState(STATE_VISIBLE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-22 19:34:46 +00:00
|
|
|
// Dimensions of the mini-map.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
void CMainMap::DimMap()
|
|
|
|
{
|
|
|
|
CWindow* pw;
|
|
|
|
CMap* pm;
|
|
|
|
CSlider* ps;
|
|
|
|
FPOINT pos, dim;
|
|
|
|
float value;
|
|
|
|
|
|
|
|
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW1);
|
|
|
|
if ( pw == 0 ) return;
|
|
|
|
pm = (CMap*)pw->SearchControl(EVENT_OBJECT_MAP);
|
|
|
|
if ( pm == 0 ) return;
|
|
|
|
|
|
|
|
pm->SetState(STATE_VISIBLE, (m_mapMode != 0));
|
|
|
|
|
|
|
|
dim.x = 100.0f/640.0f;
|
|
|
|
dim.y = 100.0f/480.0f;
|
|
|
|
pos.x = 540.0f/640.0f;
|
|
|
|
pos.y = 0.0f/480.0f;
|
|
|
|
pm->SetPos(pos);
|
|
|
|
pm->SetDim(dim);
|
|
|
|
|
|
|
|
ps = (CSlider*)pw->SearchControl(EVENT_OBJECT_MAPZOOM);
|
|
|
|
if ( ps != 0 )
|
|
|
|
{
|
|
|
|
ps->SetState(STATE_VISIBLE, (m_mapMode != 0));
|
|
|
|
|
|
|
|
dim.x = SCROLL_WIDTH;
|
|
|
|
dim.y = 66.0f/480.0f;
|
|
|
|
pos.x = 523.0f/640.0f;
|
|
|
|
pos.y = 3.0f/480.0f;
|
|
|
|
ps->SetPos(pos);
|
|
|
|
ps->SetDim(dim);
|
|
|
|
|
|
|
|
value = pm->RetZoom();
|
|
|
|
value = (value-ZOOM_MIN)/(ZOOM_MAX-ZOOM_MIN);
|
|
|
|
value = powf(value, 0.5f);
|
|
|
|
ps->SetVisibleValue(value);
|
|
|
|
ps->SetArrowStep(0.2f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-22 19:34:46 +00:00
|
|
|
// Returns the current zoom of the minimap.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
float CMainMap::RetZoomMap()
|
|
|
|
{
|
|
|
|
CWindow* pw;
|
|
|
|
CMap* pm;
|
|
|
|
CSlider* ps;
|
|
|
|
|
2012-06-08 18:30:57 +00:00
|
|
|
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW1);
|
2012-03-08 18:32:05 +00:00
|
|
|
if ( pw == 0 ) return ZOOM_MIN;
|
|
|
|
|
|
|
|
pm = (CMap*)pw->SearchControl(EVENT_OBJECT_MAP);
|
|
|
|
if ( pm == 0 ) return ZOOM_MIN;
|
|
|
|
|
|
|
|
ps = (CSlider*)pw->SearchControl(EVENT_OBJECT_MAPZOOM);
|
|
|
|
if ( ps == 0 ) return ZOOM_MIN;
|
|
|
|
|
|
|
|
return pm->RetZoom();
|
|
|
|
}
|
|
|
|
|
2012-03-22 19:34:46 +00:00
|
|
|
// Zoom the mini-map of any factor.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
void CMainMap::ZoomMap(float zoom)
|
|
|
|
{
|
|
|
|
CWindow* pw;
|
|
|
|
CMap* pm;
|
|
|
|
CSlider* ps;
|
|
|
|
|
|
|
|
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW1);
|
|
|
|
if ( pw == 0 ) return;
|
|
|
|
pm = (CMap*)pw->SearchControl(EVENT_OBJECT_MAP);
|
|
|
|
if ( pm == 0 ) return;
|
|
|
|
|
|
|
|
ps = (CSlider*)pw->SearchControl(EVENT_OBJECT_MAPZOOM);
|
|
|
|
if ( ps == 0 ) return;
|
|
|
|
|
|
|
|
if ( zoom < ZOOM_MIN ) zoom = ZOOM_MIN;
|
|
|
|
if ( zoom > ZOOM_MAX ) zoom = ZOOM_MAX;
|
|
|
|
pm->SetZoom(zoom);
|
|
|
|
|
|
|
|
DimMap();
|
|
|
|
}
|
|
|
|
|
2012-03-22 19:34:46 +00:00
|
|
|
// The mini-map zoom depending on the slider.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
void CMainMap::ZoomMap()
|
|
|
|
{
|
|
|
|
CWindow* pw;
|
|
|
|
CMap* pm;
|
|
|
|
CSlider* ps;
|
|
|
|
float zoom;
|
|
|
|
|
|
|
|
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW1);
|
|
|
|
if ( pw == 0 ) return;
|
|
|
|
pm = (CMap*)pw->SearchControl(EVENT_OBJECT_MAP);
|
|
|
|
if ( pm == 0 ) return;
|
|
|
|
|
|
|
|
ps = (CSlider*)pw->SearchControl(EVENT_OBJECT_MAPZOOM);
|
|
|
|
if ( ps == 0 ) return;
|
|
|
|
|
|
|
|
zoom = ps->RetVisibleValue();
|
|
|
|
zoom = powf(zoom, 2.0f);
|
|
|
|
zoom = ZOOM_MIN+zoom*(ZOOM_MAX-ZOOM_MIN);
|
|
|
|
pm->SetZoom(zoom);
|
|
|
|
|
|
|
|
DimMap();
|
|
|
|
}
|
|
|
|
|
2012-03-22 19:34:46 +00:00
|
|
|
// Enables or disables the card.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
void CMainMap::MapEnable(bool bEnable)
|
2012-03-08 18:32:05 +00:00
|
|
|
{
|
|
|
|
CWindow* pw;
|
|
|
|
CMap* pm;
|
|
|
|
CSlider* ps;
|
|
|
|
|
|
|
|
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW1);
|
|
|
|
if ( pw == 0 ) return;
|
|
|
|
|
|
|
|
pm = (CMap*)pw->SearchControl(EVENT_OBJECT_MAP);
|
|
|
|
if ( pm != 0 )
|
|
|
|
{
|
|
|
|
pm->SetEnable(bEnable);
|
|
|
|
}
|
|
|
|
|
|
|
|
ps = (CSlider*)pw->SearchControl(EVENT_OBJECT_MAPZOOM);
|
|
|
|
if ( ps != 0 )
|
|
|
|
{
|
|
|
|
ps->SetState(STATE_ENABLE, bEnable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-22 19:34:46 +00:00
|
|
|
// Specifies the type of icon for the selected object.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
void CMainMap::SetToy(bool bToy)
|
2012-03-08 18:32:05 +00:00
|
|
|
{
|
|
|
|
CWindow* pw;
|
|
|
|
CMap* pm;
|
|
|
|
|
|
|
|
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW1);
|
|
|
|
if ( pw == 0 ) return;
|
|
|
|
|
|
|
|
pm = (CMap*)pw->SearchControl(EVENT_OBJECT_MAP);
|
|
|
|
if ( pm == 0 ) return;
|
|
|
|
|
|
|
|
pm->SetToy(bToy);
|
|
|
|
}
|
|
|
|
|
2012-03-22 19:34:46 +00:00
|
|
|
// Specifies the parameters when using a still image.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
void CMainMap::SetFixParam(float zoom, float ox, float oy, float angle,
|
2012-06-10 13:28:12 +00:00
|
|
|
int mode, bool bDebug)
|
2012-03-08 18:32:05 +00:00
|
|
|
{
|
|
|
|
CWindow* pw;
|
|
|
|
CMap* pm;
|
|
|
|
|
|
|
|
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW1);
|
|
|
|
if ( pw == 0 ) return;
|
|
|
|
|
|
|
|
pm = (CMap*)pw->SearchControl(EVENT_OBJECT_MAP);
|
|
|
|
if ( pm == 0 ) return;
|
|
|
|
|
|
|
|
pm->SetZoom(zoom);
|
|
|
|
pm->SetOffset(ox, oy);
|
|
|
|
pm->SetAngle(angle);
|
|
|
|
pm->SetMode(mode);
|
|
|
|
pm->SetDebug(bDebug);
|
|
|
|
}
|
|
|
|
|
2012-03-22 19:34:46 +00:00
|
|
|
// Updates the mini-map following to a change of terrain.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
void CMainMap::UpdateMap()
|
|
|
|
{
|
|
|
|
CWindow* pw;
|
|
|
|
CMap* pm;
|
|
|
|
|
|
|
|
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW1);
|
|
|
|
if ( pw == 0 ) return;
|
|
|
|
|
|
|
|
pm = (CMap*)pw->SearchControl(EVENT_OBJECT_MAP);
|
|
|
|
if ( pm != 0 )
|
|
|
|
{
|
|
|
|
pm->UpdateTerrain();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-22 19:34:46 +00:00
|
|
|
// Indicates if the mini-map is visible.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
bool CMainMap::RetShowMap()
|
2012-03-08 18:32:05 +00:00
|
|
|
{
|
|
|
|
return ( m_mapMode != 0 );
|
|
|
|
}
|
|
|
|
|
2012-03-22 19:34:46 +00:00
|
|
|
// Indicates whether the mini-map displays a still image.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
bool CMainMap::RetFixImage()
|
2012-03-08 18:32:05 +00:00
|
|
|
{
|
|
|
|
return m_bFixImage;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-22 19:34:46 +00:00
|
|
|
// The object is detected in the mini-map.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
CObject* CMainMap::DetectMap(FPOINT pos, bool &bInMap)
|
2012-03-08 18:32:05 +00:00
|
|
|
{
|
|
|
|
CWindow* pw;
|
|
|
|
CMap* pm;
|
|
|
|
|
|
|
|
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW1);
|
|
|
|
if ( pw == 0 ) return 0;
|
|
|
|
|
2012-06-10 13:28:12 +00:00
|
|
|
bInMap = false;
|
2012-03-08 18:32:05 +00:00
|
|
|
pm = (CMap*)pw->SearchControl(EVENT_OBJECT_MAP);
|
|
|
|
if ( pm == 0 ) return 0;
|
|
|
|
return pm->DetectObject(pos, bInMap);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-22 19:34:46 +00:00
|
|
|
// Indicates the object with the mouse hovers over.
|
2012-03-08 18:32:05 +00:00
|
|
|
|
|
|
|
void CMainMap::SetHilite(CObject* pObj)
|
|
|
|
{
|
|
|
|
CWindow* pw;
|
|
|
|
CMap* pm;
|
|
|
|
|
|
|
|
pw = (CWindow*)m_interface->SearchControl(EVENT_WINDOW1);
|
|
|
|
if ( pw == 0 ) return;
|
|
|
|
|
|
|
|
pm = (CMap*)pw->SearchControl(EVENT_OBJECT_MAP);
|
|
|
|
if ( pm != 0 )
|
|
|
|
{
|
|
|
|
pm->SetHilite(pObj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|