Advertisement
WarPie90

Proggy for Simba

May 19th, 2023 (edited)
1,423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 6.97 KB | None | 0 0
  1. program new;
  2. {$DEFINE SRL_USE_REMOTEINPUT}
  3. {$I SRL/osr.simba}
  4.  
  5. (*
  6. Slackdebug
  7. ==========
  8. Slacky's little drawing util pack.
  9. *)
  10. {$H-}
  11. (*
  12. .. pascal::
  13.    const
  14.      clProgRed    = $1F2164;
  15.      clProgBlue   = $783F37;
  16.      clProgGreen  = $26B58A;
  17.      clProgGreen2 = $12A20D;
  18.      clProgBrown  = $76ADB8;
  19.      clProgLBlue  = $B49946;
  20.      clProgOrange = $1493E2;
  21.      clProgPink   = $A869C9;
  22.      clProgYellow = $16D4F4;
  23.      clProgGray   = $B4BCBE;
  24. *)
  25.  
  26. const
  27.   clProgRed    = $1F2164;
  28.   clProgBlue   = $783F37;
  29.   clProgGreen  = $26B58A;
  30.   clProgGreen2 = $12A20D;
  31.   clProgBrown  = $76ADB8;
  32.   clProgLBlue  = $B49946;
  33.   clProgOrange = $1493E2;
  34.   clProgPink   = $A869C9;
  35.   clProgYellow = $16D4F4;
  36.   clProgGray   = $B4BCBE;
  37.  
  38.  
  39. function TFont.Create(name:String; size:Int32; fs:TFontStyles; fq:TFontQuality): TFont; static;
  40. begin
  41.   Result.Init();
  42.   Result.SetName(name);
  43.   Result.SetSize(size);
  44.   Result.SetStyle(fs);
  45.   Result.SetQuality(fq);
  46.   Result.SetColor($FFFFFF);
  47. end;
  48.  
  49.  
  50. var
  51.   PROGGY_FONT_BAR := TFont.Create('Impact', 10, [fsBold], fqCleartype);
  52.   PROGGY_FONT_H   := TFont.Create('Impact', 10, [fsBold], fqCleartype);
  53.   PROGGY_FONT     := TFont.Create('Tahoma', 10, [fsBold], fqCleartype);
  54.  
  55.  
  56. procedure TMufasaBitmap.DrawText(txt:String; pt:TPoint; font:TFont;
  57.   color:Int32; align:Int32=0; shadow:Boolean=False; shadowDir:Byte=0); overload;
  58. var
  59.   W: Int32;
  60. begin
  61.   Self.setFontName(font.getName());
  62.   Self.setFontSize(font.getSize());
  63.   Self.setFontAntialiasing(True);
  64.  
  65.   W := Self.TextWidth(txt);
  66.   if align then
  67.     pt := Point(pt.x-W, pt.y);
  68.  
  69.   if Shadow then
  70.   begin
  71.     case ShadowDir of
  72.       0: Self.DrawText(txt, pt, 1);
  73.       1: Self.DrawText(txt, pt+Point(1,0), 1);
  74.       2: Self.DrawText(txt, pt+Point(2,0), 1);
  75.       3: Self.DrawText(txt, pt+Point(2,1), 1);
  76.       4: Self.DrawText(txt, pt+Point(2,2), 1);
  77.       5: Self.DrawText(txt, pt+Point(1,2), 1);
  78.       6: Self.DrawText(txt, pt+Point(0,2), 1);
  79.       7: Self.DrawText(txt, pt+Point(0,1), 1);
  80.     end;
  81.     Self.DrawText(txt, pt+Point(1,1), color);
  82.   end else
  83.   begin
  84.     Self.DrawText(txt, pt, color);
  85.   end;
  86. end;
  87.  
  88. procedure TMufasaBitmap.DrawTextNL(txt:TStringArray; pos:TPoint; font:TFont;
  89.           color:Int32; align:Int32=0; shadow:Boolean=False; shadowDir:Byte=0);
  90. var
  91.   i,hei:Int32;
  92. begin
  93.   hei := Round(1.2 * abs(font.GetSize()));
  94.   for i:=0 to High(txt) do
  95.   begin
  96.     Self.DrawText(txt[i],pos,font,color,align,shadow,shadowDir);
  97.     inc(pos.y,hei);
  98.   end;
  99. end;
  100.  
  101. procedure TMufasaBitmap.DrawPrecentBar(pt:TPoint; w,h,percent:Int32; BgColor, BarColor:Int32; lText, rText:String);
  102. var
  103.   B:TBox;
  104.   tx,ty:Int32;
  105.   f: Int32;
  106. begin
  107.   B := [pt.x,pt.y,pt.x+w-1,pt.y+h-1];
  108.   Self.DrawTPA(TPAFromBox(B), BgColor);
  109.   B := B.Expand(-2);
  110.   B.x2 := B.x1 + Round(B.Width() * (percent*0.01));
  111.   Self.DrawTPA(TPAFromBox(B), BarColor);
  112.  
  113.   tx := B.x1 + (W div 2) - 8;
  114.   ty := B.y1 + (H - PROGGY_FONT_BAR.GetSize()) div 2 - 1;
  115.  
  116.   Self.DrawText(ToStr(percent)+'%', Point(tx,ty),       PROGGY_FONT_BAR, $FFFFFF, 0, True, 4);
  117.   Self.DrawText(lText,              Point(b.x1+4,ty),   PROGGY_FONT_BAR, $FFFFFF, 0, True, 4);
  118.   Self.DrawText(rText,              Point(pt.x+w-6,ty), PROGGY_FONT_BAR, $FFFFFF, 1, True, 4);
  119. end;
  120.  
  121. (*
  122. TMufasaBitmap.DrawSkillReport
  123. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  124. .. pascal::
  125.   function TMufasaBitmap.DrawSkillReport(At: TPoint; Color:Int32; CurrentXP, GainedXP, Objectives: Int32; Skill:String=''): TBox;
  126.  
  127. Draws a skill report at the given location. Color can be just about any color, it will be adjusted
  128. automatically to look as good as possible.
  129.  
  130. You have to track your XP, gained XP, and how many "objects" you have complted yourself in your script.
  131. This is only for debugging that.
  132. *)
  133. function TMufasaBitmap.DrawSkillReport(At: TPoint; Color:Int32; CurrentXP, GainedXP, Objectives: Int32; Skill:String=''): TBox; constref;
  134. var
  135.   w,h,z,currLvl,atNextLvl,atCurrLvl,rem,percent: Int32;
  136.   runtime: UInt32;
  137.   txt1,txt2: TStringArray;
  138.   buffer: TMufasaBitmap;
  139.   Hue,S,L:Extended;
  140.  
  141.   function Light(Color: TColor): Double;
  142.   begin
  143.     Result := (0.12 * (Color and $FF) + 0.58 * (Color shr 8  and $FF) + 0.30 * (Color shr 16 and $FF)) / 3;
  144.   end;
  145.  
  146.   //this is a cheat to better blend title text later on.
  147.   procedure BlendTitleCheat(b: TBox; where: TPoint);
  148.   var tmp: TMufasaBitmap;
  149.   begin
  150.     buffer.SetFontName(PROGGY_FONT_H.GetName());
  151.     buffer.SetFontSize(PROGGY_FONT_H.GetSize()+2);
  152.     tmp.FromClient([At.X+4, At.y, At.X+buffer.TextWidth(Skill), At.y+PROGGY_FONT_H.GetSize()]);
  153.     buffer.DrawBitmap(tmp, [5,2]);
  154.     tmp.Free();
  155.   end;
  156.  
  157. begin
  158.   if Skill <> '' then z := 6;
  159.   Result := [At.X, At.Y, At.X+215, At.Y+50+z];
  160.   W := Result.Width;
  161.   H := Result.Height;
  162.  
  163.   ColorToHSL(Color, Hue,S,L);
  164.  
  165.   runtime   := GetTimeRunning();
  166.   currLvl   := srl.GetLevelAtXP(CurrentXP);
  167.   atCurrLvl := srl.GetXPAtLevel(currLvl);
  168.   atNextLvl := srl.GetXPAtLevel(currLvl+1);
  169.   rem       := atNextLvl - CurrentXP;
  170.   percent   := 100 - Round(rem / (atNextLvl - atCurrLvl) * 100);
  171.  
  172.   try
  173.     buffer.Init(client.GetMBitmaps);
  174.     buffer.SetSize(W,H);
  175.  
  176.     BlendTitleCheat([At.X+4, At.y, At.X+buffer.TextWidth(Skill), At.y+PROGGY_FONT_H.GetSize()], [5,2]);
  177.  
  178.     buffer.DrawBoxFilled(Box(0,z,W-1,H-1), False, HSLToColor(Hue, S*0.5, Min(24,L*0.7)));
  179.     buffer.DrawTPA([[0,z],[W-1,z],[0,H-1],[W-1,H-1]], 0);
  180.  
  181.     buffer.DrawPrecentBar(
  182.       [3,3+z], 210, 20, percent,    //pos, w,h, percent
  183.       HSLToColor(Hue, S*0.6, Min(15,Light(Color)*0.25)), Color, //colors
  184.       'Lvl: '+ToStr(CurrLvl),          //left-text
  185.       'Lvl: '+ToStr(CurrLvl+1)         //right-text
  186.     );
  187.  
  188.     txt1 := ['Uptime: '     + srl.MsToTime(runtime, Time_Bare),
  189.              'Exp Gained: ' + srl.FormatNumber(GainedXP, 1)];
  190.     txt2 := ['Exp/Hour: '   + srl.FormatNumber(GainedXP / (runtime / ONE_HOUR), 1),
  191.              'Count: '      + ToStr(Objectives)];
  192.  
  193.     buffer.DrawTextNL(txt1, Point(3,  25+z), PROGGY_FONT, $FFFFFF, 0, True, 4);
  194.     buffer.DrawTextNL(txt2, Point(115,25+z), PROGGY_FONT, $FFFFFF, 0, True, 4);
  195.  
  196.     if Skill <> '' then
  197.       buffer.DrawText(Skill, Point(5,2), PROGGY_FONT_H, $FFFFFF, 0, False, 4);
  198.  
  199.     buffer.DrawTransparent(At.X,At.Y, Self);
  200.   except
  201.     WriteLn('Error: DrawSkillReport -> Something went wrong');
  202.   finally
  203.     buffer.Free();
  204.   end;
  205. end;
  206.  
  207.  
  208. begin
  209.   AddOnTerminate(@PROGGY_FONT.Free);
  210. end;
  211.  
  212.  
  213. begin
  214.   // examples:
  215.   RSClient.Image().DrawSkillReport([MainScreen.Width-450,40],  $907000, 10000, 3000, 124, 'FISHING');
  216.   RSClient.Image().DrawSkillReport([MainScreen.Width-450,100], $006070, 10000, 3000, 124, 'MINING');
  217.   RSClient.Image().DrawSkillReport([MainScreen.Width-450,160], $AA00AA, 10000, 3000, 124, 'WOODCUTTING');
  218.   RSClient.Image().DrawSkillReport([MainScreen.Width-450,220], $777777, 10000, 3000, 124, 'SMITHING');
  219.   RSClient.Image().DrawSkillReport([MainScreen.Width-450,280], $222222, 10000, 3000, 124, 'MAGIC');
  220.   RSClient.Image().DrawSkillReport([MainScreen.Width-450,340], clProgRed, 10000, 3000, 124, "SLACKY'S MINER");
  221. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement