Advertisement
Guest User

Hunting

a guest
May 28th, 2023
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; We include Gdip to be able to draw on screen
  2. #Include Gdip.ahk
  3. #Include Hunt.ahk
  4. #Include Props.ahk
  5.  
  6. ; ########## START: Basic Setup ##########
  7.  
  8. ; START: Basic Variables
  9. myP := Props()
  10. myP.Width := 1000 ; height of the drawing screen
  11. myP.height := 1000 ; widht of the drawing screen
  12. myP.L := 0 ; radius and width of the larger pie slice
  13. myP.S := 0 ; radius and width of the smaller pie slice
  14. myP.T := 1000 / 4096 ; 4.096 tiles per pixel, means that the pixel size per tile is 0.24414
  15. myP.R := -120 ; The start rotation will always face north, so -120 degrees is when the pie slice faces north
  16. ; END: Basic Variables
  17.  
  18. ; START: GUI Setup for initial props
  19. requestGui := Gui("+AlwaysOnTop", "InputRequest") ; Setup a new GUI for the variables selection procedure
  20. requestGui.Add("Text", "w300 h50", "Select distance and direction")
  21. requestGui ; Setting the dropdown for the size of the pie
  22.         .Add("DropDownList",
  23.             "Choose1 w200 h200 vDistanceBox",
  24.             ["Very far", "Far", "Pretty far", "Rather a long distance", "Quite some distance", "Some distance"])
  25.  
  26. requestGui ; Setting the dropdown for the rotation of the pie
  27.         .Add("DropDownList",
  28.             "Choose1 w200 h200 vDirectionBox",
  29.             ["North", "North-East", "East", "South-East", "South", "South-West", "West", "North-West"])
  30.  
  31. requestGui.Add("Button", "w200 h50 Center vSubmit", "OK")
  32. requestGui["Submit"].OnEvent("Click", Submit)
  33.  
  34. requestGui.Show()
  35. ; END: Gui Setup for initial props
  36.  
  37. ; ########## END:   Basic Setup ##########
  38.  
  39. ; TODO: Comment
  40. ^F1:: {
  41.     huntDisplay := Hunt(myP)
  42.     huntDisplay.Draw()
  43. }
  44.  
  45. ; ########## START: Methods ##########
  46.  
  47. ; Event handler for submit button click
  48. Submit(b, bparam) {
  49.     SetSize(requestGui["DistanceBox"].Value)
  50.     SetDirection(requestGui["DirectionBox"].Value)
  51.     requestGui.Destroy()
  52. }
  53.  
  54. ; Sets the size based on the dropdown value, which in the Props class sets the right sizes
  55. SetSize(value) {
  56.     switch value {
  57.         case 1:
  58.             myP.SetSize(4096, 2000)
  59.         case 2:
  60.             myP.SetSize(1999, 1000)
  61.         case 3:
  62.             myP.SetSize(999, 500)
  63.         case 4:
  64.             myP.SetSize(499, 200)
  65.         case 5:
  66.             myP.SetSize(199, 50)
  67.         case 6:
  68.             myP.SetSize(49, 20)
  69.         default:
  70.             myP.SetSize(0, 0)
  71.     }
  72. }
  73.  
  74. SetDirection(value) {
  75.     switch value {
  76.         case 1:    
  77.             myP.SetDirection(-120)
  78.             return
  79.         case 2:
  80.             myP.SetDirection(-120)
  81.             return
  82.         case 3:
  83.             myP.SetDirection(-30)
  84.             return
  85.         case 4:
  86.             myP.SetDirection(30)
  87.             return
  88.         case 5:
  89.             myP.SetDirection(90)
  90.             return
  91.         case 6:
  92.             myP.SetDirection(120)
  93.             return
  94.         case 7:
  95.             myP.SetDirection(180)
  96.             return
  97.         case 8:
  98.             myP.SetDirection(240)
  99.             return
  100.         default:
  101.             myP.SetDirection(-120)
  102.             return
  103.     }
  104. }
  105. ; ########## END: Methods ##########
  106.  
  107. ; Props.ahk file
  108. class Props {
  109.     L := 0
  110.     S := 0
  111.     T := 0
  112.     R := 0
  113.     X := 0
  114.     Y := 0
  115.     Width := 0
  116.     Height := 0
  117.     __New() {
  118.     }
  119.  
  120.     SetSize(l, s) {
  121.         this.L := this.T * l
  122.         this.S := this.T * s
  123.     }
  124.  
  125.     SetDirection(r) {
  126.         this.R := r
  127.     }
  128. }
  129.  
  130. ; Hunt.ahk file
  131. #Include Props.ahk
  132.  
  133. class Hunt {
  134. ; ########## START: Variables ##########
  135.     props := Props ; this is its own class, included at the top
  136.     hWnd := 0
  137.     hbm := Object
  138.     hdc := Object
  139.     obm := Object
  140.     G := Object
  141.     brush := Object
  142.     GuiItem := Gui
  143.     gdip := Object
  144. ; ########## END:   Variables ##########
  145.     __New(props) {
  146.         this.props := props
  147.         this.FindWindow() ; Find the window over which to create the GUI (eg. the Sklotopolis map)
  148.     }
  149.    
  150.     FindWindow() {
  151.         this.hWnd := WinExist("Sklotopolis")
  152.         if this.hWnd {
  153.             WinActivate "Sklotopolis"
  154.             WinMove -1920, 0
  155.             CoordMode "Pixel", "Window"
  156.             PixelSearch &Ox, &Oy, 0, 31, 1000, 1031, 0xff1493
  157.             this.props.X := Ox
  158.             this.props.Y := Oy
  159.         }
  160.         else {
  161.             retried := MsgBox("The external map does not exist, please open it and try again", "Warning", "RetryCancel")
  162.             if (retried = "Retry")
  163.                 this.FindWindow()
  164.             else
  165.                 return
  166.         }
  167.        
  168.         return
  169.     }
  170.  
  171.     Draw() {
  172.         ; Call the setup method to actually setup the entire Gdip parts
  173.         this.Setup()
  174.  
  175.         ; Start drawing on the canvas
  176.         Gdip_DrawEllipse(this.G, this.brush, this.props.X, this.props.Y, this.props.L, this.props.L)
  177.         MsgBox "Drawn elipse on the following coordinates: 'x: " this.props.X " y: " this.props.Y "'", "reference"
  178.         Gdip_DrawPie(
  179.             this.G, ; the graphics to draw on
  180.             this.brush, ; the brush to use to draw the pie slice
  181.             this.props.X, ; the x coordinates to start on? So this should be this.props.X? I think?
  182.             this.props.Y, ; the y coordinates to start on? So this should be this.props.Y? I think?
  183.             this.props.L, ; the width of the pie slice (since it's at 60 degrees, it's the same as the height)
  184.             this.props.L, ; the height of the pie slice (since it's at 60 degrees, it's the same as the height)
  185.             this.props.R, ; The angle at which to draw, -120 should be straight up from the point of the slice
  186.             60 ; the actual angle between the point's prongs. Which is 60 degrees of a circle (or Hexagon angle)
  187.         )
  188.         MsgBox "Drawn pie slice on the following coordinates: 'x: " this.props.X " y: " this.props.Y "'", "reference"
  189.  
  190.         ; Cleanup the graphics
  191.         this.Cleanup()
  192.     }
  193.  
  194.     Setup() {
  195.         ; Start gdi+
  196.         if !this.gdip := Gdip_Startup()
  197.         {
  198.             MsgBox "Gdpi plus failed to start. pleas ensure you have GDI+ on your system"
  199.             ExitApp
  200.         }
  201.         ; Create a layered window (+E0x80000 : must be used for UpdateLayeredWindow to work!) that is always on top (+AlwaysOnTop), has no taskbar entry or caption
  202.         this.GuiItem := Gui("-Caption +E0x80000 +LastFound +AlwaysOnTop +ToolWindow +OwnDialogs")
  203.         this.GuiItem.Show("X" this.props.X " Y" this.props.Y " NA") ; Add this or not? \"X" this.props.X " Y" this.props.Y\
  204.  
  205.         ; Get a handle to this window we have created in order to update it later
  206.         hWndGraphics := WinExist()
  207.        
  208.         ; Create a gdi bitmap (I don't know what that is) with width and height of what we are going to draw into it. This is the entire drawing area for everything
  209.         ; aka should be 1000x1000px
  210.         this.hbm := CreateDIBSection(this.props.Width, this.props.Height)
  211.  
  212.         ; Get a device context compatible with the screen
  213.         this.hdc := CreateCompatibleDC()
  214.  
  215.         ; Select the bitmap into the device context
  216.         this.obm := SelectObject(this.hdc, this.hbm)
  217.  
  218.         ; Get a pointer to the graphics of the bitmap, for use with drawing functions
  219.         this.G := Gdip_GraphicsFromHDC(this.hdc)
  220.  
  221.         ; Set the smoothig mode to antialias = 4 to make shapes appear smoother (only used for vector drawing and filling)
  222.         Gdip_SetSmoothingMode(this.G, 4)
  223.  
  224.         ; Create a fully opaque red pen (ARGB = transparency, red, green, blue) of width 2 (the thickness the pen will draw at) to draw a pie slice
  225.         this.brush := Gdip_BrushCreateSolid(0xffff0000)
  226.  
  227.         ; Finish the method
  228.         return
  229.     }
  230.  
  231.     Cleanup() {
  232.         ; Delete the brush as it is no loger needed and wastes memory
  233.         Gdip_DeletePen(this.brush)
  234.         ; Update the layered window
  235.        UpdateLayeredWindow(
  236.             this.hWnd, ; the window over which to draw
  237.             this.hdc, ; the HDC?? I don't know what that is
  238.             -1912, ; TODO: Make this relative to the x and y coordinates of this.hWnd' client
  239.             31, ; TODO: Make this relative to the x and y coordinates of this.hWnd' client
  240.             this.props.Width, ; The width of the layered window (should be 1000 px)
  241.             this.props.Height ; The height of the layered window (should be 1000 px)
  242.         )
  243.  
  244.         ; Select the object back into he hdc
  245.         SelectObject(this.hdc, this.obm)
  246.  
  247.         ; Now the bitmap may be deleted
  248.         DeleteObject(this.hbm)
  249.  
  250.         ; Also the device context related to the bitmap may be deleted
  251.         DeleteDC(this.hdc)
  252.  
  253.         ; The graphics may now be deleted
  254.         Gdip_DeleteGraphics(this.G)
  255.         return
  256.     }
  257. }
  258.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement