From 66e9112b4c9629e90f79ad2ba2973d383e0a0a77 Mon Sep 17 00:00:00 2001 From: Torwent Date: Thu, 5 Dec 2024 13:20:40 +0100 Subject: [PATCH] feat(TComponent): RemoveChildren - added a method to recursively remove and free children from a component - added a new house map for WIP stuff --- osr/walker/house.png | Bin 0 -> 1648 bytes utils/forms/formutils.simba | 41 ++++++++++++++++++++++++----- utils/forms/scriptform.simba | 49 ++++++++++++++++++----------------- 3 files changed, 60 insertions(+), 30 deletions(-) create mode 100644 osr/walker/house.png diff --git a/osr/walker/house.png b/osr/walker/house.png new file mode 100644 index 0000000000000000000000000000000000000000..1abf8abbac4a34a835501cb76561be4b660c4339 GIT binary patch literal 1648 zcmdUwe@s(X6vuC2!cw3t3c@H%HYKpxMyE?vAbWLCN-3i-wg8&Z`D0^C#+b_FN1?CC z&}mg%sc6hb31AzXfIwqyTzy-#8-(eDmIWtBl@y_(Vf{@@-+OzHKlbNlmi@8)b93*x z_kPdGIp=fl@%%h~1U-%p0EiG|XTAeK&;xRw_(Bjlp4@#@20+L*LFUePtG{{rt?+dG zj__6W#7$51qsEex;gj4C3m%V3qWg#5j(M#ys$21VEN(B_E^hYOBN53K%iyL+*x|zt zStM1n-y>)Ta+VW#r+w!!qC#(q@QM3`00ny?yjY>zJ_jaXM z$j=?IPkA!(?BZChG0l3R&zjYLmG;!Z@DI+T9gy%CRQ`I>wiBoQW2z1#VOfYLw-$KH z!!@B!)HH^CeQ{86189xPsg%^XVwjGVxXNt5YuIXQ)>r}LFVrqc8p<{ktOSf%lDg3r z#@(Gee5#|f!L1op@!(bld~a{gXHg06PKYN*VyZ*_o1(Mk0OExB=?`J1{?SH#LFITe z9>vB>AH4VrB;*rWt#@*2gGbjE9_*~H-E%F1O2Q|0n8U4E>=X5rF7LldQ(irLq zH??AXIAkSDv4E$RCK+TO%U{(OXg}rpx6Y%cnMKg_@|Yx7O0tcC`o zx7dIWqr*h`JgR_k0m4)!di?pdTy_e1c1#v zLseS4gw)FJM%#Mjl|R!eC+51-pIlnES7yp5Nm`*%js!<3T|pfyd=1cSWYL9`EhIFh zk8nRnanyvfD4{g&PQj+c6}tWuPvh?ST;}kLMWYm&|3FX-Rs_XiWV2A$M>M{^P_-Fd zgX`?$bw$&j0i85&5`SW*0w&R?ee}Oa|6h8f#LYV}3-`@^;+H%G|7@S3stE61{LNje zmU?`JmJEZJL%957gd|X9JUdgv>8(c^(R8oj+^(1t*B{S0N%I#>C1I=0?$#;2)1L3y erSzYi6 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 diff --git a/utils/forms/scriptform.simba b/utils/forms/scriptform.simba index 98644eef..363bd5fe 100644 --- a/utils/forms/scriptform.simba +++ b/utils/forms/scriptform.simba @@ -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 @@ -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); @@ -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'); @@ -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