- Added tracking of "Highlighted" state in the screen buffer

This commit is contained in:
Andreas Schneider 2009-07-30 20:31:29 +02:00
parent 01d5fb98d1
commit dc1f425353
2 changed files with 67 additions and 26 deletions

View File

@ -163,6 +163,7 @@ type
LowRes: TMaterial; LowRes: TMaterial;
Normals: PNormals; Normals: PNormals;
State: TScreenState; State: TScreenState;
Highlighted: Boolean;
Next: PBlockInfo; Next: PBlockInfo;
end; end;
@ -994,6 +995,7 @@ begin
Result^.LowRes := nil; Result^.LowRes := nil;
Result^.Normals := nil; Result^.Normals := nil;
Result^.State := ssNormal; Result^.State := ssNormal;
Result^.Highlighted := False;
Result^.Next := nil; Result^.Next := nil;
if FShortCuts[0] = nil then //First element if FShortCuts[0] = nil then //First element
@ -1110,6 +1112,7 @@ begin
Result^.LowRes := nil; Result^.LowRes := nil;
Result^.Normals := nil; Result^.Normals := nil;
Result^.State := ssNormal; Result^.State := ssNormal;
Result^.Highlighted := False;
if (FShortCuts[0] = nil) or (CompareWorldItems(AItem, FShortCuts[0]) > 0) then if (FShortCuts[0] = nil) or (CompareWorldItems(AItem, FShortCuts[0]) > 0) then
begin begin

View File

@ -314,6 +314,7 @@ type
procedure SetY(const AValue: Integer); procedure SetY(const AValue: Integer);
procedure UpdateCurrentTile; procedure UpdateCurrentTile;
procedure UpdateCurrentTile(AX, AY: Integer); procedure UpdateCurrentTile(AX, AY: Integer);
procedure UpdateSelection;
procedure WriteChatMessage(ASender, AMessage: string); procedure WriteChatMessage(ASender, AMessage: string);
{ Events } { Events }
procedure OnClientHandlingPacket(ABuffer: TEnhancedMemoryStream); procedure OnClientHandlingPacket(ABuffer: TEnhancedMemoryStream);
@ -1587,6 +1588,8 @@ begin
FCurrentTile := AValue; FCurrentTile := AValue;
if FCurrentTile <> nil then if FCurrentTile <> nil then
FCurrentTile.OnDestroy.RegisterEvent(@OnTileRemoved); FCurrentTile.OnDestroy.RegisterEvent(@OnTileRemoved);
UpdateSelection;
end; end;
procedure TfrmMain.SetSelectedTile(const AValue: TWorldItem); procedure TfrmMain.SetSelectedTile(const AValue: TWorldItem);
@ -1596,6 +1599,8 @@ begin
FSelectedTile := AValue; FSelectedTile := AValue;
if FSelectedTile <> nil then if FSelectedTile <> nil then
FSelectedTile.OnDestroy.RegisterEvent(@OnTileRemoved); FSelectedTile.OnDestroy.RegisterEvent(@OnTileRemoved);
UpdateSelection;
end; end;
procedure TfrmMain.SetNormalLights; procedure TfrmMain.SetNormalLights;
@ -1657,7 +1662,7 @@ var
staticItem: TStaticItem; staticItem: TStaticItem;
staticTileData: TStaticTileData; staticTileData: TStaticTileData;
hue: THue; hue: THue;
highlight, singleTarget, multiTarget: Boolean; highlight: Boolean;
ghostTile: TWorldItem; ghostTile: TWorldItem;
tileRect: TRect; tileRect: TRect;
virtualTile: TVirtualTile; virtualTile: TVirtualTile;
@ -1685,10 +1690,29 @@ begin
item := blockInfo^.Item; item := blockInfo^.Item;
//TODO : implement CanBeEdited handling (dmNetwork.CanWrite.....)
if acSelect.Checked or item.CanBeEdited then
begin
editing := True;
intensity := 1.0; intensity := 1.0;
SetNormalLights; SetNormalLights;
end else
begin
editing := False;
intensity := 0.5;
SetDarkLights;
end;
glColor4f(intensity, intensity, intensity, 1.0); glColor4f(intensity, intensity, intensity, 1.0);
highlight := item.CanBeEdited and blockInfo^.Highlighted;
if highlight then
begin
glEnable(GL_COLOR_LOGIC_OP);
glLogicOp(GL_COPY_INVERTED);
end;
if item is TMapCell then if item is TMapCell then
begin begin
if blockInfo^.HighRes <> nil then if blockInfo^.HighRes <> nil then
@ -1725,28 +1749,11 @@ begin
glEnd; glEnd;
end; end;
if highlight then
glDisable(GL_COLOR_LOGIC_OP);
{GetDrawOffset(item.X - FX, item.Y - FY, drawX, drawY); {GetDrawOffset(item.X - FX, item.Y - FY, drawX, drawY);
singleTarget := (CurrentTile <> nil) and
(item.X = CurrentTile.X) and
(item.Y = CurrentTile.Y);
multiTarget := (CurrentTile <> nil) and
(SelectedTile <> nil) and
(CurrentTile <> SelectedTile) and
PtInRect(tileRect, Point(item.X, item.Y));
if acSelect.Checked or item.CanBeEdited then
begin
editing := True;
intensity := 1.0;
SetNormalLights;
end else
begin
editing := False;
intensity := 0.5;
SetDarkLights;
end;
{if editing and acDraw.Checked and (singleTarget or multiTarget) then {if editing and acDraw.Checked and (singleTarget or multiTarget) then
begin begin
ghostTile := FGhostTile; ghostTile := FGhostTile;
@ -1906,10 +1913,8 @@ begin
if TObject(draw[i]) <> ghostTile then if TObject(draw[i]) <> ghostTile then
FScreenBuffer.Store(Bounds(Trunc(drawX - east), Trunc(drawY + 44 - south - z * 4), mat.RealWidth, Trunc(south)), staticItem, mat); FScreenBuffer.Store(Bounds(Trunc(drawX - east), Trunc(drawY + 44 - south - z * 4), mat.RealWidth, Trunc(south)), staticItem, mat);
end; end;}
if highlight then
glDisable(GL_COLOR_LOGIC_OP);}
end; end;
FOverlayUI.Draw(oglGameWindow); FOverlayUI.Draw(oglGameWindow);
@ -2202,6 +2207,39 @@ begin
end; end;
end; end;
procedure TfrmMain.UpdateSelection;
var
selectedRect: TRect;
blockInfo: PBlockInfo;
begin
if acSelect.Checked then
begin
//no highlighted tiles in "selection" mode
blockInfo := nil;
while FScreenBuffer.Iterate(blockInfo) do
if blockInfo^.State = ssNormal then
blockInfo^.Highlighted := False;
Exit;
end;
if CurrentTile <> nil then
begin
blockInfo := nil;
if (SelectedTile <> nil) and (CurrentTile <> SelectedTile) then
begin
selectedRect := GetSelectedRect;
while FScreenBuffer.Iterate(blockInfo) do
if blockInfo^.State = ssNormal then
blockInfo^.Highlighted := PtInRect(selectedRect, Point(blockInfo^.Item.X, blockInfo^.Item.Y));
end else
begin
while FScreenBuffer.Iterate(blockInfo) do
if blockInfo^.State = ssNormal then
blockInfo^.Highlighted := (blockInfo^.Item = CurrentTile);
end;
end;
end;
procedure TfrmMain.OnTileRemoved(ATile: TMulBlock); procedure TfrmMain.OnTileRemoved(ATile: TMulBlock);
begin begin
if ATile = FCurrentTile then if ATile = FCurrentTile then