|
| 1 | +(* |
| 2 | +# Bank |
| 3 | +Methods to interact with the bank interface |
| 4 | +*) |
| 5 | + |
| 6 | +{$DEFINE SRLT_BANK_INCLUDED} |
| 7 | +{$IFNDEF SRLT_OSR} |
| 8 | + {$I SRLT/osrs.simba} |
| 9 | +{$ENDIF} |
| 10 | + |
| 11 | +type |
| 12 | + ERSBankButtons = (WORN, MENU); |
| 13 | + ERSBankArrangement = enum(SWAP, INSERT); |
| 14 | + ERSBankWithdraw = enum(ITEM, NOTE); |
| 15 | + ERSBankQuantity = enum(QUANTITY_1, QUANTITY_5, QUANTITY_10, QUANTITY_CUSTOM, QUANTITY_ALL); |
| 16 | + ERSBankDynamicButtons = enum(PLACEHOLDERS, SEARCH, DEPOSIT_INVENTORY, DEPOSIT_WORN); |
| 17 | + |
| 18 | + TRSItemBankPosition = record |
| 19 | + Tab: Integer; |
| 20 | + Scroll: Integer; |
| 21 | + Box: TBox; |
| 22 | + end; |
| 23 | + |
| 24 | + TRSBankItem = record |
| 25 | + Item: TRSItem; |
| 26 | + Quantity: Integer; |
| 27 | + Noted: Boolean; |
| 28 | + end; |
| 29 | + |
| 30 | + TRSBankItemArray = array of TRSBankItem; |
| 31 | + |
| 32 | + TRSBank = record |
| 33 | + Bounds: TBox; |
| 34 | + Slots: TRSSlotInterface; |
| 35 | + Items: TRSItemInterface; |
| 36 | + |
| 37 | + CachedQuantity: Int32; |
| 38 | + |
| 39 | + Incenerator, PotionStorage, SlotsArea: TBox; |
| 40 | + |
| 41 | + Tabs, SlotBoxes: TBoxArray; |
| 42 | + |
| 43 | + Cache: record |
| 44 | + Quantity: Integer; |
| 45 | + Items: TStringMap<TRSItemBankPosition>; |
| 46 | + end; |
| 47 | + const QUANTITY_ALL: Integer = -1; |
| 48 | + const QUANTITY_ALL_BUT_ONE: Integer = -2; |
| 49 | + end; |
| 50 | + |
| 51 | +(* |
| 52 | +## Bank.FindItemBoundaries |
| 53 | +```pascal |
| 54 | +function TRSBank.FindItemBoundaries(): TBoxArray; |
| 55 | +``` |
| 56 | +Finds item boundaries. This is an internal function used to retrieve the boxes we |
| 57 | +search for items in. |
| 58 | + |
| 59 | +Example: |
| 60 | +```pascal |
| 61 | +ShowOnClient(Self.FindItemBoundaries()); |
| 62 | +``` |
| 63 | +*) |
| 64 | +function TRSBank.FindItemBoundaries(): TBoxArray; |
| 65 | +var |
| 66 | + tpa, final: TPointArray; |
| 67 | + atpa: T2DPointArray; |
| 68 | + b: TBox; |
| 69 | + color: Int32; |
| 70 | +begin |
| 71 | + final := Target.FindColor(RSColors.ITEM_BORDER, 0, Self.SlotsArea); |
| 72 | + if final = [] then Exit; |
| 73 | + |
| 74 | + for color in RSColors.STACK_COLORS do |
| 75 | + begin |
| 76 | + tpa := Target.FindColor(color, 0, Self.SlotsArea); |
| 77 | + if tpa <> [] then final += tpa; |
| 78 | + end; |
| 79 | + |
| 80 | + atpa := final.Cluster(200, 3); |
| 81 | + |
| 82 | + for tpa in atpa do |
| 83 | + begin |
| 84 | + b := tpa.Bounds(); |
| 85 | + if b.Height <= 5 then Continue; |
| 86 | + Result += TBoxArray.Create([Self.SlotsArea.X1, b.Y1 - 1], 8, 1, 32, 32, [16, 0]); |
| 87 | + end; |
| 88 | +end; |
| 89 | + |
| 90 | +(* |
| 91 | +## Bank.SetupInterface |
| 92 | +```pascal |
| 93 | +procedure Bank.SetupInterface; |
| 94 | +``` |
| 95 | +Initializes Bank interface coordinates. |
| 96 | + |
| 97 | +```{note} |
| 98 | +This is automatically called on the **Bank** variable. |
| 99 | +``` |
| 100 | +*) |
| 101 | +procedure TRSBank.SetupInterface(); |
| 102 | +begin |
| 103 | + with InterfaceArea do |
| 104 | + begin |
| 105 | + Self.Bounds.X1 := Max(Floor(Center.X-(Width-1)/2), Floor(Center.X-487/2)); |
| 106 | + Self.Bounds.X2 := Min(Floor(Center.X+(Width-1)/2), Floor(Center.X +487/2)); |
| 107 | + Self.Bounds.Y1 := Max(Floor(Center.Y-(Height-3)/2), Floor(Center.Y-799/2)); |
| 108 | + Self.Bounds.Y2 := Min(Floor(Center.Y+(Height-3)/2), Floor(Center.Y+799/2)); |
| 109 | + end; |
| 110 | + |
| 111 | + Self.Tabs := TBoxArray.Create(Self.Bounds.TopLeft.Offset(47, 42), 10, 1, 35, 28, [5, 0]); |
| 112 | + Self.SlotBoxes := TBoxArray.Create(Self.Bounds.TopLeft.Offset(57, 77), 8, (Self.Bounds.Height - 135) div 35, 31, 31, [17, 5]); |
| 113 | + |
| 114 | + Self.SlotsArea.X1 := Self.Bounds.X1 + 57; |
| 115 | + Self.SlotsArea.Y1 := Self.Bounds.Y1 + 77; |
| 116 | + Self.SlotsArea.X2 := Self.Bounds.X2 - 63; |
| 117 | + Self.SlotsArea.Y2 := Self.Bounds.Y2 - 44; |
| 118 | + |
| 119 | + Self.Incenerator.X1 := Self.Bounds.X1 + 5; |
| 120 | + Self.Incenerator.Y1 := Self.Bounds.Y2 - 113; |
| 121 | + Self.Incenerator.X2 := Self.Bounds.X1 + 51; |
| 122 | + Self.Incenerator.Y2 := Self.Bounds.Y2 - 44; |
| 123 | + |
| 124 | + Self.PotionStorage.X1 := Self.Bounds.X1 + 8; |
| 125 | + Self.PotionStorage.Y1 := Self.Bounds.Y2 - 156; |
| 126 | + Self.PotionStorage.X2 := Self.Bounds.X1 + 51; |
| 127 | + Self.PotionStorage.Y2 := Self.Bounds.Y2 - 118; |
| 128 | + |
| 129 | + (* |
| 130 | + Self.ScrollArea.X1 := Self.Bounds.X1 + 5; |
| 131 | + Self.ScrollArea.Y1 := Self.Bounds.Y1 + 77; |
| 132 | + Self.ScrollArea.X2 := Self.Bounds.X2 - 24; |
| 133 | + Self.ScrollArea.Y2 := Self.Bounds.Y2 - 44; |
| 134 | + *) |
| 135 | + |
| 136 | + |
| 137 | + Self.Slots.Setup('Bank.Slots', Self.SlotBoxes, @Self.FindItemBoundaries); |
| 138 | + Self.Items.Setup('Bank.Items', @Self.Slots, [0, 10, 3, 0]); |
| 139 | +end; |
| 140 | + |
| 141 | + |
| 142 | + |
| 143 | +var |
| 144 | + Bank: TRSBank; |
| 145 | + |
0 commit comments