From: Luiz P. <lui...@us...> - 2001-01-16 04:05:29
|
Update of /cvsroot/pythianproject/Prototypes/SkillEditor In directory usw-pr-cvs1:/tmp/cvs-serv1848 Added Files: SkillEditor.cfg SkillEditor.dpr SkillEditor.res SkillEditorCode.dfm SkillEditorCode.pas SkillFormulaEditorCode.dfm SkillFormulaEditorCode.pas readme.txt skills.xml Log Message: no message --- NEW FILE --- -$A+ -$B- -$C+ -$D+ -$E- -$F- -$G+ -$H+ -$I+ -$J+ -$K- -$L+ -$M- -$N+ -$O+ -$P+ -$Q- -$R- -$S- -$T- -$U- -$V+ -$W- -$X+ -$YD -$Z1 -cg -AWinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE; -H+ -W+ -M -$M16384,1048576 -K$00400000 -LE"c:\arquivos de programas\borland\delphi5\Projects\Bpl" -LN"c:\arquivos de programas\borland\delphi5\Projects\Bpl" -U"C:\Delphi LPMP\Componentes" -O"C:\Delphi LPMP\Componentes" -I"C:\Delphi LPMP\Componentes" -R"C:\Delphi LPMP\Componentes" --- NEW FILE --- program SkillEditor; uses Forms, SkillEditorCode in 'SkillEditorCode.pas' {SkillEditorForm}, SkillFormulaEditorCode in 'SkillFormulaEditorCode.pas' {FormulaForm}; {$R *.RES} begin Application.Initialize; Application.CreateForm(TSkillEditorForm, SkillEditorForm); Application.CreateForm(TFormulaForm, FormulaForm); Application.Run; end. --- NEW FILE --- --- NEW FILE --- ÿ Font.ColorclWindowTextFont.Heightõ Font.Name MS Sans Serif Font.Style FormCreate PixelsPerInch` TextHeight OnDblClickTreeViewDblClickOnEditedTreeViewEditedOnKeyUp TreeViewKeyUp BevelInnerbvRaised BevelOuter bvLoweredTabOrderVisible Font.ColorclWindowTextFont.Heightó Font.Name Comic Sans MS Font.StylefsBold ParentFont Font.ColorclWindowTextFont.Heightõ Font.Name Comic Sans MS Font.Style ParentFont BevelInnerbvRaised BevelOuter bvLoweredTabOrderVisible Font.ColorclWindowTextFont.Heightó Font.Name Comic Sans MS Font.StylefsBold ParentFont Font.ColorclWindowTextFont.Heightõ Font.Name Comic Sans MS Font.Style ParentFont Font.ColorclWindowTextFont.Heightõ Font.Name Comic Sans MS Font.Style ParentFont Font.ColorclWindowTextFont.Heightõ Font.Name Comic Sans MS Font.Style ParentFont Font.ColorclWindowTextFont.Heightõ Font.Name Comic Sans MS Font.Style ParentFont Font.ColorclWindowTextFont.Heightõ Font.Name Comic Sans MS Font.Style ParentFont Font.ColorclWindowTextFont.Heightõ Font.Name Comic Sans MS Font.Style ParentFont Font.ColorclWindowTextFont.Heightõ Font.Name Comic Sans MS Font.Style ParentFont FormulaBtnLeftTop]WidthHeightFlat OnClickFormulaBtnClick GainUseBtnLeftTop® nameChangeOnExitnameExit Font.ColorclWindowTextFont.Heightõ Font.Name MS Sans Serif Font.Style ParentFontTabOrderValue TImageList ImageListLeftTop Bitmap & ImageIndex New &Skill ImageIndexShortCutS@OnClickNewSkill1Click SaveToXML1CaptionSave To &XML ImageIndexShortCutX@OnClickSaveToXML1Click ImageIndexShortCutQ@OnClick Exit1Click ImageIndexShortCutD@OnClickDeleteSelected1Click ImageIndexShortCutF@OnClickEditFormula1Click ImageIndexOnClickAbout1Click --- NEW FILE --- unit SkillEditorCode; {*******************************************************} { } { Skill Editor } { } { Copyright (c) 2001- The Pythian Project } { } {*******************************************************} // This program is free software; you can redistribute it and/or modify it // // under the terms of the GNU General Public License as published by the // // Free Software Foundation; either version 2 of the License, or (at your // // option) any later version. This program is distributed in the hope that // // it will be useful, but WITHOUT ANY WARRANTY; without even the implied // // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // // GNU General Public License for more details. // // // // You should have received a copy of the GNU General Public License // // along with this program; if not, write to the Free Software Foundation, // // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // --------------------------------------------------------------------- {Skill Editor that uses XML to store it's stuff Contributors - Luiz Paulo Monteiro Pires } interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, ComCtrls, ImgList, Menus, XDOM, StdCtrls, Spin, Buttons; type TSkillEditorForm = class(TForm) TreeView: TTreeView; GeneralPanel: TPanel; SecondaryPanel: TPanel; ImageList: TImageList; MainMenu: TMainMenu; File1: TMenuItem; NewGeneralSkill1: TMenuItem; NewSkill1: TMenuItem; N1: TMenuItem; Exit1: TMenuItem; Edit1: TMenuItem; DeleteSelected1: TMenuItem; Help1: TMenuItem; About1: TMenuItem; DomImplementation: TDomImplementation; XmlToDomParser: TXmlToDomParser; SaveToXML1: TMenuItem; N2: TMenuItem; LabelTestGeneral: TLabel; name: TEdit; formula: TEdit; gaintrain: TEdit; losegainwithouttrain: TEdit; losewithoutuse: TEdit; gainuse: TEdit; GeneralNameField: TEdit; LabelTestSecondary: TLabel; Label1: TLabel; timestogeneral: TSpinEdit; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; Label6: TLabel; Label7: TLabel; Label8: TLabel; FormulaBtn: TSpeedButton; GainTrainBtn: TSpeedButton; GainUseBtn: TSpeedButton; LoseGainWithoutTrainBtn: TSpeedButton; LoseWithoutUseBtn: TSpeedButton; N3: TMenuItem; EditFormula1: TMenuItem; Splitter: TSplitter; procedure FormCreate(Sender: TObject); procedure UpdateTreeView(const Doc: TdomDocument); procedure TreeViewChange(Sender: TObject; Node: TTreeNode); procedure nameExit(Sender: TObject); procedure SaveToXML1Click(Sender: TObject); function GetMaxValue: Integer; procedure NewGeneralSkill1Click(Sender: TObject); procedure GeneralNameFieldExit(Sender: TObject); procedure NewSkill1Click(Sender: TObject); procedure DeleteSelected1Click(Sender: TObject); procedure Exit1Click(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormulaBtnClick(Sender: TObject); procedure EditFormula1Click(Sender: TObject); procedure nameChange(Sender: TObject); procedure GeneralNameFieldChange(Sender: TObject); procedure TreeViewEdited(Sender: TObject; Node: TTreeNode; var S: String); procedure TreeViewDblClick(Sender: TObject); procedure TreeViewKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); procedure About1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; const GEN = 0; SEC = 1; RT = 5; var SkillEditorForm: TSkillEditorForm; Doc: TDomDocument; TdDoc: TDomNode; implementation uses SkillFormulaEditorCode; {$R *.DFM} procedure TSkillEditorForm.FormCreate(Sender: TObject); begin Doc := XmlToDomParser.FileToDom(ExtractFilePath(Application.ExeName) + 'skills.xml'); UpdateTreeView(Doc); ImageList.GetBitmap(7, FormulaBtn.Glyph); ImageList.GetBitmap(7, GainTrainBtn.Glyph); ImageList.GetBitmap(7, GainUseBtn.Glyph); ImageList.GetBitmap(7, LoseGainWithoutTrainBtn.Glyph); ImageList.GetBitmap(7, LoseWithoutUseBtn.Glyph); end; procedure TSkillEditorForm.UpdateTreeView(const Doc: TdomDocument); procedure HandleNodeList(Parent:TTreeNode; DomNodeList:TDomNodeList); var i: Integer; DomNode: TDomNode; Tn: TTreeNode; TnName: string; Te: TDomElement; begin for i := 0 to DomNodeList.length -1 do begin DomNode := DomNodeList.Item(i); Te := TDomElement(DomNode); TnName := Te.GetAttribute('name'); Tn := parent.owner.AddChild(Parent, TnName); Tn.Data := DomNode; if DomNode.prefix = 'Skill' then begin Tn.ImageIndex := SEC; Tn.SelectedIndex := SEC; end; if assigned(DomNode.ChildNodes) then HandleNodeList(Tn, DomNode.childNodes); end; end; var Root:TTreeNode; begin TreeView.Items.Clear; Root := TreeView.Items.Add(nil, 'Skills List'); Root.ImageIndex := RT; Root.SelectedIndex := RT; Root.StateIndex := RT; HandleNodeList(Root,Doc.documentElement.childNodes); end; procedure TSkillEditorForm.TreeViewChange(Sender: TObject; Node: TTreeNode); var Place: array[0..10] of Integer; Td: TDomNode; Te: TDomElement; Tn: TTreeNode; i: Integer; begin if Node.Level = 0 then begin GeneralPanel.Visible := False; SecondaryPanel.Visible := False; exit; end; SkillEditorForm.SetFocusedControl(TreeView); Tn := Node; for i := Node.Level -1 downto 0 do begin Place[i] := Tn.Index; Tn := Tn.Parent; end; Td := Doc.documentElement; for i := 0 to Node.Level -1 do begin Td := Td.childNodes.Item(Place[i]); end; TdDoc := Td; Te := TDomElement(Td); if Te.TagName = 'General' then begin SecondaryPanel.Visible := False; GeneralPanel.Visible := True; LabelTestGeneral.Caption := Te.GetAttribute('name'); GeneralNameField.Text := Te.GetAttribute('name'); end else if Te.TagName = 'Skill' then begin GeneralPanel.Visible := False; SecondaryPanel.Visible := True; LabelTestSecondary.Caption := Te.GetAttribute('name'); Name.Text := Te.GetAttribute('name'); Formula.Text := Te.GetAttribute('formula'); GainTrain.Text := Te.GetAttribute('gaintrain'); gainuse.Text := Te.GetAttribute('gainuse'); losegainwithouttrain.Text := Te.GetAttribute('losegainwithouttrain'); losewithoutuse.Text := Te.GetAttribute('losewithoutuse'); timestogeneral.MaxValue := GetMaxValue; try timestogeneral.Value := StrToInt(Te.GetAttribute('timestogeneral')); except timestogeneral.Value := 0; end; end; end; { Name Formula Base Gain per period of training Base Gain per period of use Loss of Gain per period of Use per period without training Loss per time period without use % of to General Skill (make sure that sec skills add up to a max total of a 100%) -XML- name= formula= gaintrain= gainuse= losegainwithouttrain= losewithouttrain= timestogeneral= } procedure TSkillEditorForm.nameExit(Sender: TObject); var Te: TDomElement; begin if (Sender as TCustomEdit).Name = 'timestogeneral' then begin if timestogeneral.Value > timestogeneral.MaxValue then timestogeneral.Value := timestogeneral.MaxValue; if timestogeneral.MaxValue = 0 then timestogeneral.Value := 0; end; Te := TDomElement(TdDoc); Te.SetAttribute((Sender as TCustomEdit).Name, (Sender as TCustomEdit).Text); //if (Sender as TCustomEdit).Name = 'name' then // begin // TreeView.Selected.Text := (Sender as TCustomEdit).Text; // LabelTestSecondary.Caption := (Sender as TCustomEdit).Text; // end; end; procedure TSkillEditorForm.SaveToXML1Click(Sender: TObject); var Memo: TMemo; begin SkillEditorForm.SetFocusedControl(TreeView); Memo := TMemo.Create(Self); //I'm in no mood to handle files so I just made a Memo to do it for me Memo.Text := Doc.codeAsString; Memo.Lines.SaveToFile(ExtractFilePath(Application.ExeName) + 'skills.xml'); Memo.Free; end; function TSkillEditorForm.GetMaxValue: Integer; var Dad: TDomNode; Son: TDomElement; i, max: integer; begin Dad := TdDoc.parentNode; max := 100; for i := 0 to Dad.childNodes.Length -1 do begin if i <> TreeView.Selected.Index then begin Son := TDomElement(Dad.childNodes.Item(i)); max := max - StrToInt(Son.GetAttribute('timestogeneral')); end; end; //ShowMessage(IntToStr(max)); Result := max; end; procedure TSkillEditorForm.NewGeneralSkill1Click(Sender: TObject); var UpTe, DownTe: TDomElement; Tr: TTreeNode; i: integer; begin if TreeView.Selected.ImageIndex = SEC then begin ShowMessage('Sorry boys. No can do.'); exit; end; if (TreeView.Selected.HasChildren) then begin for i := 0 to TreeView.Selected.Count -1 do begin if TreeView.Selected.Item[i].ImageIndex = SEC then begin ShowMessage('Sorry boys. No can do.'); exit; end; end; end; if TreeView.Selected.Level <> 0 then DownTe := TDomElement(TdDoc); UpTe := TDomDocument(Doc).CreateElement('General'); UpTe.SetAttribute('name', 'NewGeneralSkill'); if TreeView.Selected.Level = 0 then begin Doc.DocumentElement.AppendChild(UpTe); UpdateTreeView(Doc); TreeView.Items.Item[0].Expand(False); TreeView.Selected := TreeView.Items.Item[0]; exit; end else DownTe.AppendChild(UpTe); Tr := TreeView.Selected; TreeView.Items.AddChild(Tr, 'NewGeneralSkill'); Tr.ImageIndex := GEN; Tr.Expand(False); end; { all x-y/v1-vN go from 0-1 Formula --xGen*yTrain/Use(this part starts with 0) Base Gain per period of training -x = Base Gain per period of training --Gain = x * Training Time * Trainer Skill * (v1 * Stat1 + ... + vn * Statn) / 100 (v1 + v2 +...+vN is 1) Base Gain per period of use -x = Base Gain per period of use --Gain = x * Use Time * (v1 * Stat1 + ... + vn * Statn) / 100 - y * Time since last training (v1 + v2 +...+vN is 1) Loss of Gain per period of Use per period without training -y = Loss of Gain per period of Use per period without training --y * Time since last training * (v1 * Memory / 100) Loss per time period without use --Loss = x * Time without use * (v1 * Memory) / 100 } procedure TSkillEditorForm.GeneralNameFieldExit(Sender: TObject); var Te: TDomElement; begin Te := TDomElement(TdDoc); Te.SetAttribute('name', GeneralNameField.Text); end; procedure TSkillEditorForm.NewSkill1Click(Sender: TObject); var UpTe, DownTe: TDomElement; Tr: TTreeNode; i: integer; begin if TreeView.Selected.ImageIndex = SEC then begin ShowMessage('Sorry boys. No can do.'); exit; end; if (TreeView.Selected.HasChildren) then begin for i := 0 to TreeView.Selected.Count -1 do begin if TreeView.Selected.Item[i].ImageIndex = GEN then begin ShowMessage('Sorry boys. No can do.'); exit; end; end; end; if TreeView.Selected.Level <> 0 then DownTe := TDomElement(TdDoc); UpTe := TDomDocument(Doc).CreateElement('Skill'); UpTe.SetAttribute('name', 'NewSkill'); UpTe.SetAttribute('formula', ''); UpTe.SetAttribute('gaintrain', ''); UpTe.SetAttribute('gainuse', ''); UpTe.SetAttribute('losegainwithouttrain', ''); UpTe.SetAttribute('losewithoutuse', ''); UpTe.SetAttribute('timestogeneral', '0'); if TreeView.Selected.Level = 0 then begin Doc.DocumentElement.AppendChild(UpTe); UpdateTreeView(Doc); TreeView.Items.Item[0].Expand(False); TreeView.Selected := TreeView.Items.Item[0]; exit; end else DownTe.AppendChild(UpTe); Tr := TreeView.Selected; TreeView.Items.AddChild(Tr, 'NewSkill'); Tr.GetLastChild.ImageIndex := SEC; Tr.GetLastChild.SelectedIndex := SEC; Tr.Expand(False); end; procedure TSkillEditorForm.DeleteSelected1Click(Sender: TObject); begin //if not TreeView.Focused then // begin // (SkillEditorForm.ActiveControl as TCustomEdit).SelText := ''; // exit; // end; if (TreeView.Selected.Level = 0) then begin ShowMessage('Sorry boys. No can do.'); exit; end; TdDoc.ParentNode.RemoveChild(TdDoc); TreeView.Selected.Parent.Item[TreeView.Selected.Index].Delete; TreeView.Selected := TreeView.Selected.Parent; end; procedure TSkillEditorForm.Exit1Click(Sender: TObject); begin SkillEditorForm.Close; end; procedure TSkillEditorForm.FormClose(Sender: TObject; var Action: TCloseAction); var check: integer; begin check := MessageDlg('Wanna Save?', mtConfirmation, mbYesNoCancel, 0); if check = mrYes then SaveToXML1Click(Self) else if check = mrCancel then Action := caNone; end; procedure TSkillEditorForm.FormulaBtnClick(Sender: TObject); begin case (Sender as TSpeedButton).Top of 93: begin SkillFormulaEditorCode.FormulaType := 'xy-form'; SkillFormulaEditorCode.FormulaValue := formula.Text; end; 134: begin SkillFormulaEditorCode.FormulaType := 'xstat-gtrain'; SkillFormulaEditorCode.FormulaValue := gaintrain.Text; end; 174: begin SkillFormulaEditorCode.FormulaType := 'xstat-guse'; SkillFormulaEditorCode.FormulaValue := gainuse.Text; end; 215: begin SkillFormulaEditorCode.FormulaType := 'xstat-lwtrain'; SkillFormulaEditorCode.FormulaValue := losegainwithouttrain.Text; end; 255: begin SkillFormulaEditorCode.FormulaType := 'xstat-lwuse'; SkillFormulaEditorCode.FormulaValue := losewithoutuse.Text; end; end; FormulaForm.LoadFormula; FormulaForm.ShowModal; end; procedure TSkillEditorForm.EditFormula1Click(Sender: TObject); begin if (formula.Focused) then begin SkillFormulaEditorCode.FormulaType := 'xy-form'; SkillFormulaEditorCode.FormulaValue := formula.Text; FormulaForm.LoadFormula; FormulaForm.ShowModal; end; if (gaintrain.Focused) then begin SkillFormulaEditorCode.FormulaType := 'xstat-gtrain'; SkillFormulaEditorCode.FormulaValue := gaintrain.Text; FormulaForm.LoadFormula; FormulaForm.ShowModal; end; if (gainuse.Focused) then begin SkillFormulaEditorCode.FormulaType := 'xstat-guse'; SkillFormulaEditorCode.FormulaValue := gainuse.Text; FormulaForm.LoadFormula; FormulaForm.ShowModal; end; if (losegainwithouttrain.Focused) then begin SkillFormulaEditorCode.FormulaType := 'xstat-lwtrain'; SkillFormulaEditorCode.FormulaValue := losegainwithouttrain.Text; FormulaForm.LoadFormula; FormulaForm.ShowModal; end; if (losewithoutuse.Focused) then begin SkillFormulaEditorCode.FormulaType := 'xstat-lwuse'; SkillFormulaEditorCode.FormulaValue := losewithoutuse.Text; FormulaForm.LoadFormula; FormulaForm.ShowModal; end; end; procedure TSkillEditorForm.nameChange(Sender: TObject); begin TreeView.Selected.Text := (Sender as TCustomEdit).Text; LabelTestSecondary.Caption := (Sender as TCustomEdit).Text; end; procedure TSkillEditorForm.GeneralNameFieldChange(Sender: TObject); begin TreeView.Selected.Text := GeneralNameField.Text; LabelTestGeneral.Caption := GeneralNameField.Text; end; procedure TSkillEditorForm.TreeViewEdited(Sender: TObject; Node: TTreeNode; var S: String); begin if Node.ImageIndex = GEN then begin GeneralNameField.Text := S; SkillEditorForm.SetFocusedControl(GeneralNameField); SkillEditorForm.SetFocusedControl(TreeView); end else if Node.ImageIndex = SEC then begin name.Text := S; SkillEditorForm.SetFocusedControl(name); SkillEditorForm.SetFocusedControl(TreeView); end; end; procedure TSkillEditorForm.TreeViewDblClick(Sender: TObject); begin TreeView.Selected.EditText; end; procedure TSkillEditorForm.TreeViewKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); begin if Key = Word(VK_F2) then TreeView.Selected.EditText; end; procedure TSkillEditorForm.About1Click(Sender: TObject); begin ShowMessage(' Skill Editor' + #13 + #13 + 'Copyright (c) 2001- The Pythian Project' + #13 + #13 + ' v1.0 - Jan/2001'); end; end. --- NEW FILE --- ÿ Font.ColorclWindowTextFont.Heightõ Font.Name MS Sans Serif Font.Style TextHeight ScrollBars ssVerticalTabOrder OnDrawCellGridDrawCell OnKeyPressGridKeyPress SkillsListLeft0ToppWidth ItemHeight TabOrderOnChangeSkillsListChange Items.StringsLiftingCarryingEndurance (Running)Reaction speedGraceEndurance (Health) Comeliness Healing speedWitProblem-solvingMemory InductionMagic --- NEW FILE --- unit SkillFormulaEditorCode; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids, Spin; type TFormulaForm = class(TForm) Grid: TStringGrid; SkillsList: TComboBox; Add: TButton; Delete: TButton; Multi: TSpinEdit; Ok: TButton; Cancel: TButton; procedure GridDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); procedure FormShow(Sender: TObject); procedure SkillsListChange(Sender: TObject); procedure GridKeyPress(Sender: TObject; var Key: Char); procedure AddClick(Sender: TObject); procedure DeleteClick(Sender: TObject); procedure LoadFormula;//(FormType: String; FormValue: String); procedure SaveFormula; procedure OkClick(Sender: TObject); procedure CancelClick(Sender: TObject); procedure MultiExit(Sender: TObject); function GetMax(Row: Integer): Integer; private { Private declarations } public { Public declarations } end; var FormulaForm: TFormulaForm; FormulaType: String; FormulaValue: String; implementation uses SkillEditorCode; {$R *.DFM} { a) Physical (1) Lifting (2) Carrying (3) Endurance (Running) (4) Reaction speed (5) Grace (6) Endurance (Health) (7) Comeliness (8) Healing speed b) Intellectual (1) Wit (2) Problem-solving (3) Memory (4) Induction (5) Magic } procedure TFormulaForm.GridDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState); var tmpStr : String; tmpRect : TRect; begin SkillsList.Visible := False; Multi.Visible := False; tmpStr := Grid.Cells[ACol,ARow]; tmpRect := Rect; Grid.Canvas.Brush.Color := clWindow; if (gdFocused in State) and (ACol = 0) then begin if (tmpStr = 'x') or (tmpStr = 'y') then begin Grid.Canvas.Brush.Color := clHighLight; Grid.Canvas.FillRect(tmpRect); DrawText(Grid.Canvas.Handle, pChar(tmpStr), Length(tmpStr), tmpRect, DT_CENTER); Grid.Canvas.Brush.Color := clWindow; exit; end; SetWindowPos(SkillsList.Handle, 0, Rect.Left + Grid.Left + 1, Rect.Top + Grid.top + 1, Rect.Right - Rect.Left + 2, Rect.Bottom - Rect.top + 2, SWP_NOZORDER or SWP_SHOWWINDOW); SkillsList.Show; SkillsList.ItemIndex := SkillsList.Items.IndexOf(tmpStr); if SkillsList.ItemIndex = -1 then SkillsList.ItemIndex := 0; exit; end; if (gdFocused in State) and (ACol = 1) then begin SetWindowPos(Multi.Handle, 0, Rect.Left + Grid.Left + 1, Rect.Top + Grid.top + 1, Rect.Right - Rect.Left + 2, Rect.Bottom - Rect.top + 2, SWP_NOZORDER or SWP_SHOWWINDOW); Multi.Show; if tmpStr = '' then begin Multi.MaxValue := 0; Multi.Value := 0; Multi.MaxValue := GetMax(ARow); // MultiEnter(Self); end else begin Multi.MaxValue := 0; Multi.Value := StrToInt(tmpStr); Multi.MaxValue := GetMax(ARow); // MultiEnter(Self); end; exit; end; if ACol = 0 then begin if tmpStr = '' then begin tmpStr := 'Lifting'; Grid.Cells[ACol, ARow] := 'Lifting' end; end; if ACol = 1 then begin if tmpStr = '' then begin tmpStr := '0'; Grid.Cells[ACol, ARow] := '0' end; end; //if SkillsList.Visible then // SkillsList.Visible := False; Grid.Canvas.FillRect(tmpRect); DrawText(Grid.Canvas.Handle, pChar(tmpStr), Length(tmpStr), tmpRect, DT_CENTER); //if (gdFocused in State) then // begin // Grid.Canvas.Brush.Color := clHighLight; // Grid.Canvas.FillRect(tmpRect); // Grid.Canvas.Brush.Color := clWindow; // end; end; procedure TFormulaForm.FormShow(Sender: TObject); begin SkillsList.Visible := False; Multi.Visible := False; if FormulaType = 'xy-form' then Caption := 'Formula of Skill' else if FormulaType = 'xstat-gtrain' then Caption := 'Formula of Base Gain per period of training' else if FormulaType = 'xstat-guse' then Caption := 'Formula of Base Gain per period of use' else if FormulaType = 'xstat-lwtrain' then Caption := 'Formula of Loss of Gain per period of Use per period without training' else if FormulaType = 'xstat-lwuse' then Caption := 'Formula of Loss per time period without use'; end; procedure TFormulaForm.SkillsListChange(Sender: TObject); begin if Grid.Col = 0 then Grid.Cells[Grid.Col,Grid.Row] := SkillsList.Text else Grid.Cells[Grid.Col,Grid.Row] := Multi.Text; end; procedure TFormulaForm.GridKeyPress(Sender: TObject; var Key: Char); begin if (Grid.Cells[Grid.Col, Grid.Row] = 'x') or (Grid.Cells[Grid.Col, Grid.Row] = 'y') then exit; if (Key <> chr(9)) then begin if Grid.Col = 0 then begin SkillsList.SetFocus; SendMessage(SkillsList.Handle, WM_Char, word(Key), 0); end else begin Multi.SetFocus; SendMessage(Multi.Handle, WM_Char, word(Key), 0); end; end; end; procedure TFormulaForm.AddClick(Sender: TObject); begin //if Grid.RowCount = 0 then // begin // Grid.RowCount := 1; // Grid.Height := 24; // end //else // begin if Grid.RowCount = 13 then exit; Grid.RowCount := Grid.RowCount +1; Grid.Height := Grid.Height + 21; // end; Grid.Cells[1, Grid.RowCount-1] := '0'; end; procedure TFormulaForm.DeleteClick(Sender: TObject); var i: Integer; begin if (Grid.RowCount = 0) or (Grid.RowCount = 1) then exit; if (FormulaType = 'xy-form') and (Grid.RowCount = 2) then exit; if Grid.Row = 0 then exit; if (FormulaType = 'xy-form') and (Grid.Row = 1) then exit; //if Grid.RowCount = 1 then // begin // Grid.RowCount := 0; // Grid.Height := 0; // exit; // end; for i := Grid.Row to Grid.RowCount -1 do begin Grid.Cells[0, i] := Grid.Cells[0, i+1]; Grid.Cells[1, i] := Grid.Cells[1, i+1]; end; Grid.RowCount := Grid.RowCount -1; Grid.Height := Grid.Height - 21; //Grid. end; procedure TFormulaForm.SaveFormula; var i: Integer; Str: String; begin Str := ''; if FormulaType = 'xy-form' then begin if (Grid.Cells[1,0] = '') or (Grid.Cells[1,1] = '') or (Grid.Cells[0,2] = '') then exit; end else begin if (Grid.Cells[1,0] = '') or (Grid.Cells[1,1] = '') then exit; end; for i := 0 to Grid.RowCount -1 do begin if (Grid.Cells[0, i] <> '') and (Grid.Cells[1, i] <> '') then begin Str := Str + '[' + Grid.Cells[0, i]; Str := Str + '=' + Grid.Cells[1, i] + ']'; end else begin Grid.RowCount := Grid.RowCount -1; Grid.Height := Grid.Height - 21; end; end; if FormulaType = 'xy-form' then SkillEditorForm.formula.Text := Str else if FormulaType = 'xstat-gtrain' then SkillEditorForm.gaintrain.Text := Str else if FormulaType = 'xstat-guse' then SkillEditorForm.gainuse.Text := Str else if FormulaType = 'xstat-lwtrain' then SkillEditorForm.losegainwithouttrain.Text := Str else if FormulaType = 'xstat-lwuse' then SkillEditorForm.losewithoutuse.Text := Str; end; procedure TFormulaForm.LoadFormula;//(FormType: String; FormValue: String); var i: Integer; Str, Str2: String; begin Str := FormulaValue; if Str = '' then begin if FormulaType = 'xy-form' then begin Grid.RowCount := 3; Grid.Height := 66; Grid.Cells[0,0] := 'x'; Grid.Cells[1,0] := '0'; Grid.Cells[0,1] := 'y'; Grid.Cells[1,1] := '0'; Grid.Cells[2,0] := ''; Grid.Cells[2,1] := '0'; end else begin Grid.RowCount := 2; Grid.Height := 45; Grid.Cells[0,0] := 'x'; Grid.Cells[1,0] := '0'; Grid.Cells[0,1] := ''; Grid.Cells[1,1] := '0'; end; exit; end; i := 0; //else // begin // if FormulaType = 'xy-form' then // i := 2 // else // i := 1; // end; //Grid.RowCount := 1; //Grid.Height := 24; while Pos('[', Str) > 0 do begin if i > Grid.RowCount -1 then begin Grid.RowCount := Grid.RowCount +1; Grid.Height := Grid.Height + 21; end; System.Delete(Str, 1, 1); Str2 := Str; System.Delete(Str2, Pos('=', Str2), Length(Str2)); Grid.Cells[0, i] := Str2; Str2 := Str; System.Delete(Str2, 1, Pos('=', Str2)); System.Delete(Str2, Pos(']', Str2), Length(Str2)); Grid.Cells[1, i] := Str2; System.Delete(Str, 1, Pos(']', Str)); Inc(i); end; while i < Grid.RowCount do begin Grid.Cells[0, Grid.RowCount -1] := ''; Grid.Cells[1, Grid.RowCount -1] := ''; Grid.RowCount := Grid.RowCount -1; Grid.Height := Grid.Height - 21; end; end; //[Endurance (Running)-30][Wit-20][Memory-50] procedure TFormulaForm.OkClick(Sender: TObject); begin SaveFormula; Close; end; procedure TFormulaForm.CancelClick(Sender: TObject); begin Close; end; procedure TFormulaForm.MultiExit(Sender: TObject); begin if FormulaType = 'xy-form' then begin if (Multi.MaxValue = 0) and (Grid.Row > 1) then Multi.Value := 0 else exit; end else begin if (Multi.MaxValue = 0) and (Grid.Row > 0) then Multi.Value := 0 else exit; end; if Multi.Value > Multi.MaxValue then Multi.Value := Multi.MaxValue; if Multi.MaxValue = 0 then Multi.Value := 0; end; function TFormulaForm.GetMax(Row: Integer): Integer; var i, max: Integer; begin if FormulaType = 'xy-form' then i := 2 else i := 1; max := 100; if FormulaType = 'xy-form' then begin if (Row = 0) or (Row = 1) then begin Result := 0; exit; end; end else begin if (Grid.Row = 0) then begin Result := 0; exit; end; end; for i := i to Grid.RowCount -1 do begin if i <> Row then max := max - StrToInt(Grid.Cells[1, i]); end; Result := max; end; end. --- NEW FILE --- Skill Editor v1.0 This skill editor uses XML to store it's data. Check the skills.xml to see the structure if you want. Oh yeah after you change add/change stuff(and save these changes) remember to update cvs so we can all have the same version of the skill's list. As you'll see there are those general/secondary skills that we talked about. Also you'll see that there are formulas on the secondary skills. These are what the formulas are like: --xGen*yTrain/Use(this part starts with 0) Base Gain per period of training -x = Base Gain per period of training --Gain = x * Training Time * Trainer Skill * (v1 * Stat1 + ... + vn * Statn) / 100 (v1 + v2 +...+vN is 1) Base Gain per period of use -x = Base Gain per period of use --Gain = x * Use Time * (v1 * Stat1 + ... + vn * Statn) / 100 - y * Time since last training (v1 + v2 +...+vN is 1) Loss of Gain per period of Use per period without training -x = Loss of Gain per period of Use per period without training --x * Time since last training * (v1 * Memory / 100) You can also add some more stats here but it's mostily memory Loss per time period without use --Loss = x * Time without use * (v1 * Memory) / 100 You can also add some more stats here but it's mostily memory You can easily do this stuff with the Formula editor. I know this should explain more, but oh well... Luiz Paulo --- NEW FILE --- <?xml version="1.0" encoding="UTF-8"?> <Skilllist><General name="Combat"><General name="Weapons"><General name="Sword"><Skill name="Short Sword" formula="[x=30][y=55][Endurance (Running)=30][Memory=45]" gaintrain="[x=30][Induction=40][Endurance (Health)=55]" gainuse="[x=35][Comeliness=45]" losegainwithouttrain="[x=66][Wit=0][Endurance (Health)=10]" losewithoutuse="[x=20][Induction=30]" timestogeneral="0"></Skill><Skill name="Long Sword" formula="" gaintrain="" gainuse="" losegainwithouttrain="" losewithoutuse="" timestogeneral="0"></Skill></General><General name="Axe"><Skill name="Short Axe" formula="" gaintrain="" gainuse="" losegainwithouttrain="" losewithoutuse="" timestogeneral="0"></Skill><Skill name="Long Axe" formula="" gaintrain="" gainuse="" losegainwithouttrain="" losewithoutuse="" timestogeneral="0"></Skill></General></General></General><General name="Test General"><General name="New Test!!"></General></General></Skilllist> |