VB Mission Editor Tutorial Part 4 (Final)

Dedicated Forum for developers of programs/utilities. To announce new or updated products, to share knowledge and ideas for development.

Moderator: CrazySchmidt

VB Mission Editor Tutorial Part 4 (Final)

Postby CrazySchmidt on Sun Jan 30, 2005 9:02 am

Hi everyone and welcome to the part 4 of the tutorial, the final lesson of this 4 part tutorial. At the end of this lesson you will have built a simple but functional mission editor for aircraft properties suitable for single player and co-op missions. It is true to say that we have not covered all of the properties that may be edited in the mission file and there are many, many more possibilities for a thorough editor, but keep in mind that the idea of the tutorial was to offer a basic concept of building a mission editor using Visual Basic 6.

Remember you may download this entire VB project from the link at the bottom of this lesson.
Also I strongly recommend that you back up any mission files you intend to work with before commencing this tutorial.


NOTE: This lesson will not have a great deal of code displayed because it is basically applying the finishing touches and the code concepts have been covered in lessons 2 and 3. So after examining the project files as a complete project along with the understanding that has been gained over the last few weeks you should have all the knowledge you need go ahead and start on a new project of your own, or to further build on this project to make it an editor every bit as good as those already on offer!

***********************************************************

Ok, lets start with the new objects we will be using for the interface, firstly below is a screen shot of the final compiled working editor and directly below that is a screen shot from inside the Visual Basic 6 interface showing the objects at design time.

Compiled working editor.
Image

Editor in design mode inside the VB6 interface.
Image

Ok then, lets look at the new controls, their names and important property values:

Label Object
Name: “lblMap”
Caption: Defined at run time
Font: Bold - Size = 12 ,

Label Object
Name: “lblPosition”
Caption: “Player Pos”

Combo Box Control
Name: “cboPosition”
Style: 0 - Dropdown Combo


Label Object
Name: “lblWeapons”
Caption: “Weapons Choice”

Combo Box Control
Name: “cboWeapons”
Style: 0 - Dropdown Combo

Ok, those are the only new controls we need for this lesson now lets take a look at the code that makes them work.

“lblMap” Object
This label object is simply used to display the name of the map that the current mission file is working with. The code below is all that is used and is used in the “OpenMisFile” procedure

Code: Select all
If LoopCount = 2 Then
     lblMap.Caption = Trim(Left(FileData, (InStr(FileData, "/") - 1)))
     lblMap.Visible = True
End If


The data this code would be handling would look something like
“ MAP NewGuinea/load.ini” and simply separates the left part of the string away up to the “/” character and of course trims unwanted space characters.

Assigning the weapons for each aircraft type

This is done with the “cboPlaneFly_Click” and “cboPlaneNonFly_Click” event by way of a user defined procedure called “SortLoadOuts” which essentially assigns a list of weapons to the designated combo box control relative to a plane type. So the combo box and plane type are passed to the procedure as arguments and the combo box control is then populated with the appropriate list of weapons for that plane.

Below is shown the “cboPlaneFly_Click” code and the “SortLoadOuts” procedure code:


Code: Select all
Private Sub cboPlaneFly_Click()
  Call SortLoadOuts(cboWeapons, cboPlaneFly.Text)
  If cboWeapons.ListIndex < 0 Then
    cboWeapons.ListIndex = 0
  End If
End Sub

Public Sub SortLoadOuts(Combo As ComboBox, AirCraft As String)
  Select Case AirCraft
    Case "A_20G"
      Call A_20GLOut(Combo)
    Case "BEAU21"
      Call BEAU21LOut(Combo)
    Case "BI_1"
      Call BI_1LOut(Combo)
    Case "CR_42"
      Call CR_42LOut(Combo)
    Case "F4F3"
      Call F4F3LOut(Combo)
    Case "F4F4"
      Call F4F4LOut(Combo)
    Case "F4F_FM2"
      Call F4F_FM2LOut(Combo)
    Case "F4U1A"
      Call F4U1ALOut(Combo)
    Case "F4U1C"
      Call F4U1CLOut(Combo)
    Case "F4U1D"
      Call F4U1DLOut(Combo)
    Case "F4UCORSAIR1"
      Call F4UCORSAIR1LOut(Combo)
    Case "F4UCORSAIR2"
      Call F4UCORSAIR2LOut(Combo)
    Case "F4UCORSAIR4"
      Call F4UCORSAIR4LOut(Combo)
    Case "F6F3"
      Call F6F3LOut(Combo)
    Case "F6F5"
      Call F6F5LOut(Combo)
    Case "GLADIATOR1"
      Call GLADIATOR1LOut(Combo)
    Case "GLADIATOR2"
      Call GLADIATOR2LOut(Combo)
    Case "GLADIATOR1J8A"
      Call GLADIATOR1J8ALOut(Combo)
    Case "GO_229A1"
      Call GO_229A1LOut(Combo)
    Case "HurricaneMkIa"
      Call HurricaneMkIaLOut(Combo)
    Case "HurricaneMkIIb"
      Call HurricaneMkIIbLOut(Combo)
    Case "HurricaneMkIIc"
      Call HurricaneMkIIcLOut(Combo)
    Case "HurricaneMkIIbMod"
      Call HurricaneMkIIbModLOut(Combo)
    Case "I_153_M62"
      Call I_153_M62LOut(Combo)
    Case "I_153P"
      Call I_153PLOut(Combo)
    Case "I_16TYPE18"
      Call I_16TYPE18LOut(Combo)
    Case "I_16TYPE24"
      Call I_16TYPE24LOut(Combo)
    Case "I_16TYPE24DRONE"
      Call I_16TYPE24DRONELOut(Combo)
    Case "I_185M71"
      Call I_185M71LOut(Combo)
    Case "I_185M82A"
      Call I_185M82ALOut(Combo)
    Case "IL_2_1940Early"
      Call IL_2_1940EarlyLOut(Combo)
    Case "IL_2_1940Late"
      Call IL_2_1940LateLOut(Combo)
    Case "IL_2_1941Early"
      Call IL_2_1941EarlyLOut(Combo)
    Case "IL_2_1941Late"
      Call IL_2_1941LateLOut(Combo)
    Case "IL_2I"
      Call IL_2ILOut(Combo)
    Case "IL_2MEarly"
      Call IL_2MEarlyLOut(Combo)
    Case "IL_2MLate"
      Call IL_2MLateLOut(Combo)
    Case "IL_2T"
      Call IL_2TLOut(Combo)
    Case "IL_2Type3"
      Call IL_2Type3LOut(Combo)
    Case "IL_2Type3M"
      Call IL_2Type3MLOut(Combo)
    Case "LAGG_3SERIES4"
      Call LAGG_3SERIES4LOut(Combo)
    Case "LAGG_3SERIES29"
      Call LAGG_3SERIES29LOut(Combo)
    Case "LAGG_3SERIES35"
      Call LAGG_3SERIES35LOut(Combo)
    Case "LAGG_3IT"
      Call LAGG_3ITLOut(Combo)
    Case "LAGG_3SERIES66"
      Call LAGG_3SERIES66LOut(Combo)
    Case "LA_5"
      Call LA_5LOut(Combo)
    Case "LA_5F"
      Call LA_5FLOut(Combo)
    Case "LA_5FN"
      Call LA_5FNLOut(Combo)
    Case "LA_7"
      Call LA_7LOut(Combo)
    Case "LA_7B20"
      Call LA_7B20LOut(Combo)
    Case "MIG_3EARLY"
      Call MIG_3EARLYLOut(Combo)
    Case "MIG_3UD"
      Call MIG_3UDLOut(Combo)
    Case "MIG_3UB"
      Call MIG_3UBLOut(Combo)
    Case "MIG_3SHVAK"
      Call MIG_3SHVAKLOut(Combo)
    Case "MIG_3AM38"
      Call MIG_3AM38LOut(Combo)
    Case "MIG_3U"
      Call MIG_3ULOut(Combo)
    Case "P_11C"
      Call P_11CLOut(Combo)
    Case "P_38J"
      Call P_38JLOut(Combo)
    Case "P_38L"
      Call P_38LLOut(Combo)
    Case "P_39D1"
      Call P_39D1LOut(Combo)
    Case "P_39D2"
      Call P_39D2LOut(Combo)
    Case "P_39N"
      Call P_39NLOut(Combo)
    Case "P_39Q1"
      Call P_39Q1LOut(Combo)
    Case "P_39Q10"
      Call P_39Q10LOut(Combo)
    Case "P_400"
      Call P_400LOut(Combo)
    Case "P_40E"
      Call P_40ELOut(Combo)
     
    Case "P_40B"
      Call P_40SUKAISVOLOCHHAWKA2LOut(Combo)
    Case "P_40C"
      Call P_40SUKAISVOLOCHCLOut(Combo)
    Case "P_40EM105"
      Call P_40EM105LOut(Combo)
    Case "P_40M"
      Call P_40MLOut(Combo)
    Case "Hawk81A-2"
      Call P_40SUKAISVOLOCHHAWKA2LOut(Combo)
    Case "P_47D10"
      Call P_47D10LOut(Combo)
    Case "P_47D22"
      Call P_47D22LOut(Combo)
    Case "P_47D27"
      Call P_47D27LOut(Combo)
    Case "P_51B"
      Call P_51BLOut(Combo)
    Case "P_51C"
      Call P_51CLOut(Combo)
    Case "P_51D5NT"
      Call P_51D5NTLOut(Combo)
    Case "P_51D20NA"
      Call P_51D20NALOut(Combo)
    Case "P_63C"
      Call P_63CLOut(Combo)
    Case "P_80A"
      Call P_80ALOut(Combo)
    Case "SBD3"
      Call SBD3LOut(Combo)
    Case "SBD5"
      Call SBD5LOut(Combo)
    Case "SEAFIRE3"
      Call SEAFIRE3LOut(Combo)
    Case "SEAFIRE3F"
      Call SEAFIRE3FLOut(Combo)
    Case "SPITFIRE5B"
      Call SPITFIRE5BLOut(Combo)
    Case "SPITFIRE5BCLP"
      Call SPITFIRE5BCLPLOut(Combo)
    Case "SPITFIRE5BLF"
      Call SPITFIRE5BLFLOut(Combo)
    Case "SPITFIRE5BLFCLP"
      Call SPITFIRE5BLFCLPLOut(Combo)
    Case "SPITFIRE8"
      Call SPITFIRE8LOut(Combo)
    Case "SPITFIRE8CLP"
      Call SPITFIRE8CLPLOut(Combo)
    Case "SPITFIRE9C"
      Call SPITFIRE9CLOut(Combo)
    Case "SPITFIRE9CCLP"
      Call SPITFIRE9CCLPLOut(Combo)
    Case "SPITFIRE9E"
      Call SPITFIRE9ELOut(Combo)
    Case "SPITFIRE9ECLP"
      Call SPITFIRE9ECLPLOut(Combo)
    Case "SPITFIRE9EHF"
      Call SPITFIRE9EHFLOut(Combo)
    Case "TB_3_4M_17"
      Call TB_3_4M_17LOut(Combo)
    Case "TB_3_4M_34R"
      Call TB_3_4M_34RLOut(Combo)
    Case "TB_3_4M_34R_SPB"
      Call TB_3_4M_34R_SPBLOut(Combo)
    Case "TomahawkMkIIa"
      Call TomahawkMkIIaLOut(Combo)
    Case "TomahawkMkIIb"
      Call TomahawkMkIIbLOut(Combo)
    Case "YAK_1"
      Call YAK_1LOut(Combo)
    Case "YAK_1B"
      Call YAK_1BLOut(Combo)
    Case "YAK_3"
      Call YAK_3LOut(Combo)
    Case "YAK_3P"
      Call YAK_3PLOut(Combo)
    Case "YAK_7A"
      Call YAK_7ALOut(Combo)
    Case "YAK_7B"
      Call YAK_7BLOut(Combo)
    Case "YAK_9"
      Call YAK_9LOut(Combo)
    Case "YAK_9B"
      Call YAK_9BLOut(Combo)
    Case "YAK_9D"
      Call YAK_9DLOut(Combo)
    Case "YAK_9K"
      Call YAK_9KLOut(Combo)
    Case "YAK_9M"
      Call YAK_9MLOut(Combo)
    Case "YAK_9T"
      Call YAK_9TLOut(Combo)
    Case "YAK_9U"
      Call YAK_9ULOut(Combo)
    Case "YAK_9UT"
      Call YAK_9UTLOut(Combo)
    Case "A6M2"
      Call A6M2LOut(Combo)
    Case "A6M2_21"
      Call A6M2_21LOut(Combo)
    Case "A6M2N"
      Call A6M2NLOut(Combo)
    Case "A6M3"
      Call A6M3LOut(Combo)
    Case "A6M5"
      Call A6M5LOut(Combo)
    Case "A6M5A"
      Call A6M5ALOut(Combo)
    Case "A6M5B"
      Call A6M5BLOut(Combo)
    Case "A6M5C"
      Call A6M5CLOut(Combo)
    Case "A6M7_62"
      Call A6M7_62LOut(Combo)
    Case "A6M7_63"
      Call A6M7_63LOut(Combo)
    Case "F2A_B239"
      Call F2A_B239LOut(Combo)
    Case "B5N2"
      Call B5N2LOut(Combo)
    Case "BF_109E4"
      Call BF_109E4LOut(Combo)
    Case "BF_109E4B"
      Call BF_109E4BLOut(Combo)
    Case "BF_109E7"
      Call BF_109E7LOut(Combo)
    Case "BF_109E7NZ"
      Call BF_109E7NZLOut(Combo)
    Case "BF_109F2"
      Call BF_109F2LOut(Combo)
    Case "BF_109F4"
      Call BF_109F4LOut(Combo)
    Case "BF_109G2"
      Call BF_109G2LOut(Combo)
    Case "BF_109G6"
      Call BF_109G6LOut(Combo)
    Case "BF_109G6Late"
      Call BF_109G6LateLOut(Combo)
    Case "BF_109G6AS"
      Call BF_109G6ASLOut(Combo)
    Case "BF_109G10"
      Call BF_109G10LOut(Combo)
    Case "BF_109G14"
      Call BF_109G14LOut(Combo)
    Case "BF_109K4"
      Call BF_109K4LOut(Combo)
    Case "BF_109Z"
      Call BF_109ZLOut(Combo)
    Case "FW_190A4"
      Call FW_190A4LOut(Combo)
    Case "FW_190A5"
      Call FW_190A5LOut(Combo)
    Case "FW_190A6"
      Call FW_190A6LOut(Combo)
    Case "FW_190A8"
      Call FW_190A8LOut(Combo)
    Case "FW_190A9"
      Call FW_190A9LOut(Combo)
    Case "FW_190D9"
      Call FW_190D9LOut(Combo)
    Case "FW_190D9LATE"
      Call FW_190D9LATELOut(Combo)
    Case "FW_190F8"
      Call FW_190F8LOut(Combo)
    Case "HE_111H2"
      Call HE_111H2LOut(Combo)
    Case "HE_111H6"
      Call HE_111H6LOut(Combo)
    Case "IAR_80"
      Call IAR_80LOut(Combo)
    Case "IAR_81A"
      Call IAR_81ALOut(Combo)
    Case "IAR_81C"
      Call IAR_81CLOut(Combo)
    Case "JU_87B2"
      Call JU_87B2LOut(Combo)
    Case "JU_87D3"
      Call JU_87D3LOut(Combo)
    Case "JU_87D5"
      Call JU_87D5LOut(Combo)
    Case "JU_87G1"
      Call JU_87G1LOut(Combo)
    Case "KI_43_IA"
      Call KI_43_IALOut(Combo)
    Case "KI_43_IA"
      Call KI_43_IALOut(Combo)
    Case "KI_43_IB"
      Call KI_43_IBLOut(Combo)
    Case "KI_43_IC"
      Call KI_43_ICLOut(Combo)
    Case "KI_43_II"
      Call KI_43_IILOut(Combo)
    Case "KI_43_IIKAI"
      Call KI_43_IIKAILOut(Combo)
    Case "KI_46_OTSU"
      Call KI_46_OTSULOut(Combo)
    Case "KI_46_OTSUHEI"
      Call KI_46_OTSUHEILOut(Combo)
    Case "KI_46_RECCE"
      Call KI_46_RECCELOut(Combo)
    Case "KI_61_IKO"
      Call KI_61_IKOLOut(Combo)
    Case "KI_61_IHEI"
      Call KI_61_IHEILOut(Combo)
    Case "KI_61_IOTSU"
      Call KI_61_IOTSULOut(Combo)
    Case "KI_84_IA"
      Call KI_84_IALOut(Combo)
    Case "KI_84_IB"
      Call KI_84_IBLOut(Combo)
    Case "KI_84_IC"
      Call KI_84_ICLOut(Combo)
    Case "ME_262A1A"
      Call ME_262A1ALOut(Combo)
    Case "ME_262A1AU4"
      Call ME_262A1AU4LOut(Combo)
    Case "ME_262A2A"
      Call ME_262A2ALOut(Combo)
    Case "TA_152H1"
      Call TA_152H1LOut(Combo)
     
'Start Non Flyable List
    Case "B_17D"
      Call B_17DLOut(Combo)
    Case "B_17E"
      Call B_17ELOut(Combo)
    Case "B_17F"
      Call B_17FLOut(Combo)
    Case "B_17G"
      Call B_17GLOut(Combo)
    Case "B_24J100"
      Call B_24J100LOut(Combo)
    Case "B_25C25"
      Call B_25C25LOut(Combo)
    Case "B_25G1"
      Call B_25G1LOut(Combo)
    Case "B_25H1"
      Call B_25H1LOut(Combo)
    Case "B_25J1"
      Call B_25J1LOut(Combo)
    Case "C_47"
      Call C_47LOut(Combo)
    Case "D3A1"
      Call D3A1LOut(Combo)
    Case "F2A2"
      Call F2A2LOut(Combo)
    Case "IL_4_IL4"
      Call IL_4_IL4LOut(Combo)
    Case "IL_4_DB3B"
      Call IL_4_DB3BLOut(Combo)
    Case "IL_4_DB3M"
      Call IL_4_DB3MLOut(Combo)
    Case "IL_4_DB3T"
      Call IL_4_DB3TLOut(Combo)
    Case "IL_4_DB3F"
      Call IL_4_DB3FLOut(Combo)
    Case "G_11"
      Call G_11LOut(Combo)
    Case "L2D"
      Call L2DLOut(Combo)
    Case "LI_2"
      Call LI_2LOut(Combo)
    Case "MBR_2AM34"
      Call MBR_2AM34LOut(Combo)
    Case "P_36A3"
      Call P_36A3LOut(Combo)
    Case "P_36A4"
      Call P_36A4LOut(Combo)
    Case "PBN1"
      Call PBN1LOut(Combo)
    Case "PE_2SERIES1"
      Call PE_2SERIES1LOut(Combo)
    Case "PE_2SERIES84"
      Call PE_2SERIES84LOut(Combo)
    Case "PE_2SERIES110"
      Call PE_2SERIES110LOut(Combo)
    Case "PE_2SERIES359"
      Call PE_2SERIES359LOut(Combo)
    Case "PE_3SERIES1"
      Call PE_3SERIES1LOut(Combo)
    Case "PE_3BIS"
      Call PE_3BISLOut(Combo)
    Case "PE_8"
      Call PE_8LOut(Combo)
    Case "P_51D20NA"
      Call P_51D20NALOut(Combo)
    Case "R_10"
      Call R_10LOut(Combo)
    Case "SB_2M100A"
      Call SB_2M100ALOut(Combo)
    Case "SB_2M103"
      Call SB_2M103LOut(Combo)
    Case "SU_2"
      Call SU_2LOut(Combo)
    Case "TBF1"
      Call TBF1LOut(Combo)
    Case "TBM3"
      Call TBM3LOut(Combo)
    Case "TBF1C"
      Call TBF1CLOut(Combo)
    Case "TBM3AVENGER3"
      Call TBM3AVENGER3LOut(Combo)
    Case "TU_2S"
      Call TU_2SLOut(Combo)
    Case "U_2VS"
      Call U_2VSLOut(Combo)
    Case "AR_196A3"
      Call AR_196A3LOut(Combo)
    Case "BF_110C4"
      Call BF_110C4LOut(Combo)
    Case "BF_110C4B"
      Call BF_110C4BLOut(Combo)
    Case "BF_110G2"
      Call BF_110G2LOut(Combo)
    Case "BLENHEIM1"
      Call BLENHEIM1LOut(Combo)
    Case "BLENHEIM4"
      Call BLENHEIM4LOut(Combo)
    Case "FI_156"
      Call FI_156LOut(Combo)
    Case "FW_189A2"
      Call FW_189A2LOut(Combo)
    Case "FW_200C3U4"
      Call FW_200C3U4LOut(Combo)
    Case "G4M1_11"
      Call G4M1_11LOut(Combo)
    Case "G50"
      Call G50LOut(Combo)
    Case "H8K1"
      Call H8K1LOut(Combo)
    Case "HE_111Z"
      Call HE_111ZLOut(Combo)
    Case "HE_162A2"
      Call HE_162A2LOut(Combo)
    Case "HS_129B2"
      Call HS_129B2LOut(Combo)
    Case "HS_129B3Wa"
      Call HS_129B3WaLOut(Combo)
    Case "J2M3"
      Call J2M3LOut(Combo)
    Case "JU_52_3MG4E"
      Call JU_52_3MG4ELOut(Combo)
    Case "JU_52_3MG5E"
      Call JU_52_3MG5ELOut(Combo)
    Case "JU_88A4"
      Call JU_88A4LOut(Combo)
    Case "MC_202"
      Call MC_202LOut(Combo)
    Case "ME_210CA1"
      Call ME_210CA1LOut(Combo)
    Case "ME_210CA1ZSTR"
      Call ME_210CA1ZSTRLOut(Combo)
    Case "ME_321"
      Call ME_321LOut(Combo)
    Case "ME_323"
      Call ME_323LOut(Combo)
    Case "N1K1J"
      Call N1K1JLOut(Combo)
    Case "N1K1JA"
      Call N1K1JALOut(Combo)
    Case "MS406"
      Call MS406LOut(Combo)
    Case "MS410"
      Call MS410LOut(Combo)
    Case "MSMORKO"
      Call MSMORKOLOut(Combo)
    Case "YAK_9TALBERT"
      Call YAK_9TALBERTLOut(Combo)
    Case "I_16TYPE24SAFONOV"
      Call I_16TYPE24SAFONOVLOut(Combo)
    Case "MIG_3POKRYSHKIN"
      Call MIG_3POKRYSHKINLOut(Combo)
    Case "P_39NPOKRYSHKIN"
      Call P_39NPOKRYSHKINLOut(Combo)
    Case "P_39Q15RECHKALOV"
      Call P_39Q15RECHKALOVLOut(Combo)
    Case "LA_7KOJEDUB"
      Call LA_7KOJEDUBLOut(Combo)
    Case "BF_109G6GRAF"
      Call BF_109G6GRAFLOut(Combo)
    Case "BF_109G6HARTMANN"
      Call BF_109G6HARTMANNLOut(Combo)
    Case "JU_87G2RUDEL"
      Call JU_87G2RUDELLOut(Combo)
    Case "BF_109G6HEPPES"
      Call BF_109G6HEPPESLOut(Combo)
    Case "BF_109G6KOVACS"
      Call BF_109G6KOVACSLOut(Combo)
    Case "BF_109G6MOLNAR"
      Call BF_109G6MOLNARLOut(Combo)
    Case "BF_109G10FABIAN"
      Call BF_109G10FABIANLOut(Combo)
     Case "ME_262A1ANOWOTNY"
      Call ME_262A1ANOWOTNYLOut(Combo)
  End Select
End Sub


As you can see from this long procedure, the aircraft type is examined via the “Select Case” statement and when the matching aircraft type is found it then calls an individual aircraft weapons procedure with the combo box being passed through as an argument. Lets just say for arguments sake that the aircraft the user has selected was the A-20, then the “A_20GLOut” procedure would be called and would populate the combo box with the appropriate list of weapons. In this case the “cboWeapons” combo box control has been passed as the argument and so this is the list that will be populated will the list as below.

Code: Select all
Public Sub A_20GLOut(Combo As ComboBox)
  Combo.Clear
  Combo.AddItem "default"
  Combo.AddItem "40xParaF"
  Combo.AddItem "2x100"
  Combo.AddItem "2x1008x100"
  Combo.AddItem "2x1008x1002x100"
  Combo.AddItem "2x3004x300"
  Combo.AddItem "2x3004x3002x100"
  Combo.AddItem "2x500"
  Combo.AddItem "2x5008x100"
  Combo.AddItem "2x5004x300"
  Combo.AddItem "2x5002x500"
  Combo.AddItem "1x1000"
  Combo.AddItem "1x10008x100"
  Combo.AddItem "1x10004x300"
  Combo.AddItem "1x10002x500"
  Combo.AddItem "1xmk13"
  Combo.AddItem "none"
End Sub


This whole sequence is firstly invoked by the “lstFlightGrps_Click” as shown below

Code: Select all
Private Sub lstFlightGrps_Click()
  Dim CurPlane As String
  If lstFlightGrps.List(lstFlightGrps.ListIndex) = PlyrGrp Then
    lblSelGrp.Caption = "Player Group Selected"
    btnFlyInGrp.Enabled = False
    TabPlanes.TabEnabled(1) = False
    cboPosition.Enabled = True
  Else
    lblSelGrp.Caption = "AI Group Selected"
    TabPlanes.TabEnabled(1) = True
    If Not PlyrGrp = "" Then
      btnFlyInGrp.Enabled = True
    End If
    cboPosition.Enabled = False
  End If
  ActiveGrpIndex = GetGrpIndex(lstFlightGrps.Text)
  ActiveGrpWayIndex = GetGrpWayIndex(lstFlightGrps.Text)
  lblSelGrp.Visible = True
  CurPlane = GetPlaneType(lstFlightGrps.Text)
  If IsFlyable(CurPlane) Then
    TabPlanes.Tab = 0
    cboPlaneFly.Text = CurPlane
  Else
    TabPlanes.Tab = 1
    btnFlyInGrp.Enabled = False
    cboPlaneNonFly.Text = CurPlane
  End If
  CurPlaneQty = GetPlaneQty(lstFlightGrps.Text)
  cboPlaneQty.Text = CurPlaneQty
  cboFuel.Text = GetFuel(lstFlightGrps.Text)
  If TabPlanes.Tab = 0 Then
    Call SortLoadOuts(cboWeapons, cboPlaneFly.Text)
    cboWeapons.ListIndex = 0
  Else
    Call SortLoadOuts(cboWeapons, cboPlaneNonFly.Text)
    cboWeapons.ListIndex = 0
  End If
  cboWeapons.Text = GetWeapons(lstFlightGrps.Text)
  lstWayPoints.Clear
  Call WaypointsList(lstFlightGrps.Text)
End Sub


The relevant code above to the weapons list loading is shown below

Code: Select all
 
  If IsFlyable(CurPlane) Then
    TabPlanes.Tab = 0
    cboPlaneFly.Text = CurPlane
  Else
    TabPlanes.Tab = 1
    btnFlyInGrp.Enabled = False
    cboPlaneNonFly.Text = CurPlane
  End If


Here the lines “cboPlaneFly.Text = CurPlane” and "cboPlaneNonFly.Text = CurPlane" which displays the current flight groups plane type.

Also note the relevance with the code:

Code: Select all
 
  If TabPlanes.Tab = 0 Then
    Call SortLoadOuts(cboWeapons, cboPlaneFly.Text)
    cboWeapons.ListIndex = 0
  Else
    Call SortLoadOuts(cboWeapons, cboPlaneNonFly.Text)
    cboWeapons.ListIndex = 0
  End If


This code is used in sevaral places within project and prepares the available weapons selection for each aircraft type.

With the weapons list populated with the correct weapons options, the weapons currently set for that flight group are displayed to the user with the user defined function “GetWeapons” with the line code below:

Code: Select all
“cboWeapons.Text = GetWeapons(lstFlightGrps.Text)”


This function is exactly the same in principle as the ones that get the fuel, plane type, plane qty etc… except with this procedure of course the code is looking for weapons identification. The line in the mission file that this function would isolate would look something like this:

“ weapons 2x5008x100”
The “GetWeapons” function would return the “2x5008x100” portion.

Setting player position in flight group.

Next we look at setting what position the user may wish to occupy in the player flight group. This is controlled primarily by the “cboPlaneQty” controls click event. Lets look at the code:

Code: Select all
Private Sub cboPlaneQty_Click()
  If lstFlightGrps.List(lstFlightGrps.ListIndex) = PlyrGrp Then
    Call PopPosition
    CurPlyrPos = GetCurPosition
    If CurPlyrPos > cboPlaneQty.ListIndex Then
      MsgBox "The current player position in the mission file is set at " + CStr(CurPlyrPos + 1) + _
      " which exceeds the number of planes you are trying to set for this flight group. To reduce " + _
      "the quantity of planes you must first change and apply the current flight position." + Chr(13) + Chr(13) + _
      "The editor is returning to the previous selected values.", vbExclamation + vbOKOnly, "Flight Position Exceeds Plane Qunatity."
      cboPlaneQty.Text = CurPlaneQty
    Else
      cboPosition.ListIndex = CurPlyrPos
    End If
  End If
End Sub


“Call PopPosition” is the first line of code and is a user defined procedure as described below:

Code: Select all
Public Sub PopPosition()
  cboPosition.Clear
  cboPosition.AddItem "1"
  If cboPlaneQty.ListIndex > 0 Then
    cboPosition.AddItem "2"
  End If
  If cboPlaneQty.ListIndex > 1 Then
    cboPosition.AddItem "3"
  End If
  If cboPlaneQty.ListIndex > 2 Then
    cboPosition.AddItem "4"
  End If
End Sub


What this is doing is populating the “cboPosition” control with only the available positions that the user may select from based on the quantity of plane in that group. This has to be done each time a different flight group is selected, because there is no way to tell how many planes will be in each flight group until the editor takes a look at the selected flight groups plane quantity. If the code simply populated the “cboPosition” control with the option of 4 flight positions and the user selected position 4 but there were only 3 planes in that flight group, there would of course be and error. Also note that the “cboPosition” control is only enabled when the player flight group is selected.

One point to note before we conclude the tutorial is that with new P-40 series of aircraft that came with Pacific Fighters (P-40’B and C’s and Hawk 81-A2) use long confusing type plane codes in the mission files such as

“P_40SUKAISVOLOCHB”
“P_40SUKAISVOLOCH2A”

and so on. In this case instead of using direct plane codes into the plane lists, I have created 2 functions to convert the codes into something more identifiable to be displayed to the user . One function converts the plane codes from the mission file into the identifiable description and the other converts the identifiable description back into the plane code required for the mission file. The functions are as shown below:

Code: Select all
Public Function GetPlaneCode(PlaneName As String) As String
  Select Case PlaneName
    Case "Hawk81A-2"
      GetPlaneCode = "P_40SUKAISVOLOCHHAWKA2"
    Case "P_40B"
      GetPlaneCode = "P_40SUKAISVOLOCHB"
    Case "P_40C"
      GetPlaneCode = "P_40SUKAISVOLOCHC"
    Case "TomahawkMkIIa"
      GetPlaneCode = "P_40SUKAISVOLOCH2A"
    Case "TomahawkMkIIb"
      GetPlaneCode = "P_40SUKAISVOLOCH2B"
    Case Else
      GetPlaneCode = PlaneName
  End Select
End Function

Public Function ConvertPlaneCode(PlaneName As String) As String
  Select Case PlaneName
    Case "P_40SUKAISVOLOCHHAWKA2"
      ConvertPlaneCode = "Hawk81A-2"
    Case "P_40SUKAISVOLOCHB"
      ConvertPlaneCode = "P_40B"
    Case "P_40SUKAISVOLOCHC"
      ConvertPlaneCode = "P_40C"
    Case "P_40SUKAISVOLOCH2A"
      ConvertPlaneCode = "TomahawkMkIIa"
    Case "P_40SUKAISVOLOCH2B"
      ConvertPlaneCode = "TomahawkMkIIb"
    Case Else
      ConvertPlaneCode = PlaneName
  End Select
End Function


Here we see that the “ConvertPlaneCode” function uses the plane type as an argument and from that returns the new description. So instead of "P_40SUKAISVOLOCHHAWKA2" being displayed to the user, the user will see "Hawk81A-2" and description that is more quickly identifiable. Then the “GetPlaneCode” function performs the reverse so that the correct codes may be written back down to the mission file.
With these 2 functions you could of course expand them to perhaps include your own naming conventions for aircraft or perhaps allow the user to define their own naming conventions, save them to file and read them back into the editor each time on start up. This would improve the feel of selecting aircraft quite a bit for the user I think.

Final point to note:
In this tutorial the combo box controls have been left with the “Style” property set to “0 - Dropdown Combo” this is because the plane lists are not complete (for example the Mistel is not accounted for) and this allows any value to be introduced to the combo box control without causing an error. The down side to this, is that the user may type in a value that is totally inappropriate and cause and error when attempting to run the mission. Where ever possible I recommend setting the “Style” property to “2 - Dropdown List” which only allows the user to select from a predefined list and cannot type in any value at all. The down side to this is that if the combo box tries to receive a value that is not in the list it will cause an error and crash the programme if there is no error handling in place. I recommend managing the “2 - Dropdown List” value with error handling and remove the chance of the user typing something stupid into the control. However for this tutorial to keep it simple I have left these controls at “0 - Dropdown Combo”

Ok then that’s it for the tutorial. I do sincerely hope that you have enjoyed it and gained some knowledge along the way. I also hope to see one of your utilities doing the rounds in the IL-2 community sometime in the future.

Please download the project files from the link below.
http://airwarfare.com/AWX/Files/cs/VB%20Editor%20Lesson%204.zip

Happy coding, CrazySchmidt. :)
User avatar
CrazySchmidt
Utilities Developer
 
Posts: 358
Joined: Wed Dec 08, 2004 1:59 am
Location: Auckland, New Zealand

Postby 4Shades on Sun Jan 30, 2005 2:18 pm

Excellent! :D
4Shades
Air Cadet Level 2
 
Posts: 13
Joined: Thu Dec 16, 2004 10:42 am


Return to Developers Central

Who is online

Users browsing this forum: No registered users and 1 guest

cron