* Fixed drop down toolbar buttons to correct their state

* Added terrain grid (ported from CentrED+; Thanks to StaticZ!)
This commit is contained in:
Andreas Schneider 2015-05-17 12:39:57 +02:00
parent 1ddaee39d5
commit 39280f927b
3 changed files with 224 additions and 32 deletions

View File

@ -257,6 +257,8 @@ type
ScreenRect: TRect;
DrawQuad: array[0..3,0..1] of TGLint;
RealQuad: array[0..3,0..1] of TGLint;
LineWidth: array[0..2] of GLfloat;
LineDraw: array[0..2,0..1,0..1] of TGLint;
Item: TWorldItem;
HighRes: TMaterial;
LowRes: TMaterial;

View File

@ -123,7 +123,7 @@ object frmMain: TfrmMain
AnchorSideLeft.Control = cbTerrain
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = cbTerrain
Left = 91
Left = 88
Height = 13
Top = 8
Width = 31
@ -362,7 +362,7 @@ object frmMain: TfrmMain
Left = 158
Height = 22
Hint = 'Save Preset'
Top = 137
Top = 139
Width = 22
Anchors = [akTop, akRight]
BorderSpacing.Right = 4
@ -414,7 +414,7 @@ object frmMain: TfrmMain
Left = 184
Height = 22
Hint = 'Delete Preset'
Top = 137
Top = 139
Width = 22
Anchors = [akTop, akRight]
BorderSpacing.Right = 4
@ -469,7 +469,7 @@ object frmMain: TfrmMain
AnchorSideBottom.Control = cbRandomPreset
Cursor = 63
Left = 4
Height = 109
Height = 111
Top = 24
Width = 202
Anchors = [akTop, akLeft, akRight, akBottom]
@ -517,8 +517,8 @@ object frmMain: TfrmMain
AnchorSideBottom.Control = gbRandom
AnchorSideBottom.Side = asrBottom
Left = 4
Height = 27
Top = 137
Height = 25
Top = 139
Width = 150
Anchors = [akLeft, akRight, akBottom]
BorderSpacing.Left = 4
@ -571,10 +571,10 @@ object frmMain: TfrmMain
AnchorSideTop.Side = asrBottom
AnchorSideRight.Control = tsTiles
AnchorSideRight.Side = asrBottom
Left = 91
Left = 88
Height = 23
Top = 21
Width = 107
Width = 110
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Right = 16
OnEditingDone = edFilterEditingDone
@ -585,10 +585,10 @@ object frmMain: TfrmMain
AnchorSideLeft.Side = asrCenter
AnchorSideTop.Control = cbTerrain
AnchorSideTop.Side = asrBottom
Left = 3
Left = 4
Height = 26
Top = 34
Width = 73
Width = 68
Caption = 'Statics'
Checked = True
OnChange = cbStaticsChange
@ -601,7 +601,7 @@ object frmMain: TfrmMain
Left = 4
Height = 26
Top = 8
Width = 71
Width = 68
BorderSpacing.Left = 4
BorderSpacing.Top = 8
Caption = 'Terrain'
@ -935,18 +935,15 @@ object frmMain: TfrmMain
end
object tbTerrain: TToolButton
Left = 274
Hint = 'Show Terrain'
Top = 2
Caption = 'Terrain'
Down = True
ImageIndex = 10
OnClick = tbTerrainClick
Action = acTerrain
DropdownMenu = pmViewTerrainSettings
ParentShowHint = False
ShowHint = True
Style = tbsCheck
Style = tbsDropDown
end
object tbStatics: TToolButton
Left = 297
Left = 309
Top = 2
Action = acStatics
DropdownMenu = pmViewStaticSettings
@ -955,7 +952,7 @@ object frmMain: TfrmMain
Style = tbsDropDown
end
object tbSeparator5: TToolButton
Left = 436
Left = 448
Height = 22
Top = 2
Width = 5
@ -963,7 +960,7 @@ object frmMain: TfrmMain
Style = tbsDivider
end
object tbRadarMap: TToolButton
Left = 441
Left = 453
Hint = 'Radar Map'
Top = 2
Caption = 'Radar Map'
@ -985,14 +982,14 @@ object frmMain: TfrmMain
Style = tbsCheck
end
object tbFlat: TToolButton
Left = 401
Left = 413
Top = 2
Action = acFlat
DropdownMenu = pmFlatViewSettings
Style = tbsDropDown
end
object tbNoDraw: TToolButton
Left = 332
Left = 344
Top = 2
Action = acNoDraw
Style = tbsCheck
@ -1011,12 +1008,12 @@ object frmMain: TfrmMain
Action = acUndo
end
object tbLightlevel: TToolButton
Left = 378
Left = 390
Top = 2
Action = acLightlevel
end
object tbWalkable: TToolButton
Left = 355
Left = 367
Top = 2
Action = acWalkable
Style = tbsCheck
@ -2698,6 +2695,13 @@ object frmMain: TfrmMain
OnExecute = acWalkableExecute
ShortCut = 16471
end
object acTerrain: TAction
Category = 'Settings'
Checked = True
Hint = 'Show Terrain'
ImageIndex = 10
OnExecute = acTerrainExecute
end
object acStatics: TAction
Category = 'Settings'
Checked = True
@ -2727,6 +2731,7 @@ object frmMain: TfrmMain
end
end
object pmFlatViewSettings: TPopupMenu
OnClose = pmFlatViewSettingsClose
left = 368
top = 136
object mnuFlatShowHeight: TMenuItem
@ -2745,6 +2750,7 @@ object frmMain: TfrmMain
end
object pmViewStaticSettings: TPopupMenu
Images = ImageList1
OnClose = pmFlatViewSettingsClose
left = 584
top = 33
object mnuShowWalls: TMenuItem
@ -2790,4 +2796,24 @@ object frmMain: TfrmMain
OnClick = mnuShowWallsClick
end
end
object tmToolbarFix: TTimer
Enabled = False
Interval = 25
OnTimer = tmToolbarFixTimer
left = 584
top = 296
end
object pmViewTerrainSettings: TPopupMenu
OnClose = pmFlatViewSettingsClose
left = 584
top = 88
object mnuShowGrid: TMenuItem
Caption = 'Show Grid'
OnClick = mnuShowGridClick
end
object mnuShowBlocks: TMenuItem
Caption = 'Show Blocks'
OnClick = mnuShowBlocksClick
end
end
end

View File

@ -73,6 +73,7 @@ type
acNoDraw: TAction;
acLightlevel: TAction;
acStatics: TAction;
acTerrain: TAction;
acWalkable: TAction;
acUndo: TAction;
acVirtualLayer: TAction;
@ -104,6 +105,8 @@ type
lblY: TLabel;
lbClients: TListBox;
MainMenu1: TMainMenu;
mnuShowBlocks: TMenuItem;
mnuShowGrid: TMenuItem;
mnuChangePassword: TMenuItem;
mnuShowBridges: TMenuItem;
mnuShowFoliage: TMenuItem;
@ -155,6 +158,7 @@ type
pnlChat: TPanel;
pnlChatHeader: TPanel;
pmFlatViewSettings: TPopupMenu;
pmViewTerrainSettings: TPopupMenu;
spChat: TSplitter;
spTileList: TSplitter;
tbFilter: TToolButton;
@ -164,6 +168,7 @@ type
tbUndo: TToolButton;
tbLightlevel: TToolButton;
tbWalkable: TToolButton;
tmToolbarFix: TTimer;
tsLocations: TTabSheet;
tbSetHue: TToolButton;
tmGrabTileInfo: TTimer;
@ -203,6 +208,7 @@ type
procedure acNoDrawExecute(Sender: TObject);
procedure acSelectExecute(Sender: TObject);
procedure acStaticsExecute(Sender: TObject);
procedure acTerrainExecute(Sender: TObject);
procedure acUndoExecute(Sender: TObject);
procedure acVirtualLayerExecute(Sender: TObject);
procedure acWalkableExecute(Sender: TObject);
@ -245,6 +251,8 @@ type
procedure mnuLargeScaleCommandsClick(Sender: TObject);
procedure mnuRegionControlClick(Sender: TObject);
procedure mnuShowAnimationsClick(Sender: TObject);
procedure mnuShowBlocksClick(Sender: TObject);
procedure mnuShowGridClick(Sender: TObject);
procedure mnuShowWallsClick(Sender: TObject);
procedure mnuShutdownClick(Sender: TObject);
procedure mnuWhiteBackgroundClick(Sender: TObject);
@ -263,13 +271,14 @@ type
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
procedure oglGameWindowPaint(Sender: TObject);
procedure oglGameWindowResize(Sender: TObject);
procedure pmFlatViewSettingsClose(Sender: TObject);
procedure pmGrabTileInfoPopup(Sender: TObject);
procedure tbFilterMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure tbRadarMapClick(Sender: TObject);
procedure tbTerrainClick(Sender: TObject);
procedure tmGrabTileInfoTimer(Sender: TObject);
procedure tmMovementTimer(Sender: TObject);
procedure tmToolbarFixTimer(Sender: TObject);
procedure vdtRandomClick(Sender: TObject);
procedure vdtRandomDragDrop(Sender: TBaseVirtualTree; Source: TObject;
DataObject: IDataObject; Formats: TFormatArray; Shift: TShiftState;
@ -524,6 +533,22 @@ begin
RebuildScreenBuffer;
end;
procedure TfrmMain.mnuShowBlocksClick(Sender: TObject);
begin
mnuShowBlocks.Checked := not mnuShowBlocks.Checked;
mnuShowGrid.Checked := False; //If ShowBlocks is active, ShowGrid cannot be.
RebuildScreenBuffer;
FRepaintNeeded := True;
end;
procedure TfrmMain.mnuShowGridClick(Sender: TObject);
begin
mnuShowGrid.Checked := not mnuShowGrid.Checked;
mnuShowBlocks.Checked := False; //If ShowGrid is active, ShowBlocks cannot be.
RebuildScreenBuffer;
FRepaintNeeded := True;
end;
procedure TfrmMain.mnuShowWallsClick(Sender: TObject);
begin
// Update filters. First, start off empty.
@ -1177,6 +1202,12 @@ begin
RebuildScreenBuffer;
end;
procedure TfrmMain.acTerrainExecute(Sender: TObject);
begin
acTerrain.Checked := not acTerrain.Checked;
RebuildScreenBuffer;
end;
procedure TfrmMain.acUndoExecute(Sender: TObject);
var
i: Integer;
@ -1513,6 +1544,11 @@ begin
InvalidateScreenBuffer;
end;
procedure TfrmMain.pmFlatViewSettingsClose(Sender: TObject);
begin
tmToolbarFix.Enabled := True;
end;
procedure TfrmMain.pmGrabTileInfoPopup(Sender: TObject);
begin
mnuGrabHue.Enabled := CurrentTile is TStaticItem;
@ -1531,11 +1567,6 @@ begin
frmRadarMap.BringToFront;
end;
procedure TfrmMain.tbTerrainClick(Sender: TObject);
begin
RebuildScreenBuffer;
end;
procedure TfrmMain.tmGrabTileInfoTimer(Sender: TObject);
begin
tmGrabTileInfo.Enabled := False;
@ -1559,6 +1590,17 @@ begin
end;
end;
procedure TfrmMain.tmToolbarFixTimer(Sender: TObject);
begin
// This is a workaround for the TToolButton to not stay "down" when
// a popup menu was shown. Thanks to StaticZ for finding that :-)
// Only necessary till this is fixed: http://bugs.freepascal.org/view.php?id=15263
tmToolbarFix.Enabled := False;
tbFlat.Down := acFlat.Checked;
tbTerrain.Down := acTerrain.Checked;
tbStatics.Down := acStatics.Checked;
end;
procedure TfrmMain.vdtRandomClick(Sender: TObject);
var
node: PVirtualNode;
@ -2237,8 +2279,8 @@ procedure TfrmMain.PrepareScreenBlock(ABlockInfo: PBlockInfo);
var
item: TWorldItem;
drawX, drawY: Integer;
z, west, south, east: SmallInt;
rawZ, rawWest, rawSouth, rawEast: SmallInt;
z, west, south, east, tileNorth, tileWest, tileLeft, tileRight: SmallInt;
rawZ, rawWest, rawSouth, rawEast, rawTileNorth, rawTileWest, rawTileLeft, rawTileRight: SmallInt;
staticItem: TStaticItem;
begin
//add normals to map tiles and materials where possible
@ -2332,6 +2374,22 @@ begin
ABlockInfo^.DrawQuad[2][1] := drawY + 44 - south * 4;
ABlockInfo^.DrawQuad[3][0] := drawX - 22;
ABlockInfo^.DrawQuad[3][1] := drawY + 22 - west * 4;
// Set lines to visualize the terrain mesh
if mnuShowGrid.Checked or mnuShowBlocks.Checked then
begin
ABlockInfo^.LineWidth[0] := 0.9;
ABlockInfo^.LineDraw[0][0] := ABlockInfo^.DrawQuad[0];
ABlockInfo^.LineDraw[0][1] := ABlockInfo^.DrawQuad[1];
ABlockInfo^.LineWidth[1] := 0.9;
ABlockInfo^.LineDraw[1][0] := ABlockInfo^.DrawQuad[0];
ABlockInfo^.LineDraw[1][1] := ABlockInfo^.DrawQuad[3];
ABlockInfo^.LineWidth[2] := 0.8;
//ABlockInfo^.LineDraw[2][0] := ABlockInfo^.DrawQuad[0];
//ABlockInfo^.LineDraw[2][1] := ABlockInfo^.DrawQuad[2];
ABlockInfo^.LineDraw[2][0] := ABlockInfo^.DrawQuad[1];
ABlockInfo^.LineDraw[2][1] := ABlockInfo^.DrawQuad[3];
end;
end else
begin
ABlockInfo^.DrawQuad[0][0] := drawX - 22;
@ -2342,6 +2400,32 @@ begin
ABlockInfo^.DrawQuad[2][1] := drawY + ABlockInfo^.LowRes.Height - z * 4;
ABlockInfo^.DrawQuad[3][0] := drawX - 22;
ABlockInfo^.DrawQuad[3][1] := drawY + ABlockInfo^.LowRes.Height - z * 4;
// Set lines to visualize the terrain mesh
if mnuShowGrid.Checked or mnuShowBlocks.Checked then
begin
GetLandAlt(item.X, item.Y - 1, z, rawZ, tileNorth, rawTileNorth);
GetLandAlt(item.X - 1, item.Y, z, rawZ, tileWest, rawTileWest);
GetLandAlt(item.X - 1, item.Y + 1, z, rawZ, tileLeft, rawTileLeft);
GetLandAlt(item.X + 1, item.Y - 1, z, rawZ, tileRight, rawTileRight);
if (tileNorth <> z) or (tileRight <> z) then
ABlockInfo^.LineWidth[0] := 0.9
else
ABlockInfo^.LineWidth[0] := 0.8;
ABlockInfo^.LineDraw[0][0][0] := drawX;
ABlockInfo^.LineDraw[0][0][1] := ABlockInfo^.DrawQuad[0][1];
ABlockInfo^.LineDraw[0][1][0] := ABlockInfo^.DrawQuad[1][0];
ABlockInfo^.LineDraw[0][1][1] := ABlockInfo^.DrawQuad[1][1] + 22;
if (tileWest <> z) or (tileLeft <> z) then
ABlockInfo^.LineWidth[1] := 0.9
else
ABlockInfo^.LineWidth[1] := 0.8;
ABlockInfo^.LineDraw[1][0][0] := drawX;
ABlockInfo^.LineDraw[1][0][1] := ABlockInfo^.DrawQuad[0][1];
ABlockInfo^.LineDraw[1][1][0] := ABlockInfo^.DrawQuad[3][0];
ABlockInfo^.LineDraw[1][1][1] := ABlockInfo^.DrawQuad[3][1] - 22;
ABlockInfo^.LineWidth[2] := 0.0;
end;
end;
end else
if item is TVirtualTile then
@ -2493,6 +2577,86 @@ begin
if (blockInfo^.Text <> nil) then
blockInfo^.Text.Render(blockInfo^.ScreenRect);
// Rending mesh terrain
if (mnuShowGrid.Checked) and (blockInfo^.Item is TMapCell) then
begin
glDisable(GL_TEXTURE_2D); // Do not use color texture
glEnable(GL_LINE_SMOOTH); // smoothing lines
//glDisable(GL_LINE_SMOOTH);
if (tbFlat.Down) then
begin
glColor4f(0.8, 0.8, 0.8, 0.9); // Color lines
glLineWidth(0.1); // line width
glBegin(GL_LINES);
glVertex2iv(@blockInfo^.LineDraw[0][0]);
glVertex2iv(@blockInfo^.LineDraw[0][1]);
glVertex2iv(@blockInfo^.LineDraw[1][0]);
glVertex2iv(@blockInfo^.LineDraw[1][1]);
glEnd;
end else
begin
if blockInfo^.LineWidth[0] < 0.85
then glColor4f(1.0, 1.0, 0.0, 0.5) // Color lines
else glColor4f(1.0, 1.0, 1.0, 1.0); // Color lines
glLineWidth(blockInfo^.LineWidth[0]); // line width
glBegin(GL_LINES);
glVertex2iv(@blockInfo^.LineDraw[0][0]);
glVertex2iv(@blockInfo^.LineDraw[0][1]);
glEnd;
if blockInfo^.LineWidth[1] < 0.85
then glColor4f(1.0, 1.0, 0.0, 0.5) // Color lines
else glColor4f(1.0, 1.0, 1.0, 1.0); // Color lines
glLineWidth(blockInfo^.LineWidth[1]); // line width
glBegin(GL_LINES);
glVertex2iv(@blockInfo^.LineDraw[1][0]);
glVertex2iv(@blockInfo^.LineDraw[1][1]);
glEnd;
if blockInfo^.LineWidth[2] > 0 then
begin
glColor4f(1.3281, 0.2510, 1.0, 0.8); // Color lines
glLineWidth(blockInfo^.LineWidth[2]);// line width
glBegin(GL_LINES);
glVertex2iv(@blockInfo^.LineDraw[2][0]);
glVertex2iv(@blockInfo^.LineDraw[2][1]);
glEnd;
end;
end;
glDisable(GL_LINE_SMOOTH);
glEnable(GL_TEXTURE_2D);
end else if (mnuShowBlocks.Checked) and (blockInfo^.Item is TMapCell) then
begin // Rending the grid blocks
glDisable(GL_TEXTURE_2D); // Do not use color texture
glEnable(GL_LINE_SMOOTH); // smoothing lines
if (blockInfo^.Item.X mod 8 = 0) then begin
glLineWidth(2.0);
glColor4f(1.0, 1.0, 0.0, 0.5);
end else begin
glColor4f(0.8, 0.8, 0.8, 0.9);
glLineWidth(0.1);
end;
glBegin(GL_LINES);
glVertex2iv(@blockInfo^.LineDraw[1][0]);
glVertex2iv(@blockInfo^.LineDraw[1][1]);
glEnd;
if (blockInfo^.Item.Y mod 8 = 0) then begin
glLineWidth(2.0);
glColor4f(1.0, 1.0, 0.0, 0.5);
end else begin
glColor4f(0.8, 0.8, 0.8, 0.9);
glLineWidth(0.1);
end;
glBegin(GL_LINES);
glVertex2iv(@blockInfo^.LineDraw[0][0]);
glVertex2iv(@blockInfo^.LineDraw[0][1]);
glEnd;
glDisable(GL_LINE_SMOOTH);
glEnable(GL_TEXTURE_2D);
end
end;
if (FLightManager.LightLevel > 0) and not acFlat.Checked then