Revision 119:66352054ce4d Client/UfrmTileInfo.pas

b/Client/UfrmTileInfo.pas
1
(*
2
 * CDDL HEADER START
3
 *
4
 * The contents of this file are subject to the terms of the
5
 * Common Development and Distribution License, Version 1.0 only
6
 * (the "License").  You may not use this file except in compliance
7
 * with the License.
8
 *
9
 * You can obtain a copy of the license at
10
 * http://www.opensource.org/licenses/cddl1.php.
11
 * See the License for the specific language governing permissions
12
 * and limitations under the License.
13
 *
14
 * When distributing Covered Code, include this CDDL HEADER in each
15
 * file and include the License file at
16
 * http://www.opensource.org/licenses/cddl1.php.  If applicable,
17
 * add the following below this CDDL HEADER, with the fields enclosed
18
 * by brackets "[]" replaced with your own identifying * information:
19
 *      Portions Copyright [yyyy] [name of copyright owner]
20
 *
21
 * CDDL HEADER END
22
 *
23
 *
24
 *      Portions Copyright 2007 Andreas Schneider
25
 *)
26
unit UfrmTileInfo;
27

  
28
{$mode objfpc}{$H+}
29

  
30
interface
31

  
32
uses
33
  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls,
34
  ExtCtrls, LCLIntf, LCLType, LMessages, strutils;
35

  
36
type
37

  
38
  { TfrmTileInfo }
39

  
40
  TfrmTileInfo = class(TForm)
41
    lblName: TLabel;
42
    lblFlags: TLabel;
43
    lblTileID: TLabel;
44
    tmHide: TTimer;
45
    procedure FormShow(Sender: TObject);
46
    procedure tmHideTimer(Sender: TObject);
47
  private
48
    { private declarations }
49
  public
50
    procedure Update(ATileID: Word);
51
    //procedure Show; overload; reintroduce;
52
    procedure Show(ATileID: Word); overload;
53
  end; 
54

  
55
var
56
  frmTileInfo: TfrmTileInfo;
57

  
58
implementation
59

  
60
uses
61
  UGameResources, UTiledata;
62

  
63
{ TfrmTileInfo }
64

  
65
procedure TfrmTileInfo.tmHideTimer(Sender: TObject);
66
begin
67
  tmHide.Enabled := False;
68
  Hide;
69
end;
70

  
71
procedure TfrmTileInfo.FormShow(Sender: TObject);
72
begin
73
  tmHide.Enabled := True;
74
  Left := Mouse.CursorPos.x + 8;
75
  Top := Mouse.CursorPos.y + 8;
76
end;
77

  
78
procedure TfrmTileInfo.Update(ATileID: Word);
79
var
80
  tileData: TTiledata;
81
  prefix, flags: string;
82
  
83
  procedure UpdateFlags(AFlag: TTileDataFlag; AName: string);
84
  begin
85
    if AFlag in tileData.Flags then
86
    begin
87
      if flags <> '' then
88
        flags := flags + ', ' + AName
89
      else
90
        flags := AName;
91
    end;
92
  end;
93
  
94
begin
95
  if Visible then
96
  begin
97
    Left := Mouse.CursorPos.x + 8;
98
    Top := Mouse.CursorPos.y + 8;
99
  end;
100

  
101
  flags := '';
102

  
103
  if ATileID < $4000 then
104
  begin
105
    tileData := ResMan.Tiledata.LandTiles[ATileID];
106
    if TLandTiledata(tileData).TextureID > 0 then
107
      flags := 'Stretchable';
108
  end else
109
  begin
110
    Dec(ATileID, $4000);
111
    tileData := ResMan.Tiledata.StaticTiles[ATileID];
112
  end;
113

  
114
  if tdfArticleA in tileData.Flags then
115
    prefix := 'a '
116
  else if tdfArticleAn in tileData.Flags then
117
    prefix := 'an '
118
  else
119
    prefix := '';
120

  
121
  lblName.Caption := AnsiProperCase(Format('%s%s', [prefix, tileData.TileName]), [' ']);
122
  lblTileID.Caption := Format('Tile ID: $%x (%0:d)', [ATileID]);
123
  
124
  UpdateFlags(tdfBackground, 'Background');
125
  UpdateFlags(tdfWeapon, 'Weapon');
126
  UpdateFlags(tdfTransparent, 'Transparent');
127
  UpdateFlags(tdfTranslucent, 'Translucent');
128
  UpdateFlags(tdfWall, 'Wall');
129
  UpdateFlags(tdfDamaging, 'Damaging');
130
  UpdateFlags(tdfImpassable, 'Impassable');
131
  UpdateFlags(tdfWet, 'Wet');
132
  UpdateFlags(tdfSurface, 'Surface');
133
  UpdateFlags(tdfBridge, 'Bridge');
134
  UpdateFlags(tdfGeneric, 'Generic');
135
  UpdateFlags(tdfWindow, 'Window');
136
  UpdateFlags(tdfNoShoot, 'NoShoot');
137
  UpdateFlags(tdfInternal, 'Internal');
138
  UpdateFlags(tdfFoliage, 'Foliage');
139
  UpdateFlags(tdfPartialHue, 'PartialHue');
140
  UpdateFlags(tdfMap, 'Map');
141
  UpdateFlags(tdfContainer, 'Container');
142
  UpdateFlags(tdfWearable, 'Wearable');
143
  UpdateFlags(tdfLightSource, 'Lightsource');
144
  UpdateFlags(tdfAnimation, 'Animation');
145
  UpdateFlags(tdfNoDiagonal, 'NoDiagonal');
146
  UpdateFlags(tdfArmor, 'Armor');
147
  UpdateFlags(tdfRoof, 'Roof');
148
  UpdateFlags(tdfDoor, 'Door');
149
  UpdateFlags(tdfStairBack, 'StairBack');
150
  UpdateFlags(tdfStairRight, 'StairRight');
151
  
152
  lblFlags.Caption := Format('Flags = [%s]', [flags]);
153
  
154
  if tmHide.Enabled then
155
  begin
156
    tmHide.Enabled := False;
157
    tmHide.Enabled := True; //Refresh timer
158
  end;
159
end;
160

  
161
{procedure TfrmTileInfo.Show;
162
begin
163
  ShowWindow(Handle, SW_SHOWNOACTIVATE);
164
  Include(FormState, fsVisible);
165
  VisibleChanging;
166
  try
167
    Perform(CM_VISIBLECHANGED, WParam(Ord(True)), 0);
168
    AdjustSize;
169
    RequestAlign;
170
  finally
171
    VisibleChanged;
172
  end;
173
  //FormShow(Self);
174
end;}
175

  
176
procedure TfrmTileInfo.Show(ATileID: Word);
177
begin
178
  Update(ATileID);
179
  Show;
180
end;
181

  
182
initialization
183
  {$I UfrmTileInfo.lrs}
184

  
185
end.
186

  
1
(*
2
 * CDDL HEADER START
3
 *
4
 * The contents of this file are subject to the terms of the
5
 * Common Development and Distribution License, Version 1.0 only
6
 * (the "License").  You may not use this file except in compliance
7
 * with the License.
8
 *
9
 * You can obtain a copy of the license at
10
 * http://www.opensource.org/licenses/cddl1.php.
11
 * See the License for the specific language governing permissions
12
 * and limitations under the License.
13
 *
14
 * When distributing Covered Code, include this CDDL HEADER in each
15
 * file and include the License file at
16
 * http://www.opensource.org/licenses/cddl1.php.  If applicable,
17
 * add the following below this CDDL HEADER, with the fields enclosed
18
 * by brackets "[]" replaced with your own identifying * information:
19
 *      Portions Copyright [yyyy] [name of copyright owner]
20
 *
21
 * CDDL HEADER END
22
 *
23
 *
24
 *      Portions Copyright 2009 Andreas Schneider
25
 *)
26
unit UfrmTileInfo;
27

  
28
{$mode objfpc}{$H+}
29

  
30
interface
31

  
32
uses
33
  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls,
34
  ExtCtrls, LCLIntf, LCLType, strutils;
35

  
36
type
37

  
38
  { TfrmTileInfo }
39

  
40
  TfrmTileInfo = class(TForm)
41
    lblName: TLabel;
42
    lblFlags: TLabel;
43
    lblTileID: TLabel;
44
    tmHide: TTimer;
45
    procedure FormShow(Sender: TObject);
46
    procedure tmHideTimer(Sender: TObject);
47
  private
48
    { private declarations }
49
  public
50
    procedure Update(ATileID: Word);
51
    procedure Show(ATileID: Word); overload;
52
  end; 
53

  
54
var
55
  frmTileInfo: TfrmTileInfo;
56

  
57
implementation
58

  
59
uses
60
  UGameResources, UTiledata;
61

  
62
{ TfrmTileInfo }
63

  
64
procedure TfrmTileInfo.tmHideTimer(Sender: TObject);
65
begin
66
  tmHide.Enabled := False;
67
  Hide;
68
end;
69

  
70
procedure TfrmTileInfo.FormShow(Sender: TObject);
71
begin
72
  tmHide.Enabled := True;
73
  Left := Mouse.CursorPos.x + 8;
74
  Top := Mouse.CursorPos.y + 8;
75
end;
76

  
77
procedure TfrmTileInfo.Update(ATileID: Word);
78
var
79
  tileData: TTiledata;
80
  prefix, flags: string;
81
  
82
  procedure UpdateFlags(AFlag: TTileDataFlag; AName: string);
83
  begin
84
    if AFlag in tileData.Flags then
85
    begin
86
      if flags <> '' then
87
        flags := flags + ', ' + AName
88
      else
89
        flags := AName;
90
    end;
91
  end;
92
  
93
begin
94
  if Visible then
95
  begin
96
    Left := Mouse.CursorPos.x + 8;
97
    Top := Mouse.CursorPos.y + 8;
98
  end;
99

  
100
  flags := '';
101

  
102
  if ATileID < $4000 then
103
  begin
104
    tileData := ResMan.Tiledata.LandTiles[ATileID];
105
    if TLandTiledata(tileData).TextureID > 0 then
106
      flags := 'Stretchable';
107
  end else
108
  begin
109
    Dec(ATileID, $4000);
110
    tileData := ResMan.Tiledata.StaticTiles[ATileID];
111
  end;
112

  
113
  if tdfArticleA in tileData.Flags then
114
    prefix := 'a '
115
  else if tdfArticleAn in tileData.Flags then
116
    prefix := 'an '
117
  else
118
    prefix := '';
119

  
120
  lblName.Caption := AnsiProperCase(Format('%s%s', [prefix, tileData.TileName]), [' ']);
121
  lblTileID.Caption := Format('Tile ID: $%x (%0:d)', [ATileID]);
122
  
123
  UpdateFlags(tdfBackground, 'Background');
124
  UpdateFlags(tdfWeapon, 'Weapon');
125
  UpdateFlags(tdfTransparent, 'Transparent');
126
  UpdateFlags(tdfTranslucent, 'Translucent');
127
  UpdateFlags(tdfWall, 'Wall');
128
  UpdateFlags(tdfDamaging, 'Damaging');
129
  UpdateFlags(tdfImpassable, 'Impassable');
130
  UpdateFlags(tdfWet, 'Wet');
131
  UpdateFlags(tdfSurface, 'Surface');
132
  UpdateFlags(tdfBridge, 'Bridge');
133
  UpdateFlags(tdfGeneric, 'Generic');
134
  UpdateFlags(tdfWindow, 'Window');
135
  UpdateFlags(tdfNoShoot, 'NoShoot');
136
  UpdateFlags(tdfInternal, 'Internal');
137
  UpdateFlags(tdfFoliage, 'Foliage');
138
  UpdateFlags(tdfPartialHue, 'PartialHue');
139
  UpdateFlags(tdfMap, 'Map');
140
  UpdateFlags(tdfContainer, 'Container');
141
  UpdateFlags(tdfWearable, 'Wearable');
142
  UpdateFlags(tdfLightSource, 'Lightsource');
143
  UpdateFlags(tdfAnimation, 'Animation');
144
  UpdateFlags(tdfNoDiagonal, 'NoDiagonal');
145
  UpdateFlags(tdfArmor, 'Armor');
146
  UpdateFlags(tdfRoof, 'Roof');
147
  UpdateFlags(tdfDoor, 'Door');
148
  UpdateFlags(tdfStairBack, 'StairBack');
149
  UpdateFlags(tdfStairRight, 'StairRight');
150
  
151
  lblFlags.Caption := Format('Flags = [%s]', [flags]);
152
  
153
  if tmHide.Enabled then
154
  begin
155
    tmHide.Enabled := False;
156
    tmHide.Enabled := True; //Refresh timer
157
  end;
158
end;
159

  
160
procedure TfrmTileInfo.Show(ATileID: Word);
161
begin
162
  Update(ATileID);
163
  Show;
164
end;
165

  
166
initialization
167
  {$I UfrmTileInfo.lrs}
168

  
169
end.
170

  

Also available in: Unified diff