Subversion Repositories plumbers

Rev

Rev 11 | Rev 14 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 11 Rev 12
Line 202... Line 202...
202
    function CurScene: PSceneDef;
202
    function CurScene: PSceneDef;
203
    procedure LoadScene;
203
    procedure LoadScene;
204
    procedure Load;
204
    procedure Load;
205
    procedure Save;
205
    procedure Save;
206
    procedure ReloadActionSceneLists;
206
    procedure ReloadActionSceneLists;
207
    function FindSceneIndex(sceneID: integer): integer;
-
 
208
    function GetGreatestSceneID: integer;
207
    function GetGreatestSceneID: integer;
209
    function SearchSceneIDGapFromTop: integer;
208
    function SearchSceneIDGapFromTop: integer;
210
    procedure RedrawDecisionBitmap;
209
    procedure RedrawDecisionBitmap;
211
    function CurPicture: PPictureDef;
210
    function CurPicture: PPictureDef;
212
    function CurPictureTimepos: Cardinal;
211
    function CurPictureTimepos: Cardinal;
Line 237... Line 236...
237
const
236
const
238
  DEFAULT_DURATION = 0;
237
  DEFAULT_DURATION = 0;
239
  DEFAULT_FILENAME = 'DUMMY.BMP';
238
  DEFAULT_FILENAME = 'DUMMY.BMP';
240
 
239
 
241
function GetSceneIDFromName(sceneName: string): Integer;
240
function GetSceneIDFromName(sceneName: string): Integer;
-
 
241
resourcestring
-
 
242
  S_SCENENAME_INVALID = 'Scene name invalid';
242
var
243
var
243
  sSceneID: string;
244
  sSceneID: string;
244
begin
245
begin
245
  if Copy(sceneName, 1, 2) <> 'SC' then raise Exception.Create('Scene name invalid');
246
  if Copy(sceneName, 1, 2) <> 'SC' then raise Exception.Create(S_SCENENAME_INVALID);
246
  sSceneID := Copy(sceneName, 3, 2);
247
  sSceneID := Copy(sceneName, 3, 2);
247
  if not TryStrToInt(sSceneID, result) then raise Exception.Create('Scene name invalid');
248
  if not TryStrToInt(sSceneID, result) then raise Exception.Create(S_SCENENAME_INVALID);
248
end;
249
end;
249
 
250
 
250
procedure SelectFilenameBase(Edit: TEdit);
251
procedure SelectFilenameBase(Edit: TEdit);
251
begin
252
begin
252
  if Edit.CanFocus then
253
  if Edit.CanFocus then
Line 332... Line 333...
332
  Label10.Caption := '';
333
  Label10.Caption := '';
333
  Label28.Visible := false;
334
  Label28.Visible := false;
334
  Label29.Visible := false;
335
  Label29.Visible := false;
335
end;
336
end;
336
 
337
 
337
procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
338
procedure TForm1.Image1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
338
  Y: Integer);
339
resourcestring
-
 
340
  S_COORDS = 'Coords: [%d, %d]';
339
begin
341
begin
340
  label10.Caption := Format('Coords: [%d, %d]', [Round(Image1.Picture.Width*(X/Image1.Width)),
342
  label10.Caption := Format(S_COORDS, [Round(Image1.Picture.Width*(X/Image1.Width)),
341
                                                 Round(Image1.Picture.Height*(Y/Image1.Height))]);
343
                                       Round(Image1.Picture.Height*(Y/Image1.Height))]);
342
end;
344
end;
343
 
345
 
344
function TForm1.SearchSceneIDGapFromTop: integer;
346
function TForm1.SearchSceneIDGapFromTop: integer;
345
var
347
var
Line 355... Line 357...
355
    end;
357
    end;
356
  end;
358
  end;
357
end;
359
end;
358
 
360
 
359
procedure TForm1.Button10Click(Sender: TObject);
361
procedure TForm1.Button10Click(Sender: TObject);
-
 
362
resourcestring
-
 
363
  S_NOTFOUND = 'GAME.BIN saved; ShowTime32.exe not found.';
360
begin
364
begin
361
  Save;
365
  Save;
362
  if not FileExists('ShowTime32.exe') then raise Exception.Create('GAME.BIN saved; ShowTime32.exe not found.');
366
  if not FileExists('ShowTime32.exe') then raise Exception.Create(S_NOTFOUND);
363
  ShellExecute(Application.Handle, 'open', 'ShowTime32.exe', '', '', SW_NORMAL);
367
  ShellExecute(Application.Handle, 'open', 'ShowTime32.exe', '', '', SW_NORMAL);
364
end;
368
end;
365
 
369
 
366
procedure TForm1.Button11Click(Sender: TObject);
370
procedure TForm1.Button11Click(Sender: TObject);
367
var
371
var
Line 613... Line 617...
613
  if not FileExists(fileName) then exit;
617
  if not FileExists(fileName) then exit;
614
  ShellExecute(Application.Handle, 'open', PChar(fileName), '', '', SW_NORMAL);
618
  ShellExecute(Application.Handle, 'open', PChar(fileName), '', '', SW_NORMAL);
615
end;
619
end;
616
 
620
 
617
procedure TForm1.Button19Click(Sender: TObject);
621
procedure TForm1.Button19Click(Sender: TObject);
-
 
622
resourcestring
-
 
623
  S_DISCARD = 'Are you sure you want to discard all changes?';
618
begin
624
begin
619
  if MessageDlg('Are you sure you want to discard all changes?', mtConfirmation, mbYesNoCancel, 0) = mrYes then
625
  if MessageDlg(S_DISCARD, mtConfirmation, mbYesNoCancel, 0) = mrYes then
620
  begin
626
  begin
621
    CopyMemory(@Game, @GameBak, SizeOf(Game));
627
    CopyMemory(@Game, @GameBak, SizeOf(Game));
622
    SetupGUIAfterLoad;
628
    SetupGUIAfterLoad;
623
  end;
629
  end;
624
end;
630
end;
625
 
631
 
626
procedure TForm1.NewScene;
632
procedure TForm1.NewScene;
-
 
633
resourcestring
-
 
634
  S_SCENE_FULL = 'No more space for another scene';
627
var
635
var
628
  sceneID: integer;
636
  sceneID: integer;
629
  newScene: PSceneDef;
637
  newScene: PSceneDef;
630
begin
638
begin
631
  if ListBox1.Items.Count = 100 then
639
  if ListBox1.Items.Count = 100 then
632
  begin
640
  begin
633
    raise Exception.Create('No more space for another scene');
641
    raise Exception.Create(S_SCENE_FULL);
634
  end;
642
  end;
635
 
643
 
636
  sceneID := GetGreatestSceneID+1;
644
  sceneID := GetGreatestSceneID+1;
637
  if sceneID >= Length(Game.scenes) then sceneID := SearchSceneIDGapFromTop;
645
  if sceneID >= Length(Game.scenes) then sceneID := SearchSceneIDGapFromTop;
638
 
646
 
Line 656... Line 664...
656
  Game.Defrag;
664
  Game.Defrag;
657
  RecalcStats;
665
  RecalcStats;
658
end;
666
end;
659
 
667
 
660
procedure TForm1.Button2Click(Sender: TObject);
668
procedure TForm1.Button2Click(Sender: TObject);
-
 
669
resourcestring
-
 
670
  S_CONFLICT = 'Can''t delete this scene. There are following dependencies:'+#13#10#13#10+'%s';
-
 
671
  S_SCENEID = 'Scene %s, action #%d';
-
 
672
  // S_ONLYONE = 'Can''t delete the scene if there is only one.';
-
 
673
  S_REALLY_DEL = 'Do you really want to delete scene %s?';
-
 
674
  S_NEW_INTRO = 'Attention: This will make %s to your new intro sequence. Is that OK?';
661
var
675
var
662
  iScene, iAction, sceneID: integer;
676
  iScene, iAction, sceneID: integer;
663
  conflicts: TStringList;
677
  conflicts: TStringList;
664
  sWarning: string;
678
  sWarning: string;
665
  bakItemindex: integer;
679
  bakItemindex: integer;
Line 667... Line 681...
667
  if ListBox1.Count = 0 then exit;
681
  if ListBox1.Count = 0 then exit;
668
 
682
 
669
  (*
683
  (*
670
  if ListBox1.Count = 1 then
684
  if ListBox1.Count = 1 then
671
  begin
685
  begin
672
    raise Exception.Create('Can''t delete the scene if there is only one.');
686
    raise Exception.Create(S_ONLYONE);
673
  end;
687
  end;
674
  *)
688
  *)
675
 
689
 
676
  conflicts := TStringList.Create;
690
  conflicts := TStringList.Create;
677
  try
691
  try
Line 680... Line 694...
680
    begin
694
    begin
681
      for iAction := 0 to Game.scenes[iScene].numActions-1 do
695
      for iAction := 0 to Game.scenes[iScene].numActions-1 do
682
      begin
696
      begin
683
        if Game.scenes[iScene].actions[iAction].nextSceneID = sceneID then
697
        if Game.scenes[iScene].actions[iAction].nextSceneID = sceneID then
684
        begin
698
        begin
685
          conflicts.Add(Format('Scene %s, action #%d', [Game.scenes[iScene].szSceneFolder, iAction+1]));
699
          conflicts.Add(Format(S_SCENEID, [Game.scenes[iScene].szSceneFolder, iAction+1]));
686
        end;
700
        end;
687
      end;
701
      end;
688
    end;
702
    end;
689
    if conflicts.Count > 0 then
703
    if conflicts.Count > 0 then
690
    begin
704
    begin
691
      raise Exception.Create('Can''t delete this scene. There are following dependencies:'+#13#10#13#10+conflicts.Text);
705
      raise Exception.CreateFmt(S_CONFLICT, [conflicts.Text]);
692
    end;
706
    end;
693
  finally
707
  finally
694
    FreeAndNil(conflicts);
708
    FreeAndNil(conflicts);
695
  end;
709
  end;
696
 
710
 
697
  sWarning := Format('Do you really want to delete scene %s?', [CurScene^.szSceneFolder]);
711
  sWarning := Format(S_REALLY_DEL, [CurScene^.szSceneFolder]);
698
  if (ListBox1.ItemIndex = 0) and (ListBox1.Count >= 2) then
712
  if (ListBox1.ItemIndex = 0) and (ListBox1.Count >= 2) then
699
    sWarning := Format('Attention: This will make %s to your new intro sequence. Is that OK?', [ListBox1.Items[ListBox1.ItemIndex+1]]);
713
    sWarning := Format(S_NEW_INTRO, [ListBox1.Items[ListBox1.ItemIndex+1]]);
700
  if (MessageDlg(sWarning, mtConfirmation, mbYesNoCancel, 0) <> mrYes) then
714
  if (MessageDlg(sWarning, mtConfirmation, mbYesNoCancel, 0) <> mrYes) then
701
  begin
715
  begin
702
    Exit;
716
    Exit;
703
  end;
717
  end;
704
 
718
 
Line 809... Line 823...
809
    FreeAndNil(fs);
823
    FreeAndNil(fs);
810
  end;
824
  end;
811
end;
825
end;
812
 
826
 
813
procedure TForm1.ActionTargetChange(Sender: TObject);
827
procedure TForm1.ActionTargetChange(Sender: TObject);
-
 
828
resourcestring
-
 
829
  S_ASSERT_SENDER = 'Unexpected sender for ActionTargetChange()';
814
var
830
var
815
  actionIdx: integer;
831
  actionIdx: integer;
816
  itemIdx: Integer;
832
  itemIdx: Integer;
817
begin
833
begin
818
       if Sender = ComboBox1 then actionIdx := 0
834
       if Sender = ComboBox1 then actionIdx := 0
819
  else if Sender = ComboBox2 then actionIdx := 1
835
  else if Sender = ComboBox2 then actionIdx := 1
820
  else if Sender = ComboBox3 then actionIdx := 2
836
  else if Sender = ComboBox3 then actionIdx := 2
821
  else raise Exception.Create('Unexpected sender for ActionTargetChange()');
837
  else raise Exception.Create(S_ASSERT_SENDER);
822
 
838
 
823
  itemIdx := TComboBox(Sender).ItemIndex;
839
  itemIdx := TComboBox(Sender).ItemIndex;
824
  if itemIdx = 0 then
840
  if itemIdx = 0 then
825
    CurScene^.actions[actionIdx].nextSceneID := SCENEID_ENDGAME
841
    CurScene^.actions[actionIdx].nextSceneID := SCENEID_ENDGAME
826
  else if itemIdx = 1 then
842
  else if itemIdx = 1 then
Line 869... Line 885...
869
  Label26.Visible := not FileExists(IncludeTrailingPathDelimiter(CurScene^.szSceneFolder) + Edit3.Text);
885
  Label26.Visible := not FileExists(IncludeTrailingPathDelimiter(CurScene^.szSceneFolder) + Edit3.Text);
870
  Button12.Visible := CurPicture^.szBitmapFile <> '';
886
  Button12.Visible := CurPicture^.szBitmapFile <> '';
871
end;
887
end;
872
 
888
 
873
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
889
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
-
 
890
resourcestring
-
 
891
  S_SAVE_CHANGES = 'Do you want to save the changes?';
874
begin
892
begin
875
  if not CompareMem(@Game, @GameBak, SizeOf(Game)) then
893
  if not CompareMem(@Game, @GameBak, SizeOf(Game)) then
876
  begin
894
  begin
877
    case MessageDlg('Do you want to save the changes?', mtConfirmation, mbYesNoCancel, 0) of
895
    case MessageDlg(S_SAVE_CHANGES, mtConfirmation, mbYesNoCancel, 0) of
878
      mrYes:
896
      mrYes:
879
      begin
897
      begin
880
        Save;
898
        Save;
881
        CanClose := true;
899
        CanClose := true;
882
      end;
900
      end;
Line 909... Line 927...
909
  else
927
  else
910
    New;
928
    New;
911
end;
929
end;
912
 
930
 
913
function TForm1.CurScene: PSceneDef;
931
function TForm1.CurScene: PSceneDef;
-
 
932
resourcestring
-
 
933
  S_NO_SCENE_AVAILABLE = 'No scenes available. Please create one.';
-
 
934
  S_NO_SCENE_SELECTED = 'No scene selected. Please select one.';
914
begin
935
begin
915
  if ListBox1.Count = 0 then raise Exception.Create('No scene available. Please create one.');
936
  if ListBox1.Count = 0 then raise Exception.Create(S_NO_SCENE_AVAILABLE);
916
  if ListBox1.ItemIndex = -1 then raise Exception.Create('No scene selected. Please select one.');
937
  if ListBox1.ItemIndex = -1 then raise Exception.Create(S_NO_SCENE_SELECTED);
917
  result := @Game.scenes[ListBox1.ItemIndex];
938
  result := @Game.scenes[ListBox1.ItemIndex];
918
end;
939
end;
919
 
940
 
920
procedure TForm1.ListBox1Click(Sender: TObject);
941
procedure TForm1.ListBox1Click(Sender: TObject);
921
begin
942
begin
Line 936... Line 957...
936
begin
957
begin
937
  Close;
958
  Close;
938
end;
959
end;
939
 
960
 
940
function TForm1.CurPicture: PPictureDef;
961
function TForm1.CurPicture: PPictureDef;
-
 
962
resourcestring
-
 
963
  S_NO_PICTURE_AVAILABLE = 'No pictures available. Please create one.';
-
 
964
  S_NO_PICTURE_SELECTED = 'No picture selected. Please select one.';
941
begin
965
begin
942
  if ListBox2.Count = 0 then raise Exception.Create('No pictures available. Please create one.');
966
  if ListBox2.Count = 0 then raise Exception.Create(S_NO_PICTURE_AVAILABLE);
943
  if ListBox2.ItemIndex = -1 then raise Exception.Create('No pictures selected. Please select one.');
967
  if ListBox2.ItemIndex = -1 then raise Exception.Create(S_NO_PICTURE_SELECTED);
944
  result := @Game.pictures[CurScene^.pictureIndex + ListBox2.ItemIndex]
968
  result := @Game.pictures[CurScene^.pictureIndex + ListBox2.ItemIndex]
945
end;
969
end;
946
 
970
 
947
function TForm1.CurPictureTimepos: Cardinal;
971
function TForm1.CurPictureTimepos: Cardinal;
948
var
972
var
Line 1101... Line 1125...
1101
 
1125
 
1102
  SetupGUIAfterLoad;
1126
  SetupGUIAfterLoad;
1103
end;
1127
end;
1104
 
1128
 
1105
procedure TForm1.Load;
1129
procedure TForm1.Load;
-
 
1130
resourcestring
-
 
1131
  S_CORRECTED_PICTURE_COUNT = 'Picture count was wrong. Value was corrected.';
1106
var
1132
var
1107
  fs: TFileStream;
1133
  fs: TFileStream;
1108
begin
1134
begin
1109
  fs := TFileStream.Create('GAME.BIN', fmOpenRead);
1135
  fs := TFileStream.Create('GAME.BIN', fmOpenRead);
1110
  try
1136
  try
Line 1115... Line 1141...
1115
 
1141
 
1116
  CopyMemory(@GameBak, @Game, SizeOf(Game));
1142
  CopyMemory(@GameBak, @Game, SizeOf(Game));
1117
 
1143
 
1118
  if Game.RealPictureCount <> Game.numPics then
1144
  if Game.RealPictureCount <> Game.numPics then
1119
  begin
1145
  begin
1120
    MessageDlg('Picture count was wrong. Value was corrected.', mtInformation, [mbOk], 0);
1146
    MessageDlg(S_CORRECTED_PICTURE_COUNT, mtInformation, [mbOk], 0);
1121
    Game.numPics := Game.RealPictureCount;
1147
    Game.numPics := Game.RealPictureCount;
1122
  end;
1148
  end;
1123
 
1149
 
1124
  SetupGUIAfterLoad;
1150
  SetupGUIAfterLoad;
1125
end;
1151
end;
1126
 
1152
 
1127
function TForm1.FindSceneIndex(sceneID: integer): integer;
-
 
1128
var
-
 
1129
  i: Integer;
-
 
1130
  sSceneID: string;
-
 
1131
begin
-
 
1132
  sSceneID := Format('SC%.2d', [sceneID]);
-
 
1133
  for i := 0 to ListBox1.Count - 1 do
-
 
1134
  begin
-
 
1135
    if ListBox1.Items.Strings[i] = sSceneID then
-
 
1136
    begin
-
 
1137
      result := i;
-
 
1138
      exit;
-
 
1139
    end;
-
 
1140
  end;
-
 
1141
  result := -1;
-
 
1142
end;
-
 
1143
 
-
 
1144
procedure TForm1.RecalcSlideshowLength;
1153
procedure TForm1.RecalcSlideshowLength;
1145
var
1154
var
1146
  i: integer;
1155
  i: integer;
1147
  Sum: integer;
1156
  Sum: integer;
1148
begin
1157
begin
Line 1201... Line 1210...
1201
end;
1210
end;
1202
 
1211
 
1203
procedure TForm1.RecalcSoundtrackLength;
1212
procedure TForm1.RecalcSoundtrackLength;
1204
var
1213
var
1205
  FileName: string;
1214
  FileName: string;
-
 
1215
resourcestring
-
 
1216
  S_NA = 'n/a';
1206
begin
1217
begin
1207
  if MediaPlayer1.Mode = mpPlaying then exit;
1218
  if MediaPlayer1.Mode = mpPlaying then exit;
1208
 
1219
 
1209
  FileName := IncludeTrailingPathDelimiter(CurScene^.szSceneFolder) + CurScene^.szDialogWav;
1220
  FileName := IncludeTrailingPathDelimiter(CurScene^.szSceneFolder) + CurScene^.szDialogWav;
1210
  if not FileExists(FileName) then
1221
  if not FileExists(FileName) then
1211
  begin
1222
  begin
1212
    Label23.Caption := 'n/a';
1223
    Label23.Caption := S_NA;
1213
    exit;
1224
    exit;
1214
  end;
1225
  end;
1215
  MediaPlayer1.FileName := FileName;
1226
  MediaPlayer1.FileName := FileName;
1216
  MediaPlayer1.TimeFormat := tfMilliseconds;
1227
  MediaPlayer1.TimeFormat := tfMilliseconds;
1217
  MediaPlayer1.Open;
1228
  MediaPlayer1.Open;
Line 1229... Line 1240...
1229
      ComboBox.ItemIndex := 0
1240
      ComboBox.ItemIndex := 0
1230
    else if sceneID = SCENEID_PREVDECISION then
1241
    else if sceneID = SCENEID_PREVDECISION then
1231
      ComboBox.ItemIndex := 1
1242
      ComboBox.ItemIndex := 1
1232
    else
1243
    else
1233
    begin
1244
    begin
1234
      idx := FindSceneIndex(sceneID);
1245
      idx := Game.FindSceneIndex(sceneID);
1235
      if idx = -1 then
1246
      if idx = -1 then
1236
        ComboBox.ItemIndex := -1
1247
        ComboBox.ItemIndex := -1
1237
      else
1248
      else
1238
        ComboBox.ItemIndex := 2 + idx;
1249
        ComboBox.ItemIndex := 2 + idx;
1239
    end;
1250
    end;
Line 1319... Line 1330...
1319
end;
1330
end;
1320
 
1331
 
1321
procedure TForm1.ReloadActionSceneLists;
1332
procedure TForm1.ReloadActionSceneLists;
1322
 
1333
 
1323
  procedure _ReloadActionSceneLists(ComboBox: TComboBox);
1334
  procedure _ReloadActionSceneLists(ComboBox: TComboBox);
-
 
1335
  resourcestring
-
 
1336
    S_TERMINATE = 'Terminate program';
-
 
1337
    S_PREV_DEC = 'Previous decision';
1324
  var
1338
  var
1325
    prevSelection: string;
1339
    prevSelection: string;
1326
    i: Integer;
1340
    i: Integer;
1327
  begin
1341
  begin
1328
    prevSelection := ComboBox.Text;
1342
    prevSelection := ComboBox.Text;
1329
    try
1343
    try
1330
      ComboBox.Items.Clear;
1344
      ComboBox.Items.Clear;
1331
      ComboBox.Items.Add('Terminate program');
1345
      ComboBox.Items.Add(S_TERMINATE);
1332
      ComboBox.Items.Add('Previous decision');
1346
      ComboBox.Items.Add(S_PREV_DEC);
1333
      ComboBox.Items.AddStrings(ListBox1.Items);
1347
      ComboBox.Items.AddStrings(ListBox1.Items);
1334
    finally
1348
    finally
1335
      ComboBox.ItemIndex := 0;
1349
      ComboBox.ItemIndex := 0;
1336
      for i := ComboBox.Items.Count - 1 downto 0 do
1350
      for i := ComboBox.Items.Count - 1 downto 0 do
1337
      begin
1351
      begin