1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-11-25 10:42:20 -05:00
Simba/trunk/Projects/SAMufasaGUI/simbasettings.pas
Raymond 865779c59a So yeah.. Some user information is now actually printed to Simba (like Your bitmap has not been freed etc).
Windows users now have the option to use a console or not (it's the little CMD-image-button).
Non-important information will still be written to the console (so you must open it if you want some lil extra information).

Now default compiles *without* the -WG switch, otherwise you LCL will raise exceptions when the Console is closed

Added some exceptions to the Files unit, rather than returning -1.

Use mDebug to write something to the terminal (it's inside the MufasaBase unit).

git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@581 3f818213-9676-44b0-a9b4-5e4c4e03d09d
2010-03-07 15:57:10 +00:00

125 lines
2.9 KiB
ObjectPascal

unit simbasettings;
{$mode objfpc} {$M+}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls,MufasaBase, Graphics, Dialogs,
ComCtrls, StdCtrls, settings;
type
{ TSettingsForm }
TSettingsForm = class(TForm)
SettingsFormButtonCancel: TButton;
SettingsFormButtonOK: TButton;
SettingsTreeView: TTreeView;
Settings: TMMLSettings;
procedure SettingsFormButtonCancelClick(Sender: TObject);
procedure SettingsFormButtonOKClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure SettingsTreeViewDblClick(Sender: TObject);
{ private declarations }
public
procedure SaveCurrent;
procedure Reload;
{ public declarations }
end;
var
SettingsForm: TSettingsForm;
SimbaSettingsFile : string;
implementation
{ TSettingsForm }
procedure TSettingsForm.FormCreate(Sender: TObject);
var
FirstNode : TTreeNode;
begin
Settings := TMMLSettings.Create(SettingsTreeView.Items);
if not FileExists(SimbaSettingsFile) then
begin
SettingsTreeView.Items.Clear;
Settings.SaveToXML(SimbaSettingsFile);
end;
SettingsTreeView.Items.Clear;
Settings.LoadFromXML(SimbaSettingsFile);
FirstNode := SettingsTreeView.Items.GetFirstNode;
if FirstNode <> nil then
if FirstNode.Text = 'Settings' then
FirstNode.Expand(false);
end;
procedure TSettingsForm.SettingsFormButtonOKClick(Sender: TObject);
begin
Self.Settings.SaveToXML(SimbaSettingsFile);
Self.ModalResult:=mrOK;
end;
procedure TSettingsForm.SettingsFormButtonCancelClick(Sender: TObject);
begin
if not FileExists(SimbaSettingsFile) then
begin
Self.SettingsTreeView.Items.Clear;
Self.Settings.SaveToXML(SimbaSettingsFile);
Self.SettingsTreeView.Items.Clear;
Self.Settings.LoadFromXML(SimbaSettingsFile);
end;
Self.ModalResult:=mrOK;
end;
procedure TSettingsForm.FormDestroy(Sender: TObject);
begin
Settings.Free;
end;
procedure TSettingsForm.SettingsTreeViewDblClick(Sender: TObject);
var
p, pp: TPoint;
N: TTreeNode;
Path, NewVal: String;
begin
p := Mouse.CursorPos;
pp := TSettingsForm(Sender).ScreenToClient(p);
N := SettingsTreeView.GetNodeAt(pp.x, pp.y);
if N <> nil then
if assigned(N.Data) then
begin
Path := Settings.GetNodePath(N.Parent);
NewVal := InputBox('Change Setting', 'Change value for ' + TSettingData(N.Data).Val,
Settings.GetKeyValue(Path));
mDebugLn('NewVal: ' + NewVal);
Settings.SetKeyValue(Path, NewVal);
N.Text := NewVal;
end;
end;
procedure TSettingsForm.SaveCurrent;
begin
Settings.SaveToXML(SimbaSettingsFile);
end;
procedure TSettingsForm.Reload;
begin
if not FileExists(SimbaSettingsFile) then
begin
SettingsTreeView.Items.Clear;
Settings.SaveToXML(SimbaSettingsFile);
end;
SettingsTreeView.Items.Clear;
Settings.LoadFromXML(SimbaSettingsFile);
end;
initialization
{$I simbasettings.lrs}
end.