Skip to content

Commit

Permalink
feat(fairy ring): more methods added, can already be sort of used
Browse files Browse the repository at this point in the history
  • Loading branch information
Torwent committed Jan 21, 2024
1 parent 1a86b70 commit c0ef2f5
Showing 1 changed file with 143 additions and 46 deletions.
189 changes: 143 additions & 46 deletions optional/interfaces/mainscreen/fairyring.simba
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,59 @@ FairyRing
{$ENDIF}

type
ERSFairyRingWheel = (LEFT, MIDDLE, RIGHT);
TRSFairyRing = type TRSInterface;

(*
FairyRing.Setup
~~~~~~~~~~~~~~~
.. pascal:: procedure FairyRing.Setup();

Initializes TRSFairyRing variables.

.. note:: This is automatically called on the **FairyRing** variable.
*)
procedure TRSFairyRing.Setup(); override;
begin
inherited;

Self.Name := 'FairyRing';
end;

procedure TRSFairyRing.SetupAlignment(mode: ERSClientMode); override;
begin
Self.Mode := mode;

case Self.Mode of
ERSClientMode.FIXED:
begin
Self.Alignment.Left := [@InterfaceArea.X1];
Self.Alignment.Right := [@InterfaceArea.X2];
Self.Alignment.Top := [@InterfaceArea.Y1];
Self.Alignment.Bottom := [@InterfaceArea.Y2];
Self.Alignment.Center.MaxWidth := 500;
Self.Alignment.Center.MaxHeight := 320;
end;

ERSClientMode.RESIZABLE_CLASSIC, ERSClientMode.RESIZABLE_MODERN:
begin
Self.Alignment.Left := [@InterfaceArea.X1];
Self.Alignment.Right := [@InterfaceArea.X2];
Self.Alignment.Top := [@InterfaceArea.Y1, 2];
Self.Alignment.Bottom := [@InterfaceArea.Y2, -2];
Self.Alignment.Center.MaxWidth := 500;
Self.Alignment.Center.MaxHeight := 320;
end;
end;
end;

(*
FairyRing.IsOpen
~~~~~~~~~~~~
.. pascal:: function TRSFairyRing.IsOpen(): Boolean;
~~~~~~~~~~~~~~~~
.. pascal::
function TRSFairyRing.IsOpen(): Boolean;

Returns true/false whether the fairy ring interface is open or not.
Returns true/false whether the FairyRing interface is open or not.

Example
-------
Expand All @@ -25,86 +70,138 @@ Example
*)
function TRSFairyRing.IsOpen(): Boolean;
begin
Result := True;
Result := InRange(SRL.CountColor(CTS2(3949742, 14, 0.03, 0.70), Self.Bounds()), 18000, 19000);
end;

(*
FairyRing.Close
~~~~~~~~~~~~~~~
.. pascal:: function TRSFairyRing.Close(pressEscape: Boolean = False): Boolean;
.. pascal::
function TRSFairyRing.Close(pressEscape: Boolean): Boolean;
function TRSFairyRing.Close(chance: Double = BioHash): Boolean; overload;

Closes the fairy ring interface.
Depending on `pressEscape` the function will either click the button or press backspace.
Closes the FairyRing interface, depending on `pressEscape` the function will either click the button
or press escape.

Example
-------

WriteLn FairyRing.Close();
*)
function TRSFairyRing.Close(pressEscape: Boolean = False): Boolean;
function TRSFairyRing.Close(pressEscape: Boolean): Boolean;
begin
if not Self.IsOpen then
if not Self.IsOpen() then
Exit(True);
Result := MainScreen.ClickCloseButton(pressEscape);
end;

function TRSFairyRing.Close(chance: Double = BioHash): Boolean; overload;
begin
Result := MainScreen.CloseInterface(chance);
end;


function TRSFairyRing.GetWheels(): TBoxArray;
begin
Result := Grid(3, 1, 159, 159, [11, 0], [Self.X1()+2, Self.Y1()+75]);
Result[2].X1 -= 2;
Result[2].X2 -= 2;
end

function TRSFairyRing.GetWheel(wheel: ERSFairyRingWheel): TBox;
begin
Result := Self.GetWheels()[Ord(wheel)];
end;


function TRSFairyRing.GetLeftRotationBox(wheel: ERSFairyRingWheel): TBox;
begin
Result := Self.GetWheel(wheel);
Result.X2 -= 80;
end;

Result := MainScreen.CloseInterface(PressEscape);
function TRSFairyRing.GetRightRotationBox(wheel: ERSFairyRingWheel): TBox;
begin
Result := Self.GetWheel(wheel);
Result.X1 += 80;
end;

procedure TRSFairyRing.Draw(Bitmap: TMufasaBitmap); override;

function TRSFairyRing.GetTeleportButton(): TBox;
begin
Result := Self.Bounds();
Result.X1 += 166;
Result.Y1 += 247;
Result.X2 -= 165;
Result.Y2 -= 20;
end;


procedure TRSFairyRing.Draw(bitmap: TMufasaBitmap); override;
var
Boxes: TBoxArray;
i: Int32;
wheel: ERSFairyRingWheel;
b: TBox;
begin
if not Self.IsOpen() then
Exit;

inherited;

bitmap.DrawBoxes(Self.GetWheels(), $00FFFF);
for wheel := ERSFairyRingWheel.LEFT to ERSFairyRingWheel.RIGHT do
begin
b := Self.GetLeftRotationBox(wheel).Expand(-1);
bitmap.DrawBox(b, $00FF00);
b := Self.GetRightRotationBox(wheel).Expand(-1);
bitmap.DrawBox(b, $0000FF);
end;

bitmap.DrawBox(Self.GetTeleportButton(), $00FFFF);
end;

(*
var FairyRing
~~~~~~~~~~~~~
Global FairyRing variable.
*)
var
FairyRing: TRSFairyRing;

procedure TRSClient.ClientModeChanged(); override;
begin
inherited;

(*
FairyRing.Setup
~~~~~~~~~~~~~~~
.. pascal:: procedure FairyRing.Setup;
FairyRing.SetupAlignment(Self.Mode);
end;

Initializes TRSFairyRing variables.
procedure TSRL.Setup(); override;
begin
inherited;

.. note:: This is automatically called on the **FairyRing** variable.
*)
procedure TRSFairyRing.Setup(); override;
FairyRing.Setup();
end;

procedure TSRL.Debug(bitmap: TMufasaBitmap); override;
begin
inherited;

Self.Name := 'FairyRing';
FairyRing.Draw(bitmap);
end;

procedure TRSFairyRing.SetupAlignment(Mode: ERSClientMode); override;
function TRSMainScreen.IsVisible(p: TPoint): Boolean; override;
begin
Self.Mode := Mode;
Result := inherited;

case Self.Mode of
ERSClientMode.FIXED:
begin
Self.Alignment.Left := [@InterfaceArea.X1];
Self.Alignment.Right := [@InterfaceArea.X2];
Self.Alignment.Top := [@InterfaceArea.Y1, 2];
Self.Alignment.Bottom := [@InterfaceArea.Y2, -1];
Self.Alignment.Center.MaxWidth := 500;
Self.Alignment.Center.MaxHeight := 320;
end;
if not Result or (RSClient.Mode = ERSClientMode.FIXED) then
Exit;

ERSClientMode.RESIZABLE_CLASSIC, ERSClientMode.RESIZABLE_MODERN:
begin
Self.Alignment.Left := [@InterfaceArea.X1];
Self.Alignment.Right := [@InterfaceArea.X2];
Self.Alignment.Top := [@InterfaceArea.Y1, 2];
Self.Alignment.Bottom := [@InterfaceArea.Y2, -2];
Self.Alignment.Center.MaxWidth := 500;
Self.Alignment.Center.MaxHeight := 320;
end;
end;
if FairyRing.Bounds().Expand(5).Contains(p) and FairyRing.IsOpen() then
Exit(False);
end;

var
FairyRing: TRSFairyRing;
function TRSMainScreen.IsVisible(tpa: TPointArray; useCenter: Boolean = True): Boolean; override;
begin
Result := inherited;
if FairyRing.IsOpen() then
Exit(False);
end;

0 comments on commit c0ef2f5

Please sign in to comment.