From b3db6929c3ed87db0fc40d01928ad83e12f4d22f Mon Sep 17 00:00:00 2001 From: Torwent Date: Tue, 24 Dec 2024 01:42:19 +0100 Subject: [PATCH] feat(house): layouts are now saved per user You will "lose" your would layout unless you move the old file and rename it with your player index. "lose" as in, it won't be accessible through the form, the config file is not deleted. Improved free of the house loader --- optional/handlers/house/house.simba | 23 +++++++++++++++-- optional/handlers/house/housemap.simba | 34 +++++++++++++++++++++++--- templates/househandler_example.simba | 3 +-- utils/config.simba | 3 +-- 4 files changed, 53 insertions(+), 10 deletions(-) diff --git a/optional/handlers/house/house.simba b/optional/handlers/house/house.simba index f6315508..93c03907 100644 --- a/optional/handlers/house/house.simba +++ b/optional/handlers/house/house.simba @@ -620,6 +620,7 @@ begin Result.Create(owner, 'House teleport:', 'Choose your method of house teleportation.', topleft, [170, 40], offset, True); Result.AddItemArray(['Spell', 'Tablet', 'Contruction/Max cape']); + Self.Loader.SetupConfig(); if Self.Loader.Config.Has('teleport') then i := Self.Loader.Config.GetInt('teleport'); @@ -1264,7 +1265,23 @@ begin tmp.Free(); end; -procedure TScriptForm.POHBuilderOnShow(sender: TObject); +procedure TScriptForm.POHBuilderLeftOnShow(sender: TObject); +var + combobox: TComboBox; + imgbox: TSimbaImageBox; +begin + if Login.PlayerIndex <> House.Loader.LayoutIndex then + begin + WriteLn 'Refreshing layout.'; + House.Loader.Free(); + combobox := TPanel(sender).GetChild('decoration_combobox'); + Self.POHDecorationUpdate(combobox); + combobox := TPanel(sender).GetChild('room_combobox'); + Self.RoomUpdate(combobox); + end; +end; + +procedure TScriptForm.POHBuilderClientOnShow(sender: TObject); var imgbox: TSimbaImageBox; begin @@ -1301,9 +1318,11 @@ begin panel.Create(Result); panel.setAlign(TAlign.alLeft); panel.setBevelWidth(0); + panel.setOnPaint(@Self.POHBuilderLeftOnShow); decoration.Create(panel, 'Decoration:', 'Change your house decoration', [0, 10], [166,0], True); decoration.AddItemArray(['Basic wood', 'Basic stone', 'Whitewashed stone', 'Fremennik-style wood', 'Tropical wood', 'Fancy stone', 'Deathly mansion', 'Twisted theme', 'Hosidius house', 'Cosy cabin']); + decoration.SetName('decoration'); decoration.SetItemIndex(0); decoration.ComboBox.setOnChange(@Self.POHDecorationUpdate); @@ -1334,7 +1353,7 @@ begin panel.setAlign(TAlign.alClient); panel.setBevelWidth(0); - panel.setOnPaint(@Self.POHBuilderOnShow); + panel.setOnPaint(@Self.POHBuilderClientOnShow); caption.Create(panel,'LEFT CLICK to select a room, RIGHT CLICK to pan around. CTRL + WHEEL to zoom.', '', [0,0], [0,0], True); caption.setAlign(TAlign.alTop); diff --git a/optional/handlers/house/housemap.simba b/optional/handlers/house/housemap.simba index d9dd85b2..7651cffe 100644 --- a/optional/handlers/house/housemap.simba +++ b/optional/handlers/house/housemap.simba @@ -46,7 +46,7 @@ Helper record used by the {ref}`THouseHandler`. All `THouseLoader` methods are helper methods for the {ref}`THouseHandler` and you shouldn't have to call them for anything. *) THouseLoader = record - AMOUNT, SIZE, Downscale: Int32; + AMOUNT, SIZE, Downscale, LayoutIndex: Int32; Map, Collision, DownscaledMap: TMufasaBitmap; Rooms: array of array of THouseRoom; @@ -81,14 +81,30 @@ procedure THouseLoader.Free(); var room: EHouseRoom; begin + Self.Config.Free(); Self.Map.Free(); Self.DownscaledMap.Free(); Self.RoomsBitmap.Free(); Self.IconBitmap.Free(); + + Self.Map := nil; + Self.DownscaledMap := nil; + Self.RoomsBitmap := nil; + Self.IconBitmap := nil; + for room := Low(EHouseRoom) to High(EHouseRoom) do begin - if Self.RoomBitmaps[room] <> nil then Self.RoomBitmaps[room].Free(); - if Self.IconBitmaps[room] <> nil then Self.IconBitmaps[room].Free(); + if Self.RoomBitmaps[room] <> nil then + begin + Self.RoomBitmaps[room].Free(); + Self.RoomBitmaps[room] := nil; + end; + + if Self.IconBitmaps[room] <> nil then + begin + Self.IconBitmaps[room].Free(); + Self.IconBitmaps[room] := nil; + end; end; Self.Rooms := []; @@ -105,6 +121,16 @@ begin Self.Colors := decoration.GetColors(); end; +procedure THouseLoader.SetupConfig(); +begin + if Self.Config.IsSetup and (Self.LayoutIndex = Login.PlayerIndex) then Exit; + Self.LayoutIndex := Login.PlayerIndex; + Self.Config.Setup( + AppPath + 'Configs' + DirectorySeparator + 'house' + + DirectorySeparator + ToStr(Self.LayoutIndex) + ); +end; + (* ## THouseLoader.Init() ```pascal @@ -115,7 +141,7 @@ You don't usually have to call it yourself. *) procedure THouseLoader.Init(size, amount: Int32); begin - Self.Config.Setup('pohhandler'); + Self.SetupConfig(); if not Self.Config.Has('size') then Self.Config.Put('size', size); if not Self.Config.Has('amount') then Self.Config.Put('amount', amount); diff --git a/templates/househandler_example.simba b/templates/househandler_example.simba index 02d200ac..0cc5bb3a 100644 --- a/templates/househandler_example.simba +++ b/templates/househandler_example.simba @@ -58,10 +58,9 @@ begin SetTop(TControl.AdjustToDPI(190)); end; - Self.CreateHouseBuilder(); - House.CreateHouseTeleportCombobox(tab, [40, 210], [0,0]); + Self.CreateHouseBuilder(); Self.CreateAntibanManager(); Self.CreateWaspLibSettings(); Self.CreateAPISettings(); diff --git a/utils/config.simba b/utils/config.simba index 7b2a2a12..60554836 100644 --- a/utils/config.simba +++ b/utils/config.simba @@ -154,8 +154,7 @@ you wish to unlock the ram used by this (which should be minimal). *) procedure TConfigJSON.Free(); begin - if not Self.IsSetup then - Exit; + if not Self.IsSetup then Exit; Self.JSON.Free(); Self.JSON := nil;