Skip to content

Commit

Permalink
feat(TComponent): RemoveChildren
Browse files Browse the repository at this point in the history
- added a method to recursively remove and free children from a component
- added a new house map for WIP stuff
  • Loading branch information
Torwent committed Dec 5, 2024
1 parent a7e7e72 commit 66e9112
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 30 deletions.
Binary file added osr/walker/house.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 35 additions & 6 deletions utils/forms/formutils.simba
Original file line number Diff line number Diff line change
Expand Up @@ -133,28 +133,57 @@ begin
Result := (Self <> nil) and (Self.GetName() = name);
end;

(*
## TComponent.GetChild
```pascal
function TComponent.GetChild(name: TComponentName): TComponent;
```
Recursively search for a children with the specified name.
*)
function TComponent.GetChild(name: TComponentName): TComponent;
var
i: Int32;
child: TComponent;
begin
if Self = nil then
Exit;
if Self = nil then Exit;

if Self.GetName() = name then
Exit(Self);
if Self.GetName() = name then Exit(Self);

for i := 0 to Self.getComponentCount() - 1 do
begin
child := Self.GetComponent(i);
Result := child.GetChild(name);
if Result <> nil then
Exit;
if Result <> nil then Exit;
end;

Result := nil;
end;

(*
## TComponent.RemoveChildren
```pascal
procedure TComponent.RemoveChildren(release: Boolean = False);
```
Recursively remove children from a parent. To also free the parent set **release** to true.
All children are freed when using this.
*)
procedure TComponent.RemoveChildren(release: Boolean = False);
var
child: TComponent;
begin
if Self.getComponentCount() = 0 then
begin
if release then Self.Free();
Exit;
end;

child := Self.GetComponent(0);
Self.RemoveComponent(child);
child.RemoveChildren(True);
Self.RemoveChildren(release);
end;


(*
## Component.NumberField
```pascal
Expand Down
49 changes: 25 additions & 24 deletions utils/forms/scriptform.simba
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,20 @@ begin
end;


procedure TScriptForm.OnClose({$H-}sender: TObject; var closeAction: TCloseAction);{$H+}
begin
TerminateScript();
end;

procedure TScriptForm.OnShow(sender: TObject);
begin
Self.Running := True;
if not Self.LightMode then
SetWindowDarkTitleBar(TForm(sender).getHandle());
TForm(sender).EnsureVisible(False);
end;


(*
## TScriptForm.CreateTabs
```pascal
Expand Down Expand Up @@ -1539,21 +1553,22 @@ function TScriptForm.CreateBankSettings(): TTabSheet;
WLSettings.SaveConfig();
end;

procedure TScriptForm._FormOnShow(sender: TObject);
procedure TScriptForm.OnShow(sender: TObject); override;
var
imgBox: TSimbaImageBox;
imgbox: TSimbaImageBox;
combobox: TComboBox;
begin
Self.Running := True;
if not Self.LightMode then
SetWindowDarkTitleBar(TForm(sender).getHandle());
TForm(sender).EnsureVisible(False);
imgBox := TForm(sender).GetChild('map_selector');
inherited;

imgbox := TForm(sender).GetChild('map_selector');
combobox := form.GetChild('bank_selector_combobox');

imgBox.BackgroundChanged();
imgBox.Update();
Self._BankOnChange(combobox);
if (imgbox <> nil) and (combobox <> nil) then
begin
imgbox.BackgroundChanged();
imgbox.Update();
Self._BankOnChange(combobox);
end;
end;

procedure TScriptForm._FormOnHide(sender: TObject);
Expand All @@ -1571,7 +1586,6 @@ var
imgBox: TSimbaImageBox;
fullWidth, w, space, x, y: Int32;
begin
Self.Form.setOnShow(@Self._FormOnShow);
Self.Form.setOnHide(@Self._FormOnHide);

Self.AddTab('Bank Settings');
Expand Down Expand Up @@ -2096,19 +2110,6 @@ begin
end;


procedure TScriptForm.OnClose({$H-}sender: TObject; var closeAction: TCloseAction);{$H+}
begin
TerminateScript();
end;

procedure TScriptForm.OnShow(sender: TObject);
begin
Self.Running := True;
if not Self.LightMode then
SetWindowDarkTitleBar(TForm(sender).getHandle());
TForm(sender).EnsureVisible(False);
end;

(*
## TScriptForm.Setup
```pascal
Expand Down

0 comments on commit 66e9112

Please sign in to comment.