⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 formherodata.pas

📁 著名的J2ME动作编辑器.<金刚>也是由这个编辑器制作动作的.
💻 PAS
📖 第 1 页 / 共 2 页
字号:
    FaceName:= ChangeFileExt(ExtractFileName(FFaceFileName), '');
    try
      WriteByteToStream(FileStream, StrToInt(FaceName));
    except
      raise Exception.Create('文件名必须是数字!');
    end;
    //写入帧数据
    WriteByteToStream(FileStream, FActionList.Count);
    for i:= 0 to FActionList.PartList.Count - 1 do
    begin
      Part:= TPartItem(FActionList.PartList.Items[i]);
      WriteByteToStream(FileStream, Part.PartX);
      WriteByteToStream(FileStream, Part.PartY);
      WriteByteToStream(FileStream, Part.PartW);
      WriteByteToStream(FileStream, Part.PartH);
    end;
  finally
    FileStream.Free;
  end;
end;

function TFrmHeroData.GetActionItem: TActionItem;
begin
  Result:= TActionItem( FrameListView.List);
end;

procedure TFrmHeroData.ActDelExecute(Sender: TObject);
begin
  CurrentAction.DelSelected;
end;

procedure TFrmHeroData.ActNewExecute(Sender: TObject);
begin
  if Assigned(CurrentAction.Selected) then
    CurrentAction.InsItem(CurrentAction.ItemIndex, TFrameItem.Create(CurrentAction))
  else
    CurrentAction.AddItem(TFrameItem.Create(CurrentAction));
end;

procedure TFrmHeroData.ActUpMoveExecute(Sender: TObject);
begin
  if (CurrentAction.ItemIndex > 0) and (CurrentAction.ItemIndex < CurrentAction.Count) then
  begin
    CurrentAction.Exchange(CurrentAction.ItemIndex, CurrentAction.ItemIndex - 1);
    CurrentAction.ItemIndex:= CurrentAction.ItemIndex - 1;
  end;
end;

procedure TFrmHeroData.ActDownMoveExecute(Sender: TObject);
begin
  if (CurrentAction.ItemIndex >= 0) and (CurrentAction.ItemIndex < CurrentAction.Count - 1) then
  begin
    CurrentAction.Exchange(CurrentAction.ItemIndex, CurrentAction.ItemIndex + 1);
    CurrentAction.ItemIndex:= CurrentAction.ItemIndex + 1;
  end;
end;

procedure TFrmHeroData.ActCopyExecute(Sender: TObject);
var
  FData: String;
  FrameItem: TFrameItem;
begin
  if Assigned(FrameListView.Selected) then
  begin
    FrameItem:= TFrameItem(FrameListView.Selected);
    FData:= '<Sign>FrameData-1.0</Sign>' + Ln;
    FData:= FData + TFrameItem(CurrentAction.Selected).Data;
    ClipBoard.AsText:= FData;
  end;
end;

procedure TFrmHeroData.ActPasteExecute(Sender: TObject);
var
  FData: String;
  FrameItem: TFrameItem;
begin
  FData:= ClipBoard.AsText;
  if ReadText(FData, 'Sign') <> 'FrameData-1.0' then Exit;
  if Assigned(CurrentAction) then
  begin
    FrameItem:= TFrameItem.Create(CurrentAction);
    FrameItem.Data:= FData;
    if Assigned(CurrentAction.Selected) then
      CurrentAction.InsItem(CurrentAction.ItemIndex, FrameItem)
    else
      CurrentAction.AddItem(FrameItem);
  end;
end;


procedure TFrmHeroData.ActPlayStartExecute(Sender: TObject);
begin
  if not Assigned(CurrentAction) then Exit;
  if CurrentAction.Count = 0 then Exit;
  ActNew.Enabled:= False;
  ActDel.Enabled:= False;
  ActCopy.Enabled:= False;
  ActPaste.Enabled:= False;
  ActUpMove.Enabled:= False;
  ActDownMove.Enabled:= False;
  ActPlayStart.Enabled:= False;
  ActPlayEnd.Enabled:= True;
  FrameListview.Enabled:= False;
  PartListView.Enabled:= False;
  ActionListView.Enabled:= False;
  Timer.Enabled:= True;
  if (CurrentAction.ItemIndex < 0) or (CurrentAction.ItemIndex >= CurrentAction.Count) then
    CurrentAction.ItemIndex:= 0;
end;

procedure TFrmHeroData.ActPlayEndExecute(Sender: TObject);
begin
  ActNew.Enabled:= True;
  ActDel.Enabled:= True;
  ActCopy.Enabled:= True;
  ActPaste.Enabled:= True;
  ActUpMove.Enabled:= True;
  ActDownMove.Enabled:= True;
  ActPlayStart.Enabled:= True;
  ActPlayEnd.Enabled:= False;
  FrameListview.Enabled:= True;
  PartListView.Enabled:= True;
  ActionListView.Enabled:= True;
  Timer.Enabled:= False;
end;

procedure TFrmHeroData.TimerTimer(Sender: TObject);
begin
  if CurrentAction.ItemIndex < CurrentAction.Count - 1 then
    CurrentAction.ItemIndex:= CurrentAction.ItemIndex + 1
  else
    CurrentAction.ItemIndex:= 0;
  FFrameControl.FrameItem:= TFrameItem(CurrentAction.Selected);
end;

procedure TFrmHeroData.NdtFaceChange(Sender: TObject);
var
  Part: TPartItem;
begin
  if Assigned(LvwFrame.Selected) then
  begin
    Part:= FActionList.PartList.Parts[LvwFrame.Selected.Index];
    Part.PartX:= NdtFaceX.Number;
    Part.PartY:= NdtFaceY.Number;
    Part.PartW:= NdtFaceW.Number;
    Part.PartH:= NdtFaceH.Number;
  end;
end;

procedure TFrmHeroData.LvwFrameData(Sender: TObject; Item: TListItem);
var
  Rec: TPartItem;
begin
  Rec:= FActionList.PartList.Parts[Item.Index];
  Item.Caption:= IntToStr(Item.Index);
  Item.SubItems.Add(IntToStr(Rec.PartX));
  Item.SubItems.Add(IntToStr(Rec.PartY));
  Item.SubItems.Add(IntToStr(Rec.PartW));
  Item.SubItems.Add(IntToStr(Rec.PartH));
end;

procedure TFrmHeroData.LvwFrameSelectItem(Sender: TObject; Item: TListItem;
  Selected: Boolean);
var
  Rec: TPartItem;
begin
  if Selected then
  begin
    Rec:= FActionList.PartList.Parts[Item.Index];
    NdtFaceX.OnChange:= nil;
    NdtFaceY.OnChange:= nil;
    NdtFaceW.OnChange:= nil;
    NdtFaceH.OnChange:= nil;

    NdtFaceX.Number:= Rec.PartX;
    NdtFaceY.Number:= Rec.PartY;
    NdtFaceW.Number:= Rec.PartW;
    NdtFaceH.Number:= Rec.PartH;

    NdtFaceX.OnChange:= NdtFaceChange;
    NdtFaceY.OnChange:= NdtFaceChange;
    NdtFaceW.OnChange:= NdtFaceChange;
    NdtFaceH.OnChange:= NdtFaceChange;
  end;
end;

procedure TFrmHeroData.NdtTotalChange(Sender: TObject);
begin
  if NdtTotal.Number < 0 then NdtTotal.Number:= 0;
    FActionList.PartList.SetCount(NdtTotal.Number);
end;

procedure TFrmHeroData.PartsChange(Sender: TObject);
begin
  LvwFrame.Items.Count:= FActionList.PartList.Count;
  NdtTotal.OnChange:= nil;
  NdtTotal.Number:= FActionList.PartList.Count;
  NdtTotal.OnChange:= NdtTotalChange;
end;

procedure TFrmHeroData.ActNumbVisibleExecute(Sender: TObject);
begin
  FPartsControl.NumbVisible:= ActNumbVisible.Checked;
end;

procedure TFrmHeroData.ActFaceVisibleExecute(Sender: TObject);
begin
  FPartsControl.PartVisible:= ActFaceVisible.Checked;
end;

procedure TFrmHeroData.SpbDelPartClick(Sender: TObject);
begin
  FActionList.PartList.DelItem(LvwFrame.ItemIndex);
  LvwFrame.Items.Count:= FActionList.PartList.Count;
  LvwFrame.Refresh;
end;

procedure TFrmHeroData.ActSelectPicExecute(Sender: TObject);
begin
  if not OpenDialogSelectPic.Execute then Exit;
  FActionList.PartList.LoadPicture(OpenDialogSelectPic.FileName);
end;

procedure TFrmHeroData.ActExportPicExecute(Sender: TObject);
var
  FileName: String;
  FFaceData: String;
  FileStream: TFileStream;
begin
  if not SaveDialogExportPic.Execute then Exit;
  FileName:= SaveDialogExportPic.FileName;
  if (FileExists(FileName)) and (not QueryOverWriteFile(FileName)) then Exit;
  FileStream:= TFileStream.Create(FileName, fmCreate or fmShareExclusive);
  FFaceData:= DecodeData(FActionList.PartList.Face);
  FileStream.Write(FFaceData[1], Length(FFaceData));
  FileStream.Free;
end;


procedure TFrmHeroData.ActionListViewSelectItem(Sender: TObject;
  Item: TManaItem; Selected: Boolean);
begin
  FrameListView.List:= FActionList.Actions[ActionListView.List.ItemIndex];
end;

procedure TFrmHeroData.FrameListViewSelectItem(Sender: TObject;
  Item: TManaItem; Selected: Boolean);
begin
  if Selected then
    FFrameControl.FrameItem:= TFrameItem(Item);
end;

procedure TFrmHeroData.FramePartDragDrop(Sender, Source: TObject; X,
  Y: Integer);
begin
  TLinkControl(Sender).PartIndex:= PartListView.ItemIndex;
end;

procedure TFrmHeroData.FramePartDragOver(Sender, Source: TObject; X,
  Y: Integer; State: TDragState; var Accept: Boolean);
begin
  Accept:= TObject(PartListView) = Source;
end;

procedure TFrmHeroData.ActRectVisibleExecute(Sender: TObject);
begin
  FFrameControl.RectVisible:= ActRectVisible.Checked;
end;

procedure TFrmHeroData.ActActionUpMoveExecute(Sender: TObject);
begin
  if ActionListView.List.ItemIndex > 0 then
  begin
    FActionList.ExChangeAction(ActionListView.List.ItemIndex, ActionListView.List.ItemIndex - 1);
    RefreshActionList;
    ActionListView.List.ItemIndex:= ActionListView.List.ItemIndex - 1;
  end;
end;

procedure TFrmHeroData.ActActionDownMoveExecute(Sender: TObject);
begin
  if ActionListView.List.ItemIndex < FActionList.Count - 1 then
  begin
    FActionList.ExChangeAction(ActionListView.List.ItemIndex, ActionListView.List.ItemIndex + 1);
    RefreshActionList;
    ActionListView.List.ItemIndex:= ActionListView.List.ItemIndex + 1;
  end;
end;

procedure TFrmHeroData.RefreshActionList;
var
  i: Integer;
begin
  ActionListView.List.Clear;
  for i:= 0 to FActionList.Count - 1 do
    ActionListView.NewItem(FActionList.Actions[i].Caption);
end;

procedure TFrmHeroData.ActNewActionExecute(Sender: TObject);
begin
  FActionList.NewAction('动作' + IntToStr(FActionList.Count));
  RefreshActionList;
end;

procedure TFrmHeroData.ActDelActionExecute(Sender: TObject);
begin
  if (ActionListView.List.ItemIndex >= 0) and
    (ActionListView.List.ItemIndex < FActionList.Count) then
  begin
    FActionList.DelAction(ActionListView.List.ItemIndex);
    FrameListView.List:= nil;
    RefreshActionList;
    if ActionListView.List.ItemIndex >= ActionListView.List.Count then
      ActionListView.List.ItemIndex:= ActionListView.List.Count - 1;
  end;
end;

procedure TFrmHeroData.ActionListViewChange(Sender: TObject);
var
  i: Integer;
begin
  for i:= 0 to ActionListView.List.Count - 1 do
  begin
    FActionList.Actions[i].Name:= ActionListView.List.Items[i].Caption;
    FActionList.Actions[i].Caption:= ActionListView.List.Items[i].Caption;
  end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -