PageRenderTime 59ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/source/GUI.dba

https://bitbucket.org/TheComet/ponycraft-prototype
Unknown | 1771 lines | 1365 code | 406 blank | 0 comment | 0 complexity | df823695a00ebe42e9514a9085f76272 MD5 | raw file
Possible License(s): GPL-3.0
  1. rem ---------------------------------------------------------------------------
  2. rem GUI - handles the grahpical user interface
  3. rem ---------------------------------------------------------------------------
  4. remstart
  5. This file is part of PonyCraft - Tainted Skies (prototype)
  6. PonyCraft - Tainted Skies (prototype) is free software: you can
  7. redistribute it and/or modify it under the terms of the
  8. GNU General Public License as published by the Free Software
  9. Foundation, either version 3 of the License, or (at your option)
  10. any later version.
  11. PonyCraft - Tainted Skies (prototype) is distributed in the hope
  12. that it will be useful, but WITHOUT ANY WARRANTY; without even
  13. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  14. PURPOSE. See the GNU General Public License for more details.
  15. You should have received a copy of the GNU General Public License
  16. along with PonyCraft - Tainted Skies (prototype). If not, see
  17. <http://www.gnu.org/licenses/>.
  18. remend
  19. rem ---------------------------------------------------------------------------
  20. rem Constants
  21. rem ---------------------------------------------------------------------------
  22. #constant GUIBindUnitMax 500
  23. #constant GUICLICK_NOT_CLICKED 0
  24. #constant GUICLICK_CLICKED 1
  25. rem ---------------------------------------------------------------------------
  26. rem User Defined Types
  27. rem ---------------------------------------------------------------------------
  28. type ButtonVT
  29. Clicked as integer
  30. endtype
  31. type GUIVT
  32. logging as integer
  33. Mouse3DInvalid as integer
  34. CurrentMax as integer
  35. CurrentFrameMax as integer
  36. CurrentFrameCountMax as integer
  37. CurrentUnitBindMax as integer
  38. ButtonClicked as integer
  39. ButtonReleased as integer
  40. ButtonActivateAbility as integer
  41. ButtonCancelAbility as integer
  42. SplashObj as integer
  43. SplashImg as integer
  44. SplashFillObj as integer
  45. PortraitPos as vec2
  46. InfoPanelPos as vec2
  47. InfoPanelDescriptionPos as vec2
  48. HealthPos as vec2
  49. ManaPos as vec2
  50. ShieldPos as vec2
  51. MiniatureGridStartPos as vec2
  52. MiniatureGridEndPos as vec2
  53. MiniatureGridSize as vec2
  54. endtype
  55. type GUIAT
  56. Active as integer
  57. IMG as word
  58. GlowIMG as word
  59. PressIMG as word
  60. LockedIMG as word
  61. IconIMG as word
  62. HotKeyIMG as word
  63. KeyBind as byte
  64. KeyBindFlag as integer
  65. ID as integer
  66. ToggleMode as integer
  67. KeepLastImage as integer
  68. Locked as integer
  69. Hidden as integer
  70. ClickState as integer
  71. BindCount as integer
  72. ButtonIconDiffuseNormal as dword
  73. ButtonIconDiffuseGlow as dword
  74. ButtonIconDiffusePress as dword
  75. ButtonIconDiffuseLocked as dword
  76. EventClickActive as integer
  77. EventClickScript as integer
  78. EventClickLine as integer
  79. EventReleaseActive as integer
  80. EventReleaseScript as integer
  81. EventReleaseLine as integer
  82. BindKeyPressed as integer
  83. Ability as integer
  84. endtype
  85. type GUIFrameAAT
  86. Active as integer
  87. pos as vec2
  88. EndPos as vec2
  89. IMG as integer
  90. SPR as integer
  91. FrameCount as integer
  92. CurrentFrame as integer
  93. FrameDelayDefault as integer
  94. FrameDelay as integer
  95. FrameDelayCounter as integer
  96. endtype
  97. rem ---------------------------------------------------------------------------
  98. rem Initialise
  99. rem ---------------------------------------------------------------------------
  100. function InitGUI()
  101. rem local variables
  102. local g as integer
  103. local b as integer
  104. rem debug
  105. DebugOutput( 0 , "Initialising GUI" , DEBUG_NORMAL )
  106. rem ---------------------------------------------------------------------------
  107. rem Global Variables
  108. rem ---------------------------------------------------------------------------
  109. global uGUI as GUIVT
  110. global Button as ButtonVT
  111. rem ---------------------------------------------------------------------------
  112. rem Global Arrays
  113. rem ---------------------------------------------------------------------------
  114. global dim GUI() as GUIAT
  115. global dim GUIFrame() as GUIFrameAAT
  116. global dim GUIBindUnit() as integer
  117. Button.Clicked = -1
  118. uGUI.CurrentMax = -1
  119. uGUI.CurrentFrameMax = -1
  120. uGUI.CurrentFrameCountMax = 0
  121. uGUI.CurrentUnitBindMax = -1
  122. rem initialise other GUI elements
  123. InitGUIDragBox()
  124. endfunction
  125. function GUIAddStaticImage( ID , x , y , Filename$ )
  126. rem logging
  127. if uGUI.logging = 1 then AddTextToConsole( 0 , "GUIAddStaticImage " + str$(ID) + "," + str$(x) + "," + str$(y) + chr$(34) + Filename$ + chr$(34) )
  128. rem local variable
  129. local n as integer
  130. rem make sure ID doesn't already exist
  131. for n = 0 to uGUI.CurrentMax
  132. if GUI( n ).Active > 1
  133. if GUI( n ).ID = ID
  134. AddTextToConsole( 3 , "ID already in use!" )
  135. exitfunction -1
  136. endif
  137. endif
  138. next n
  139. rem find free slot
  140. for n = 0 to uGUI.CurrentMax
  141. if GUI( n ).Active < 2 then exit
  142. next n
  143. rem no free slot, create
  144. if n = uGUI.CurrentMax + 1
  145. array insert at bottom GUI()
  146. inc uGUI.CurrentMax
  147. endif
  148. rem add frame and image
  149. GUI( n ).IMG = GUICreateFrame( GetRealScreenX( x ) , GetRealScreenY( y ) )
  150. GUIAddFrame( GUI( n ).IMG , Filename$ , -1 )
  151. rem set values
  152. GUI( n ).Active = 2
  153. GUI( n ).BindCount = -1
  154. GUI( n ).Locked = 0
  155. GUI( n ).Hidden = 0
  156. GUI( n ).ToggleMode = 0
  157. GUI( n ).EventClickActive = 0
  158. GUI( n ).EventReleaseActive = 0
  159. GUI( n ).Ability = 0
  160. GUI( n ).ID = ID
  161. endfunction n
  162. function GUICreateFrame( x , y )
  163. rem local variables
  164. local n as integer
  165. rem find free slot
  166. for n = 0 to uGUI.CurrentFrameMax
  167. if GUIFrame( n , 0 ).Active < 0 then exit
  168. next n
  169. rem none found, allocate space
  170. if n = uGUI.CurrentFrameMax + 1
  171. inc uGUI.CurrentFrameMax
  172. dim GUIFrame( uGUI.CurrentFrameMax , uGUI.CurrentFrameCountMax ) as GUIFrameAAT
  173. endif
  174. rem set parameters
  175. GUIFrame( n , 0 ).Active = 2
  176. GUIFrame( n , 0 ).FrameCount = -1
  177. GUIFrame( n , 0 ).CurrentFrame = 0
  178. GUIFrame( n , 0 ).FrameDelayDefault = 0
  179. GUIFrame( n , 0 ).pos.x = x
  180. GUIFrame( n , 0 ).pos.y = y
  181. GUIFrame( n , 0 ).SPR = 0
  182. endfunction n
  183. function GUIAddFrame( n , Filename$ , delay )
  184. rem make sure file exists
  185. if file exist( Filename$ ) = 0
  186. AddTextToConsole( 3 , "File " + chr$(34) + Filename$ + chr$(34) + " does not exist!" )
  187. exitfunction -1
  188. endif
  189. rem allocate space
  190. inc GUIFrame( n , 0 ).FrameCount
  191. if GUIFrame( n , 0 ).FrameCount > uGUI.CurrentFrameCountMax
  192. inc uGUI.CurrentFrameCountMax
  193. dim GUIFrame( uGUI.CurrentFrameMax , uGUI.CurrentFrameCountMax ) as GUIFrameAAT
  194. endif
  195. rem add frame
  196. GUIFrame( n , GUIFrame( n , 0 ).FrameCount ).IMG = LoadImage( Filename$ , 1 )
  197. rem scale to fit screen resolution
  198. ik resize image GUIFrame( n , GUIFrame( n , 0 ).FrameCount ).IMG , (image width( GUIFrame( n , GUIFrame( n , 0 ).FrameCount ).IMG ) * uScreen.sc_wx) / 1600.0 , (image height( GUIFrame( n , GUIFrame( n , 0 ).FrameCount ).IMG) * uScreen.sch) / 1200.0 , 1
  199. rem sprite it
  200. if GUIFrame( n , 0 ).SPR = 0 then GUIFrame( n , 0 ).SPR = find free sprite()
  201. if sprite exist( GUIFrame( n , 0 ).SPR )
  202. repeat
  203. set cursor 0,0
  204. print "HOLY SHIT"
  205. print n
  206. paste image GUIFrame( n , 0 ).IMG , 300 , 0 , 1
  207. sync
  208. until returnkey()
  209. repeat:until returnkey()=0
  210. endif
  211. sprite GUIFrame( n , 0 ).SPR , GUIFrame( n , 0 ).pos.x , GUIFrame( n , 0 ).pos.y , GUIFrame( n , 0 ).IMG
  212. rem use default delay if necessary
  213. if delay = -1 then delay = GUIFrame( n , 0 ).FrameDelayDefault
  214. rem set end positions
  215. GUIFrame( n , GUIFrame( n , 0 ).FrameCount ).pos.x = GUIFrame( n , 0 ).pos.x
  216. GUIFrame( n , GUIFrame( n , 0 ).FrameCount ).pos.y = GUIFrame( n , 0 ).pos.y
  217. GUIFrame( n , GUIFrame( n , 0 ).FrameCount ).EndPos.x = GUIFrame( n , 0 ).pos.x + image width( GUIFrame( n , GUIFrame( n , 0 ).FrameCount ).IMG )
  218. GUIFrame( n , GUIFrame( n , 0 ).FrameCount ).EndPos.y = GUIFrame( n , 0 ).pos.y + image height( GUIFrame( n , GUIFrame( n , 0 ).FrameCount ).IMG )
  219. GUIFrame( n , GUIFrame( n , 0 ).FrameCount ).FrameDelay = delay
  220. endfunction n
  221. function GUIDestroyFrame( n )
  222. rem make sure in range
  223. if n < 0 or n > uGUI.CurrentFrameMax then exitfunction
  224. if GUIFrame( n , 0 ).Active < 2 then exitfunction
  225. rem destroy
  226. if GUIFrame( n , 0 ).SPR > 0
  227. if sprite exist( GUIFrame( n , 0 ).SPR ) then delete sprite GUIFrame( n , 0 ).SPR
  228. GUIFrame( n , 0 ).SPR = 0
  229. endif
  230. rem delete images
  231. for s = 0 to GUIFrame( n , 0 ).FrameCount
  232. if image exist( GUIFrame( n , s ).IMG ) then delete image GUIFrame( n , s ).IMG
  233. next s
  234. GUIFrame( n , 0 ).Active = 0
  235. endfunction
  236. function GUIPositionFrame( n , x , y )
  237. rem re-sprite
  238. if GUIFrame( n , 0 ).FrameCount > -1
  239. sprite GUIFrame( n , 0 ).SPR , x , y , GUIFrame( n , GUIFrame( n , 0 ).CurrentFrame ).IMG
  240. endif
  241. rem set positions
  242. GUIFrame( n , 0 ).pos.x = x
  243. GUIFrame( n , 0 ).pos.y = y
  244. GUIFrame( n , GUIFrame( n , 0 ).FrameCount ).EndPos.x = GUIFrame( n , 0 ).pos.x + image width( GUIFrame( n , GUIFrame( n , 0 ).FrameCount ).IMG )
  245. GUIFrame( n , GUIFrame( n , 0 ).FrameCount ).EndPos.x = GUIFrame( n , 0 ).pos.x + image height( GUIFrame( n , GUIFrame( n , 0 ).FrameCount ).IMG )
  246. endfunction
  247. function GUIShowFrame( n )
  248. rem show sprite
  249. if GUIFrame( n , 0 ).SPR > 0
  250. if sprite exist( GUIFrame( n , 0 ).SPR )
  251. show sprite GUIFrame( n , 0 ).SPR
  252. endif
  253. endif
  254. endfunction
  255. function GUIHideFrame( n )
  256. rem hide sprite
  257. if GUIFrame( n , 0 ).SPR > 0
  258. if sprite exist( GUIFrame( n , 0 ).SPR )
  259. hide sprite GUIFrame( n , 0 ).SPR
  260. endif
  261. endif
  262. endfunction
  263. function GUIGetFrameStartX( n )
  264. if GUIFrame( n , 0 ).FrameCount = -1 then exitfunction 0
  265. result = GUIFrame( n , GUIFrame( n , 0 ).CurrentFrame ).pos.x
  266. endfunction result
  267. function GUIGetFrameEndX( n )
  268. if GUIFrame( n , 0 ).FrameCount = -1 then exitfunction 0
  269. result = GUIFrame( n , GUIFrame( n , 0 ).CurrentFrame ).EndPos.x
  270. endfunction result
  271. function GUIGetFrameStartY( n )
  272. if GUIFrame( n , 0 ).FrameCount = -1 then exitfunction 0
  273. result = GUIFrame( n , GUIFrame( n , 0 ).CurrentFrame ).pos.y
  274. endfunction result
  275. function GUIGetFrameEndY( n )
  276. if GUIFrame( n , 0 ).FrameCount = -1 then exitfunction 0
  277. result = GUIFrame( n , GUIFrame( n , 0 ).CurrentFrame ).EndPos.y
  278. endfunction result
  279. function GUISetFrameDiffuse( n , diffuse )
  280. if GUIFrame( n , 0 ).FrameCount = -1 then exitfunction
  281. set sprite diffuse GUIFrame( n , 0 ).SPR , rgbr( diffuse ) , rgbg( diffuse ) , rgbb( diffuse )
  282. endfunction
  283. function GUIAddStaticFrame( ID , Filename$ , delay )
  284. rem local variables
  285. local n as integer
  286. rem find ID of GUI element
  287. for n = 0 to uGUI.CurrentMax
  288. if GUI( n ).ID = ID then exit
  289. next n
  290. rem not found
  291. if n = uGUI.CurrentMax + 1
  292. AddTextToConsole( 3 , "GUI ID not found!" )
  293. exitfunction -1
  294. endif
  295. rem make sure active
  296. if GUI( n ).Active <> 2
  297. AddTextToConsole( 3 , "GUI element not in correct state!" )
  298. exitfunction -1
  299. endif
  300. rem add the frame
  301. GUIAddFrame( GUI( n ).IMG , Filename$ , delay )
  302. endfunction n
  303. function GUIAddButtonNormalFrame( ID , Filename$ , delay )
  304. rem local variables
  305. local n as integer
  306. rem find ID of GUI element
  307. for n = 0 to uGUI.CurrentMax
  308. if GUI( n ).ID = ID then exit
  309. next n
  310. rem not found
  311. if n = uGUI.CurrentMax + 1
  312. AddTextToConsole( 3 , "GUI ID not found!" )
  313. exitfunction -1
  314. endif
  315. rem make sure active
  316. if GUI( n ).Active <> 3
  317. AddTextToConsole( 3 , "GUI element not in correct state!" )
  318. exitfunction -1
  319. endif
  320. rem add the frame
  321. GUIAddFrame( GUI( n ).IMG , Filename$ , delay )
  322. endfunction n
  323. function GUIAddButtonMouseOverFrame( ID , Filename$ , delay )
  324. rem local variables
  325. local n as integer
  326. rem find ID of GUI element
  327. for n = 0 to uGUI.CurrentMax
  328. if GUI( n ).ID = ID then exit
  329. next n
  330. rem not found
  331. if n = uGUI.CurrentMax + 1
  332. AddTextToConsole( 3 , "GUI ID not found!" )
  333. exitfunction -1
  334. endif
  335. rem make sure active
  336. if GUI( n ).Active <> 3
  337. AddTextToConsole( 3 , "GUI element not in correct state!" )
  338. exitfunction -1
  339. endif
  340. rem add the frame
  341. GUIAddFrame( GUI( n ).GlowIMG , Filename$ , delay )
  342. endfunction n
  343. function GUIAddButtonPressFrame( ID , Filename$ , delay )
  344. rem local variables
  345. local n as integer
  346. rem find ID of GUI element
  347. for n = 0 to uGUI.CurrentMax
  348. if GUI( n ).ID = ID then exit
  349. next n
  350. rem not found
  351. if n = uGUI.CurrentMax + 1
  352. AddTextToConsole( 3 , "GUI ID not found!" )
  353. exitfunction -1
  354. endif
  355. rem make sure active
  356. if GUI( n ).Active <> 3
  357. AddTextToConsole( 3 , "GUI element not in correct state!" )
  358. exitfunction -1
  359. endif
  360. rem add the frame
  361. GUIAddFrame( GUI( n ).PressIMG , Filename$ , delay )
  362. endfunction n
  363. function GUIAddButtonLockedFrame( ID , Filename$ , delay )
  364. rem local variables
  365. local n as integer
  366. rem find ID of GUI element
  367. for n = 0 to uGUI.CurrentMax
  368. if GUI( n ).ID = ID then exit
  369. next n
  370. rem not found
  371. if n = uGUI.CurrentMax + 1
  372. AddTextToConsole( 3 , "GUI ID not found!" )
  373. exitfunction -1
  374. endif
  375. rem make sure active
  376. if GUI( n ).Active <> 3
  377. AddTextToConsole( 3 , "GUI element not in correct state!" )
  378. exitfunction -1
  379. endif
  380. rem add the frame
  381. GUIAddFrame( GUI( n ).LockedIMG , Filename$ , delay )
  382. endfunction n
  383. function GUIAddButtonIconFrame( ID , Filename$ , delay )
  384. rem local variables
  385. local n as integer
  386. rem find ID of GUI element
  387. for n = 0 to uGUI.CurrentMax
  388. if GUI( n ).ID = ID then exit
  389. next n
  390. rem not found
  391. if n = uGUI.CurrentMax + 1
  392. AddTextToConsole( 3 , "GUI ID not found!" )
  393. exitfunction -1
  394. endif
  395. rem make sure active
  396. if GUI( n ).Active <> 3
  397. AddTextToConsole( 3 , "GUI element not in correct state!" )
  398. exitfunction -1
  399. endif
  400. rem add the frame
  401. GUIAddFrame( GUI( n ).IconIMG , Filename$ , delay )
  402. endfunction n
  403. function GUISetStaticFrameDelayDefault( ID , delay )
  404. rem local variables
  405. local n as integer
  406. local s as integer
  407. rem find ID of GUI element
  408. for n = 0 to uGUI.CurrentMax
  409. if GUI( n ).ID = ID then exit
  410. next n
  411. rem not found
  412. if n = uGUI.CurrentMax + 1
  413. AddTextToConsole( 3 , "GUI ID not found!" )
  414. exitfunction -1
  415. endif
  416. rem make sure active
  417. if GUI( n ).Active <> 3
  418. AddTextToConsole( 3 , "GUI element not in correct state!" )
  419. exitfunction -1
  420. endif
  421. rem add delay
  422. s = GUI( n ).IMG
  423. GUIFrame( s , 0 ).FrameDelayDefault = delay
  424. for n = 0 to GUIFrame( s , 0 ).FrameCount
  425. GUIFrame( s , n ).FrameDelay = delay
  426. next n
  427. endfunction n
  428. function GUISetButtonNormalFrameDelayDefault( ID , delay )
  429. rem local variables
  430. local n as integer
  431. local s as integer
  432. rem find ID of GUI element
  433. for n = 0 to uGUI.CurrentMax
  434. if GUI( n ).ID = ID then exit
  435. next n
  436. rem not found
  437. if n = uGUI.CurrentMax + 1
  438. AddTextToConsole( 3 , "GUI ID not found!" )
  439. exitfunction -1
  440. endif
  441. rem make sure active
  442. if GUI( n ).Active <> 3
  443. AddTextToConsole( 3 , "GUI element not in correct state!" )
  444. exitfunction -1
  445. endif
  446. rem add delay
  447. s = GUI( n ).IMG
  448. GUIFrame( s , 0 ).FrameDelayDefault = delay
  449. for n = 0 to GUIFrame( s , 0 ).FrameCount
  450. GUIFrame( s , n ).FrameDelay = delay
  451. next n
  452. endfunction n
  453. function GUISetButtonMouseOverFrameDelayDefault( ID , delay )
  454. rem local variables
  455. local n as integer
  456. local s as integer
  457. rem find ID of GUI element
  458. for n = 0 to uGUI.CurrentMax
  459. if GUI( n ).ID = ID then exit
  460. next n
  461. rem not found
  462. if n = uGUI.CurrentMax + 1
  463. AddTextToConsole( 3 , "GUI ID not found!" )
  464. exitfunction -1
  465. endif
  466. rem make sure active
  467. if GUI( n ).Active <> 3
  468. AddTextToConsole( 3 , "GUI element not in correct state!" )
  469. exitfunction -1
  470. endif
  471. rem add delay
  472. s = GUI( n ).GlowIMG
  473. GUIFrame( s , 0 ).FrameDelayDefault = delay
  474. for n = 0 to GUIFrame( s , 0 ).FrameCount
  475. GUIFrame( s , n ).FrameDelay = delay
  476. next n
  477. endfunction n
  478. function GUISetButtonPressFrameDelayDefault( ID , delay )
  479. rem local variables
  480. local n as integer
  481. local s as integer
  482. rem find ID of GUI element
  483. for n = 0 to uGUI.CurrentMax
  484. if GUI( n ).ID = ID then exit
  485. next n
  486. rem not found
  487. if n = uGUI.CurrentMax + 1
  488. AddTextToConsole( 3 , "GUI ID not found!" )
  489. exitfunction -1
  490. endif
  491. rem make sure active
  492. if GUI( n ).Active <> 3
  493. AddTextToConsole( 3 , "GUI element not in correct state!" )
  494. exitfunction -1
  495. endif
  496. rem add delay
  497. s = GUI( n ).PressIMG
  498. GUIFrame( s , 0 ).FrameDelayDefault = delay
  499. for n = 0 to GUIFrame( s , 0 ).FrameCount
  500. GUIFrame( s , n ).FrameDelay = delay
  501. next n
  502. endfunction n
  503. function GUISetButtonLockedFrameDelayDefault( ID , delay )
  504. rem local variables
  505. local n as integer
  506. local s as integer
  507. rem find ID of GUI element
  508. for n = 0 to uGUI.CurrentMax
  509. if GUI( n ).ID = ID then exit
  510. next n
  511. rem not found
  512. if n = uGUI.CurrentMax + 1
  513. AddTextToConsole( 3 , "GUI ID not found!" )
  514. exitfunction -1
  515. endif
  516. rem make sure active
  517. if GUI( n ).Active <> 3
  518. AddTextToConsole( 3 , "GUI element not in correct state!" )
  519. exitfunction -1
  520. endif
  521. rem add delay
  522. s = GUI( n ).LockedIMG
  523. GUIFrame( s , 0 ).FrameDelayDefault = delay
  524. for n = 0 to GUIFrame( s , 0 ).FrameCount
  525. GUIFrame( s , n ).FrameDelay = delay
  526. next n
  527. endfunction n
  528. function GUISetButtonIconFrameDelayDefault( ID , delay )
  529. rem local variables
  530. local n as integer
  531. local s as integer
  532. rem find ID of GUI element
  533. for n = 0 to uGUI.CurrentMax
  534. if GUI( n ).ID = ID then exit
  535. next n
  536. rem not found
  537. if n = uGUI.CurrentMax + 1
  538. AddTextToConsole( 3 , "GUI ID not found!" )
  539. exitfunction -1
  540. endif
  541. rem make sure active
  542. if GUI( n ).Active <> 3
  543. AddTextToConsole( 3 , "GUI element not in correct state!" )
  544. exitfunction -1
  545. endif
  546. rem add delay
  547. s = GUI( n ).IconIMG
  548. GUIFrame( s , 0 ).FrameDelayDefault = delay
  549. for n = 0 to GUIFrame( s , 0 ).FrameCount
  550. GUIFrame( s , n ).FrameDelay = delay
  551. next n
  552. endfunction n
  553. function GUIDestroyElement( ID )
  554. rem local variables
  555. local n as integer
  556. rem logging
  557. if uGUI.logging = 1 then AddTextToConsole( 0 , "GUIDestroyElement " + str$(ID) )
  558. rem find ID of GUI element
  559. for n = 0 to uGUI.CurrentMax
  560. if GUI( n ).ID = ID then exit
  561. next n
  562. rem not found
  563. if n = uGUI.CurrentMax + 1
  564. AddTextToConsole( 3 , "GUI ID not found!" )
  565. exitfunction -1
  566. endif
  567. rem not active
  568. if GUI( n ).Active < 2
  569. AddTextToConsole( 3 , "GUI ID not active!" )
  570. exitfunction -1
  571. endif
  572. rem unbind anything from it
  573. for b = 0 to GUI( n ).BindCount
  574. GUIBindUnit( n , b ) = -1
  575. next b
  576. GUI( n ).BindCount = -1
  577. rem destroy
  578. GUIDestroyFrame( GUI( n ).IMG )
  579. GUIDestroyFrame( GUI( n ).GlowIMG )
  580. GUIDestroyFrame( GUI( n ).PressIMG )
  581. GUIDestroyFrame( GUI( n ).LockedIMG )
  582. GUIDestroyFrame( GUI( n ).IconIMG )
  583. GUIDestroyFrame( GUI( n ).HotKeyIMG )
  584. GUI( n ).Active = 0
  585. endfunction n
  586. function GUIAddButton( ID , x , y , KeyBind , BackFilename$ , GlowFilename$ , PressFilename$ , LockedFilename$ , IconFilename$ , KeepLastImage )
  587. rem logging
  588. if uGUI.logging = 1 then AddTextToConsole( 0 , "GUIAddButton " + str$(ID) + "," + str$(x) + "," + str$(y) + "," + str$(KeyBind) + chr$(34) + BackFilename$ + chr$(34) + "," + chr$(34) + GlowFilename$ + chr$(34) + "," + chr$(34) + PressFilename$ + chr$(34) + "," + chr$(34) + LockedFilename$ + chr$(34) )
  589. rem local variables
  590. local n as integer
  591. rem make sure ID doesn't already exist
  592. for n = 0 to uGUI.CurrentMax
  593. if GUI( n ).Active > 1
  594. if GUI( n ).ID = ID
  595. AddTextToConsole( 3 , "ID already in use!" )
  596. exitfunction -1
  597. endif
  598. endif
  599. next n
  600. rem find free slot
  601. for n = 0 to uGUI.CurrentMax
  602. if GUI( n ).Active < 2 then exit
  603. next n
  604. rem no free slot, create
  605. if n = uGUI.CurrentMax + 1
  606. array insert at bottom GUI()
  607. inc uGUI.CurrentMax
  608. endif
  609. rem create frames
  610. GUI( n ).IMG = GUICreateFrame( GetRealScreenX( x ) , GetRealScreenY( y ) )
  611. GUI( n ).GlowIMG = GUICreateFrame( GetRealScreenX( x ) , GetRealScreenY( y ) )
  612. GUI( n ).PressIMG = GUICreateFrame( GetRealScreenX( x ) , GetRealScreenY( y ) )
  613. GUI( n ).LockedIMG = GUICreateFrame( GetRealScreenX( x ) , GetRealScreenY( y ) )
  614. GUI( n ).IconIMG = GUICreateFrame( GetRealScreenX( x ) , GetRealScreenY( y ) )
  615. GUI( n ).HotKeyIMG = GUICreateFrame( GetRealScreenX( x ) , GetRealScreenY( y ) )
  616. GUIAddFrame( GUI( n ).IMG , BackFilename$ , -1 )
  617. GUIAddFrame( GUI( n ).GlowIMG , GlowFilename$ , -1 )
  618. GUIAddFrame( GUI( n ).PressIMG , PressFilename$ , -1 )
  619. GUIAddFrame( GUI( n ).LockedIMG , LockedFilename$ , -1 )
  620. GUIAddFrame( GUI( n ).IconIMG , IconFilename$ , -1 )
  621. rem allocate space for frame
  622. s = GUI( n ).HotKeyIMG
  623. inc GUIFrame( s , 0 ).FrameCount
  624. if GUIFrame( s , 0 ).FrameCount > uGUI.CurrentFrameCountMax
  625. inc uGUI.CurrentFrameCountMax
  626. dim GUIFrame( uGUI.CurrentFrameMax , uGUI.CurrentFrameCountMax ) as GUIFrameAAT
  627. endif
  628. rem add frame
  629. GUIFrame( s , GUIFrame( s , 0 ).FrameCount ).IMG = find free image()
  630. create bitmap 1 , 16 , 16
  631. a2fillbox 0 , 0 , 15 , 15 , 0xFF0F0F0F
  632. a2text FontID , 1 , 0 , chr$( _GUI_Get_Character_From_Scancode_Switzerland( KeyBind ) ) , 0xFFFFFFFF
  633. get image GUIFrame( s , GUIFrame( s , 0 ).FrameCount ).IMG , 0 , 0 , 16 , 16
  634. delete bitmap 1
  635. rem scale to fit screen resolution
  636. ik resize image GUIFrame( s , GUIFrame( s , 0 ).FrameCount ).IMG , (image width( GUIFrame( s , GUIFrame( s , 0 ).FrameCount ).IMG ) * uScreen.sc_wx) / 1600.0 , (image height( GUIFrame( s , GUIFrame( s , 0 ).FrameCount ).IMG) * uScreen.sch) / 1200.0 , 1
  637. rem sprite it
  638. if GUIFrame( s , 0 ).SPR = 0 then GUIFrame( s , 0 ).SPR = find free sprite()
  639. sprite GUIFrame( s , 0 ).SPR , GUIFrame( s , 0 ).pos.x , GUIFrame( s , 0 ).pos.y , GUIFrame( s , 0 ).IMG
  640. rem set end positions
  641. GUIFrame( s , GUIFrame( s , 0 ).FrameCount ).pos.x = GUIFrame( s , 0 ).pos.x
  642. GUIFrame( s , GUIFrame( s , 0 ).FrameCount ).pos.y = GUIFrame( s , 0 ).pos.y
  643. GUIFrame( s , GUIFrame( s , 0 ).FrameCount ).EndPos.x = GUIFrame( s , 0 ).pos.x + image width( GUIFrame( s , GUIFrame( s , 0 ).FrameCount ).IMG )
  644. GUIFrame( s , GUIFrame( s , 0 ).FrameCount ).EndPos.y = GUIFrame( s , 0 ).pos.y + image height( GUIFrame( s , GUIFrame( s , 0 ).FrameCount ).IMG )
  645. GUIFrame( s , GUIFrame( s , 0 ).FrameCount ).FrameDelay = 0
  646. rem set values
  647. GUI( n ).Active = 3
  648. GUI( n ).Locked = 0
  649. GUI( n ).Hidden = 0
  650. GUI( n ).ToggleMode = 0
  651. GUI( n ).EventClickActive = 0
  652. GUI( n ).EventReleaseActive = 0
  653. GUI( n ).BindCount = -1
  654. GUI( n ).KeyBind = KeyBind
  655. GUI( n ).Ability = 0
  656. GUI( n ).ID = ID
  657. GUI( n ).KeepLastImage = KeepLastImage
  658. GUI( n ).ButtonIconDiffuseNormal = 0xFFFFFFFF
  659. GUI( n ).ButtonIconDiffuseGlow = 0xFFFFFFFF
  660. GUI( n ).ButtonIconDiffusePress = 0xFFFFFFFF
  661. GUI( n ).ButtonIconDiffuseLocked = 0xFFFFFFFF
  662. endfunction n
  663. function _GUI_Hide_Button_Frames( n )
  664. rem hide frames
  665. GUIHideFrame( GUI( n ).IMG )
  666. GUIHideFrame( GUI( n ).GlowIMG )
  667. GUIHideFrame( GUI( n ).PressIMG )
  668. GUIHideFrame( GUI( n ).LockedIMG )
  669. endfunction
  670. function GUILockButton( ID )
  671. rem local variables
  672. local n as integer
  673. rem logging
  674. if uGUI.logging = 1 then AddTextToConsole( 0 , "GUILockButton " + str$(ID) )
  675. rem find ID of GUI element
  676. for n = 0 to uGUI.CurrentMax
  677. if GUI( n ).ID = ID then exit
  678. next n
  679. rem not found
  680. if n = uGUI.CurrentMax + 1
  681. AddTextToConsole( 3 , "GUI ID not found!" )
  682. exitfunction -1
  683. endif
  684. rem make sure active
  685. if GUI( n ).Active <> 3
  686. AddTextToConsole( 3 , "GUI element not in correct state!" )
  687. exitfunction -1
  688. endif
  689. rem lock
  690. GUI( n ).Locked = 1
  691. endfunction n
  692. function GUIUnlockButton( ID )
  693. rem local variables
  694. local n as integer
  695. rem logging
  696. if uGUI.logging = 1 then AddTextToConsole( 0 , "GUIUnlockButton " + str$(ID) )
  697. rem find ID of GUI element
  698. for n = 0 to uGUI.CurrentMax
  699. if GUI( n ).ID = ID then exit
  700. next n
  701. rem not found
  702. if n = uGUI.CurrentMax + 1
  703. AddTextToConsole( 3 , "GUI ID not found!" )
  704. exitfunction -1
  705. endif
  706. rem make sure active
  707. if GUI( n ).Active <> 3
  708. AddTextToConsole( 3 , "GUI element not in correct state!" )
  709. exitfunction -1
  710. endif
  711. rem unlock
  712. GUI( n ).Locked = 0
  713. endfunction n
  714. function GUIHideElement( ID )
  715. rem logging
  716. if uGUI.logging = 1 then AddTextToConsole( 0 , "GUIHideEleemnt " + str$(ID) )
  717. rem find ID of GUI element
  718. for n = 0 to uGUI.CurrentMax
  719. if GUI( n ).ID = ID then exit
  720. next n
  721. rem not found
  722. if n = uGUI.CurrentMax + 1
  723. AddTextToConsole( 3 , "GUI ID not found!" )
  724. exitfunction -1
  725. endif
  726. rem make sure active
  727. if GUI( n ).Active < 2
  728. AddTextToConsole( 3 , "Not active!" )
  729. exitfunction -1
  730. endif
  731. rem hide
  732. GUI( n ).Hidden = 1
  733. endfunction n
  734. function GUIShowElement( ID )
  735. rem logging
  736. if uGUI.logging = 1 then AddTextToConsole( 0 , "GUIShowElement " + str$(ID) )
  737. rem find ID of GUI element
  738. for n = 0 to uGUI.CurrentMax
  739. if GUI( n ).ID = ID then exit
  740. next n
  741. rem not found
  742. if n = uGUI.CurrentMax + 1
  743. AddTextToConsole( 3 , "GUI ID not found!" )
  744. exitfunction -1
  745. endif
  746. rem make sure active
  747. if GUI( n ).Active > 1
  748. AddTextToConsole( 3 , "Not active!" )
  749. exitfunction -1
  750. endif
  751. rem hide
  752. GUI( n ).Hidden = 0
  753. endfunction n
  754. function GUIButtonEnableToggle( ID )
  755. rem logging
  756. if uGUI.logging = 1 then AddTextToConsole( 0 , "GUIButtonEnableToggle " + str$(ID) )
  757. rem find ID of GUI element
  758. for n = 0 to uGUI.CurrentMax
  759. if GUI( n ).ID = ID then exit
  760. next n
  761. rem not found
  762. if n = uGUI.CurrentMax + 1
  763. AddTextToConsole( 3 , "GUI ID not found!" )
  764. exitfunction -1
  765. endif
  766. rem make sure active
  767. if GUI( n ).Active <> 3
  768. AddTextToConsole( 3 , "Not active!" )
  769. exitfunction -1
  770. endif
  771. rem hide
  772. GUI( n ).ToggleMode = 1
  773. endfunction n
  774. function GUIButtonDisableToggle( ID )
  775. rem logging
  776. if uGUI.logging = 1 then AddTextToConsole( 0 , "GUIButtonDisableToggle " + str$(ID) )
  777. rem find ID of GUI element
  778. for n = 0 to uGUI.CurrentMax
  779. if GUI( n ).ID = ID then exit
  780. next n
  781. rem not found
  782. if n = uGUI.CurrentMax + 1
  783. AddTextToConsole( 3 , "GUI ID not found!" )
  784. exitfunction -1
  785. endif
  786. rem make sure active
  787. if GUI( n ).Active <> 3
  788. AddTextToConsole( 3 , "Not active!" )
  789. exitfunction -1
  790. endif
  791. rem hide
  792. GUI( n ).ToggleMode = 0
  793. endfunction n
  794. function GUIBindButtonToUnit( ID , UnitID )
  795. rem logging
  796. if uGUI.logging = 1 then AddTextToConsole( 0 , "GUIBindButtonToUnit " + str$(ID) + "," + str$(UnitID) )
  797. rem make sure unit is in range
  798. if UnitID < 0 or n > uUnit.CurrentMax
  799. AddTextToConsole( 3 , "Unit index not found!" )
  800. exitfunction -1
  801. endif
  802. rem find ID of GUI element
  803. for n = 0 to uGUI.CurrentMax
  804. if GUI( n ).ID = ID then exit
  805. next n
  806. rem not found
  807. if n = uGUI.CurrentMax + 1
  808. AddTextToConsole( 3 , "GUI ID not found!" )
  809. exitfunction -1
  810. endif
  811. rem make sure unit is active
  812. if Unit( UnitID ).Active < 2
  813. AddTextToConsole( 3 , "Unit not active!" )
  814. exitfunction -1
  815. endif
  816. rem make sure button is active
  817. if GUI( n ).Active <> 3
  818. AddTextToConsole( 3 , "Button not active!" )
  819. exitfunction -1
  820. endif
  821. rem find or create binding slot
  822. inc GUI( n ).BindCount
  823. if GUI( n ).BindCount > uGUI.CurrentUnitBindMax
  824. inc uGUI.CurrentUnitBindMax
  825. dim GUIBindUnit( uGUI.CurrentMax , uGUI.CurrentUnitBindMax ) as integer
  826. endif
  827. rem bind
  828. GUIBindUnit( n , GUI( n ).BindCount ) = UnitID
  829. endfunction n
  830. function GUIUnbindUnit( ID , UnitID )
  831. rem local variables
  832. local s as integer
  833. rem logging
  834. if uGUI.logging = 1 then AddTextToConsole( 0 , "GUIUnbindUnit " + str$(ID) + "," + str$(UnitID) )
  835. rem make sure unit is in range
  836. if UnitID < 0 or UnitID > uUnit.CurrentMax
  837. AddTextToConsole( 3 , "Unit index not found!" )
  838. exitfunction -1
  839. endif
  840. rem find ID of GUI element
  841. for n = 0 to uGUI.CurrentMax
  842. if GUI( n ).ID = ID then exit
  843. next n
  844. rem not found
  845. if n = uGUI.CurrentMax + 1
  846. AddTextToConsole( 3 , "GUI ID not found!" )
  847. exitfunction -1
  848. endif
  849. rem find index for bound unit
  850. for s = 0 to GUI( n ).BindCount
  851. if GUIBindUnit( n , s ) = UnitID then exit
  852. next s
  853. rem shift binding stack down
  854. if s < GUI( n ).BindCount + 1
  855. for UnitID = s + 1 to GUI( n ).BindCount
  856. GUIBindUnit( n , UnitID - 1 ) = GUIBindUnit( n , UnitID )
  857. next UnitID
  858. if GUI( n ).BindCount > -1 then dec GUI( n ).BindCount
  859. endif
  860. rem button is not clicked
  861. GUI( n ).ClickState = GUICLICK_NOT_CLICKED
  862. endfunction n
  863. function GUIPositionElement( ID , x , y )
  864. rem local variables
  865. local n as integer
  866. rem logging
  867. if uGUI.logging = 1 then AddTextToConsole( 0 , "GUIPositionElement " + str$(ID) + "," + str$(x) + "," + str$(y) )
  868. rem find ID of GUI element
  869. for n = 0 to uGUI.CurrentMax
  870. if GUI( n ).ID = ID then exit
  871. next n
  872. rem not found
  873. if n = uGUI.CurrentMax + 1
  874. AddTextToConsole( 3 , "GUI ID not found!" )
  875. exitfunction -1
  876. endif
  877. rem make sure active
  878. if GUI( n ).Active < 2
  879. AddTextToConsole( 3 , "GUI element not active!" )
  880. exitfunction -1
  881. endif
  882. rem reposition
  883. GUIPositionFrame( GUI( n ).IMG , GetRealScreenX( x ) , GetRealScreenY( y ) )
  884. rem buttons have additional frames
  885. if GUI( n ).Active = 3
  886. GUIPositionFrame( GUI( n ).GlowIMG , GetRealScreenX( x ) , GetRealScreenY( y ) )
  887. GUIPositionFrame( GUI( n ).PressIMG , GetRealScreenX( x ) , GetRealScreenY( y ) )
  888. GUIPositionFrame( GUI( n ).LockedIMG , GetRealScreenX( x ) , GetRealScreenY( y ) )
  889. GUIPositionFrame( GUI( n ).IconIMG , GetRealScreenX( x ) , GetRealScreenY( y ) )
  890. endif
  891. endfunction n
  892. function GUISetPortraitPosition( x , y )
  893. rem set
  894. uGUI.PortraitPos.x = GetRealScreenX( x )
  895. uGUI.PortraitPos.y = GetRealScreenY( y )
  896. endfunction
  897. function GUISetInfoPanelPosition( x , y )
  898. rem set
  899. uGUI.InfoPanelPos.x = GetRealScreenX( x )
  900. uGUI.InfoPanelPos.y = GetRealScreenY( y )
  901. endfunction
  902. function GUISetInfoPanelDescriptionPosition( x , y )
  903. rem set
  904. uGUI.InfoPanelDescriptionPos.x = GetRealScreenX( x )
  905. uGUI.InfoPanelDescriptionPos.y = GetRealScreenY( y )
  906. endfunction
  907. function GUISetInfoPanelHealthPosition( x , y )
  908. rem set
  909. uGUI.HealthPos.x = GetRealScreenX( x )
  910. uGUI.HealthPos.y = GetRealScreenY( y )
  911. endfunction
  912. function GUISetInfoPanelManaPosition( x , y )
  913. rem set
  914. uGUI.ManaPos.x = GetRealScreenX( x )
  915. uGUI.ManaPos.y = GetRealScreenY( y )
  916. endfunction
  917. function GUISetInfoPanelShieldPosition( x , y )
  918. rem set
  919. uGUI.ShieldPos.x = GetRealScreenX( x )
  920. uGUI.ShieldPos.y = GetRealScreenY( y )
  921. endfunction
  922. function GUISetMiniatureGrid( sx , sy , ex , ey , gridSizeX , gridSizeY )
  923. rem set
  924. uGUI.MiniatureGridStartPos.x = GetRealScreenX( sx )
  925. uGUI.MiniatureGridStartPos.y = GetRealScreenY( sy )
  926. uGUI.MiniatureGridEndPos.x = GetRealScreenX( ex )
  927. uGUI.MiniatureGridEndPos.y = GetRealScreenY( ey )
  928. uGUI.MiniatureGridSize.x = GetRealScreenX( gridSizeX )
  929. uGUI.MiniatureGridSize.y = GetRealScreenY( gridSizeY )
  930. endfunction
  931. function GUIButtonSetIconDiffuseOnNormal( ID , diffuse )
  932. rem local variables
  933. local n as integer
  934. rem logging
  935. if uGUI.logging = 1 then AddTextToConsole( 0 , "GUIUnlockButton " + str$(ID) )
  936. rem find ID of GUI element
  937. for n = 0 to uGUI.CurrentMax
  938. if GUI( n ).ID = ID then exit
  939. next n
  940. rem not found
  941. if n = uGUI.CurrentMax + 1
  942. AddTextToConsole( 3 , "GUI ID not found!" )
  943. exitfunction
  944. endif
  945. rem make sure active
  946. if GUI( n ).Active <> 3
  947. AddTextToConsole( 3 , "GUI element not in correct state!" )
  948. exitfunction
  949. endif
  950. rem set value
  951. GUI( n ).ButtonIconDiffuseNormal = diffuse
  952. endfunction
  953. function GUIButtonSetIconDiffuseOnGlow( ID , diffuse )
  954. rem local variables
  955. local n as integer
  956. rem logging
  957. if uGUI.logging = 1 then AddTextToConsole( 0 , "GUIUnlockButton " + str$(ID) )
  958. rem find ID of GUI element
  959. for n = 0 to uGUI.CurrentMax
  960. if GUI( n ).ID = ID then exit
  961. next n
  962. rem not found
  963. if n = uGUI.CurrentMax + 1
  964. AddTextToConsole( 3 , "GUI ID not found!" )
  965. exitfunction
  966. endif
  967. rem make sure active
  968. if GUI( n ).Active <> 3
  969. AddTextToConsole( 3 , "GUI element not in correct state!" )
  970. exitfunction
  971. endif
  972. rem set value
  973. GUI( n ).ButtonIconDiffuseGlow = diffuse
  974. endfunction
  975. function GUIButtonSetIconDiffuseOnPress( ID , diffuse )
  976. rem local variables
  977. local n as integer
  978. rem logging
  979. if uGUI.logging = 1 then AddTextToConsole( 0 , "GUIUnlockButton " + str$(ID) )
  980. rem find ID of GUI element
  981. for n = 0 to uGUI.CurrentMax
  982. if GUI( n ).ID = ID then exit
  983. next n
  984. rem not found
  985. if n = uGUI.CurrentMax + 1
  986. AddTextToConsole( 3 , "GUI ID not found!" )
  987. exitfunction
  988. endif
  989. rem make sure active
  990. if GUI( n ).Active <> 3
  991. AddTextToConsole( 3 , "GUI element not in correct state!" )
  992. exitfunction
  993. endif
  994. rem set value
  995. GUI( n ).ButtonIconDiffusePress = diffuse
  996. endfunction
  997. function GUIButtonSetIconDiffuseOnLocked( ID , diffuse )
  998. rem local variables
  999. local n as integer
  1000. rem logging
  1001. if uGUI.logging = 1 then AddTextToConsole( 0 , "GUIUnlockButton " + str$(ID) )
  1002. rem find ID of GUI element
  1003. for n = 0 to uGUI.CurrentMax
  1004. if GUI( n ).ID = ID then exit
  1005. next n
  1006. rem not found
  1007. if n = uGUI.CurrentMax + 1
  1008. AddTextToConsole( 3 , "GUI ID not found!" )
  1009. exitfunction
  1010. endif
  1011. rem make sure active
  1012. if GUI( n ).Active <> 3
  1013. AddTextToConsole( 3 , "GUI element not in correct state!" )
  1014. exitfunction
  1015. endif
  1016. rem set value
  1017. GUI( n ).ButtonIconDiffuseLocked = diffuse
  1018. endfunction
  1019. function GUICreateSplash( imgFile$ )
  1020. rem logging
  1021. if uGUI.logging = 1 then AddTextToConsole( 0 , "CreateSplash" )
  1022. rem make sure file exists
  1023. if file exist( imgFile$ ) = 0
  1024. AddTextToConsole( 3 , "File " + chr$(34) + imgfile$ + chr$(34) + " does not exist" )
  1025. exitfunction
  1026. endif
  1027. rem if not created, create
  1028. if uGUI.SplashObj = 0
  1029. uGUI.SplashObj = find free object()
  1030. uGUI.SplashImg = find free image()
  1031. make object plain uGUI.SplashObj , 16 , 12
  1032. lock object on uGUI.SplashObj
  1033. position object uGUI.SplashObj , 0 , 0 , 10
  1034. load image imgFile$ , uGUI.SplashImg
  1035. texture object uGUI.SplashObj , uGUI.SplashImg
  1036. set object light uGUI.SplashObj , 0
  1037. uGUI.SplashFillObj = find free object()
  1038. make object plain uGUI.SplashFillObj , 500 , 500
  1039. lock object on uGUI.SplashFillObj
  1040. position object uGUI.SplashFillObj , 0 , 0 , 11
  1041. set object light uGUI.SplashFillObj , 0
  1042. texture object uGUI.SplashFillObj , IMGBlack
  1043. endif
  1044. rem refresh screen so it appears
  1045. sync
  1046. sync
  1047. endfunction
  1048. function GUIDestroySplash()
  1049. rem logging
  1050. if uGUI.logging = 1 then AddTextToConsole( 0 , "DestroySplash" )
  1051. rem destroy splash object
  1052. if uGUI.SplashObj > 0
  1053. delete object uGUI.SplashObj
  1054. delete image uGUI.SplashImg
  1055. delete object uGUI.SplashFillObj
  1056. uGUI.SplashObj = 0
  1057. endif
  1058. endfunction
  1059. function ControlGUI()
  1060. rem control drag box
  1061. ControlGUIDragBox()
  1062. rem local variables
  1063. local n as integer
  1064. local u as integer
  1065. local a as integer
  1066. local success as integer
  1067. rem reset some values
  1068. uGUI.ButtonClicked = -1
  1069. uGUI.ButtonReleased = -1
  1070. uGUI.Mouse3DInvalid = 0
  1071. uGUI.ButtonActivateAbility = -1
  1072. uGUI.ButtonCancelAbility = -1
  1073. rem loop through all active
  1074. for n = 0 to uGUI.CurrentMax
  1075. rem static image
  1076. if GUI( n ).Active = 2
  1077. rem check if 3D mouse is invalid
  1078. if uMouse.x > GUIGetFrameStartX( n ) and uMouse.x < GUIGetFrameEndX( n )
  1079. if uMouse.y > GUIGetFrameStartY( n ) and uMouse.y < GUIGetFrameEndY( n ) then uGUI.Mouse3DInvalid = 1
  1080. endif
  1081. endif
  1082. rem button
  1083. if GUI( n ).Active = 3
  1084. rem If button is not bound to any units, button will act like a normal menu button
  1085. rem if button is bound to units, the button is shown/hidden according to the current units selected
  1086. rem and according to the ability's settings its bound to
  1087. if GUI( n ).BindCount = -1
  1088. rem draw and control input
  1089. _GUI_DrawAndControlButtons( n , 0 )
  1090. rem button is bound to units
  1091. else
  1092. rem default
  1093. GUI( n ).Locked = 1
  1094. GUI( n ).Hidden = 1
  1095. rem loop through all selected units and find bound button
  1096. for s = 0 to uUnit.CurrentMax
  1097. if Unit( s ).Active > 1
  1098. if Unit( s ).Selected > 1
  1099. rem check if button is bound to unit
  1100. for r = 0 to GUI( n ).BindCount
  1101. if GUIBindUnit( n , r ) = s then exit
  1102. next r
  1103. rem found
  1104. if r < GUI( n ).BindCount + 1 then exit
  1105. endif
  1106. endif
  1107. next s
  1108. rem found
  1109. if s < uUnit.CurrentMax + 1
  1110. rem find ability
  1111. for r = 0 to MaxUnitAbility
  1112. if UnitAbility( s , r ).Active > 0 and UnitAbility( s , r ).BindButton = n then exit
  1113. next r
  1114. if r < MaxUnitAbility + 1
  1115. rem copy settings to GUI button
  1116. rem only lock or hide ability if all units have it locked or hidden
  1117. for s = 0 to uUnit.CurrentMax
  1118. if Unit( s ).Active > 1
  1119. if Unit( s ).Selected > 1
  1120. rem check if ability is bound to button
  1121. for r = 0 to MaxUnitAbility
  1122. if UnitAbility( s , r ).Active > 0
  1123. if UnitAbility( s , r ).BindButton = n then exit
  1124. endif
  1125. next r
  1126. rem found
  1127. if r < MaxUnitAbility + 1
  1128. rem copy ability settings to button
  1129. if UnitAbility( s , r ).LockButton = 0 and Unit( s ).Stats.CurrentMana# >= UnitAbility( s , r ).ManaDrain# then GUI( n ).Locked = 0
  1130. if UnitAbility( s , r ).HideButton = 0 then GUI( n ).Hidden = 0
  1131. endif
  1132. rem no need to carry on
  1133. if GUI( n ).Locked = 0 and GUI( n ).Hidden = 0 then exit
  1134. endif
  1135. endif
  1136. next s
  1137. endif
  1138. endif
  1139. rem draw and control input
  1140. _GUI_DrawAndControlButtons( n , 1 )
  1141. endif
  1142. endif
  1143. next n
  1144. rem if mouse is on minimap, calculate 3D coordinates
  1145. uMouse.OnMinimap = 0
  1146. for n = 0 to uMinimap.CurrentMax
  1147. if Minimap( n ).Active > 1
  1148. if uMouse.x > Minimap( n ).StartPos.x and uMouse.x < Minimap( n ).EndPos.x
  1149. if uMouse.y > Minimap( n ).StartPos.y and uMouse.y < Minimap( n ).EndPos.y
  1150. rem convert to XZ
  1151. x# = uMouse.y-Minimap( n ).StartPos.y : rem cast to float
  1152. uMouse.Click3D.x# = (uMouse.x-Minimap( n ).StartPos.x) * (Minimap( n ).WorldEndPos.x# - Minimap( n ).WorldStartPos.x#) / Minimap( n ).Size.x + Minimap( n ).WorldStartPos.x#
  1153. uMouse.Click3D.z# = (1.0 - (x# / Minimap( n ).Size.y)) * (Minimap( n ).WorldEndPos.z# - Minimap( n ).WorldStartPos.z#) + Minimap( n ).WorldStartPos.z#
  1154. uMouse.OnMinimap = 1
  1155. rem find ground height
  1156. if SC_RayCastGroup( COL_TERRAIN , uMouse.Click3D.x# , 200 , uMouse.Click3D.z# , uMouse.Click3D.x# , -200 , uMouse.Click3D.z# , 0 )
  1157. uMouse.Click3D.y# = SC_GetStaticCollisionY()
  1158. endif
  1159. endif
  1160. endif
  1161. endif
  1162. next n
  1163. rem call events
  1164. if uGUI.ButtonClicked > -1
  1165. if GUI( uGUI.ButtonClicked ).EventClickActive = 1
  1166. CallEvent( GUI( uGUI.ButtonClicked ).EventClickScript , GUI( uGUI.ButtonClicked ).EventClickLine )
  1167. endif
  1168. endif
  1169. if uGUI.ButtonReleased > -1
  1170. if GUI( uGUI.ButtonReleased ).EventReleaseActive = 1
  1171. CallEvent( GUI( uGUI.ButtonReleased ).EventReleaseScript , GUI( uGUI.ButtonReleased ).EventReleaseLine )
  1172. endif
  1173. endif
  1174. endfunction
  1175. function _GUI_DrawAndControlButtons( n , ManualPress )
  1176. rem button is not hidden
  1177. if GUI( n ).Hidden = 0
  1178. rem show icon (isn't changed unless button is hidden)
  1179. GUIShowFrame( GUI( n ).IconIMG )
  1180. GUIShowFrame( GUI( n ).HotKeyIMG )
  1181. rem button is locked
  1182. if GUI( n ).Locked = 1
  1183. rem draw locked image
  1184. if GUI( n ).KeepLastImage = 0
  1185. _GUI_Hide_Button_Frames( n )
  1186. endif
  1187. GUIShowFrame( GUI( n ).LockedIMG )
  1188. GUISetFrameDiffuse( GUI( n ).IconIMG , GUI( n ).ButtonIconDiffuseLocked )
  1189. rem button is not locked
  1190. else
  1191. rem button is currently not being pressed
  1192. if GUI( n ).ClickState = GUICLICK_NOT_CLICKED
  1193. rem mouse is over button
  1194. if uMouse.x > GUIGetFrameStartX( GUI( n ).IMG ) and uMouse.x < GUIGetFrameEndX( GUI( n ).IMG ) and uMouse.y > GUIGetFrameStartY( GUI( n ).IMG ) and uMouse.y < GUIGetFrameEndY( GUI( n ).IMG )
  1195. rem sprite glow image
  1196. if GUI( n ).KeepLastImage = 0
  1197. _GUI_Hide_Button_Frames( n )
  1198. endif
  1199. GUIShowFrame( GUI( n ).GlowIMG )
  1200. GUISetFrameDiffuse( GUI( n ).IconIMG , GUI( n ).ButtonIconDiffuseGlow )
  1201. rem Mouse clicks button
  1202. if uMouse.click = 1
  1203. _GUI_ReleaseOtherButtons()
  1204. if ManualPress = 0 then GUI( n ).ClickState = GUICLICK_CLICKED
  1205. uGUI.ButtonClicked = n
  1206. rem sprite press image
  1207. if GUI( n ).KeepLastImage = 0
  1208. _GUI_Hide_Button_Frames( n )
  1209. endif
  1210. GUIShowFrame( GUI( n ).PressIMG )
  1211. GUISetFrameDiffuse( GUI( n ).IconIMG , GUI( n ).ButtonIconDiffusePress )
  1212. endif
  1213. rem 3D mouse is invalid
  1214. uGUI.Mouse3DInvalid = 1
  1215. rem mouse is not over button
  1216. else
  1217. rem show normal image
  1218. _GUI_Hide_Button_Frames( n )
  1219. GUIShowFrame( GUI( n ).IMG )
  1220. GUISetFrameDiffuse( GUI( n ).IconIMG , GUI( n ).ButtonIconDiffuseNormal )
  1221. endif
  1222. rem bind key presses
  1223. if keystate( GUI( n ).KeyBind ) and GUI( n ).KeyBindFlag = 0
  1224. _GUI_ReleaseOtherButtons()
  1225. GUI( n ).KeyBindFlag = 1
  1226. if ManualPress = 0 then GUI( n ).ClickState = GUICLICK_CLICKED
  1227. uGUI.ButtonClicked = n
  1228. rem sprite press image
  1229. if GUI( n ).KeepLastImage = 0
  1230. _GUI_Hide_Button_Frames( n )
  1231. endif
  1232. GUIShowFrame( GUI( n ).GlowIMG )
  1233. GUIShowFrame( GUI( n ).PressIMG )
  1234. GUISetFrameDiffuse( GUI( n ).IconIMG , GUI( n ).ButtonIconDiffusePress )
  1235. endif
  1236. if keystate( GUI( n ).KeyBind ) = 0 then GUI( n ).KeyBindFlag = 0
  1237. rem button is being pressed
  1238. else
  1239. rem toggle mode is activated
  1240. if GUI( n ).ToggleMode = 1
  1241. rem mouse is over button
  1242. if uMouse.x > GUIGetFrameStartX( GUI( n ).IMG ) and uMouse.x < GUIGetFrameEndX( GUI( n ).IMG ) and uMouse.y > GUIGetFrameStartY( GUI( n ).IMG ) and uMouse.y < GUIGetFrameEndY( GUI( n ).IMG )
  1243. if GUI( n ).KeepLastImage = 0
  1244. _GUI_Hide_Button_Frames( n )
  1245. endif
  1246. GUIShowFrame( GUI( n ).PressIMG )
  1247. GUISetFrameDiffuse( GUI( n ).IconIMG , GUI( n ).ButtonIconDiffusePress )
  1248. rem Mouse clicks button
  1249. if uMouse.click = 1
  1250. if ManualPress = 0 then GUI( n ).ClickState = GUICLICK_NOT_CLICKED
  1251. uGUI.ButtonReleased = n
  1252. endif
  1253. rem 3D mouse is invalid
  1254. uGUI.Mouse3DInvalid = 1
  1255. rem mouse is not over button
  1256. else
  1257. rem paste pressed image
  1258. if GUI( n ).KeepLastImage = 0
  1259. _GUI_Hide_Button_Frames( n )
  1260. endif
  1261. GUIShowFrame( GUI( n ).PressIMG )
  1262. GUISetFrameDiffuse( GUI( n ).IconIMG , GUI( n ).ButtonIconDiffusePress )
  1263. endif
  1264. rem bind key presses
  1265. if keystate( GUI( n ).KeyBind ) and GUI( n ).KeyBindFlag = 0
  1266. GUI( n ).KeyBindFlag = 1
  1267. if ManualPress = 0 then GUI( n ).ClickState = GUICLICK_NOT_CLICKED
  1268. uGUI.ButtonReleased = n
  1269. endif
  1270. if keystate( GUI( n ).KeyBind ) = 0 then GUI( n ).KeyBindFlag = 0
  1271. rem toggle mode is not activated
  1272. else
  1273. rem button is being pressed
  1274. if GUI( n ).KeepLastImage = 0
  1275. _GUI_Hide_Button_Frames( n )
  1276. endif
  1277. GUIShowFrame( GUI( n ).GlowIMG )
  1278. GUIShowFrame( GUI( n ).PressIMG )
  1279. GUISetFrameDiffuse( GUI( n ).IconIMG , GUI( n ).ButtonIconDiffusePress )
  1280. rem release button if mouse is no longer clicking
  1281. if uMouse.click <> 2 and keystate( GUI( n ).KeyBind ) = 0
  1282. if ManualPress = 0 then GUI( n ).ClickState = GUICLICK_NOT_CLICKED
  1283. uGUI.ButtonReleased = n
  1284. endif
  1285. rem activate an ability if mouse is clicked
  1286. if uMouse.click = 1
  1287. uGUI.ButtonActivateAbility = n
  1288. endif
  1289. rem cancel an ability
  1290. if uMouse.click = 4
  1291. uGUI.ButtonCancelAbility = n
  1292. endif
  1293. endif
  1294. endif
  1295. endif
  1296. rem button is hidden
  1297. else
  1298. _GUI_Hide_Button_Frames( n )
  1299. GUIHideFrame( GUI( n ).IconIMG )
  1300. GUIHideFrame( GUI( n ).HotKeyIMG )
  1301. endif
  1302. endfunction
  1303. function GUIUpdateFrame()
  1304. rem local variables
  1305. local n as integer
  1306. rem loop through all active frames
  1307. for n = 0 to uGUI.CurrentFrameMax
  1308. if GUIFrame( n , 0 ).Active = 2
  1309. if GUIFrame( n , 0 ).FrameCount > -1
  1310. rem update frame
  1311. inc GUIFrame( n , 0 ).FrameDelayCounter
  1312. if GUIFrame( n , 0 ).FrameDelayCounter > GUIFrame( n , GUIFrame( n ).CurrentFrame ).FrameDelay
  1313. GUIFrame( n , 0 ).FrameDelayCounter = 0
  1314. inc GUIFrame( n , 0 ).CurrentFrame
  1315. if GUIFrame( n , 0 ).CurrentFrame > GUIFrame( n , 0 ).FrameCount then GUIFrame( n , 0 ).CurrentFrame = 0
  1316. sprite GUIFrame( n , 0 ).SPR , GUIFrame( n , 0 ).pos.x , GUIFrame( n , 0 ).pos.y , GUIFrame( n , GUIFrame( n , 0 ).CurrentFrame ).IMG
  1317. endif
  1318. endif
  1319. endif
  1320. next n
  1321. endfunction
  1322. function _GUI_ReleaseOtherButtons()
  1323. rem release any clicked buttons
  1324. for n = 0 to uGUI.CurrentMax
  1325. if GUI( n ).Active = 3
  1326. GUI( n ).ClickState = GUICLICK_NOT_CLICKED
  1327. endif
  1328. next n
  1329. endfunction
  1330. function _GUI_Get_Character_From_Scancode_Switzerland( scan )
  1331. rem lookup table
  1332. if scan = 16 then exitfunction asc( "Q" )
  1333. if scan = 17 then exitfunction asc( "W" )
  1334. if scan = 18 then exitfunction asc( "E" )
  1335. if scan = 19 then exitfunction asc( "R" )
  1336. if scan = 20 then exitfunction asc( "T" )
  1337. if scan = 21 then exitfunction asc( "Z" )
  1338. if scan = 22 then exitfunction asc( "U" )
  1339. if scan = 23 then exitfunction asc( "I" )
  1340. if scan = 24 then exitfunction asc( "O" )
  1341. if scan = 25 then exitfunction asc( "P" )
  1342. if scan = 26 then exitfunction asc( "Ü" )
  1343. if scan = 30 then exitfunction asc( "A" )
  1344. if scan = 31 then exitfunction asc( "S" )
  1345. if scan = 32 then exitfunction asc( "D" )
  1346. if scan = 33 then exitfunction asc( "F" )
  1347. if scan = 34 then exitfunction asc( "G" )
  1348. if scan = 35 then exitfunction asc( "H" )
  1349. if scan = 36 then exitfunction asc( "J" )
  1350. if scan = 37 then exitfunction asc( "K" )
  1351. if scan = 38 then exitfunction asc( "L" )
  1352. if scan = 39 then exitfunction asc( "Ö" )
  1353. if scan = 40 then exitfunction asc( "Ä" )
  1354. if scan = 43 then exitfunction asc( "$" )
  1355. if scan = 44 then exitfunction asc( "Y" )
  1356. if scan = 45 then exitfunction asc( "X" )
  1357. if scan = 46 then exitfunction asc( "C" )
  1358. if scan = 47 then exitfunction asc( "V" )
  1359. if scan = 48 then exitfunction asc( "B" )
  1360. if scan = 49 then exitfunction asc( "N" )
  1361. if scan = 50 then exitfunction asc( "M" )
  1362. if scan = 51 then exitfunction asc( "," )
  1363. if scan = 52 then exitfunction asc( "." )
  1364. if scan = 53 then exitfunction asc( "-" )
  1365. endfunction 0