PageRenderTime 59ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/turbu/turbu format/design/EB Editors/Characters/EditHeroSprite.pas

http://turbu.googlecode.com/
Pascal | 176 lines | 151 code | 23 blank | 2 comment | 5 complexity | edfe22392ad3c68a02b664f61d33dde9 MD5 | raw file
  1. unit EditHeroSprite;
  2. interface
  3. uses
  4. Forms, DB, DBCtrls, StdCtrls, Controls, Classes, ExtCtrls,
  5. IDLookupCombo, sdl_frame, EbEdit, dm_database, EventBuilder,
  6. turbu_sprites, sg_defs;
  7. type
  8. [EditorCategory('Characters', 'Change Hero Sprite')]
  9. TfrmEBEditHeroSprite = class(TfrmEbEditBase)
  10. lstFilenames: TListBox;
  11. txtName: TStaticText;
  12. cboHero: TIDLookupCombo;
  13. srcHeroes: TDataSource;
  14. imgMapSprite: TSdlFrame;
  15. chkTranslucent: TCheckBox;
  16. procedure cboHeroClick(Sender: TObject);
  17. procedure FormShow(Sender: TObject);
  18. procedure imgMapSpriteTimer(Sender: TObject);
  19. procedure FormCreate(Sender: TObject);
  20. procedure chkTranslucentClick(Sender: TObject);
  21. procedure imgMapSpriteAvailable(Sender: TObject);
  22. private
  23. FNotNew: boolean;
  24. FMatrix: TMoveMatrix;
  25. FSpriteData: TSpriteData;
  26. FMatrixPos: TSgPoint;
  27. FRepCount: integer;
  28. procedure SetFilename(const name: string);
  29. function GetFilename: string;
  30. protected
  31. procedure UploadObject(obj: TEbObject); override;
  32. procedure DownloadObject(obj: TEbObject); override;
  33. function NewClassType: TEbClass; override;
  34. end;
  35. [EditorCategory('Characters', 'Change Vehicle Sprite')]
  36. TfrmEBEditVehicleSprite = class(TfrmEBEditHeroSprite)
  37. procedure FormShow(Sender: TObject);
  38. procedure cboHeroClick(Sender: TObject);
  39. protected
  40. function NewClassType: TEbClass; override;
  41. end;
  42. implementation
  43. uses
  44. SysUtils,
  45. sdl_frame_helper, ArchiveInterface, sdl_13,
  46. turbu_database, turbu_characters,
  47. EB_Characters;
  48. {$R *.dfm}
  49. procedure TfrmEBEditHeroSprite.FormCreate(Sender: TObject);
  50. var
  51. filename: string;
  52. begin
  53. for filename in GArchives[IMAGE_ARCHIVE].allFiles('mapsprite') do
  54. lstFilenames.Items.Add(ChangeFileExt(ExtractFileName(filename), ''));
  55. GArchives[IMAGE_ARCHIVE].currentFolder := '';
  56. end;
  57. procedure TfrmEBEditHeroSprite.FormShow(Sender: TObject);
  58. begin
  59. inherited FormShow(Sender);
  60. if not FNotNew then
  61. cboHero.id := 1;
  62. imgMapSprite.Active := true;
  63. FMatrixPos.x := 2; //sprite starts out facing down
  64. end;
  65. function TfrmEBEditHeroSprite.GetFilename: string;
  66. begin
  67. result := lstFilenames.Items[lstFilenames.ItemIndex];
  68. end;
  69. procedure TfrmEBEditHeroSprite.imgMapSpriteAvailable(Sender: TObject);
  70. begin
  71. imgMapSprite.loadMapSprite(getFilename, 0, 0, FSpriteData);
  72. chkTranslucentClick(self);
  73. end;
  74. procedure TfrmEBEditHeroSprite.imgMapSpriteTimer(Sender: TObject);
  75. begin
  76. imgMapSprite.DemoWalk(getFilename, 0, FMatrix,
  77. FSpriteData, FMatrixPos, FRepCount);
  78. end;
  79. procedure TfrmEBEditHeroSprite.SetFilename(const name: string);
  80. begin
  81. lstFilenames.ItemIndex := lstFilenames.Items.IndexOf(name);
  82. end;
  83. procedure TfrmEBEditHeroSprite.cboHeroClick(Sender: TObject);
  84. var
  85. hero: THeroTemplate;
  86. begin
  87. hero := GDatabase.hero[cboHero.id];
  88. SetFilename(hero.mapSprite);
  89. chkTranslucent.Checked := hero.translucent;
  90. chkTranslucentClick(self);
  91. FMatrix := GDatabase.moveMatrix[hero.actionMatrix];
  92. end;
  93. procedure TfrmEBEditHeroSprite.chkTranslucentClick(Sender: TObject);
  94. var
  95. opacity: byte;
  96. name: string;
  97. begin
  98. name := format('mapsprite\%s.png', [GetFilename]);
  99. if imgMapSprite.IndexOfName(name) = -1 then
  100. Exit;
  101. if chkTranslucent.Checked then
  102. opacity := $A0
  103. else opacity := $FF;
  104. SDL_SetTextureAlphaMod(imgMapSprite.TextureByName[name], opacity);
  105. end;
  106. procedure TfrmEBEditHeroSprite.UploadObject(obj: TEbObject);
  107. begin
  108. FNotNew := true;
  109. cboHero.id := obj.Values[0];
  110. SetFilename(obj.Text);
  111. chkTranslucent.Checked := boolean(obj.Values[1]);
  112. chkTranslucentClick(self);
  113. end;
  114. procedure TfrmEBEditHeroSprite.DownloadObject(obj: TEbObject);
  115. begin
  116. obj.Clear;
  117. obj.Values.Add(cboHero.id);
  118. obj.Values.Add(ord(chkTranslucent.Checked));
  119. obj.Text := getFilename;
  120. end;
  121. function TfrmEBEditHeroSprite.NewClassType: TEbClass;
  122. begin
  123. result := TEBHeroSprite;
  124. end;
  125. { TfrmEBEditVehicleSprite }
  126. procedure TfrmEBEditVehicleSprite.FormShow(Sender: TObject);
  127. begin
  128. self.Caption := 'Change Vehicle Sprite';
  129. txtName.Caption := 'Vehicle:';
  130. srcHeroes.DataSet := dmDatabase.Vehicles;
  131. inherited FormShow(Sender);
  132. end;
  133. procedure TfrmEBEditVehicleSprite.cboHeroClick(Sender: TObject);
  134. var
  135. vehicle: TVehicleTemplate;
  136. begin
  137. vehicle := GDatabase.vehicles[cboHero.id];
  138. SetFilename(vehicle.mapSprite);
  139. chkTranslucent.Checked := vehicle.translucent;
  140. chkTranslucentClick(self);
  141. FMatrix := GDatabase.moveMatrix[0];
  142. end;
  143. function TfrmEBEditVehicleSprite.NewClassType: TEbClass;
  144. begin
  145. result := TEBVehicleSprite;
  146. end;
  147. initialization
  148. RegisterEbEditor(TEBHeroSprite, TfrmEBEditHeroSprite);
  149. RegisterEbEditor(TEBVehicleSprite, TfrmEBEditVehicleSprite);
  150. finalization
  151. UnRegisterEbEditor(TEBHeroSprite);
  152. UnRegisterEbEditor(TEBVehicleSprite);
  153. end.