- Store used (random) hues for consistent behavior on commit (refs #66)

This commit is contained in:
Andreas Schneider 2011-03-29 21:51:17 +02:00
parent 4b5cf332ca
commit bfe71ae93f
2 changed files with 53 additions and 11 deletions

View File

@ -450,8 +450,7 @@
</CodeGeneration> </CodeGeneration>
<Linking> <Linking>
<Debugging> <Debugging>
<UseLineInfoUnit Value="False"/> <GenerateDebugInfo Value="True"/>
<GenerateDwarf Value="True"/>
</Debugging> </Debugging>
<Options> <Options>
<Win32> <Win32>

View File

@ -48,6 +48,8 @@ type
TAccessChangedListeners = specialize TFPGList<TAccessChangedListener>; TAccessChangedListeners = specialize TFPGList<TAccessChangedListener>;
TSelectionListeners = specialize TFPGList<TSelectionListener>; TSelectionListeners = specialize TFPGList<TSelectionListener>;
THueList = specialize TFPGList<Word>;
TTileHintInfo = record TTileHintInfo = record
Name: String; Name: String;
Flags: String; Flags: String;
@ -332,6 +334,7 @@ type
FSelectionListeners: TSelectionListeners; FSelectionListeners: TSelectionListeners;
FTileHint: TTileHintInfo; FTileHint: TTileHintInfo;
FLightManager: TLightManager; FLightManager: TLightManager;
FHueBuffer: THueList;
{ Methods } { Methods }
procedure BuildTileList; procedure BuildTileList;
function ConfirmAction: Boolean; function ConfirmAction: Boolean;
@ -639,7 +642,7 @@ procedure TfrmMain.oglGameWindowMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer); Shift: TShiftState; X, Y: Integer);
var var
map: TMapCell; map: TMapCell;
i: Integer; i, hueCount: Integer;
z: ShortInt; z: ShortInt;
blockInfo: PBlockInfo; blockInfo: PBlockInfo;
targetRect: TRect; targetRect: TRect;
@ -796,17 +799,27 @@ begin
end; end;
end else if acHue.Checked then //***** Hue tile *****// end else if acHue.Checked then //***** Hue tile *****//
begin begin
hueCount := 0;
for i := 0 to targetTiles.Count - 1 do for i := 0 to targetTiles.Count - 1 do
begin begin
tile := targetTiles.Items[i]; tile := targetTiles.Items[i];
hue := frmHueSettings.GetHue; if tile is TStaticItem then
if (tile is TStaticItem) and
(TStaticItem(tile).Hue <> hue) then
begin begin
FUndoList.Add(THueStaticPacket.Create(tile.X, tile.Y, tile.Z, //If a hue is in the buffer (see UpdateSelection), use that, otherwise
tile.TileID, hue, TStaticItem(tile).Hue)); //create a new one. (Necessary for random hues.)
dmNetwork.Send(THueStaticPacket.Create(TStaticItem(tile), hue)); if hueCount < FHueBuffer.Count then
hue := FHueBuffer[hueCount]
else
hue := frmHueSettings.GetHue;
Inc(hueCount);
if TStaticItem(tile).Hue <> hue then
begin
FUndoList.Add(THueStaticPacket.Create(tile.X, tile.Y, tile.Z,
tile.TileID, hue, TStaticItem(tile).Hue));
dmNetwork.Send(THueStaticPacket.Create(TStaticItem(tile), hue));
end;
end; end;
end; end;
end; end;
@ -946,6 +959,8 @@ begin
FSelectionListeners := TSelectionListeners.Create; FSelectionListeners := TSelectionListeners.Create;
FLastDraw := Now; FLastDraw := Now;
FHueBuffer := THueList.Create;
end; end;
procedure TfrmMain.btnGoToClick(Sender: TObject); procedure TfrmMain.btnGoToClick(Sender: TObject);
@ -1296,6 +1311,7 @@ begin
FreeAndNil(FRandomPresetsDoc); FreeAndNil(FRandomPresetsDoc);
FreeAndNil(FAccessChangedListeners); FreeAndNil(FAccessChangedListeners);
FreeAndNil(FSelectionListeners); FreeAndNil(FSelectionListeners);
FreeAndNil(FHueBuffer);
RegisterPacketHandler($0C, nil); RegisterPacketHandler($0C, nil);
end; end;
@ -2835,8 +2851,12 @@ begin
end; end;
procedure TfrmMain.UpdateSelection; procedure TfrmMain.UpdateSelection;
var
highlightCount: Integer;
procedure SetHighlight(ABlockInfo: PBlockInfo; AHighlighted: Boolean); procedure SetHighlight(ABlockInfo: PBlockInfo; AHighlighted: Boolean);
var
hue: Word;
begin begin
if (ABlockInfo^.Item is TStaticItem) and acHue.Checked then if (ABlockInfo^.Item is TStaticItem) and acHue.Checked then
begin begin
@ -2844,12 +2864,27 @@ procedure TfrmMain.UpdateSelection;
begin begin
ABlockInfo^.HueOverride := AHighlighted; ABlockInfo^.HueOverride := AHighlighted;
if AHighlighted then if AHighlighted then
begin
if highlightCount < FHueBuffer.Count then
begin
hue := FHueBuffer[highlightCount];
end else
begin
hue := frmHueSettings.GetHue;
FHueBuffer.Add(hue);
end;
ABlockInfo^.LowRes := FTextureManager.GetStaticMaterial( ABlockInfo^.LowRes := FTextureManager.GetStaticMaterial(
TStaticItem(ABlockInfo^.Item), frmHueSettings.GetHue) TStaticItem(ABlockInfo^.Item), hue);
else end else
begin
ABlockInfo^.LowRes := FTextureManager.GetStaticMaterial( ABlockInfo^.LowRes := FTextureManager.GetStaticMaterial(
TStaticItem(ABlockInfo^.Item)); TStaticItem(ABlockInfo^.Item));
end;
end; end;
if AHighlighted then
Inc(highlightCount);
end else end else
begin begin
ABlockInfo^.Highlighted := AHighlighted; ABlockInfo^.Highlighted := AHighlighted;
@ -2949,6 +2984,14 @@ begin
else else
selectedRect := GetSelectedRect; selectedRect := GetSelectedRect;
if acHue.Checked and (SelectedTile = nil) then
begin
//Prepare hue buffer
FHueBuffer.Clear;
end;
highlightCount := 0;
//clean up old ghost tiles //clean up old ghost tiles
//Logger.Send([lcClient, lcDebug], 'Cleaning ghost tiles'); //Logger.Send([lcClient, lcDebug], 'Cleaning ghost tiles');
for i := FVirtualTiles.Count - 1 downto 0 do for i := FVirtualTiles.Count - 1 downto 0 do