openclonk/src/editor/C4ToolsDlg.cpp

290 lines
7.0 KiB
C++
Raw Normal View History

2009-05-08 13:28:41 +00:00
/*
* OpenClonk, http://www.openclonk.org
*
* Copyright (c) 1998-2000, Matthes Bender
* Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
2016-04-03 18:18:29 +00:00
* Copyright (c) 2009-2016, The OpenClonk Team and contributors
2009-05-08 13:28:41 +00:00
*
* Distributed under the terms of the ISC license; see accompanying file
* "COPYING" for details.
2009-05-08 13:28:41 +00:00
*
* "Clonk" is a registered trademark of Matthes Bender, used with permission.
* See accompanying file "TRADEMARK" for details.
2009-05-08 13:28:41 +00:00
*
* To redistribute this file separately, substitute the full license texts
* for the above references.
2009-05-08 13:28:41 +00:00
*/
/* Drawing tools dialog for landscape editing in console mode */
#include "C4Include.h"
#include "editor/C4ToolsDlg.h"
#include "editor/C4Console.h"
#include "landscape/C4Texture.h"
#include "landscape/C4Landscape.h"
#include "control/C4GameControl.h"
2009-05-08 13:28:41 +00:00
bool C4ToolsDlg::Open()
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// Create dialog window
Console.ToolsDlgOpen(this);
2009-05-08 13:28:41 +00:00
Active = true;
// Update contols
InitGradeCtrl();
UpdateLandscapeModeCtrls();
UpdateToolCtrls();
UpdateIFTControls();
InitMaterialCtrls();
EnableControls();
return true;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
bool C4ToolsDlg::SetTool(int32_t iTool, bool fTemp)
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
Tool=iTool;
if (!fTemp) SelectedTool = Tool;
2009-05-08 13:28:41 +00:00
UpdateToolCtrls();
NeedPreviewUpdate();
return true;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4ToolsDlg::InitMaterialCtrls()
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// Materials
Console.ToolsDlgInitMaterialCtrls(this);
2009-05-08 13:28:41 +00:00
// Textures
UpdateTextures();
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4ToolsDlg::SetMaterial(const char *szMaterial)
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
SCopy(szMaterial,Material,C4M_MaxName);
AssertValidTexture();
EnableControls();
if (::Landscape.GetMode() == LandscapeMode::Static) UpdateTextures();
NeedPreviewUpdate();
if (ModeBack && SEqual(szMaterial, C4TLS_MatSky))
SelectBackMaterial(C4TLS_MatSky);
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4ToolsDlg::SetTexture(const char *szTexture)
2010-03-28 18:58:01 +00:00
{
2010-04-01 21:08:06 +00:00
// assert valid (for separator selection)
2009-06-05 15:09:54 +00:00
if (!::TextureMap.GetTexture(szTexture))
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// ensure correct texture is in dlg
Console.ToolsDlgSelectTexture(this, szTexture);
2009-05-08 13:28:41 +00:00
return;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
SCopy(szTexture,Texture,C4M_MaxName);
NeedPreviewUpdate();
// If the front texture changes, reset the background texture
// to something sensible.
int32_t mat = MaterialMap.Get(Material);
if (mat != MNone)
{
const C4Material* material = &MaterialMap.Map[mat];
if(DensitySemiSolid(material->Density))
{
if (!SEqual(BackMaterial, C4TLS_MatSky))
{
SelectBackMaterial("Tunnel");
SelectBackTexture("tunnel");
}
}
else
{
SelectBackMaterial(Material);
SelectBackTexture(Texture);
}
}
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4ToolsDlg::SetBackMaterial(const char *szMaterial)
{
ModeBack = true;
SCopy(szMaterial,BackMaterial,C4M_MaxName);
AssertValidBackTexture();
EnableControls();
if (::Landscape.GetMode() == LandscapeMode::Static) UpdateTextures();
}
void C4ToolsDlg::SetBackTexture(const char *szTexture)
{
ModeBack = true;
// assert valid (for separator selection)
if (!::TextureMap.GetTexture(szTexture))
{
// ensure correct texture is in dlg
Console.ToolsDlgSelectBackTexture(this, szTexture);
return;
}
SCopy(szTexture,BackTexture,C4M_MaxName);
}
bool C4ToolsDlg::SetIFT(bool fIFT)
2010-03-28 18:58:01 +00:00
{
ModeBack = false;
2009-05-08 13:28:41 +00:00
if (fIFT) ModeIFT = 1; else ModeIFT=0;
// Keep sensible default values in BackMaterial / BackTexture
if (ModeIFT == 0)
{
SCopy(C4TLS_MatSky, BackMaterial, C4M_MaxName);
}
else
{
SCopy(C4TLS_MatSky, BackMaterial, C4M_MaxName);
int32_t index = ::TextureMap.GetIndexMatTex(Material);
if (index != -1)
{
BYTE bg_index = ::TextureMap.DefaultBkgMatTex(index);
const C4TexMapEntry* entry = ::TextureMap.GetEntry(bg_index);
if (entry != NULL)
{
SCopy(entry->GetMaterialName(), BackMaterial, C4M_MaxName);
SCopy(entry->GetTextureName(), BackTexture, C4M_MaxName);
}
}
}
2009-05-08 13:28:41 +00:00
UpdateIFTControls();
NeedPreviewUpdate();
return true;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4ToolsDlg::SetColorPattern(const char *szMaterial, const char *szTexture)
2010-03-28 18:58:01 +00:00
{
}
2009-05-08 13:28:41 +00:00
bool C4ToolsDlg::SetGrade(int32_t iGrade)
2010-03-28 18:58:01 +00:00
{
Grade = Clamp(iGrade,C4TLS_GradeMin,C4TLS_GradeMax);
NeedPreviewUpdate();
return true;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
bool C4ToolsDlg::ChangeGrade(int32_t iChange)
2010-03-28 18:58:01 +00:00
{
Grade = Clamp(Grade+iChange,C4TLS_GradeMin,C4TLS_GradeMax);
NeedPreviewUpdate();
2009-05-08 13:28:41 +00:00
InitGradeCtrl();
return true;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
bool C4ToolsDlg::SetLandscapeMode(LandscapeMode mode, bool fThroughControl)
2010-03-28 18:58:01 +00:00
{
auto last_mode = ::Landscape.GetMode();
2009-05-08 13:28:41 +00:00
// Exact to static: confirm data loss warning
if (last_mode == LandscapeMode::Exact)
if (mode == LandscapeMode::Static)
2009-05-08 13:28:41 +00:00
if (!fThroughControl)
if (!Console.Message(LoadResStr("IDS_CNS_EXACTTOSTATIC"), true))
return false;
2009-05-08 13:28:41 +00:00
// send as control
if (!fThroughControl)
2010-03-28 18:58:01 +00:00
{
::Control.DoInput(CID_EMDrawTool, new C4ControlEMDrawTool(EMDT_SetMode, mode), CDT_Decide);
return true;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
// Set landscape mode
::Landscape.SetMode(mode);
2009-05-08 13:28:41 +00:00
// Exact to static: redraw landscape from map
if (last_mode == LandscapeMode::Exact)
if (mode == LandscapeMode::Static)
2009-06-05 15:20:41 +00:00
::Landscape.MapToLandscape();
2009-05-08 13:28:41 +00:00
// Assert valid tool
if (mode != LandscapeMode::Exact)
if (SelectedTool == C4TLS_Fill)
2009-05-08 13:28:41 +00:00
SetTool(C4TLS_Brush, false);
// Update controls
UpdateLandscapeModeCtrls();
EnableControls();
UpdateTextures();
// Success
return true;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4ToolsDlg::AssertValidTexture()
2010-03-28 18:58:01 +00:00
{
2009-05-08 13:28:41 +00:00
// Static map mode only
if (::Landscape.GetMode() != LandscapeMode::Static) return;
2009-05-08 13:28:41 +00:00
// Ignore if sky
if (SEqual(Material,C4TLS_MatSky)) return;
// Current material-texture valid
if (::TextureMap.GetIndex(Material,Texture,false)) return;
2009-05-08 13:28:41 +00:00
// Find valid material-texture
const char *szTexture;
2010-01-25 04:00:59 +00:00
for (int32_t iTexture=0; (szTexture=::TextureMap.GetTexture(iTexture)); iTexture++)
2010-03-28 18:58:01 +00:00
{
if (::TextureMap.GetIndex(Material,szTexture,false))
2009-05-08 13:28:41 +00:00
{ SelectTexture(szTexture); return; }
}
2010-03-28 18:58:01 +00:00
// No valid texture found
}
2009-05-08 13:28:41 +00:00
void C4ToolsDlg::AssertValidBackTexture()
{
// Static map mode only
if (::Landscape.GetMode() != LandscapeMode::Static) return;
// Ignore if not enabled
if (!ModeBack) return;
// Ignore if sky
if (SEqual(BackMaterial,C4TLS_MatSky)) return;
// Current material-texture valid
if (::TextureMap.GetIndex(BackMaterial,BackTexture,false)) return;
// Find valid material-texture
const char *szTexture;
for (int32_t iTexture=0; (szTexture=::TextureMap.GetTexture(iTexture)); iTexture++)
{
if (::TextureMap.GetIndex(BackMaterial,szTexture,false))
{ SelectBackTexture(szTexture); return; }
}
// No valid texture found
}
bool C4ToolsDlg::SelectTexture(const char *szTexture)
2010-03-28 18:58:01 +00:00
{
Console.ToolsDlgSelectTexture(this, szTexture);
2009-05-08 13:28:41 +00:00
SetTexture(szTexture);
return true;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
bool C4ToolsDlg::SelectMaterial(const char *szMaterial)
2010-03-28 18:58:01 +00:00
{
Console.ToolsDlgSelectMaterial(this, szMaterial);
2009-05-08 13:28:41 +00:00
SetMaterial(szMaterial);
return true;
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
bool C4ToolsDlg::SelectBackTexture(const char *szTexture)
{
Console.ToolsDlgSelectBackTexture(this, szTexture);
SetBackTexture(szTexture);
return true;
}
bool C4ToolsDlg::SelectBackMaterial(const char *szMaterial)
{
Console.ToolsDlgSelectBackMaterial(this, szMaterial);
SetBackMaterial(szMaterial);
return true;
}
2009-05-08 13:28:41 +00:00
void C4ToolsDlg::SetAlternateTool()
2010-03-28 18:58:01 +00:00
{
// alternate tool is the picker in any mode
SetTool(C4TLS_Picker, true);
2010-03-28 18:58:01 +00:00
}
2009-05-08 13:28:41 +00:00
void C4ToolsDlg::ResetAlternateTool()
2010-03-28 18:58:01 +00:00
{
// reset tool to selected tool in case alternate tool was set
SetTool(SelectedTool, true);
2010-03-28 18:58:01 +00:00
}