@@ -62,7 +62,7 @@ void C4EditCursor::Execute()
62
62
switch (Console.ToolsDlg .Tool )
63
63
{
64
64
case C4TLS_Fill:
65
- // if (Hold) if (!Game.HaltCount) if (Console.Editing) ApplyToolFill();
65
+ if (Hold) if (!Game.HaltCount ) if (Console.Editing ) ApplyToolFill ();
66
66
break ;
67
67
}
68
68
break ;
@@ -117,8 +117,19 @@ void C4EditCursor::ClearPointers(C4Object *pObj)
117
117
OnSelectionChanged ();
118
118
}
119
119
120
+ void C4EditCursor::ClearSectionPointers (C4Section §ion)
121
+ {
122
+ if (CurrentSection == §ion)
123
+ {
124
+ CurrentSection = nullptr ;
125
+ ResetSectionDependentState ();
126
+ }
127
+ }
128
+
120
129
bool C4EditCursor::Move (C4Section §ion, int32_t iX, int32_t iY, uint16_t wKeyFlags)
121
130
{
131
+ UpdateCurrentSection (section);
132
+
122
133
// Offset movement
123
134
int32_t xoff = iX - X; int32_t yoff = iY - Y; X = iX; Y = iY;
124
135
@@ -129,7 +140,7 @@ bool C4EditCursor::Move(C4Section §ion, int32_t iX, int32_t iY, uint16_t wKe
129
140
if (!DragFrame && Hold)
130
141
{
131
142
MoveSelection (xoff, yoff);
132
- UpdateDropTarget (section, wKeyFlags);
143
+ UpdateDropTarget (wKeyFlags);
133
144
}
134
145
// Update target
135
146
// Shift always indicates a target outside the current selection
@@ -147,7 +158,7 @@ bool C4EditCursor::Move(C4Section §ion, int32_t iX, int32_t iY, uint16_t wKe
147
158
switch (Console.ToolsDlg .Tool )
148
159
{
149
160
case C4TLS_Brush:
150
- if (Hold) ApplyToolBrush (section );
161
+ if (Hold) ApplyToolBrush ();
151
162
break ;
152
163
case C4TLS_Line: case C4TLS_Rect:
153
164
break ;
@@ -178,8 +189,7 @@ bool C4EditCursor::UpdateStatusBar()
178
189
break ;
179
190
180
191
case C4CNS_ModeDraw:
181
- // text = std::format("{}/{} ({})", X, Y, (Section->MatValid(Section->Landscape.GetMat(X, Y)) ? Section->Material.Map[Section->Landscape.GetMat(X, Y)].Name : LoadResStr(C4ResStrTableKey::IDS_CNS_NOTHING)));
182
- text = " FIXME: C4CNS_ModeDraw" ; // FIXME
192
+ text = std::format (" {}/{} ({})" , X, Y, (CurrentSection->MatValid (CurrentSection->Landscape .GetMat (X, Y)) ? CurrentSection->Material .Map [CurrentSection->Landscape .GetMat (X, Y)].Name : LoadResStr (C4ResStrTableKey::IDS_CNS_NOTHING)));
183
193
break ;
184
194
}
185
195
return Console.UpdateCursorBar (text.c_str ());
@@ -192,6 +202,8 @@ void C4EditCursor::OnSelectionChanged()
192
202
193
203
bool C4EditCursor::LeftButtonDown (C4Section §ion, bool fControl )
194
204
{
205
+ UpdateCurrentSection (section);
206
+
195
207
// Hold
196
208
Hold = true ;
197
209
@@ -223,7 +235,7 @@ bool C4EditCursor::LeftButtonDown(C4Section §ion, bool fControl)
223
235
case C4CNS_ModeDraw:
224
236
switch (Console.ToolsDlg .Tool )
225
237
{
226
- case C4TLS_Brush: ApplyToolBrush (section ); break ;
238
+ case C4TLS_Brush: ApplyToolBrush (); break ;
227
239
case C4TLS_Line: DragLine = true ; X2 = X; Y2 = Y; break ;
228
240
case C4TLS_Rect: DragFrame = true ; X2 = X; Y2 = Y; break ;
229
241
case C4TLS_Fill:
@@ -232,7 +244,7 @@ bool C4EditCursor::LeftButtonDown(C4Section §ion, bool fControl)
232
244
Hold = false ; Console.Message (LoadResStr (C4ResStrTableKey::IDS_CNS_FILLNOHALT)); return false ;
233
245
}
234
246
break ;
235
- case C4TLS_Picker: ApplyToolPicker (section ); break ;
247
+ case C4TLS_Picker: ApplyToolPicker (); break ;
236
248
}
237
249
break ;
238
250
}
@@ -243,8 +255,10 @@ bool C4EditCursor::LeftButtonDown(C4Section §ion, bool fControl)
243
255
return true ;
244
256
}
245
257
246
- bool C4EditCursor::RightButtonDown (bool fControl )
258
+ bool C4EditCursor::RightButtonDown (C4Section §ion, bool fControl )
247
259
{
260
+ UpdateCurrentSection (section);
261
+
248
262
switch (Mode)
249
263
{
250
264
case C4CNS_ModeEdit:
@@ -278,22 +292,24 @@ bool C4EditCursor::RightButtonDown(bool fControl)
278
292
279
293
bool C4EditCursor::LeftButtonUp (C4Section §ion)
280
294
{
295
+ UpdateCurrentSection (section);
296
+
281
297
// Finish edit/tool
282
298
switch (Mode)
283
299
{
284
300
case C4CNS_ModeEdit:
285
- if (DragFrame) FrameSelection (section );
301
+ if (DragFrame) FrameSelection ();
286
302
if (DropTarget) PutContents ();
287
303
break ;
288
304
289
305
case C4CNS_ModeDraw:
290
306
switch (Console.ToolsDlg .Tool )
291
307
{
292
308
case C4TLS_Line:
293
- if (DragLine) ApplyToolLine (section );
309
+ if (DragLine) ApplyToolLine ();
294
310
break ;
295
311
case C4TLS_Rect:
296
- if (DragFrame) ApplyToolRect (section );
312
+ if (DragFrame) ApplyToolRect ();
297
313
break ;
298
314
}
299
315
break ;
@@ -330,8 +346,9 @@ bool SetMenuItemText(HMENU hMenu, WORD id, const char *szText)
330
346
331
347
#endif
332
348
333
- bool C4EditCursor::RightButtonUp ()
349
+ bool C4EditCursor::RightButtonUp (C4Section §ion )
334
350
{
351
+ UpdateCurrentSection (section);
335
352
Target = nullptr ;
336
353
337
354
DoContextMenu ();
@@ -343,9 +360,10 @@ bool C4EditCursor::RightButtonUp()
343
360
344
361
void C4EditCursor::MiddleButtonUp (C4Section §ion)
345
362
{
363
+ UpdateCurrentSection (section);
346
364
if (Hold) return ;
347
365
348
- ApplyToolPicker (section );
366
+ ApplyToolPicker ();
349
367
}
350
368
351
369
bool C4EditCursor::Delete ()
@@ -368,7 +386,7 @@ bool C4EditCursor::OpenPropTools()
368
386
Console.PropertyDlg .Update (Selection);
369
387
break ;
370
388
case C4CNS_ModeDraw:
371
- Console.ToolsDlg .Open ();
389
+ Console.ToolsDlg .Open (*CurrentSection );
372
390
break ;
373
391
}
374
392
return true ;
@@ -448,11 +466,11 @@ void C4EditCursor::MoveSelection(int32_t iXOff, int32_t iYOff)
448
466
EMMoveObject (EMMO_Move, iXOff, iYOff, nullptr , Selection);
449
467
}
450
468
451
- void C4EditCursor::FrameSelection (C4Section §ion )
469
+ void C4EditCursor::FrameSelection ()
452
470
{
453
471
Selection.Clear ();
454
472
C4Object *cobj; C4ObjectLink *clnk;
455
- for (clnk = section. Objects .First ; clnk && (cobj = clnk->Obj ); clnk = clnk->Next )
473
+ for (clnk = CurrentSection-> Objects .First ; clnk && (cobj = clnk->Obj ); clnk = clnk->Next )
456
474
if (cobj->Status ) if (cobj->OCF & OCF_NotContained)
457
475
{
458
476
if (Inside (cobj->x , (std::min)(X, X2), (std::max)(X, X2)) && Inside (cobj->y , (std::min)(Y, Y2), (std::max)(Y, Y2)))
@@ -548,36 +566,36 @@ bool C4EditCursor::ToggleMode()
548
566
return true ;
549
567
}
550
568
551
- void C4EditCursor::ApplyToolBrush (C4Section §ion )
569
+ void C4EditCursor::ApplyToolBrush ()
552
570
{
553
571
if (!EditingOK ()) return ;
554
572
C4ToolsDlg *pTools = &Console.ToolsDlg ;
555
573
// execute/send control
556
- EMControl (CID_EMDrawTool, new C4ControlEMDrawTool (EMDT_Brush, section. Landscape .Mode , X, Y, 0 , 0 , pTools->Grade , !!pTools->ModeIFT , section. Number , pTools->Material , pTools->Texture ));
574
+ EMControl (CID_EMDrawTool, new C4ControlEMDrawTool (EMDT_Brush, CurrentSection-> Landscape .Mode , X, Y, 0 , 0 , pTools->Grade , !!pTools->ModeIFT , CurrentSection-> Number , pTools->Material , pTools->Texture ));
557
575
}
558
576
559
- void C4EditCursor::ApplyToolLine (C4Section §ion )
577
+ void C4EditCursor::ApplyToolLine ()
560
578
{
561
579
if (!EditingOK ()) return ;
562
580
C4ToolsDlg *pTools = &Console.ToolsDlg ;
563
581
// execute/send control
564
- EMControl (CID_EMDrawTool, new C4ControlEMDrawTool (EMDT_Line, section. Landscape .Mode , X, Y, X2, Y2, pTools->Grade , !!pTools->ModeIFT , section. Number , pTools->Material , pTools->Texture ));
582
+ EMControl (CID_EMDrawTool, new C4ControlEMDrawTool (EMDT_Line, CurrentSection-> Landscape .Mode , X, Y, X2, Y2, pTools->Grade , !!pTools->ModeIFT , CurrentSection-> Number , pTools->Material , pTools->Texture ));
565
583
}
566
584
567
- void C4EditCursor::ApplyToolRect (C4Section §ion )
585
+ void C4EditCursor::ApplyToolRect ()
568
586
{
569
587
if (!EditingOK ()) return ;
570
588
C4ToolsDlg *pTools = &Console.ToolsDlg ;
571
589
// execute/send control
572
- EMControl (CID_EMDrawTool, new C4ControlEMDrawTool (EMDT_Rect, section. Landscape .Mode , X, Y, X2, Y2, pTools->Grade , !!pTools->ModeIFT , section. Number , pTools->Material , pTools->Texture ));
590
+ EMControl (CID_EMDrawTool, new C4ControlEMDrawTool (EMDT_Rect, CurrentSection-> Landscape .Mode , X, Y, X2, Y2, pTools->Grade , !!pTools->ModeIFT , CurrentSection-> Number , pTools->Material , pTools->Texture ));
573
591
}
574
592
575
- void C4EditCursor::ApplyToolFill (C4Section §ion )
593
+ void C4EditCursor::ApplyToolFill ()
576
594
{
577
595
if (!EditingOK ()) return ;
578
596
C4ToolsDlg *pTools = &Console.ToolsDlg ;
579
597
// execute/send control
580
- EMControl (CID_EMDrawTool, new C4ControlEMDrawTool (EMDT_Fill, section. Landscape .Mode , X, Y, 0 , Y2, pTools->Grade , false , section. Number , pTools->Material ));
598
+ EMControl (CID_EMDrawTool, new C4ControlEMDrawTool (EMDT_Fill, CurrentSection-> Landscape .Mode , X, Y, 0 , Y2, pTools->Grade , false , CurrentSection-> Number , pTools->Material ));
581
599
}
582
600
583
601
bool C4EditCursor::DoContextMenu ()
@@ -634,15 +652,15 @@ void C4EditCursor::GrabContents()
634
652
EMMoveObject (EMMO_Exit, 0 , 0 , nullptr , Selection);
635
653
}
636
654
637
- void C4EditCursor::UpdateDropTarget (C4Section §ion, uint16_t wKeyFlags)
655
+ void C4EditCursor::UpdateDropTarget (uint16_t wKeyFlags)
638
656
{
639
657
C4Object *cobj; C4ObjectLink *clnk;
640
658
641
659
DropTarget = nullptr ;
642
660
643
661
if (wKeyFlags & MK_CONTROL)
644
662
if (Selection.GetObject ())
645
- for (clnk = section. Objects .First ; clnk && (cobj = clnk->Obj ); clnk = clnk->Next )
663
+ for (clnk = CurrentSection-> Objects .First ; clnk && (cobj = clnk->Obj ); clnk = clnk->Next )
646
664
if (cobj->Status )
647
665
if (!cobj->Contained )
648
666
if (Inside<int32_t >(X - (cobj->x + cobj->Shape .x ), 0 , cobj->Shape .Wdt - 1 ))
@@ -680,17 +698,17 @@ int32_t C4EditCursor::GetMode()
680
698
return Mode;
681
699
}
682
700
683
- void C4EditCursor::ApplyToolPicker (C4Section §ion )
701
+ void C4EditCursor::ApplyToolPicker ()
684
702
{
685
703
int32_t iMaterial;
686
704
uint8_t byIndex;
687
- switch (section. Landscape .Mode )
705
+ switch (CurrentSection-> Landscape .Mode )
688
706
{
689
707
case C4LSC_Static:
690
708
// Material-texture from map
691
- if (byIndex = section. Landscape .GetMapIndex (X / section. Landscape .MapZoom , Y / section. Landscape .MapZoom ))
709
+ if (byIndex = CurrentSection-> Landscape .GetMapIndex (X / CurrentSection-> Landscape .MapZoom , Y / CurrentSection-> Landscape .MapZoom ))
692
710
{
693
- const C4TexMapEntry *pTex = section. TextureMap .GetEntry (byIndex & (IFT - 1 ));
711
+ const C4TexMapEntry *pTex = CurrentSection-> TextureMap .GetEntry (byIndex & (IFT - 1 ));
694
712
if (pTex)
695
713
{
696
714
Console.ToolsDlg .SelectMaterial (pTex->GetMaterialName ());
@@ -703,10 +721,10 @@ void C4EditCursor::ApplyToolPicker(C4Section §ion)
703
721
break ;
704
722
case C4LSC_Exact:
705
723
// Material only from landscape
706
- if (section. MatValid (iMaterial = section. Landscape .GetMat (X, Y)))
724
+ if (CurrentSection-> MatValid (iMaterial = CurrentSection-> Landscape .GetMat (X, Y)))
707
725
{
708
- Console.ToolsDlg .SelectMaterial (section. Material .Map [iMaterial].Name );
709
- Console.ToolsDlg .SetIFT (section. Landscape .GBackIFT (X, Y));
726
+ Console.ToolsDlg .SelectMaterial (CurrentSection-> Material .Map [iMaterial].Name );
727
+ Console.ToolsDlg .SetIFT (CurrentSection-> Landscape .GBackIFT (X, Y));
710
728
}
711
729
else
712
730
Console.ToolsDlg .SelectMaterial (C4TLS_MatSky);
@@ -730,14 +748,38 @@ void C4EditCursor::EMMoveObject(C4ControlEMObjectAction eAction, int32_t tx, int
730
748
}
731
749
732
750
// execute control
733
- EMControl (CID_EMMoveObj, new C4ControlEMMoveObject (eAction, tx, ty, pTargetObj-> Section ->Number , pTargetObj, iObjCnt, pObjIDs, szScript, Config.Developer .ConsoleScriptStrictness ));
751
+ EMControl (CID_EMMoveObj, new C4ControlEMMoveObject (eAction, tx, ty, CurrentSection ->Number , pTargetObj, iObjCnt, pObjIDs, szScript, Config.Developer .ConsoleScriptStrictness ));
734
752
}
735
753
736
754
void C4EditCursor::EMControl (C4PacketType eCtrlType, C4ControlPacket *pCtrl)
737
755
{
738
756
Game.Control .DoInput (eCtrlType, pCtrl, CDT_Decide);
739
757
}
740
758
759
+ void C4EditCursor::UpdateCurrentSection (C4Section §ion)
760
+ {
761
+ if (CurrentSection != §ion)
762
+ {
763
+ CurrentSection = §ion;
764
+ ResetSectionDependentState ();
765
+ }
766
+ }
767
+
768
+ void C4EditCursor::ResetSectionDependentState ()
769
+ {
770
+ Target = nullptr ;
771
+ DropTarget = nullptr ;
772
+ Selection.Clear ();
773
+ DragFrame = false ;
774
+ DragLine = false ;
775
+ fSelectionChanged = true ;
776
+
777
+ if (CurrentSection && Mode == C4CNS_ModeDraw)
778
+ {
779
+ Console.ToolsDlg .SetSection (*CurrentSection);
780
+ }
781
+ }
782
+
741
783
#ifdef WITH_DEVELOPER_MODE
742
784
743
785
// GTK+ callbacks
0 commit comments