OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4ToolsDlg.cpp
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 1998-2000, Matthes Bender
5  * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de/
6  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
7  *
8  * Distributed under the terms of the ISC license; see accompanying file
9  * "COPYING" for details.
10  *
11  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
12  * See accompanying file "TRADEMARK" for details.
13  *
14  * To redistribute this file separately, substitute the full license texts
15  * for the above references.
16  */
17 
18 /* Drawing tools dialog for landscape editing in console mode */
19 
20 #include "C4Include.h"
21 #include "editor/C4ToolsDlg.h"
22 #include "editor/C4Console.h"
23 #include "landscape/C4Texture.h"
24 #include "landscape/C4Landscape.h"
25 #include "control/C4GameControl.h"
26 
28 {
29  // Create dialog window
30  Console.ToolsDlgOpen(this);
31  Active = true;
32  // Update contols
33  InitGradeCtrl();
39  return true;
40 }
41 
42 bool C4ToolsDlg::SetTool(int32_t iTool, bool fTemp)
43 {
44  Tool=iTool;
45  if (!fTemp) SelectedTool = Tool;
48  return true;
49 }
50 
52 {
53  // Materials
55  // Textures
57 }
58 
59 void C4ToolsDlg::SetMaterial(const char *szMaterial)
60 {
61  SCopy(szMaterial,Material,C4M_MaxName);
66  if (ModeBack && SEqual(szMaterial, C4TLS_MatSky))
68 }
69 
70 void C4ToolsDlg::SetTexture(const char *szTexture)
71 {
72  // assert valid (for separator selection)
73  if (!::TextureMap.GetTexture(szTexture))
74  {
75  // ensure correct texture is in dlg
76  Console.ToolsDlgSelectTexture(this, szTexture);
77  return;
78  }
79 
80  SCopy(szTexture,Texture,C4M_MaxName);
82 
83  // If the front texture changes, reset the background texture
84  // to something sensible.
85  int32_t mat = MaterialMap.Get(Material);
86  if (mat != MNone)
87  {
88  const C4Material* material = &MaterialMap.Map[mat];
89  if(DensitySemiSolid(material->Density))
90  {
92  {
93  SelectBackMaterial("Tunnel");
94  SelectBackTexture("tunnel");
95  }
96  }
97  else
98  {
101  }
102  }
103 }
104 
105 void C4ToolsDlg::SetBackMaterial(const char *szMaterial)
106 {
107  ModeBack = true;
108 
109  SCopy(szMaterial,BackMaterial,C4M_MaxName);
111  EnableControls();
113 }
114 
115 void C4ToolsDlg::SetBackTexture(const char *szTexture)
116 {
117  ModeBack = true;
118 
119  // assert valid (for separator selection)
120  if (!::TextureMap.GetTexture(szTexture))
121  {
122  // ensure correct texture is in dlg
123  Console.ToolsDlgSelectBackTexture(this, szTexture);
124  return;
125  }
126 
127  SCopy(szTexture,BackTexture,C4M_MaxName);
128 }
129 
130 bool C4ToolsDlg::SetIFT(bool fIFT)
131 {
132  ModeBack = false;
133  if (fIFT) ModeIFT = 1; else ModeIFT=0;
134 
135  // Keep sensible default values in BackMaterial / BackTexture
136  if (ModeIFT == 0)
137  {
139  }
140  else
141  {
143  int32_t index = ::TextureMap.GetIndexMatTex(Material);
144  if (index != -1)
145  {
146  BYTE bg_index = ::TextureMap.DefaultBkgMatTex(index);
147  const C4TexMapEntry* entry = ::TextureMap.GetEntry(bg_index);
148  if (entry != nullptr)
149  {
152  }
153  }
154  }
155 
158  return true;
159 }
160 
161 void C4ToolsDlg::SetColorPattern(const char *szMaterial, const char *szTexture)
162 {
163 }
164 
165 bool C4ToolsDlg::SetGrade(int32_t iGrade)
166 {
169  return true;
170 }
171 
172 bool C4ToolsDlg::ChangeGrade(int32_t iChange)
173 {
176  InitGradeCtrl();
177  return true;
178 }
179 
180 bool C4ToolsDlg::SetLandscapeMode(LandscapeMode mode, bool flat_chunk_shapes, bool fThroughControl)
181 {
182  auto last_mode = ::Landscape.GetMode();
183  auto last_flat_chunk_shapes = ::Game.C4S.Landscape.FlatChunkShapes;
184  // Exact to static: confirm data loss warning
185  if (last_mode == LandscapeMode::Exact)
186  if (mode == LandscapeMode::Static)
187  if (!fThroughControl)
188  if (!Console.Message(LoadResStr("IDS_CNS_EXACTTOSTATIC"), true))
189  return false;
190  // send as control
191  if (!fThroughControl)
192  {
193  ::Control.DoInput(CID_EMDrawTool, new C4ControlEMDrawTool(EMDT_SetMode, mode, flat_chunk_shapes ? 1 : 0), CDT_Decide);
194  return true;
195  }
196  // Set landscape mode
197  ::Game.C4S.Landscape.FlatChunkShapes = flat_chunk_shapes;
198  ::Landscape.SetMode(mode);
199  // Exact to static: redraw landscape from map
200  if (last_mode == LandscapeMode::Exact || (last_flat_chunk_shapes != flat_chunk_shapes))
201  if (mode == LandscapeMode::Static)
203  // Assert valid tool
204  if (mode != LandscapeMode::Exact)
205  if (SelectedTool == C4TLS_Fill)
206  SetTool(C4TLS_Brush, false);
207  // Update controls
209  EnableControls();
210  UpdateTextures();
211  // Success
212  return true;
213 }
214 
216 {
217 #ifndef WITH_QT_EDITOR // Qt Editor textures are always valid, because MatTex entries are selected directly
218  // Static map mode only
219  if (::Landscape.GetMode() != LandscapeMode::Static) return;
220  // Ignore if sky
221  if (SEqual(Material,C4TLS_MatSky)) return;
222  // Current material-texture valid
223  if (::TextureMap.GetIndex(Material,Texture,false)) return;
224  // Find valid material-texture
225  const char *szTexture;
226  for (int32_t iTexture=0; (szTexture=::TextureMap.GetTexture(iTexture)); iTexture++)
227  {
228  if (::TextureMap.GetIndex(Material,szTexture,false))
229  { SelectTexture(szTexture); return; }
230  }
231  // No valid texture found
232 #endif
233 }
234 
236 {
237  // Static map mode only
238  if (::Landscape.GetMode() != LandscapeMode::Static) return;
239  // Ignore if not enabled
240  if (!ModeBack) return;
241  // Ignore if sky
242  if (SEqual(BackMaterial,C4TLS_MatSky)) return;
243  // Current material-texture valid
244  if (::TextureMap.GetIndex(BackMaterial,BackTexture,false)) return;
245  // Find valid material-texture
246  const char *szTexture;
247  for (int32_t iTexture=0; (szTexture=::TextureMap.GetTexture(iTexture)); iTexture++)
248  {
249  if (::TextureMap.GetIndex(BackMaterial,szTexture,false))
250  { SelectBackTexture(szTexture); return; }
251  }
252  // No valid texture found
253 }
254 
255 bool C4ToolsDlg::SelectTexture(const char *szTexture, bool by_console_gui)
256 {
257  if (!by_console_gui) Console.ToolsDlgSelectTexture(this, szTexture);
258  SetTexture(szTexture);
259  return true;
260 }
261 
262 bool C4ToolsDlg::SelectMaterial(const char *szMaterial, bool by_console_gui)
263 {
264  if (!by_console_gui) Console.ToolsDlgSelectMaterial(this, szMaterial);
265  SetMaterial(szMaterial);
266  return true;
267 }
268 
269 bool C4ToolsDlg::SelectBackTexture(const char *szTexture, bool by_console_gui)
270 {
271  if (!by_console_gui) Console.ToolsDlgSelectBackTexture(this, szTexture);
272  SetBackTexture(szTexture);
273  return true;
274 }
275 
276 bool C4ToolsDlg::SelectBackMaterial(const char *szMaterial, bool by_console_gui)
277 {
278  if (!by_console_gui) Console.ToolsDlgSelectBackMaterial(this, szMaterial);
279  SetBackMaterial(szMaterial);
280  return true;
281 }
282 
284 {
285  // alternate tool is the picker in any mode
286  SetTool(C4TLS_Picker, true);
287 }
288 
290 {
291  // reset tool to selected tool in case alternate tool was set
292  SetTool(SelectedTool, true);
293 }
bool SetGrade(int32_t iGrade)
Definition: C4ToolsDlg.cpp:165
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:122
C4Console Console
Definition: C4Globals.cpp:45
void SetColorPattern(const char *szMaterial, const char *szTexture)
Definition: C4ToolsDlg.cpp:161
C4Game Game
Definition: C4Globals.cpp:52
C4Scenario C4S
Definition: C4Game.h:76
void SetAlternateTool()
Definition: C4ToolsDlg.cpp:283
BYTE DefaultBkgMatTex(BYTE fg) const
Definition: C4Texture.cpp:513
void ToolsDlgSelectMaterial(C4ToolsDlg *dlg, const char *material)
Definition: C4Console.cpp:700
C4SLandscape Landscape
Definition: C4Scenario.h:234
C4Material * Map
Definition: C4Material.h:171
void ToolsDlgSelectBackTexture(C4ToolsDlg *dlg, const char *texture)
Definition: C4Console.cpp:703
void ToolsDlgInitMaterialCtrls(class C4ToolsDlg *dlg)
Definition: C4Console.cpp:698
uint8_t BYTE
void AssertValidTexture()
Definition: C4ToolsDlg.cpp:215
C4TextureMap TextureMap
Definition: C4Texture.cpp:580
void SetTexture(const char *szTexture)
Definition: C4ToolsDlg.cpp:70
bool DensitySemiSolid(int32_t dens)
Definition: C4Landscape.h:204
const C4TexMapEntry * GetEntry(int32_t iIndex) const
Definition: C4Texture.h:85
Definition: C4Texture.h:48
bool SEqual(const char *szStr1, const char *szStr2)
Definition: Standard.h:97
void InitMaterialCtrls()
Definition: C4ToolsDlg.cpp:51
bool Active
Definition: C4ToolsDlg.h:52
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
int32_t GetIndex(const char *szMaterial, const char *szTexture, bool fAddIfNotExist=true, const char *szErrorIfFailed=nullptr)
Definition: C4Texture.cpp:423
T Clamp(T bval, T lbound, T rbound)
Definition: Standard.h:46
const int C4M_MaxName
Definition: C4Constants.h:49
int32_t Grade
Definition: C4ToolsDlg.h:54
char Texture[C4M_MaxName+1]
Definition: C4ToolsDlg.h:57
void ToolsDlgSelectTexture(C4ToolsDlg *dlg, const char *texture)
Definition: C4Console.cpp:701
const int32_t MNone
Definition: C4Constants.h:178
const char * GetMaterialName() const
Definition: C4Texture.h:60
const int32_t C4TLS_Picker
Definition: C4ToolsDlg.h:32
void AssertValidBackTexture()
Definition: C4ToolsDlg.cpp:235
bool MapToLandscape()
C4GameControl Control
const char * GetTextureName() const
Definition: C4Texture.h:61
C4Landscape Landscape
bool SetIFT(bool fIFT)
Definition: C4ToolsDlg.cpp:130
void SetMode(LandscapeMode iMode)
void ResetAlternateTool()
Definition: C4ToolsDlg.cpp:289
char Material[C4M_MaxName+1]
Definition: C4ToolsDlg.h:56
void DoInput(C4PacketType eCtrlType, C4ControlPacket *pPkt, C4ControlDeliveryType eDelivery)
const int32_t C4TLS_GradeMin
Definition: C4ToolsDlg.h:36
const int32_t C4TLS_GradeMax
Definition: C4ToolsDlg.h:35
void SetBackMaterial(const char *szMaterial)
Definition: C4ToolsDlg.cpp:105
void ToolsDlgSelectBackMaterial(C4ToolsDlg *dlg, const char *material)
Definition: C4Console.cpp:702
LandscapeMode GetMode() const
void InitGradeCtrl()
Definition: C4Console.cpp:706
int32_t Density
Definition: C4Material.h:94
void UpdateIFTControls()
Definition: C4Console.cpp:710
bool SelectBackTexture(const char *szTexture, bool by_console_gui=false)
Definition: C4ToolsDlg.cpp:269
bool ModeBack
Definition: C4ToolsDlg.h:58
bool FlatChunkShapes
Definition: C4Scenario.h:186
bool ToolsDlgOpen(class C4ToolsDlg *dlg)
Definition: C4Console.cpp:699
bool SetLandscapeMode(LandscapeMode iMode, bool flat_chunk_shapes, bool fThroughControl=false)
Definition: C4ToolsDlg.cpp:180
LandscapeMode
Definition: C4Landscape.h:30
int32_t Get(const char *szMaterial)
Definition: C4Material.cpp:362
void NeedPreviewUpdate()
Definition: C4Console.cpp:707
bool SelectBackMaterial(const char *szMaterial, bool by_console_gui=false)
Definition: C4ToolsDlg.cpp:276
const char * GetTexture(int32_t iIndex)
Definition: C4Texture.cpp:503
const int32_t C4TLS_Brush
Definition: C4ToolsDlg.h:28
void SetBackTexture(const char *szTexture)
Definition: C4ToolsDlg.cpp:115
void UpdateToolCtrls()
Definition: C4Console.cpp:713
const int32_t C4TLS_Fill
Definition: C4ToolsDlg.h:31
void UpdateLandscapeModeCtrls()
Definition: C4Console.cpp:711
C4MaterialMap MaterialMap
Definition: C4Material.cpp:970
char BackMaterial[C4M_MaxName+1]
Definition: C4ToolsDlg.h:59
bool Open()
Definition: C4ToolsDlg.cpp:27
#define C4TLS_MatSky
Definition: C4ToolsDlg.h:39
bool SelectMaterial(const char *szMaterial, bool by_console_gui=false)
Definition: C4ToolsDlg.cpp:262
int32_t SelectedTool
Definition: C4ToolsDlg.h:53
bool ChangeGrade(int32_t iChange)
Definition: C4ToolsDlg.cpp:172
bool SelectTexture(const char *szTexture, bool by_console_gui=false)
Definition: C4ToolsDlg.cpp:255
char BackTexture[C4M_MaxName+1]
Definition: C4ToolsDlg.h:60
int32_t GetIndexMatTex(const char *szMaterialTexture, const char *szDefaultTexture=nullptr, bool fAddIfNotExist=true, const char *szErrorIfFailed=nullptr)
Definition: C4Texture.cpp:450
bool SetTool(int32_t iTool, bool fTemp)
Definition: C4ToolsDlg.cpp:42
void SetMaterial(const char *szMaterial)
Definition: C4ToolsDlg.cpp:59
void UpdateTextures()
Definition: C4Console.cpp:712
int32_t Tool
Definition: C4ToolsDlg.h:53
bool Message(const char *szMessage, bool fQuery=false)
Definition: C4Console.cpp:297
bool ModeIFT
Definition: C4ToolsDlg.h:55
void EnableControls()
Definition: C4Console.cpp:705