@@ -53,7 +53,7 @@ class DeviceFile
5353 public List < string > SupportedPidVid {
5454 get {
5555 List < string > ret = new List < string > ( ) ;
56- foreach ( var id in InputDevices ) {
56+ foreach ( var id in InputDevices ) {
5757 ret . AddRange ( id . DevicePIDVID ) ;
5858 }
5959 return ret ;
@@ -63,13 +63,24 @@ public List<string> SupportedPidVid {
6363 /// <summary>
6464 /// Create all possible ShapeItems for this Mapping File
6565 /// </summary>
66- public void CreateShapes ( )
66+ public void CreateShapes ( )
6767 {
6868 for ( int i = 0 ; i < InputDevices . Count ; i ++ ) {
6969 InputDevices [ i ] . CreateShapes ( ) ;
7070 }
7171 }
7272
73+ /// <summary>
74+ /// Create all possible KeyLabels when the controls requires it
75+ /// </summary>
76+ /// <param name="dList">A Display List</param>
77+ public void LoadKeyLabels ( DisplayList dList )
78+ {
79+ for ( int i = 0 ; i < InputDevices . Count ; i ++ ) {
80+ InputDevices [ i ] . LoadKeyLabels ( dList ) ;
81+ }
82+ }
83+
7384 /// <summary>
7485 /// Find a Control entry with the given product guid and input command
7586 /// </summary>
@@ -101,7 +112,7 @@ public Control FindItem( string pidVid, string input, bool firstInstance )
101112 /// Get all devices with Name (only first GUID is returned)
102113 /// </summary>
103114 /// <returns></returns>
104- public List < Device . DeviceDescriptor > Devices ( )
115+ public List < Device . DeviceDescriptor > Devices ( )
105116 {
106117 var ret = new List < Device . DeviceDescriptor > ( ) ;
107118 for ( int i = 0 ; i < InputDevices . Count ; i ++ ) {
@@ -127,21 +138,26 @@ class Device
127138 [ DataMember ( Name = "DeviceName" , IsRequired = true ) ]
128139 public string DeviceName { get ; set ; } // The device name
129140
130- [ DataMember ( Name = "DeviceProdGuid" , IsRequired = true ) ]
141+ [ DataMember ( Name = "DeviceProdGuid" , IsRequired = true ) ]
131142 private List < string > DeviceProdGuid_ { get ; set ; } = new List < string > ( ) ; // The device product GUIDs as read by DirectInput
132143
133- [ DataMember ( Name = "Controls" ) ]
144+ [ DataMember ( Name = "Controls" ) ]
134145 public List < Control > Controls { get ; set ; } = new List < Control > ( ) ; // The list of Controls supported (see below)
135146
136147 // non Json
137148
149+ public bool IsInputType_Joystick => InputTypeLetter == "J" ;
150+ public bool IsInputType_Gamepad => InputTypeLetter == "G" ;
151+ public bool IsInputType_Mouse => InputTypeLetter == "M" ;
152+ public bool IsInputType_Kbd => InputTypeLetter == "K" ;
153+ public bool IsInputType_Kbd_Keys => InputTypeLetter == "X" ;
154+
138155
139156 private Font m_deviceFont = null ;
140157 /// <summary>
141158 /// Get the base font for this device
142159 /// </summary>
143- public Font DeviceFont
144- {
160+ public Font DeviceFont {
145161 get {
146162 if ( ! string . IsNullOrEmpty ( FontFamily ) ) {
147163 return m_deviceFont ;
@@ -158,23 +174,21 @@ public class DeviceDescriptor
158174 {
159175 public string DevGuid { get ; set ; } = "" ;
160176 public string DevName { get ; set ; } = "" ;
161- public override string ToString ( )
177+ public override string ToString ( )
162178 {
163179 return DevName ;
164180 }
165181 }
166182
167- public DeviceDescriptor DevDescriptor
168- {
183+ public DeviceDescriptor DevDescriptor {
169184 get {
170- return new DeviceDescriptor ( ) { DevGuid = DeviceProdGuid_ [ 0 ] . ToLowerInvariant ( ) , DevName = DeviceName } ;
185+ return new DeviceDescriptor ( ) { DevGuid = DeviceProdGuid_ [ 0 ] . ToLowerInvariant ( ) , DevName = DeviceName } ;
171186 }
172187 }
173188
174189
175190 public string InputTypeLetter { get => InputType . Substring ( 0 , 1 ) ; }
176- public int InputTypeNumber
177- {
191+ public int InputTypeNumber {
178192 get {
179193 if ( InputType . Length > 1 ) {
180194 if ( int . TryParse ( InputType . Substring ( 1 ) , out int num ) ) {
@@ -188,8 +202,7 @@ public int InputTypeNumber
188202 /// <summary>
189203 /// returns the PID VID part of the GUID (seems how this is composed in Win)
190204 /// </summary>
191- public List < string > DevicePIDVID
192- {
205+ public List < string > DevicePIDVID {
193206 get {
194207 var ret = new List < string > ( ) ;
195208 foreach ( string s in DeviceProdGuid_ ) {
@@ -207,7 +220,7 @@ public List<string> DevicePIDVID
207220 private int m_kbdItemTracker = 0 ;
208221 /// <summary>
209222 /// Find a Control entry with the given input command
210- /// For Keyboards there is not an entry for every possible key - so return just the next one
223+ /// For Keyboards with drawn Keys there is not an entry for every possible key - so return just the next one
211224 /// </summary>
212225 /// <param name="input">the Item (device property)</param>
213226 /// <returns>The found Control or Null</returns>
@@ -219,8 +232,8 @@ public Control FindItem( string input )
219232 return Controls [ i ] ;
220233 }
221234 }
222- // if not - and Keyboard - assign a new one and tag it
223- if ( this . InputTypeLetter == "X" ) {
235+ // if not - and Keyboard with drawn Keys - assign a new one and tag it
236+ if ( this . IsInputType_Kbd_Keys ) {
224237 if ( Controls . Count > m_kbdItemTracker ) {
225238 int item = m_kbdItemTracker ++ ;
226239 Controls [ item ] . Input = input ; // mark to reuse
@@ -234,15 +247,25 @@ public Control FindItem( string input )
234247 /// <summary>
235248 /// Create all possible ShapeItems for this Device
236249 /// </summary>
237- public void CreateShapes ( )
250+ public void CreateShapes ( )
238251 {
239252 m_kbdItemTracker = 0 ; // reset
240253 if ( m_deviceFont != null ) m_deviceFont . Dispose ( ) ;
241254 if ( ! string . IsNullOrEmpty ( FontFamily ) ) {
242255 m_deviceFont = new Font ( FontFamily , MapProps . FontSize ) ; // create actual Font here
243256 }
244257 for ( int i = 0 ; i < Controls . Count ; i ++ ) {
245- Controls [ i ] . CreateShapes ( DeviceFont , this . InputTypeLetter == "X" ) ; // symbols only for X type maps (keyboard with Symbols)
258+ Controls [ i ] . CreateShapes ( DeviceFont , this . IsInputType_Kbd_Keys ) ; // symbols only for X type maps (keyboard with Symbols)
259+ }
260+ }
261+ /// <summary>
262+ /// Create all possible KeyLabels when the control requires it
263+ /// </summary>
264+ /// <param name="dList"></param>
265+ public void LoadKeyLabels ( DisplayList dList )
266+ {
267+ for ( int i = 0 ; i < Controls . Count ; i ++ ) {
268+ Controls [ i ] . LoadKeyLabels ( dList , this . IsInputType_Kbd_Keys ) ; // symbols only for X type maps (keyboard with Symbols)
246269 }
247270 }
248271
@@ -258,7 +281,7 @@ class Control
258281 public string Input { get ; set ; } = "" ; // buttonN, hatN_up,_right,_down,_left, [rot]xyz, sliderN (CryInput notification)
259282
260283 [ DataMember ( Name = "Type" ) ]
261- public string Type { get ; set ; } = "" ; // "" or Analog or Digital
284+ public string Type { get ; set ; } = "" ; // "" or Analog or Digital or Key
262285
263286 [ DataMember ( Name = "X" , IsRequired = true ) ]
264287 public int X { get ; set ; } = 0 ; // X label pos (left=0)
@@ -293,6 +316,8 @@ class Control
293316 /// </summary>
294317 public void CreateShapes ( Font deviceFontRef , bool useSymbol )
295318 {
319+ // define the number of Actionlabels to fit into the Control rectangle
320+
296321 // this is a bit messy...
297322 // have to allocate a number of Rectangles to draw into but the layout rects are very different in size..
298323 this . ShapeItems = new Queue < ShapeItem > ( ) ; // get rid of previous ones
@@ -312,22 +337,40 @@ public void CreateShapes( Font deviceFontRef, bool useSymbol )
312337 }
313338 baseHeight = ( int ) Math . Floor ( ( double ) Height / nLines ) ; // fill rectangle
314339
340+ // create as many shapes to hold action labels for this control
315341 bool symbol = useSymbol ;
342+ // create one to draw the whole key
343+ if ( this . Type == "Key" && useSymbol ) {
344+ // Type Keyboard with keys drawn
345+ var sh = new ShapeKey {
346+ X = this . X ,
347+ Y = this . Y ,
348+ Width = this . Width ,
349+ Height = this . Height / 2 ,
350+ IsSymbolShape = true ,
351+ TextFontRef = MapProps . KbdSymbolFont ,
352+ } ;
353+ ShapeItems . Enqueue ( sh ) ; // will only be drawn when used
354+ }
355+
316356 for ( int l = 0 ; l < nLines ; l ++ ) {
317357 for ( int c = 0 ; c < nCols ; c ++ ) {
318- if ( this . Type == "Key" ) {
358+
359+ if ( this . Type == "KeyS" ) {
360+ // Type Keyboard with keys drawn
319361 var sh = new ShapeKey {
320362 X = X + c * baseWidth ,
321363 Y = Y + l * baseHeight ,
322364 Width = baseWidth ,
323365 Height = baseHeight ,
324- IsSymbolShape = symbol ,
366+ IsSymbolShape = false ,
325367 TextFontRef = deviceFontRef
326368 } ;
327369 symbol = false ; // only once
328370 ShapeItems . Enqueue ( sh ) ;
329371 }
330372 else {
373+ // other types - create labels only
331374 var sh = new ShapeItem {
332375 X = X + c * baseWidth ,
333376 Y = Y + l * baseHeight ,
@@ -341,6 +384,27 @@ public void CreateShapes( Font deviceFontRef, bool useSymbol )
341384 }
342385 }
343386
387+ /// <summary>
388+ /// Load KeyLabels if required by the control and mode (not if using symbols though)
389+ /// </summary>
390+ /// <param name="dList">A display list to add them</param>
391+ /// <param name="useSymbol">Wether or not usin Key Symbols rather than a drawn map</param>
392+ public void LoadKeyLabels ( DisplayList dList , bool useSymbol )
393+ {
394+ if ( this . Type == "Key" && ! useSymbol ) {
395+ // Type Keyboard with keys drawn
396+ var sh = new ShapeKey {
397+ X = this . X ,
398+ Y = this . Y ,
399+ Width = this . Width ,
400+ Height = this . Height / 2 ,
401+ IsLabelShape = true ,
402+ DispText = "DUMMY" ,
403+ SCGameKey = this . Input ,
404+ } ;
405+ dList . Add ( sh ) ;
406+ }
344407
408+ }
345409 }
346410}
0 commit comments