home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / jpi / gameinte.bas < prev    next >
Encoding:
BASIC Source File  |  1998-01-29  |  22.8 KB  |  599 lines

  1. Attribute VB_Name = "GameInterface"
  2. Global Const EXTRABORDER = 5
  3. Global Const MouseDragThreshhold = 4
  4.  
  5. Global Const MAXMOUSEBUTTONS = 5
  6. 'Mouse
  7. Type MousePoint
  8.   DragStartPosition As Point3D
  9.   DragCurrentPosition As Point3D
  10.   IsDragging As Boolean
  11.   Position As Point3D
  12.   OldButtonStates(1 To MAXMOUSEBUTTONS) As Boolean
  13.   ButtonStates(1 To MAXMOUSEBUTTONS) As Boolean
  14.   CursorPic As Integer
  15. End Type
  16. Public Mouse As MousePoint
  17.  
  18. 'Keyboard
  19. Global Const KEY_SHIFT = 16
  20. Global Const KEY_ENTER = 13
  21. Global Const KEY_ESCAPE = 27
  22. Global Const KEY_T = 84
  23. Global Const KEY_S = 83
  24. Global Const KEY_D = 68
  25. Global Const KEY_CONTROL = 17
  26. Global Const KEY_ALT = 18
  27. Global Const KEY_TAB = 9
  28.  
  29. Global Const KEY_UP = 38
  30. Global Const KEY_DOWN = 40
  31. Global Const KEY_LEFT = 37
  32. Global Const KEY_RIGHT = 39
  33.  
  34.  
  35. Global KeyStates(250) As Boolean
  36.  
  37. Type ObjectSelect
  38.   MaxSelected As Integer
  39.   SelectedList(MAXOBJECTS) As Integer
  40. End Type
  41. Type Interflags
  42.   WritingAMessage As Boolean
  43.   Message As String
  44.   PlacingABuilding As Boolean
  45.   PlaceIndex As Integer
  46. End Type
  47. Global InterfaceFlags As Interflags
  48. Global ObjectSelectedList As IndexGroup
  49. 'Real stuff
  50. Public Const INTERFACEWIDTH = 320
  51. Public Const INTERFACEHEIGHT = 200
  52. Public Const HALFINTERFACEWIDTH = INTERFACEWIDTH / 2
  53. Public Const HALFINTERFACEHEIGHT = INTERFACEHEIGHT / 2
  54. Private Const NOCONTROL = 0
  55.  
  56.  
  57. Private Const MAXPROPERTIES = 10
  58. Public Const CONTROLPROPERTY_TEXT = 1
  59. Public Const CONTROLPROPERTY_PICTURE = 2
  60. Public Const CONTROLPROPERTY_STATE = 3
  61.  
  62. Type PropertyArray
  63.   Properties(MAXPROPERTIES) As Variant
  64. End Type
  65. Type ControlObject
  66.   Outline As RECT
  67.   ControlProperties As PropertyArray
  68.   ControlType As Integer
  69. End Type
  70. Private Const MAXCONTROLAMOUNT = 30
  71. Type ControlGroup
  72.   ControlAmount As Integer
  73.   ControlObjects(MAXCONTROLAMOUNT) As ControlObject
  74. End Type
  75. Type InterfaceReturnObj
  76.   Controls As ControlGroup
  77.   Canceled As Boolean
  78. End Type
  79. Type InterfaceObj
  80.   BackgroundPic As Integer
  81.   BackgroundSound As String
  82.   MouseCursorPic As Integer
  83.   Controls As ControlGroup
  84.   ControlFocus As Integer
  85. End Type
  86. Public Const CONTROLTYPE_PICTUREBOX = 1
  87. Public Const CONTROLTYPE_BUTTONLARGE = 2
  88. Public Const CONTROLTYPE_LABEL = 3
  89. Public Const CONTROLTYPE_TEXTBOX = 4
  90. Public Function CreateControl(ControlType, X, Y, Width, Height, Content) As ControlObject
  91. Dim NewControl As ControlObject
  92. NewControl.ControlType = ControlType
  93. Select Case ControlType
  94. Case CONTROLTYPE_PICTUREBOX
  95.   NewControl.ControlProperties.Properties(CONTROLPROPERTY_PICTURE) = Content
  96.   NewControl.Outline.Top = Y - Int(Height / 2)
  97.   NewControl.Outline.bottom = Y + Int(Height / 2)
  98.   NewControl.Outline.Left = X - Int(Width / 2)
  99.   NewControl.Outline.Right = X + Int(Width / 2)
  100. Case CONTROLTYPE_BUTTONLARGE
  101.   NewControl.ControlProperties.Properties(CONTROLPROPERTY_TEXT) = Content
  102.   NewControl.ControlProperties.Properties(CONTROLPROPERTY_STATE) = False
  103.   NewControl.Outline.Top = Y
  104.   NewControl.Outline.bottom = Y + Height
  105.   NewControl.Outline.Left = X
  106.   NewControl.Outline.Right = X + Width
  107. Case CONTROLTYPE_LABEL
  108.   NewControl.ControlProperties.Properties(CONTROLPROPERTY_TEXT) = Content
  109.   NewControl.Outline.Top = Y
  110.   NewControl.Outline.bottom = Y + Height
  111.   NewControl.Outline.Left = X
  112.   NewControl.Outline.Right = X + Width
  113. Case CONTROLTYPE_TEXTBOX
  114.   NewControl.ControlProperties.Properties(CONTROLPROPERTY_TEXT) = Content
  115.   NewControl.Outline.Top = Y - Int((Height * FONT_SPACINGY) / 2)
  116.   NewControl.Outline.bottom = Y + Int((Height * FONT_SPACINGY) / 2)
  117.   NewControl.Outline.Left = X - Int((Width * FONT_SPACINGX) / 2)
  118.   NewControl.Outline.Right = X + Int((Width * FONT_SPACINGX) / 2)
  119. End Select
  120. CreateControl = NewControl
  121. End Function
  122. Public Function ProjectRectToCenterScreen(RectToConvert As RECT) As RECT
  123. ProjectRectToCenterScreen.Left = (RectToConvert.Left - HALFINTERFACEWIDTH) + ResolutionMidX
  124. ProjectRectToCenterScreen.Right = (RectToConvert.Right - HALFINTERFACEWIDTH) + ResolutionMidX
  125. ProjectRectToCenterScreen.Top = (RectToConvert.Top - HALFINTERFACEHEIGHT) + ResolutionMidY
  126. ProjectRectToCenterScreen.bottom = (RectToConvert.bottom - HALFINTERFACEHEIGHT) + ResolutionMidY
  127. End Function
  128. Private Sub DrawInterface(Interface As InterfaceObj)
  129. Call GraphicsEngine.SplashGraphic(InGameConstants(InGameConstant_PICINDEX_ProgramBackground))
  130. Call GraphicsEngine.DisplayText("JPI v" & VERSION, ResolutionMidX - HALFINTERFACEWIDTH, ResolutionMidY - HALFINTERFACEHEIGHT, PALLETE_YELLOW)
  131. For I = 1 To Interface.Controls.ControlAmount
  132.   'Display controls
  133.   With Interface.Controls.ControlObjects(I)
  134.     Select Case .ControlType
  135.     Case CONTROLTYPE_PICTUREBOX
  136.       Call GraphicsEngine.PutGraphicOntoBackBuffer(.Outline.Left + Pics(.ControlProperties.Properties(CONTROLPROPERTY_PICTURE)).HalfWidth, .Outline.Top + Pics(.ControlProperties.Properties(CONTROLPROPERTY_PICTURE)).HalfHeight, .ControlProperties.Properties(CONTROLPROPERTY_PICTURE), BltType_Mask)
  137.     Case CONTROLTYPE_BUTTONLARGE
  138.       Call GraphicsEngine.PutGraphicOntoBackBuffer(.Outline.Left + Pics(InGameConstants(InGameConstant_PICINDEX_ButtonLarge)).HalfWidth, .Outline.Top + Pics(InGameConstants(InGameConstant_PICINDEX_ButtonLarge)).HalfHeight, InGameConstants(InGameConstant_PICINDEX_ButtonLarge), BltType_Fast)
  139.       Call GraphicsEngine.DisplayTextCenterRelative(.ControlProperties.Properties(CONTROLPROPERTY_TEXT), .Outline.Left + 70, .Outline.Top + 6, PALLETE_WHITE)
  140.     Case CONTROLTYPE_TEXTBOX
  141.       Call GraphicsEngine.DisplayText(.ControlProperties.Properties(CONTROLPROPERTY_TEXT), .Outline.Left, .Outline.Top + 1, PALLETE_YELLOW)
  142.       Call GraphicsEngine.GethDC
  143.       Call GraphicsEngine.DrawBox(.Outline.Left, .Outline.Top + 2, .Outline.Right, .Outline.bottom - 1, 255, 255, 255, 0, 0, 0, LINEMODE_NORMAL)
  144.       Call GraphicsEngine.ReleasehDC
  145.     Case CONTROLTYPE_LABEL
  146.       Call GraphicsEngine.DisplayTextCenterRelative(.ControlProperties.Properties(CONTROLPROPERTY_TEXT), .Outline.Left + ((.Outline.Right - .Outline.Left) / 2), .Outline.Top + ((.Outline.bottom - .Outline.Top) / 2), PALLETE_YELLOW)
  147.     End Select
  148.   End With
  149. Next I
  150. End Sub
  151. Public Function RunStaticInterface(InterfaceToRun As InterfaceObj) As InterfaceReturnObj
  152. Dim InterfaceReturn As InterfaceReturnObj, Interface As InterfaceObj
  153. ViewForm.KeyboardInputBox.Text = ""
  154. Interface = InitializeInterfaceObj(InterfaceToRun)
  155. Call ClearKeyStates
  156. If InterfaceToRun.BackgroundSound <> "" Then Call Sound.Play_LoopSound(Sound.GetSoundIndex(InterfaceToRun.BackgroundSound), 100)
  157. Do
  158.   
  159.   DoEvents
  160.   If Interface.ControlFocus <> NOCONTROL Then
  161.     If RunControlKeyboardInput(Interface.Controls.ControlObjects(Interface.ControlFocus)) = True Then
  162.       Interface.ControlFocus = NOCONTROL
  163.     End If
  164.   End If
  165.   For I = 1 To Interface.Controls.ControlAmount
  166.     If RunControlMouseInput(Interface.Controls.ControlObjects(I)) = True Then
  167.       Select Case Interface.Controls.ControlObjects(I).ControlType
  168.       Case CONTROLTYPE_TEXTBOX
  169.         Interface.ControlFocus = I
  170.         ViewForm.KeyboardInputBox.Text = Interface.Controls.ControlObjects(I).ControlProperties.Properties(CONTROLPROPERTY_TEXT)
  171.         ViewForm.KeyboardInputBox.SelStart = Len(ViewForm.KeyboardInputBox.Text)
  172.         ViewForm.KeyboardInputBox.MaxLength = (Interface.Controls.ControlObjects(I).Outline.Right - Interface.Controls.ControlObjects(I).Outline.Left) / FONT_SPACINGX
  173.       End Select
  174.       If Interface.Controls.ControlObjects(I).ControlType = CONTROLTYPE_BUTTONLARGE Then
  175.         Exit Do
  176.       End If
  177.     End If
  178.   Next I
  179.   Call GraphicsEngine.ClearBackBuffer
  180.   Call DrawInterface(Interface)
  181.   GraphicsEngine.SwapScreen
  182.   'Display mouse cursor (make a sub DisplayMousecursor(CursorPic)
  183.   If KeyStates(KEY_ESCAPE) = True Then
  184.     RunStaticInterface.Canceled = True
  185.     Exit Do
  186.   End If
  187. Loop
  188. Call Sound.Stop_Sounds
  189. RunStaticInterface.Controls = Interface.Controls
  190. ViewForm.KeyboardInputBox.MaxLength = 0
  191. End Function
  192. Public Sub RunImmediateInterface(Interface As InterfaceObj)
  193. For I = 1 To Interface.Controls.ControlAmount
  194. '  Call RunControl(Interface.Controls.ControlObjects(I))
  195. Next I
  196. Call DrawInterface(Interface)
  197. End Sub
  198. Private Function RunControlMouseInput(Control As ControlObject) As Boolean
  199. If InClipper(Mouse.Position.X, Mouse.Position.Y, Control.Outline) = True Then
  200.   'run the mouse input
  201.   If Mouse.ButtonStates(1) = True Then
  202.     Mouse.ButtonStates(1) = False
  203.     RunControlMouseInput = True
  204.     If Control.ControlProperties.Properties(CONTROLPROPERTY_STATE) = False Then
  205.       Control.ControlProperties.Properties(CONTROLPROPERTY_STATE) = True
  206.     Else
  207.       Control.ControlProperties.Properties(CONTROLPROPERTY_STATE) = False
  208.     End If
  209.   End If
  210. End If
  211. End Function
  212. Private Function RunControlKeyboardInput(Control As ControlObject) As Boolean
  213. 'run the keyboard input
  214. Control.ControlProperties.Properties(CONTROLPROPERTY_TEXT) = ViewForm.KeyboardInputBox.Text
  215. If KeyStates(KEY_ENTER) = True Then
  216.   RunControlKeyboardInput = True
  217. End If
  218. End Function
  219. Public Function InitializeInterfaceObj(Interface As InterfaceObj) As InterfaceObj
  220. InitializeInterfaceObj = Interface
  221. For I = 1 To InitializeInterfaceObj.Controls.ControlAmount
  222.   InitializeInterfaceObj.Controls.ControlObjects(I).Outline = ProjectRectToCenterScreen(InitializeInterfaceObj.Controls.ControlObjects(I).Outline)
  223. Next I
  224. End Function
  225. Public Function ConstructInterface(InterfaceFile As String) As InterfaceObj
  226. Dim NewInterface As InterfaceObj
  227. 'put load interface crap here!
  228. NewInterface = InitializeInterfaceObj(NewInterface)
  229. ConstructInterface = NewInterface
  230. End Function
  231. Public Sub ClearKeyStates()
  232. For I = 0 To 250
  233.   KeyStates(I) = False
  234. Next I
  235. End Sub
  236. Public Sub InitializeInterface()
  237. ViewForm.KeyboardInputBox.SetFocus
  238. End Sub
  239. Public Sub ClearMouseButtons()
  240. For I = 1 To MAXMOUSEBUTTONS
  241.   Mouse.ButtonStates(I) = False
  242.   Mouse.OldButtonStates(I) = False
  243. Next I
  244. End Sub
  245. Public Sub SelectUnits(StartPoint As Point3D, ClickPoint As Point3D)
  246. If ClickPoint.X < StartPoint.X Then
  247.   TmpX = ClickPoint.X
  248.   ClickPoint.X = StartPoint.X
  249.   StartPoint.X = TmpX
  250. End If
  251. If ClickPoint.Y < StartPoint.Y Then
  252.   TmpY = ClickPoint.Y
  253.   ClickPoint.Y = StartPoint.Y
  254.   StartPoint.Y = TmpY
  255. End If
  256. GameInterface.ObjectSelectedList.IndexesActive = 0
  257. For I = 1 To ObjectsActive
  258.   If CheckObject(I, OBJCHECK_ALIVE) = True Then
  259.     If CheckObject(I, OBJCHECK_CANBESELECTED) = True Then
  260.       If Objects(I).Side = LocalPlayer.PlayerIndex Then
  261.         If Objects(I).Position.X <= ClickPoint.X Then
  262.           If Objects(I).Position.X >= StartPoint.X Then
  263.             If Objects(I).Position.Y <= ClickPoint.Y Then
  264.               If Objects(I).Position.Y >= StartPoint.Y Then
  265.                 If ObjModels(Objects(I).ModelIndex).BehaviorType = BEHAVIORMODE_TANK Then
  266.                   GameInterface.ObjectSelectedList.IndexesActive = GameInterface.ObjectSelectedList.IndexesActive + 1
  267.                   GameInterface.ObjectSelectedList.Indexes(GameInterface.ObjectSelectedList.IndexesActive) = I
  268.                 End If
  269.               End If
  270.             End If
  271.           End If
  272.         End If
  273.       End If
  274.     End If
  275.   End If
  276. Next I
  277. End Sub
  278. Public Sub DetermineMouseDrag()
  279. Mouse.IsDragging = True
  280. If Mouse.Position.X < Mouse.DragStartPosition.X + MouseDragThreshhold Then
  281.   If Mouse.Position.X > Mouse.DragStartPosition.X - MouseDragThreshhold Then
  282.     If Mouse.Position.Y < Mouse.DragStartPosition.Y + MouseDragThreshhold Then
  283.       If Mouse.Position.Y > Mouse.DragStartPosition.Y - MouseDragThreshhold Then
  284.         Mouse.IsDragging = False
  285.       End If
  286.     End If
  287.   End If
  288. End If
  289. If Mouse.IsDragging = True Then
  290.   Mouse.IsDragging = False
  291.   If Mouse.DragStartPosition.X > BattleViewPort.PortRect.Left - 1 Then
  292.     If Mouse.DragStartPosition.Y > BattleViewPort.PortRect.Top - 1 Then
  293.       If Mouse.DragStartPosition.X < BattleViewPort.PortRect.Right Then
  294.         If Mouse.DragStartPosition.Y < BattleViewPort.PortRect.bottom Then
  295.           Mouse.IsDragging = True
  296.         End If
  297.       End If
  298.     End If
  299.   End If
  300. End If
  301. End Sub
  302. Sub SelectSingleUnit(Mouse3D As Point3D)
  303. Dim Temppoint As Point3D
  304. For I = 1 To ObjectsActive
  305.   If CheckObject(I, OBJCHECK_ALIVE) = True Then
  306.     If CheckObject(I, OBJCHECK_CANBESELECTED) = True Then
  307.       If CheckIfPointIsOnUnit(I, Mouse3D) = True Then
  308.         If KeyStates(KEY_SHIFT) = True Then
  309.           ObjectSelectedList.IndexesActive = ObjectSelectedList.IndexesActive + 1
  310.           ObjectSelectedList.Indexes(ObjectSelectedList.IndexesActive) = I
  311.         Else
  312.           ObjectSelectedList.IndexesActive = 1
  313.           ObjectSelectedList.Indexes(1) = I
  314.           Exit For
  315.         End If
  316.       End If
  317.     End If
  318.   End If
  319. Next I
  320. End Sub
  321. Public Function CheckIfPointIsOnUnit(ObjIndex, PointPosition As Point3D) As Boolean
  322. Dim Temppoint As Point3D
  323. With Objects(ObjIndex)
  324.     Temppoint = ProjectPointToView(.Position)
  325.     SpriteXOffset = ObjModels(.ModelIndex).Attributes(ATTRIBUTE_SPRITEPOSITIONX)
  326.     SpriteYOffset = ObjModels(.ModelIndex).Attributes(ATTRIBUTE_SPRITEPOSITIONY)
  327.     PicIndex = SpriteStuff.Sprites(.Sprite.SpriteNumber).SpriteGroups(.Sprite.SpriteGroupNumber).Frames(.Sprite.SpriteFrameNumber).PicNum
  328.     If PointPosition.X > Temppoint.X - SpriteXOffset Then
  329.       If PointPosition.X < (Temppoint.X - SpriteXOffset) + Pics(PicIndex).Width Then
  330.         If PointPosition.Y > Temppoint.Y - SpriteYOffset Then
  331.           If PointPosition.Y < (Temppoint.Y - SpriteYOffset) + Pics(PicIndex).Height Then
  332.             CheckIfPointIsOnUnit = True
  333.           End If
  334.         End If
  335.       End If
  336.     End If
  337. End With
  338. End Function
  339. Public Function InClipper(X, Y, ClipRect As RECT) As Boolean
  340. With ClipRect
  341.   If X <= .Right + EXTRABORDER Then
  342.     If X >= .Left - EXTRABORDER Then
  343.       If Y >= .Top - EXTRABORDER Then
  344.         If Y <= .bottom + EXTRABORDER Then
  345.           InClipper = True
  346.         End If
  347.       End If
  348.     End If
  349.   End If
  350. End With
  351. End Function
  352. Public Sub ProcessMouseInput()
  353. 'View Scrolling
  354. If InClipper(Mouse.Position.X, Mouse.Position.Y, BattleViewPort.PortRect) = True Then
  355.   Call ProcessWindow_BattleViewPort
  356. End If
  357. If InClipper(Mouse.Position.X, Mouse.Position.Y, GameControlPanel.PortRect) = True Then
  358.   If Mouse.IsDragging = True Then
  359.     Call ProcessWindow_BattleViewPort
  360.   Else
  361.     Call ProcessWindow_ControlPanel
  362.   End If
  363. End If
  364. Call ProcessMiscMouse
  365. For I = 1 To 5
  366.   Mouse.OldButtonStates(I) = Mouse.ButtonStates(I)
  367. Next I
  368. End Sub
  369. Sub ProcessWindow_ControlPanel()
  370. Dim Building As Boolean
  371. For I = 1 To MAXBUILDWINDOWS
  372.   If InClipper(Mouse.Position.X, Mouse.Position.Y, BuildWindows(I).PortRect) = True Then
  373.     If Player(LocalPlayer.PlayerIndex).CurrentlySelectedBuildClass + (I - 1) <= Player(LocalPlayer.PlayerIndex).BuildClassesActive Then
  374.       If Mouse.ButtonStates(1) = True Then
  375.         If Players.StartBuilding(LocalPlayer.PlayerIndex, Player(LocalPlayer.PlayerIndex).CurrentlySelectedBuildClass + (I - 1)) = False Then
  376.           For I2 = 1 To Player(LocalPlayer.PlayerIndex).BuildsInProgressesActive
  377.             If Player(LocalPlayer.PlayerIndex).BuildClasses(Player(LocalPlayer.PlayerIndex).CurrentlySelectedBuildClass + (I - 1)).ClassReference = Player(LocalPlayer.PlayerIndex).BuildsInProgress(I2).ClassReference Then
  378.               If Player(LocalPlayer.PlayerIndex).BuildsInProgress(I2).CanBePlaced = True Then
  379.                 InterfaceFlags.PlaceIndex = Player(LocalPlayer.PlayerIndex).BuildsInProgress(I2).ClassReference
  380.                 InterfaceFlags.PlacingABuilding = True
  381.               End If
  382.               Exit For
  383.             End If
  384.           Next I2
  385.         End If
  386.         Mouse.ButtonStates(1) = False
  387.       ElseIf Mouse.ButtonStates(2) = True Then
  388.         Call CancelBuild(LocalPlayer.PlayerIndex, Player(LocalPlayer.PlayerIndex).CurrentlySelectedBuildClass + (I - 1))
  389.         Mouse.ButtonStates(2) = False
  390.       End If
  391.     End If
  392.   End If
  393. Next I
  394. If InClipper(Mouse.Position.X, Mouse.Position.Y, RadarButton.PortRect) = True Then
  395.   If Mouse.ButtonStates(1) = True Then
  396.     If RadarWindow.Enabled = True Then
  397.       RadarWindow.Enabled = False
  398.     Else
  399.       RadarWindow.Enabled = True
  400.     End If
  401.     Call GraphicsEngine.RedrawControlPanel
  402.     Mouse.ButtonStates(1) = False
  403.   End If
  404. End If
  405. End Sub
  406. Sub ProcessMiscMouse()
  407. If Mouse.IsDragging = True Then
  408.     Mouse.DragCurrentPosition = Mouse.Position
  409.     With BattleViewPort.PortRect
  410.       If Mouse.Position.X < .Left Then
  411.         Mouse.DragCurrentPosition.X = .Left
  412.       End If
  413.       If Mouse.Position.X > .Right - 1 Then
  414.         Mouse.DragCurrentPosition.X = .Right - 1
  415.       End If
  416.       If Mouse.Position.Y < .Top - 1 Then
  417.         Mouse.DragCurrentPosition.Y = .Top - 1
  418.       End If
  419.       If Mouse.Position.Y > .bottom - 1 Then
  420.         Mouse.DragCurrentPosition.Y = .bottom - 1
  421.       End If
  422.     End With
  423. Else
  424.     With Mouse.Position
  425.       If .X = 0 Then
  426.         Call AddInertiaToScroll(DIRECTION_LEFT)
  427.       End If
  428.       If .Y = 0 Then
  429.         Call AddInertiaToScroll(DIRECTION_UP)
  430.       End If
  431.       If .X = ResolutionX - 1 Then
  432.         Call AddInertiaToScroll(DIRECTION_RIGHT)
  433.       End If
  434.       If .Y = ResolutionY - 1 Then
  435.         Call AddInertiaToScroll(DIRECTION_DOWN)
  436.       End If
  437.     End With
  438. End If
  439. End Sub
  440. Sub ProcessWindow_BattleViewPort()
  441. If InterfaceFlags.PlacingABuilding = True Then
  442.   If Mouse.ButtonStates(1) = True Then
  443.     If ObjectSelectedList.IndexesActive = NOOBJECT Then
  444.       Mouse.ButtonStates(1) = False
  445.       MouseX = Map.ProjectToMapX(ProjectXToBattlefield(Mouse.Position.X))
  446.       MouseY = Map.ProjectToMapY(ProjectYToBattlefield(Mouse.Position.Y))
  447.       If Map.IsImprintSpaceOccupied(MouseX, MouseY, ObjModels(Player(PlayerIndex).BuildsInProgress(InterfaceFlags.PlaceIndex).ClassReference).MapImprintNumber) = False Then
  448.         Call BuildBuilding(MouseX, MouseY, LocalPlayer.PlayerIndex)
  449.       Else
  450.         Beep
  451.       End If
  452.     End If
  453.   End If
  454. End If
  455. If Mouse.OldButtonStates(1) = True Then
  456.   'mouse has been pressed down
  457.   If Mouse.ButtonStates(1) = False Then
  458.     'Mouse has just been pressed and let go
  459.     Call DetermineMouseDrag
  460.     If Mouse.IsDragging = False Then
  461.       If ObjectSelectedList.IndexesActive = NOOBJECT Then
  462.         Call SelectSingleUnit(Mouse.Position)
  463.       Else
  464.         Call HandleUnitGroupInstructions(ProjectPointToBattlefield(Mouse.Position))
  465.       End If
  466.     Else
  467.       Call SelectUnits(ProjectPointToBattlefield(Mouse.DragStartPosition), ProjectPointToBattlefield(Mouse.DragCurrentPosition))
  468.     End If
  469.   Else
  470.     Call DetermineMouseDrag
  471.   End If
  472. Else
  473.   Mouse.IsDragging = False
  474. End If
  475. If Mouse.ButtonStates(2) = True Then
  476.   'Deselect Units
  477.   GameInterface.ObjectSelectedList.IndexesActive = NOOBJECT
  478. End If
  479. End Sub
  480. Public Sub StandbyMinimized()
  481. Call TempCloseGraphicsDevice
  482. ViewForm.WindowState = 1
  483. Do
  484.   DoEvents
  485.   If ViewForm.WindowState <> 1 Then Exit Do
  486. Loop
  487. DoEvents
  488. Call TempOpenGraphicsDevice
  489. DoEvents
  490. GraphicsEngine.GraphicsEngineData.TotalRefresh = True
  491. End Sub
  492. Sub MiscKeyboardProcessing()
  493. Call CheckAltTab
  494. End Sub
  495. Public Sub CheckAltTab()
  496. If KeyStates(KEY_TAB) = True Then
  497.   If KeyStates(KEY_ALT) = True Then
  498.     Call StandbyMinimized
  499.     Call ClearKeyStates
  500.   End If
  501. End If
  502. End Sub
  503. Public Sub ProcessKeyboardEvents()
  504. If InterfaceFlags.WritingAMessage = True Then
  505.     InterfaceFlags.Message = ViewForm.KeyboardInputBox.Text
  506.     If KeyStates(KEY_ESCAPE) = True Then
  507.       InterfaceFlags.WritingAMessage = False
  508.     End If
  509.     If KeyStates(KEY_ENTER) = True Then
  510.       Call Internet.TransmitMessage(ViewForm.KeyboardInputBox.Text)
  511.       InterfaceFlags.WritingAMessage = False
  512.       ViewForm.KeyboardInputBox.Text = ""
  513.     End If
  514.     For I = 1 To 127
  515.       KeyStates(I) = False
  516.     Next I
  517. Else
  518.     If KeyStates(KEY_T) = True Then
  519.       InterfaceFlags.WritingAMessage = True
  520.       ViewForm.KeyboardInputBox.Text = ""
  521.     End If
  522.     If KeyStates(KEY_UP) = True Then
  523.       Call AddInertiaToScroll(DIRECTION_UP)
  524.     End If
  525.     If KeyStates(KEY_DOWN) = True Then
  526.       Call AddInertiaToScroll(DIRECTION_DOWN)
  527.     End If
  528.     If KeyStates(KEY_LEFT) = True Then
  529.       Call AddInertiaToScroll(DIRECTION_LEFT)
  530.     End If
  531.     If KeyStates(KEY_RIGHT) = True Then
  532.       Call AddInertiaToScroll(DIRECTION_RIGHT)
  533.     End If
  534.     If KeyStates(KEY_ESCAPE) = True Then
  535.       Call GameEngine.CauseEngineInterrupt(IR_PLAYEREXITEDGAME)
  536.     End If
  537. End If
  538. End Sub
  539. Public Sub ClearSelectedListEntry(EntryNum)
  540. For I = EntryNum To ObjectSelectedList.IndexesActive - 1
  541.   ObjectSelectedList.Indexes(I) = ObjectSelectedList.Indexes(I + 1)
  542. Next I
  543. ObjectSelectedList.IndexesActive = ObjectSelectedList.IndexesActive - 1
  544. End Sub
  545. Public Function GetManualInstruction()
  546. If KeyStates(KEY_CONTROL) = True Then
  547.   If KeyStates(KEY_ALT) = True Then
  548.     GetManualInstruction = INSTRUCTION_FORCEPROTECT
  549.   Else
  550.     GetManualInstruction = INSTRUCTION_FORCEATTACK
  551.   End If
  552. ElseIf KeyStates(KEY_ALT) = True Then
  553.   GetManualInstruction = INSTRUCTION_FORCEMOVE
  554. End If
  555. End Function
  556. Public Sub HandleUnitGroupInstructions(RealMouseClickPoint As Point3D)
  557. Dim ClickPoint As Point3D
  558. If ObjectSelectedList.IndexesActive < 1 Then Exit Sub
  559. ManualInstruction = GetManualInstruction
  560. For I = 1 To GameInterface.ObjectSelectedList.IndexesActive
  561.   If CheckObject(ObjectSelectedList.Indexes(I), OBJCHECK_SELECTABLE) = True Then
  562.     IgnoreCommand = False
  563.     If ObjModels(Objects(ObjectSelectedList.Indexes(I)).ModelIndex).Abilities(ABILITY_DEPLOYS) Then
  564.       If CheckIfPointIsOnUnit(ObjectSelectedList.Indexes(I), GameInterface.ProjectPointToView(RealMouseClickPoint)) = True Then
  565.         If Objects(ObjectSelectedList.Indexes(I)).Side = LocalPlayer.PlayerIndex Then
  566.           Objects(ObjectSelectedList.Indexes(I)).Frozen = True
  567.           Call Events.SpawnEvent(Events.Event_DeployUnit, ObjectSelectedList.Indexes(I))
  568.           IgnoreCommand = True
  569.         End If
  570.       End If
  571.     End If
  572.     If IgnoreCommand = False Then Call Events.SpawnEvent(Events.Event_DirectUnit, GameInterface.ObjectSelectedList.Indexes(I), RealMouseClickPoint.X, RealMouseClickPoint.Y, ManualInstruction)
  573.   End If
  574. Next I
  575. End Sub
  576. Function ProjectXToView(XVal) As Integer
  577. ProjectXToView = (XVal - GameEngine.View.Left)
  578. End Function
  579. Function ProjectYToView(YVal) As Integer
  580. ProjectYToView = (YVal - GameEngine.View.Top)
  581. End Function
  582. Function ProjectXToBattlefield(XVal) As Integer
  583. ProjectXToBattlefield = (GameEngine.View.Left + XVal) - BattleViewPort.PortRect.Left
  584. End Function
  585. Function ProjectYToBattlefield(YVal) As Integer
  586. ProjectYToBattlefield = (GameEngine.View.Top + YVal) - BattleViewPort.PortRect.Top
  587. End Function
  588. Public Function ProjectPointToView(OrigPoint As Point3D) As Point3D
  589. ProjectPointToView.X = ProjectXToView(OrigPoint.X)
  590. ProjectPointToView.Y = ProjectYToView(OrigPoint.Y)
  591. ProjectPointToView.Z = OrigPoint.Z
  592. End Function
  593. Public Function ProjectPointToBattlefield(OrigPoint As Point3D) As Point3D
  594. ProjectPointToBattlefield.X = ProjectXToBattlefield(OrigPoint.X)
  595. ProjectPointToBattlefield.Y = ProjectYToBattlefield(OrigPoint.Y)
  596. ProjectPointToBattlefield.Z = OrigPoint.Z
  597. End Function
  598.  
  599.