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 
23 #include "control/C4GameControl.h"
24 #include "editor/C4Console.h"
25 #include "landscape/C4Texture.h"
26 #include "landscape/C4Landscape.h"
27 
29 {
30  // Create dialog window
31  Console.ToolsDlgOpen(this);
32  Active = true;
33  // Update contols
34  InitGradeCtrl();
40  return true;
41 }
42 
43 bool C4ToolsDlg::SetTool(int32_t iTool, bool fTemp)
44 {
45  Tool=iTool;
46  if (!fTemp) SelectedTool = Tool;
49  return true;
50 }
51 
53 {
54  // Materials
56  // Textures
58 }
59 
60 void C4ToolsDlg::SetMaterial(const char *szMaterial)
61 {
62  SCopy(szMaterial,Material,C4M_MaxName);
67  if (ModeBack && SEqual(szMaterial, C4TLS_MatSky))
69 }
70 
71 void C4ToolsDlg::SetTexture(const char *szTexture)
72 {
73  // assert valid (for separator selection)
74  if (!::TextureMap.GetTexture(szTexture))
75  {
76  // ensure correct texture is in dlg
77  Console.ToolsDlgSelectTexture(this, szTexture);
78  return;
79  }
80 
81  SCopy(szTexture,Texture,C4M_MaxName);
83 
84  // If the front texture changes, reset the background texture
85  // to something sensible.
86  int32_t mat = MaterialMap.Get(Material);
87  if (mat != MNone)
88  {
89  const C4Material* material = &MaterialMap.Map[mat];
90  if(DensitySemiSolid(material->Density))
91  {
93  {
94  SelectBackMaterial("Tunnel");
95  SelectBackTexture("tunnel");
96  }
97  }
98  else
99  {
102  }
103  }
104 }
105 
106 void C4ToolsDlg::SetBackMaterial(const char *szMaterial)
107 {
108  ModeBack = true;
109 
110  SCopy(szMaterial,BackMaterial,C4M_MaxName);
112  EnableControls();
114 }
115 
116 void C4ToolsDlg::SetBackTexture(const char *szTexture)
117 {
118  ModeBack = true;
119 
120  // assert valid (for separator selection)
121  if (!::TextureMap.GetTexture(szTexture))
122  {
123  // ensure correct texture is in dlg
124  Console.ToolsDlgSelectBackTexture(this, szTexture);
125  return;
126  }
127 
128  SCopy(szTexture,BackTexture,C4M_MaxName);
129 }
130 
131 bool C4ToolsDlg::SetIFT(bool fIFT)
132 {
133  ModeBack = false;
134  if (fIFT) ModeIFT = true; else ModeIFT=false;
135 
136  // Keep sensible default values in BackMaterial / BackTexture
137  if (ModeIFT == 0)
138  {
140  }
141  else
142  {
144  int32_t index = ::TextureMap.GetIndexMatTex(Material);
145  if (index != -1)
146  {
147  BYTE bg_index = ::TextureMap.DefaultBkgMatTex(index);
148  const C4TexMapEntry* entry = ::TextureMap.GetEntry(bg_index);
149  if (entry != nullptr)
150  {
153  }
154  }
155  }
156 
159  return true;
160 }
161 
162 void C4ToolsDlg::SetColorPattern(const char *szMaterial, const char *szTexture)
163 {
164 }
165 
166 bool C4ToolsDlg::SetGrade(int32_t iGrade)
167 {
170  return true;
171 }
172 
173 bool C4ToolsDlg::ChangeGrade(int32_t iChange)
174 {
177  InitGradeCtrl();
178  return true;
179 }
180 
181 bool C4ToolsDlg::SetLandscapeMode(LandscapeMode mode, bool flat_chunk_shapes, bool fThroughControl)
182 {
183  auto last_mode = ::Landscape.GetMode();
184  auto last_flat_chunk_shapes = ::Game.C4S.Landscape.FlatChunkShapes;
185  // Exact to static: confirm data loss warning
186  if (last_mode == LandscapeMode::Exact)
187  if (mode == LandscapeMode::Static)
188  if (!fThroughControl)
189  if (!Console.Message(LoadResStr("IDS_CNS_EXACTTOSTATIC"), true))
190  return false;
191  // send as control
192  if (!fThroughControl)
193  {
194  ::Control.DoInput(CID_EMDrawTool, new C4ControlEMDrawTool(EMDT_SetMode, mode, flat_chunk_shapes ? 1 : 0), CDT_Decide);
195  return true;
196  }
197  // Set landscape mode
198  ::Game.C4S.Landscape.FlatChunkShapes = flat_chunk_shapes;
199  ::Landscape.SetMode(mode);
200  // Exact to static: redraw landscape from map
201  if (last_mode == LandscapeMode::Exact || (last_flat_chunk_shapes != flat_chunk_shapes))
202  if (mode == LandscapeMode::Static)
204  // Assert valid tool
205  if (mode != LandscapeMode::Exact)
206  if (SelectedTool == C4TLS_Fill)
207  SetTool(C4TLS_Brush, false);
208  // Update controls
210  EnableControls();
211  UpdateTextures();
212  // Success
213  return true;
214 }
215 
217 {
218 #ifndef WITH_QT_EDITOR // Qt Editor textures are always valid, because MatTex entries are selected directly
219  // Static map mode only
220  if (::Landscape.GetMode() != LandscapeMode::Static) return;
221  // Ignore if sky
222  if (SEqual(Material,C4TLS_MatSky)) return;
223  // Current material-texture valid
224  if (::TextureMap.GetIndex(Material,Texture,false)) return;
225  // Find valid material-texture
226  const char *szTexture;
227  for (int32_t iTexture=0; (szTexture=::TextureMap.GetTexture(iTexture)); iTexture++)
228  {
229  if (::TextureMap.GetIndex(Material,szTexture,false))
230  { SelectTexture(szTexture); return; }
231  }
232  // No valid texture found
233 #endif
234 }
235 
237 {
238  // Static map mode only
239  if (::Landscape.GetMode() != LandscapeMode::Static) return;
240  // Ignore if not enabled
241  if (!ModeBack) return;
242  // Ignore if sky
243  if (SEqual(BackMaterial,C4TLS_MatSky)) return;
244  // Current material-texture valid
245  if (::TextureMap.GetIndex(BackMaterial,BackTexture,false)) return;
246  // Find valid material-texture
247  const char *szTexture;
248  for (int32_t iTexture=0; (szTexture=::TextureMap.GetTexture(iTexture)); iTexture++)
249  {
250  if (::TextureMap.GetIndex(BackMaterial,szTexture,false))
251  { SelectBackTexture(szTexture); return; }
252  }
253  // No valid texture found
254 }
255 
256 bool C4ToolsDlg::SelectTexture(const char *szTexture, bool by_console_gui)
257 {
258  if (!by_console_gui) Console.ToolsDlgSelectTexture(this, szTexture);
259  SetTexture(szTexture);
260  return true;
261 }
262 
263 bool C4ToolsDlg::SelectMaterial(const char *szMaterial, bool by_console_gui)
264 {
265  if (!by_console_gui) Console.ToolsDlgSelectMaterial(this, szMaterial);
266  SetMaterial(szMaterial);
267  return true;
268 }
269 
270 bool C4ToolsDlg::SelectBackTexture(const char *szTexture, bool by_console_gui)
271 {
272  if (!by_console_gui) Console.ToolsDlgSelectBackTexture(this, szTexture);
273  SetBackTexture(szTexture);
274  return true;
275 }
276 
277 bool C4ToolsDlg::SelectBackMaterial(const char *szMaterial, bool by_console_gui)
278 {
279  if (!by_console_gui) Console.ToolsDlgSelectBackMaterial(this, szMaterial);
280  SetBackMaterial(szMaterial);
281  return true;
282 }
283 
285 {
286  // alternate tool is the picker in any mode
287  SetTool(C4TLS_Picker, true);
288 }
289 
291 {
292  // reset tool to selected tool in case alternate tool was set
293  SetTool(SelectedTool, true);
294 }
bool SetGrade(int32_t iGrade)
Definition: C4ToolsDlg.cpp:166
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:130
C4Console Console
Definition: C4Globals.cpp:45
void SetColorPattern(const char *szMaterial, const char *szTexture)
Definition: C4ToolsDlg.cpp:162
C4Game Game
Definition: C4Globals.cpp:52
C4Scenario C4S
Definition: C4Game.h:74
void SetAlternateTool()
Definition: C4ToolsDlg.cpp:284
BYTE DefaultBkgMatTex(BYTE fg) const
Definition: C4Texture.cpp:504
void ToolsDlgSelectMaterial(C4ToolsDlg *dlg, const char *material)
Definition: C4Console.cpp:695
C4SLandscape Landscape
Definition: C4Scenario.h:234
C4Material * Map
Definition: C4Material.h:169
void ToolsDlgSelectBackTexture(C4ToolsDlg *dlg, const char *texture)
Definition: C4Console.cpp:698
void ToolsDlgInitMaterialCtrls(class C4ToolsDlg *dlg)
Definition: C4Console.cpp:693
uint8_t BYTE
void AssertValidTexture()
Definition: C4ToolsDlg.cpp:216
C4TextureMap TextureMap
Definition: C4Texture.cpp:576
void SetTexture(const char *szTexture)
Definition: C4ToolsDlg.cpp:71
bool DensitySemiSolid(int32_t dens)
Definition: C4Landscape.h:203
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:93
void InitMaterialCtrls()
Definition: C4ToolsDlg.cpp:52
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:414
T Clamp(T bval, T lbound, T rbound)
Definition: Standard.h:44
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:696
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:236
bool MapToLandscape()
C4GameControl Control
const char * GetTextureName() const
Definition: C4Texture.h:61
C4Landscape Landscape
bool SetIFT(bool fIFT)
Definition: C4ToolsDlg.cpp:131
void SetMode(LandscapeMode iMode)
void ResetAlternateTool()
Definition: C4ToolsDlg.cpp:290
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:106
void ToolsDlgSelectBackMaterial(C4ToolsDlg *dlg, const char *material)
Definition: C4Console.cpp:697
LandscapeMode GetMode() const
void InitGradeCtrl()
Definition: C4Console.cpp:701
int32_t Density
Definition: C4Material.h:92
void UpdateIFTControls()
Definition: C4Console.cpp:705
bool SelectBackTexture(const char *szTexture, bool by_console_gui=false)
Definition: C4ToolsDlg.cpp:270
bool ModeBack
Definition: C4ToolsDlg.h:58
bool FlatChunkShapes
Definition: C4Scenario.h:186
bool ToolsDlgOpen(class C4ToolsDlg *dlg)
Definition: C4Console.cpp:694
bool SetLandscapeMode(LandscapeMode iMode, bool flat_chunk_shapes, bool fThroughControl=false)
Definition: C4ToolsDlg.cpp:181
LandscapeMode
Definition: C4Landscape.h:29
int32_t Get(const char *szMaterial)
Definition: C4Material.cpp:361
void NeedPreviewUpdate()
Definition: C4Console.cpp:702
bool SelectBackMaterial(const char *szMaterial, bool by_console_gui=false)
Definition: C4ToolsDlg.cpp:277
const char * GetTexture(int32_t iIndex)
Definition: C4Texture.cpp:494
const int32_t C4TLS_Brush
Definition: C4ToolsDlg.h:28
void SetBackTexture(const char *szTexture)
Definition: C4ToolsDlg.cpp:116
void UpdateToolCtrls()
Definition: C4Console.cpp:708
const int32_t C4TLS_Fill
Definition: C4ToolsDlg.h:31
void UpdateLandscapeModeCtrls()
Definition: C4Console.cpp:706
C4MaterialMap MaterialMap
Definition: C4Material.cpp:969
char BackMaterial[C4M_MaxName+1]
Definition: C4ToolsDlg.h:59
bool Open()
Definition: C4ToolsDlg.cpp:28
#define C4TLS_MatSky
Definition: C4ToolsDlg.h:39
bool SelectMaterial(const char *szMaterial, bool by_console_gui=false)
Definition: C4ToolsDlg.cpp:263
int32_t SelectedTool
Definition: C4ToolsDlg.h:53
bool ChangeGrade(int32_t iChange)
Definition: C4ToolsDlg.cpp:173
bool SelectTexture(const char *szTexture, bool by_console_gui=false)
Definition: C4ToolsDlg.cpp:256
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:441
bool SetTool(int32_t iTool, bool fTemp)
Definition: C4ToolsDlg.cpp:43
void SetMaterial(const char *szMaterial)
Definition: C4ToolsDlg.cpp:60
void UpdateTextures()
Definition: C4Console.cpp:707
int32_t Tool
Definition: C4ToolsDlg.h:53
bool Message(const char *szMessage, bool fQuery=false)
Definition: C4Console.cpp:292
bool ModeIFT
Definition: C4ToolsDlg.h:55
void EnableControls()
Definition: C4Console.cpp:700