Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#region ================== Copyright (c) 2007 Pascal vd Heiden
/*
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
* This program is released under GNU General Public License
*
* 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.
*
*/
#endregion
#region ================== Namespaces
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
using CodeImp.DoomBuilder.Windows;
using CodeImp.DoomBuilder.IO;
using CodeImp.DoomBuilder.Map;
using CodeImp.DoomBuilder.Rendering;
using CodeImp.DoomBuilder.Geometry;
using CodeImp.DoomBuilder.Editing;
using CodeImp.DoomBuilder.Actions;
using CodeImp.DoomBuilder.VisualModes;
#endregion
namespace CodeImp.DoomBuilder.BuilderModes
{
[EditMode(DisplayName = "Visual Mode",
SwitchAction = "visualmode", // Action name used to switch to this mode
ButtonImage = "VisualMode.png", // Image resource name for the button
ButtonOrder = 0, // Position of the button (lower is more to the left)
ButtonGroup = "001_visual",
UseByDefault = true)]
public class BaseVisualMode : VisualMode
{
#region ================== Constants
// Object picking
private const double PICK_INTERVAL = 80.0d;
private const float PICK_RANGE = 0.98f;
// Gravity
private const float GRAVITY = -0.06f;
private const float CAMERA_FLOOR_OFFSET = 41f; // same as in doom
private const float CAMERA_CEILING_OFFSET = 10f;
#endregion
#region ================== Variables
// Object picking
private VisualPickResult target;
private double lastpicktime;
private bool locktarget;
// Gravity vector
private Vector3D gravity;
#endregion
#region ================== Properties
public IRenderer3D Renderer { get { return renderer; } }
#endregion
#region ================== Constructor / Disposer
// Constructor
public BaseVisualMode()
{
// Initialize
this.gravity = new Vector3D(0.0f, 0.0f, 0.0f);
// We have no destructor
GC.SuppressFinalize(this);
}
// Disposer
public override void Dispose()
{
// Not already disposed?
if(!isdisposed)
{
// Clean up
// Done
base.Dispose();
}
}
#endregion
#region ================== Methods
// This creates a visual sector
protected override VisualSector CreateVisualSector(Sector s)
{
BaseVisualSector vs = new BaseVisualSector(this, s);
return vs;
}
// This creates a visual thing
protected override VisualThing CreateVisualThing(Thing t)
{
BaseVisualThing vt = new BaseVisualThing(this, t);
if(vt.Setup()) return vt; else return null;
}
// This locks the target so that it isn't changed until unlocked
public void LockTarget()
{
locktarget = true;
}
// This unlocks the target so that is changes to the aimed geometry again
public void UnlockTarget()
{
locktarget = false;
}
// This picks a new target, if not locked
private void PickTargetUnlocked()
{
if(!locktarget) PickTarget();
}
// This picks a new target
private void PickTarget()
{
// Find the object we are aiming at
Vector3D start = General.Map.VisualCamera.Position;
Vector3D delta = General.Map.VisualCamera.Target - General.Map.VisualCamera.Position;
delta = delta.GetFixedLength(General.Settings.ViewDistance * PICK_RANGE);
VisualPickResult newtarget = PickObject(start, start + delta);
// Should we update the info on panels?
bool updateinfo = (newtarget.picked != target.picked);
// Apply new target
target = newtarget;
// Show target info
if(updateinfo) ShowTargetInfo();
}
// This shows the picked target information
public void ShowTargetInfo()
{
// Any result?
if(target.picked != null)
{
// Geometry picked?
if(target.picked is VisualGeometry)
{
VisualGeometry pickedgeo = (target.picked as VisualGeometry);
if(pickedgeo.Sidedef != null)
General.Interface.ShowLinedefInfo(pickedgeo.Sidedef.Line);
else if(pickedgeo.Sidedef == null)
General.Interface.ShowSectorInfo(pickedgeo.Sector.Sector);
else
General.Interface.HideInfo();
}
// Thing picked?
if(target.picked is VisualThing)
{
VisualThing pickedthing = (target.picked as VisualThing);
General.Interface.ShowThingInfo(pickedthing.Thing);
}
}
else
{
General.Interface.HideInfo();
}
}
#endregion
#region ================== Events
// Help!
public override void OnHelp()
{
General.ShowHelp("e_visual.html");
}
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
// Processing
public override void OnProcess(double deltatime)
{
// Process things?
base.ProcessThings = (BuilderPlug.Me.ShowVisualThings != 0);
// Setup the move multiplier depending on gravity
Vector3D movemultiplier = new Vector3D(1.0f, 1.0f, 1.0f);
if(BuilderPlug.Me.UseGravity) movemultiplier.z = 0.0f;
General.Map.VisualCamera.MoveMultiplier = movemultiplier;
// Apply gravity?
if(BuilderPlug.Me.UseGravity && (General.Map.VisualCamera.Sector != null))
{
// Camera below floor level?
if(General.Map.VisualCamera.Position.z <= (General.Map.VisualCamera.Sector.FloorHeight + CAMERA_FLOOR_OFFSET + 0.1f))
{
// Stay above floor
gravity = new Vector3D(0.0f, 0.0f, 0.0f);
General.Map.VisualCamera.Position = new Vector3D(General.Map.VisualCamera.Position.x,
General.Map.VisualCamera.Position.y,
General.Map.VisualCamera.Sector.FloorHeight + CAMERA_FLOOR_OFFSET);
}
else
{
// Fall down
gravity += new Vector3D(0.0f, 0.0f, (float)(GRAVITY * deltatime));
General.Map.VisualCamera.Position += gravity;
}
// Camera above ceiling level?
if(General.Map.VisualCamera.Position.z >= (General.Map.VisualCamera.Sector.CeilHeight - CAMERA_CEILING_OFFSET - 0.1f))
{
// Stay below ceiling
General.Map.VisualCamera.Position = new Vector3D(General.Map.VisualCamera.Position.x,
General.Map.VisualCamera.Position.y,
General.Map.VisualCamera.Sector.CeilHeight - CAMERA_CEILING_OFFSET);
}
}
else
{
gravity = new Vector3D(0.0f, 0.0f, 0.0f);
}
// Do processing
base.OnProcess(deltatime);
// Process visible geometry
foreach(IVisualEventReceiver g in visiblegeometry)
{
g.OnProcess(deltatime);
}
// Time to pick a new target?
if(General.Clock.CurrentTime > (lastpicktime + PICK_INTERVAL))
{
PickTargetUnlocked();
lastpicktime = General.Clock.CurrentTime;
}
// The mouse is always in motion
MouseEventArgs args = new MouseEventArgs(General.Interface.MouseButtons, 0, 0, 0, 0);
OnMouseMove(args);
}
// This draws a frame
public override void OnRedrawDisplay()
{
// Start drawing
if(renderer.Start())
{
// Use fog!
renderer.SetFogMode(true);
// Set target for highlighting
renderer.SetHighlightedObject(target.picked);
// Begin with geometry
renderer.StartGeometry();
// Render all visible sectors
foreach(VisualGeometry g in visiblegeometry)
renderer.AddSectorGeometry(g);
if(BuilderPlug.Me.ShowVisualThings != 0)
{
// Render things in cages?
renderer.DrawThingCages = ((BuilderPlug.Me.ShowVisualThings & 2) != 0);
// Render all visible things
foreach(VisualThing t in visiblethings)
renderer.AddThingGeometry(t);
}
// Done rendering geometry
renderer.FinishGeometry();
// Render crosshair
renderer.RenderCrosshair();
// Present!
renderer.Finish();
}
}
// After resources were reloaded
protected override void ResourcesReloaded()
{
base.ResourcesReloaded();
PickTarget();
}
// Mouse moves
public override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
if(target.picked != null) (target.picked as IVisualEventReceiver).OnMouseMove(e);
}
#endregion
#region ================== Actions
[BeginAction("visualselect", BaseAction = true)]
public void BeginSelect()
{
PickTargetUnlocked();
if(target.picked != null) (target.picked as IVisualEventReceiver).OnSelectBegin();
}
[EndAction("visualselect", BaseAction = true)]
public void EndSelect()
{
if(target.picked != null) (target.picked as IVisualEventReceiver).OnSelectEnd();
}
[BeginAction("visualedit", BaseAction = true)]
public void BeginEdit()
{
PickTargetUnlocked();
if(target.picked != null) (target.picked as IVisualEventReceiver).OnEditBegin();
}
[EndAction("visualedit", BaseAction = true)]
public void EndEdit()
{
if(target.picked != null) (target.picked as IVisualEventReceiver).OnEditEnd();
ShowTargetInfo();
}
[BeginAction("raisesector8")]
public void RaiseSector8()
{
PickTargetUnlocked();
if(target.picked != null) (target.picked as IVisualEventReceiver).OnChangeTargetHeight(8);
ShowTargetInfo();
}
[BeginAction("lowersector8")]
public void LowerSector8()
{
PickTargetUnlocked();
if(target.picked != null) (target.picked as IVisualEventReceiver).OnChangeTargetHeight(-8);
ShowTargetInfo();
}
[BeginAction("raisesector1")]
public void RaiseSector1()
{
PickTargetUnlocked();
if(target.picked != null) (target.picked as IVisualEventReceiver).OnChangeTargetHeight(1);
ShowTargetInfo();
}
[BeginAction("lowersector1")]
public void LowerSector1()
{
PickTargetUnlocked();
if(target.picked != null) (target.picked as IVisualEventReceiver).OnChangeTargetHeight(-1);
ShowTargetInfo();
}
[BeginAction("showvisualthings")]
public void ShowVisualThings()
{
BuilderPlug.Me.ShowVisualThings++;
if(BuilderPlug.Me.ShowVisualThings > 2) BuilderPlug.Me.ShowVisualThings = 0;
}
[BeginAction("raisebrightness8")]
public void RaiseBrightness8()
{
PickTargetUnlocked();
if(target.picked != null) (target.picked as IVisualEventReceiver).OnChangeTargetBrightness(true);
ShowTargetInfo();
}
[BeginAction("lowerbrightness8")]
public void LowerBrightness8()
{
PickTargetUnlocked();
if(target.picked != null) (target.picked as IVisualEventReceiver).OnChangeTargetBrightness(false);
ShowTargetInfo();
}
[BeginAction("movetextureleft")]
public void MoveTextureLeft1()
{
PickTargetUnlocked();
if(target.picked != null) (target.picked as IVisualEventReceiver).OnChangeTextureOffset(-1, 0);
ShowTargetInfo();
}
[BeginAction("movetextureright")]
public void MoveTextureRight1()
{
PickTargetUnlocked();
if(target.picked != null) (target.picked as IVisualEventReceiver).OnChangeTextureOffset(1, 0);
ShowTargetInfo();
}
[BeginAction("movetextureup")]
public void MoveTextureUp1()
{
PickTargetUnlocked();
if(target.picked != null) (target.picked as IVisualEventReceiver).OnChangeTextureOffset(0, -1);
ShowTargetInfo();
}
[BeginAction("movetexturedown")]
public void MoveTextureDown1()
{
PickTargetUnlocked();
if(target.picked != null) (target.picked as IVisualEventReceiver).OnChangeTextureOffset(0, 1);
ShowTargetInfo();
}
[BeginAction("movetextureleft8")]
public void MoveTextureLeft8()
{
PickTargetUnlocked();
if(target.picked != null) (target.picked as IVisualEventReceiver).OnChangeTextureOffset(-8, 0);
ShowTargetInfo();
}
[BeginAction("movetextureright8")]
public void MoveTextureRight8()
{
PickTargetUnlocked();
if(target.picked != null) (target.picked as IVisualEventReceiver).OnChangeTextureOffset(8, 0);
ShowTargetInfo();
}
[BeginAction("movetextureup8")]
public void MoveTextureUp8()
{
PickTargetUnlocked();
if(target.picked != null) (target.picked as IVisualEventReceiver).OnChangeTextureOffset(0, -8);
ShowTargetInfo();
}
[BeginAction("movetexturedown8")]
public void MoveTextureDown8()
{
PickTargetUnlocked();
if(target.picked != null) (target.picked as IVisualEventReceiver).OnChangeTextureOffset(0, 8);
ShowTargetInfo();
}
[BeginAction("textureselect")]
public void TextureSelect()
{
PickTargetUnlocked();
renderer.SetCrosshairBusy(true);
General.Interface.RedrawDisplay();
if(target.picked != null) (target.picked as IVisualEventReceiver).OnSelectTexture();
renderer.SetCrosshairBusy(false);
ShowTargetInfo();
}
[BeginAction("texturecopy")]
public void TextureCopy()
{
PickTargetUnlocked();
if(target.picked != null) (target.picked as IVisualEventReceiver).OnCopyTexture();
ShowTargetInfo();
}
[BeginAction("texturepaste")]
public void TexturePaste()
{
PickTargetUnlocked();
if(target.picked != null) (target.picked as IVisualEventReceiver).OnPasteTexture();
ShowTargetInfo();
}
[BeginAction("visualautoalignx")]
public void TextureAutoAlignX()
{
PickTargetUnlocked();
renderer.SetCrosshairBusy(true);
General.Interface.RedrawDisplay();
if(target.picked != null) (target.picked as IVisualEventReceiver).OnTextureAlign(true, false);
renderer.SetCrosshairBusy(false);
ShowTargetInfo();
}
[BeginAction("visualautoaligny")]
public void TextureAutoAlignY()
{
PickTargetUnlocked();
renderer.SetCrosshairBusy(true);
General.Interface.RedrawDisplay();
if(target.picked != null) (target.picked as IVisualEventReceiver).OnTextureAlign(false, true);
renderer.SetCrosshairBusy(false);
ShowTargetInfo();
}
[BeginAction("toggleupperunpegged")]
public void ToggleUpperUnpegged()
{
PickTargetUnlocked();
if(target.picked != null) (target.picked as IVisualEventReceiver).OnToggleUpperUnpegged();
ShowTargetInfo();
}
[BeginAction("togglelowerunpegged")]
public void ToggleLowerUnpegged()
{
PickTargetUnlocked();
if(target.picked != null) (target.picked as IVisualEventReceiver).OnToggleLowerUnpegged();
ShowTargetInfo();
}
[BeginAction("togglegravity")]
public void ToggleGravity()
{
BuilderPlug.Me.UseGravity = !BuilderPlug.Me.UseGravity;
string onoff = BuilderPlug.Me.UseGravity ? "ON" : "OFF";
General.Interface.DisplayStatus(StatusType.Action, "Gravity is now " + onoff + ".");
}
[BeginAction("togglebrightness")]
public void ToggleBrightness()
{
renderer.FullBrightness = !renderer.FullBrightness;
string onoff = renderer.FullBrightness ? "ON" : "OFF";
General.Interface.DisplayStatus(StatusType.Action, "Full Brightness is now " + onoff + ".");
}
[BeginAction("resettexture")]
public void ResetTexture()
{
PickTargetUnlocked();
if(target.picked != null) (target.picked as IVisualEventReceiver).OnResetTextureOffset();
ShowTargetInfo();
}
[BeginAction("floodfilltextures")]
public void FloodfillTextures()
{
PickTargetUnlocked();
if(target.picked != null) (target.picked as IVisualEventReceiver).OnTextureFloodfill();
ShowTargetInfo();
}
[BeginAction("texturecopyoffsets")]
public void TextureCopyOffsets()
{
PickTargetUnlocked();
if(target.picked != null) (target.picked as IVisualEventReceiver).OnCopyTextureOffsets();
ShowTargetInfo();
}
[BeginAction("texturepasteoffsets")]
public void TexturePasteOffsets()
{
PickTargetUnlocked();
if(target.picked != null) (target.picked as IVisualEventReceiver).OnPasteTextureOffsets();
ShowTargetInfo();
}
[BeginAction("copyproperties")]
public void CopyProperties()
{
PickTargetUnlocked();
if(target.picked != null) (target.picked as IVisualEventReceiver).OnCopyProperties();
ShowTargetInfo();
}
[BeginAction("pasteproperties")]
public void PasteProperties()
{
PickTargetUnlocked();
if(target.picked != null) (target.picked as IVisualEventReceiver).OnPasteProperties();
ShowTargetInfo();
}
[BeginAction("insertitem", BaseAction = true)]
public void Insert()
{
PickTargetUnlocked();
if(target.picked != null) (target.picked as IVisualEventReceiver).OnInsert();
ShowTargetInfo();
}
[BeginAction("deleteitem", BaseAction = true)]
public void Delete()
{
PickTargetUnlocked();
if(target.picked != null) (target.picked as IVisualEventReceiver).OnDelete();
ShowTargetInfo();
}
#endregion
}
}