From b5580a7182c148e0e6b7f25c56a84536b2b94a94 Mon Sep 17 00:00:00 2001 From: bm98 Date: Sun, 14 May 2017 19:13:54 +0200 Subject: [PATCH] V 2.30 - BETA Build 64 - second commit - add - addbind of Mouse input is possible for Keyboard actions - seems to work somehow in the game... - fixes and refacturing while encountered... --- FormMain.cs | 22 +++++++++--- Options/Tuningoptions.cs | 8 +++-- actions/ActionTree.cs | 71 ++++++++++++++++++++++++++++++++++----- actions/ActionTreeNode.cs | 15 ++++++++- doc/ReadMe.txt | 4 ++- 5 files changed, 102 insertions(+), 18 deletions(-) diff --git a/FormMain.cs b/FormMain.cs index 1247ec6..9db4c8c 100644 --- a/FormMain.cs +++ b/FormMain.cs @@ -130,6 +130,13 @@ namespace SCJMapper_V2 } } + private void UpdateDDMapping(string mapName ) + { + tsDDbtMappings.Text = mapName; + m_AppSettings.DefMappingName = mapName; m_AppSettings.Save( ); + } + + #endregion #region Main Form Handling @@ -229,8 +236,7 @@ namespace SCJMapper_V2 SetRebindField( txMappingName.Text ); foreach ( ToolStripDropDownItem d in tsDDbtMappings.DropDownItems ) { if ( d.Text == txMappingName.Text ) { - tsDDbtMappings.Text = txMappingName.Text; - m_AppSettings.DefMappingName = txMappingName.Text; m_AppSettings.Save( ); // update if it exists + UpdateDDMapping( txMappingName.Text ); break; } } @@ -391,8 +397,14 @@ namespace SCJMapper_V2 log.Debug( "InitActionTree - Entry" ); // build TreeView and the ActionMaps - if ( m_AT != null ) m_AT.NodeSelectedEvent -= M_AT_NodeSelectedEvent; // disconnect the Event + if ( m_AT != null ) { + m_AT.NodeSelectedEvent -= M_AT_NodeSelectedEvent; // disconnect the Event + m_AT.Dispose( ); + } + m_AT = new ActionTree( ); + log.DebugFormat( "InitActionTree - New AT: {0}", m_AT.GetHashCode().ToString() ); + m_AT.NodeSelectedEvent += M_AT_NodeSelectedEvent; // connect the Event m_AT.Ctrl = treeView1; // the ActionTree owns the TreeView control @@ -879,8 +891,7 @@ namespace SCJMapper_V2 private void tsDDbtMappings_DropDownItemClicked( object sender, ToolStripItemClickedEventArgs e ) { - tsDDbtMappings.Text = e.ClickedItem.Text; - m_AppSettings.DefMappingName = e.ClickedItem.Text; m_AppSettings.Save( ); + UpdateDDMapping( e.ClickedItem.Text ); } @@ -1162,6 +1173,7 @@ namespace SCJMapper_V2 // get the new one into the list LoadMappingDD( ); + UpdateDDMapping( txMappingName.Text ); m_AppSettings.MyMappingName = txMappingName.Text; m_AppSettings.Save( );// last used - persist txMappingName.BackColor = MyColors.SuccessColor; } diff --git a/Options/Tuningoptions.cs b/Options/Tuningoptions.cs index 0f0f90e..d719ac6 100644 --- a/Options/Tuningoptions.cs +++ b/Options/Tuningoptions.cs @@ -340,13 +340,17 @@ namespace SCJMapper_V2.Options this[toID].fromXML( xml ); } else { - log.InfoFormat( "Read XML Options - instance {0} is not available - dropped this content", nInstance ); + log.InfoFormat( "Read XML Options - joystick instance {0} is not available - dropped this content", nInstance ); } } else if ( type.ToLowerInvariant( ) == "xboxpad" ) { string toID = TuneOptionID( GamepadCls.DeviceClass, nInstance ); - if ( this.ContainsKey( toID ) ) // 20170513: bugfix if gamepad is in the XML but not connected right now - ignore + if ( this.ContainsKey( toID ) ) {// 20170513: bugfix if gamepad is in the XML but not connected right now - ignore this[toID].fromXML( xml ); + } + else { + log.InfoFormat( "Read XML Options - xboxpad instance {0} is not available - dropped this content", nInstance ); + } } } diff --git a/actions/ActionTree.cs b/actions/ActionTree.cs index b0c0bf7..833af2c 100644 --- a/actions/ActionTree.cs +++ b/actions/ActionTree.cs @@ -100,6 +100,7 @@ namespace SCJMapper_V2 /// public ActionTree() { + log.DebugFormat( "ctor - Entry {0}", m_MasterTree.GetHashCode( ).ToString( ) ); IgnoreMaps = ""; // nothing to ignore } @@ -110,6 +111,7 @@ namespace SCJMapper_V2 if ( m_MasterTree != null ) m_MasterTree.Dispose( ); } // free native resources + m_tvCtrlRef.AfterSelect -= M_ctrl_AfterSelect; } public void Dispose() @@ -152,11 +154,14 @@ namespace SCJMapper_V2 } } + /// + /// Returns true if a binding can be cleared + /// public bool CanClearBinding { get { if ( Ctrl.SelectedNode == null ) return false; - else return ( Ctrl.SelectedNode.Level == 1 ) && IsMappedAction; + else return ( ( Ctrl.SelectedNode.Level == 1 ) && (IsMappedAction || IsDisabledAction)) ; } } @@ -177,6 +182,9 @@ namespace SCJMapper_V2 } } + /// + /// Returns true if the action is mapped + /// public bool IsMappedAction { get { @@ -188,6 +196,20 @@ namespace SCJMapper_V2 } } + /// + /// Returns true if the action is disabled + /// + public bool IsDisabledAction + { + get { + if ( ( Ctrl.SelectedNode.Level == 0 ) || ( Ctrl.SelectedNode.Level > 2 ) ) return false; // not on node + if ( Ctrl.SelectedNode == null ) return false; // no node selected + if ( Ctrl.SelectedNode.Parent == null ) return false; // ERROR EXIT + + return ( Ctrl.SelectedNode as ActionTreeNode ).IsDisabledAction; + } + } + public bool ShowAction( ActionCls.ActionDevice actDev, string input ) { @@ -291,6 +313,7 @@ namespace SCJMapper_V2 private void UpdateMasterNode( ActionTreeInputNode node ) { + log.DebugFormat( "UpdateMasterNode - Entry {0}", m_MasterTree.GetHashCode( ).ToString( ) ); // copy to master node TreeNode[] masterNode = m_MasterTree.Nodes.Find( node.Name, true ); // find the same node in master if ( masterNode.Length == 0 ) throw new IndexOutOfRangeException( "ActionTree ERROR - cannot find synched node in master" ); // OUT OF SYNC @@ -310,6 +333,7 @@ namespace SCJMapper_V2 /// The sought node or null private ActionTreeNode FindMasterAction( ActionTreeNode atn ) { + log.DebugFormat( "FindMasterAction(ActionTreeNode) - Entry {0}", m_MasterTree.GetHashCode( ).ToString( ) ); if ( atn.Level != 1 ) return null; // sanity TreeNode[] masterNode = m_MasterTree.Nodes.Find( atn.Name, true ); // find the same node in master @@ -323,6 +347,27 @@ namespace SCJMapper_V2 return null; } + /// + /// Find the master element for the given ActionTreeInputNode + /// + /// The ActionTreeInputNode to find + /// The sought node or null + private ActionTreeInputNode FindMasterAction( ActionTreeInputNode atn ) + { + log.DebugFormat( "FindMasterAction(ActionTreeInputNode) - Entry {0}", m_MasterTree.GetHashCode().ToString() ); + if ( atn.Level != 2 ) return null; // sanity + + TreeNode[] masterNode = m_MasterTree.Nodes.Find( atn.Name, true ); // find the same node in master + if ( masterNode.Length == 0 ) throw new IndexOutOfRangeException( "ActionTree ERROR - cannot find synched node in master" ); // OUT OF SYNC + // could return more than one if the action is the same in different actionmaps + foreach ( ActionTreeInputNode mtn in masterNode ) { + if ( mtn.Parent.Name == atn.Parent.Name ) { + return mtn; + } + } + return null; + } + /// @@ -666,10 +711,17 @@ namespace SCJMapper_V2 if ( string.IsNullOrEmpty( input ) ) atn.Action = "UNDEF"; // apply UNDEF else - atn.Action = ""; // remove UNDEF + atn.Action = patn.Action; // apply the parent Action ActionCls ac = FindActionObject( patn.Parent.Name, patn.Name ); // the related action in an actionmap if ( ac == null ) return false; // ERROR exit - if ( checkKind && ( ac.actionDevice != inKind ) ) return false; // ERROR exit + if ( checkKind ) { + if (ac.actionDevice == ActionCls.ActionDevice.AD_Keyboard ) { + if (( inKind != ActionCls.ActionDevice.AD_Keyboard ) && (inKind != ActionCls.ActionDevice.AD_Mouse)) return false; // ERROR exit + } + else { + if ( ac.actionDevice != inKind ) return false; // ERROR exit + } + } ActionCommandCls acc = ac.FindActionInputObject( atn.Index ); if ( acc == null ) return false; // ERROR exit // have it - continue @@ -772,7 +824,7 @@ namespace SCJMapper_V2 /// public void ReloadTreeView() { - log.Debug( "ReloadTreeView - Entry" ); + log.DebugFormat( "ReloadTreeView - Entry {0}", m_MasterTree.GetHashCode().ToString() ); foreach ( ActionMapCls acm in ActionMaps ) { if ( IgnoreMaps.Contains( "," + acm.name + "," ) ) break; // next @@ -794,7 +846,9 @@ namespace SCJMapper_V2 } else { // have to recreate the action child nodes - ActionTreeInputNode matin = new ActionTreeInputNode( "UNDEF" ); matin.ImageKey = "Add"; + //ActionTreeInputNode matin = new ActionTreeInputNode( "UNDEF" ); matin.ImageKey = "Add"; + ActionTreeInputNode matin = new ActionTreeInputNode( ac.name ); matin.ImageKey = "Add"; + matin.Name = matn.Name + "_" + matin.Index; // unique name needed acc.NodeIndex = matin.Index; // assign visual reference matn.Nodes.Add( matin ); // add to master tree matin.UpdateAction( acc ); UpdateMasterNode( matin ); @@ -802,12 +856,11 @@ namespace SCJMapper_V2 } catch { ; // key not found } - NodeSelected( this.SelectedAction, this.SelectedCtrl ); Dirty = true; } // foreach } - } catch { - ; // map key not found ?? + } catch (Exception e) { + log.DebugFormat( "ReloadTreeView - Exception in loading Treevie\n{0}", e.Message ); // map key not found ?? } } @@ -1061,7 +1114,7 @@ namespace SCJMapper_V2 return ActionTreeNode.CommandFromNodeText( matn.Text ); } else if ( Ctrl.SelectedNode.Level == 2 ) { - ActionTreeNode matn = FindMasterAction( (ActionTreeNode)Ctrl.SelectedNode.Parent ); // the parent treenode + ActionTreeNode matn = FindMasterAction( (ActionTreeInputNode)Ctrl.SelectedNode ); // the parent treenode return ActionTreeNode.CommandFromNodeText( matn.Text ); } else return ""; diff --git a/actions/ActionTreeNode.cs b/actions/ActionTreeNode.cs index 12316b6..c1ed1a3 100644 --- a/actions/ActionTreeNode.cs +++ b/actions/ActionTreeNode.cs @@ -173,7 +173,7 @@ namespace SCJMapper_V2 else { // mapped ( regular ones ) this.Command = actionCmd.DevInput; - if ( this.Level == 2 ) this.Action = ""; // remove UNDEF - 20160525 fix addbind not showing UNDEF if assigned + //if ( this.Level == 2 ) this.Action = ""; // remove UNDEF - 20160525 fix addbind not showing UNDEF if assigned // background is along the input this.BackColor = ActionCls.DeviceColor( actionCmd.DevInput ); } @@ -253,6 +253,9 @@ namespace SCJMapper_V2 get { return ( m_actionDevice == ActionCls.ActionDevice.AD_Mouse ); } } + /// + /// Returns true if the action is mapped + /// public Boolean IsMappedAction { get { @@ -260,6 +263,16 @@ namespace SCJMapper_V2 } } + /// + /// Returns true if the action is disabled + /// + public Boolean IsDisabledAction + { + get { + return ActionCls.IsBlendedInput( m_command ); + } + } + } } diff --git a/doc/ReadMe.txt b/doc/ReadMe.txt index f4eafe6..777d938 100644 --- a/doc/ReadMe.txt +++ b/doc/ReadMe.txt @@ -1,5 +1,5 @@ SC Joystick Mapper V 2.30 - Build 64 BETA -(c) Cassini, StandardToaster - 13-May-2017 +(c) Cassini, StandardToaster - 14-May-2017 Contains 9 files: @@ -32,8 +32,10 @@ Changelog: V 2.30 - BETA Build 64 - add - Tab to show all mappings for the current input (Tabbed with XML other Dump items) - add - Setting (enabled, disabled -> default) to automatically switch the new tabs - either Input or Dump +- add - addbind of Mouse input is possible for Keyboard actions - seems to work somehow in the game... - fix - issue with user activations modes while dumping the mapping list - fix - issue with loading a map with gamepad mappings and the gamepad is not connected +- fixes and refacturing while encountered... - update - doc SCJMapper_QGuide V2.30beta.pdf Changelog: V 2.29 - BETA Build 63