unit Umain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Spin, Inifiles, ExtCtrls, Menus,
ShellAPI,
Uabout, Uutils, Misc, JobCommon,
JobKnight, JobNovice, JobPierro, JobMagician, JobWarrior, JobPriest, JobCraftman,
DebugUnit
;
type
TMainForm = class(TForm)
SpinEditLv: TSpinEdit;
SpinEditStatus1: TSpinEdit;
SpinEditStatus2: TSpinEdit;
SpinEditStatus3: TSpinEdit;
JobComboBox: TComboBox;
SpinEditStatus4: TSpinEdit;
SpinEditStatus5: TSpinEdit;
SpinEditStatus6: TSpinEdit;
PointEdit: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
ReloadButton: TButton;
ResetButton: TButton;
SpinEditFame: TSpinEdit;
EtcSkillComboBox: TComboBox;
Panel1: TPanel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
Label14: TLabel;
Label15: TLabel;
Label16: TLabel;
Panel2: TPanel;
Label19: TLabel;
Label20: TLabel;
ResultEdit1: TEdit;
ResultEdit2: TEdit;
ResultEdit3: TEdit;
ResultEdit4: TEdit;
ResultEdit5: TEdit;
ResultEdit6: TEdit;
ResultEdit7: TEdit;
ResultEdit10: TEdit;
ResultEdit11: TEdit;
ResultPopupMenu: TPopupMenu;
N1: TMenuItem;
N2: TMenuItem;
MainMenu: TMainMenu;
N3: TMenuItem;
N4: TMenuItem;
Version: TMenuItem;
LvI1: TMenuItem;
Label17: TLabel;
Label18: TLabel;
ResultEdit8: TEdit;
ResultEdit9: TEdit;
Attention: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure menuClearResult(Sender: TObject);
procedure OnStatusChange(Sender: TObject);
procedure OnResetClick(Sender: TObject);
procedure SpinEditFameChange(Sender: TObject);
procedure LvI1Click(Sender: TObject);
procedure OnResultChange(Sender : TObject);
procedure FormShow(Sender: TObject);
procedure JobComboBoxChange(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure ReloadButtonClick(Sender: TObject);
procedure VersionClick(Sender: TObject);
procedure WMWindowPosChanging(var Message: TWMWindowPosChanging); message WM_WINDOWPOSCHANGING;
procedure IniExec(Sender: TObject);
procedure Iniload(Sender: TObject);
private
IniFile : TMemIniFile;
FScreenSnap : boolean;
FSnapBuffer : integer;
public
Knight : TKnight;
Novice : TNovice;
Warrior : TWarrior;
Pierro : TPierro;
Magician : TMagician;
Priest : TPriest;
Craftman : TCraftman;
Procedure AppException(Sender: TObject; E: Exception);
end;
var
MainForm: TMainForm;
FormAbout : TAboutDialog;
implementation
procedure TMainForm.AppException(Sender: TObject; E: Exception);
begin
DebugOut('Exception:[' + 'Sender=' + Sender.ClassName + ',' +
'ExceptAddr=' + IntToHex(Integer(ExceptAddr)-Integer($00001000)-Integer($00400000),8)+
',' + E.Message + ']');
Application.ShowException(E);
Application.Terminate;
end;
procedure TMainForm.WMWindowPosChanging(var Message: TWMWindowPosChanging);
procedure HandleEdge(var Edge: Integer; SnapToEdge: Integer;
SnapDistance: Integer = 0);
begin
if (Abs(Edge + SnapDistance - SnapToEdge) < FSnapBuffer) then
Edge := SnapToEdge - SnapDistance;
end;
begin
if FScreenSnap and ((Message.WindowPos^.X <> 0) or (Message.WindowPos^.Y <> 0)) then
with Message.WindowPos^, Monitor.WorkareaRect do
begin
HandleEdge(x, Left, Monitor.WorkareaRect.Left);
HandleEdge(y, Top, Monitor.WorkareaRect.Top);
HandleEdge(x, Right, Width);
HandleEdge(y, Bottom, Height);
end;
end;
procedure TMainForm.FormCreate(Sender: TObject);
var
frtop,frLeft : integer;
opLvI : boolean;
Menutmp : TMenuItem;
begin
Application.OnException := AppException;
Attention.Hint := AttentionHint;
Attention.Caption := '';
IniFile := TMemIniFile.Create(ChangeFileExt(Application.ExeName,'.ini'));
Novice := TNovice.Create;
Warrior := TWarrior.Create;
Knight := TKnight.Create;
Pierro := TPierro.Create;
Magician := TMagician.Create;
Priest := TPriest.Create;
Craftman := TCraftman.Create;
Novice.OnDataChange := OnResultChange;
Warrior.OnDataChange := OnResultChange;
Knight.OnDataChange := OnResultChange;
Pierro.OnDataChange := OnResultChange;
Magician.OnDataChange := OnResultChange;
Priest.OnDataChange := OnResultChange;
Craftman.OnDataChange := OnResultChange;
FScreenSnap := True;
FSnapBuffer := 15;
MainForm.ScreenSnap := True;
MainForm.SnapBuffer := 15;
ReadIniFormStatus(IniFile,frtop,frLeft,opLvI);
if (frtop = -1) and (frLeft = -1) then
MainForm.Position := poScreenCenter
else
begin
MainForm.Top := frtop;
MainForm.Left := frLeft;
end;
LvI1.checked := opLvI;
Menutmp := TMenuItem.Create(nil);
Menutmp.Caption := '編集(&E)';
MainMenu.Items.Insert(1,Menutmp);
Menutmp := TMenuItem.Create(nil);
Menutmp.OnClick := IniExec;
Menutmp.Caption := 'IniFile編集(&D)';
MainMenu.Items[1].Add(Menutmp);
Menutmp := TMenuItem.Create(nil);
Menutmp.OnClick := Iniload;
Menutmp.Caption := 'IniFile再読み込み(&R)';
MainMenu.Items[1].Add(Menutmp);
Iniload(nil);
DebugOut('FormCreate');
end;
procedure TMainForm.IniExec(Sender: TObject);
begin
ShellExecute(MainForm.Handle,'open',
PChar(ChangeFileExt(Application.ExeName,'.ini')),'',
PChar(ExtractFileDir(Application.ExeName)),SW_SHOWDEFAULT);
end;
procedure TMainForm.Iniload(Sender: TObject);
begin
if (Sender is TMenuItem) then
begin
IniFile.Free;
IniFile := TMemIniFile.Create(ChangeFileExt(Application.ExeName,'.ini'));
end;
ReadIniJobClassData(IniFile,Novice);
ReadIniJobClassData(IniFile,Warrior);
ReadIniJobClassData(IniFile,Knight);
ReadIniJobClassData(IniFile,Pierro);
ReadIniJobClassData(IniFile,Magician);
ReadIniJobClassData(IniFile,Priest);
ReadIniJobClassData(IniFile,Craftman);
if (Sender is TMenuItem) then
begin
OnStatusChange(nil);
end;
end;
procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Craftman.Free;
Priest.Free;
Magician.Free;
Pierro.Free;
Knight.Free;
Warrior.Free;
Novice.Free;
MainForm.WindowState := wsNormal;
WriteIniFormStatus(IniFile,MainForm.Top,MainForm.Left,LvI1.checked);
IniFile.UpdateFile;
IniFile.Free;
DebugOut('FormClose');
end;
procedure TMainForm.menuClearResult(Sender: TObject);
var
i : integer;
begin
for i:= 1 to 11 do
begin
if FindComponent('ResultEdit'+IntToStr(i)) <> nil then
begin
(FindComponent('ResultEdit'+IntToStr(i)) as TEdit).Text := '0';
end;
end;
end;
procedure TMainForm.OnStatusChange(Sender: TObject);
var
i,intTotal,level : integer;
begin
intTotal := 0;
level := SpinEditLv.Value -1;
for i := 1 to 7 do
begin
if FindComponent('SpinEditStatus'+IntToStr(i)) <> nil then
begin
intTotal := intTotal +
(FindComponent('SpinEditStatus'+IntToStr(i)) as TSpinEdit).Value;
end;
end;
if LvI1.Checked then
begin
while (((level*3)+DefaultStatus) - intTotal) < 0 do
begin
level := level + 1;
end;
end;
PointEdit.Text := IntToStr(((level*3)+DefaultStatus) - intTotal);
SpinEditLv.Value := level +1;
try
if Lvcheck(SpinEditLv.Value)then
begin
Attention.Caption := '';
case JobComboBox.ItemIndex of
0:
begin
Novice.SetStatuses(SpinEditLv.Value,
SpinEditStatus1.Value,
SpinEditStatus2.Value,SpinEditStatus3.Value,
SpinEditStatus4.Value,SpinEditStatus5.Value,
SpinEditStatus6.Value,SpinEditFame.Value);
Novice.Calc;
end;
1:
begin
Warrior.SetStatuses(SpinEditLv.Value,
SpinEditStatus1.Value,
SpinEditStatus2.Value,SpinEditStatus3.Value,
SpinEditStatus4.Value,SpinEditStatus5.Value,
SpinEditStatus6.Value,SpinEditFame.Value);
Warrior.Calc;
end;
2:
begin
Knight.SetStatuses(SpinEditLv.Value,
SpinEditStatus1.Value,
SpinEditStatus2.Value,SpinEditStatus3.Value,
SpinEditStatus4.Value,SpinEditStatus5.Value,
SpinEditStatus6.Value,SpinEditFame.Value);
Knight.Calc;
end;
3:
begin
Priest.SetStatuses(SpinEditLv.Value,
SpinEditStatus1.Value,
SpinEditStatus2.Value,SpinEditStatus3.Value,
SpinEditStatus4.Value,SpinEditStatus5.Value,
SpinEditStatus6.Value,SpinEditFame.Value);
Priest.Calc;
end;
4:
begin
Magician.SetStatuses(SpinEditLv.Value,
SpinEditStatus1.Value,
SpinEditStatus2.Value,SpinEditStatus3.Value,
SpinEditStatus4.Value,SpinEditStatus5.Value,
SpinEditStatus6.Value,SpinEditFame.Value);
Magician.Calc;
end;
5:begin
Pierro.SetStatuses(SpinEditLv.Value,
SpinEditStatus1.Value,
SpinEditStatus2.Value,SpinEditStatus3.Value,
SpinEditStatus4.Value,SpinEditStatus5.Value,
SpinEditStatus6.Value,SpinEditFame.Value);
Pierro.Calc;
end;
6:begin
Craftman.SetStatuses(SpinEditLv.Value,
SpinEditStatus1.Value,
SpinEditStatus2.Value,SpinEditStatus3.Value,
SpinEditStatus4.Value,SpinEditStatus5.Value,
SpinEditStatus6.Value,SpinEditFame.Value);
Craftman.Calc;
end;
end;
end
else
begin
Novice.SetStatuses(SpinEditLv.Value,
SpinEditStatus1.Value,
SpinEditStatus2.Value,SpinEditStatus3.Value,
SpinEditStatus4.Value,SpinEditStatus5.Value,
SpinEditStatus6.Value,SpinEditFame.Value);
Novice.Calc;
Attention.Caption := '無職データ使用中!';
end;
except
on EClacSeed do
begin
Showmessage(CalcAttention + #13#10 + '設定を見直して再起動してください。');
end;
end;
end;
procedure TMainForm.OnResultChange(Sender : TObject);
var
Jobtmp : TjobClass;
begin
Jobtmp := nil;
if (Sender <> nil)and(Lvcheck(SpinEditLv.Value)) then
begin
case JobComboBox.ItemIndex of
0:Jobtmp := Sender as TNovice;
1:Jobtmp := Sender as TWarrior;
2:Jobtmp := Sender as TKnight;
3:Jobtmp := Sender as TPriest;
4:Jobtmp := Sender as TMagician;
5:Jobtmp := Sender as TPierro;
6:Jobtmp := Sender as TCraftman;
end;
end
else if (Sender <> nil)and(not Lvcheck(SpinEditLv.Value))then
begin
Jobtmp := Sender as TNovice;
end;
if Jobtmp <> nil then
begin
ResultEdit1.Text := FloattoStr(Jobtmp.fAttack);
ResultEdit2.Text := FloattoStr(Jobtmp.fMagic);
ResultEdit3.Text := FloattoStr(5);
ResultEdit4.Text := FloattoStr(Jobtmp.fHit);
ResultEdit5.Text := FloattoStr(Jobtmp.fEvasion);
ResultEdit6.Text := FloattoStr(0);
ResultEdit7.Text := FloattoStr(Jobtmp.fCritical);
ResultEdit8.Text := FloattoStr(Jobtmp.fHp);
ResultEdit9.Text := FloattoStr(Jobtmp.fAp);
if Jobtmp.fRecoveryHp = 0 then
ResultEdit10.Text := '--'
else
ResultEdit10.Text := FloattoStr(Jobtmp.fRecoveryHp);
if Jobtmp.fRecoveryAp = 0 then
ResultEdit11.Text := '--'
else
ResultEdit11.Text := FloattoStr(Jobtmp.fRecoveryAp);
EtcSkillComboBox.Enabled := Jobtmp.UseSkillLv;
end;
end;
procedure TMainForm.OnResetClick(Sender: TObject);
var
i : integer;
begin
for i := 1 to 6 do
begin
if FindComponent('SpinEditStatus'+IntToStr(i)) <> nil then
begin
(FindComponent('SpinEditStatus'+IntToStr(i)) as TSpinEdit).Value := 5;
end;
end;
SpinEditLv.Value := 1;
SpinEditFame.Value := 0;
end;
procedure TMainForm.SpinEditFameChange(Sender: TObject);
begin
if SpinEditFame.Value < 0 then
begin
SpinEditFame.Value := 0;
end;
end;
procedure TMainForm.LvI1Click(Sender: TObject);
begin
LvI1.Checked := Not(LvI1.Checked);
OnStatusChange(nil);
end;
procedure TMainForm.FormShow(Sender: TObject);
begin
Jobcombobox.ItemIndex := 0;
OnStatusChange(Sender);
DebugOut('FormShow');
end;
procedure TMainForm.JobComboBoxChange(Sender: TObject);
begin
OnStatusChange(nil);
end;
procedure TMainForm.FormDestroy(Sender: TObject);
begin
DebugAddDateTime('FormDestroy');
DebugSeparate;
end;
procedure TMainForm.ReloadButtonClick(Sender: TObject);
begin
OnStatusChange(nil)
end;
procedure TMainForm.VersionClick(Sender: TObject);
begin
FormAbout := TAboutDialog.Create(Owner);
FormAbout.ShowModal;
FormAbout.Free;
end;
end.