11using avaness . PluginLoader . Compiler ;
22using avaness . PluginLoader . Config ;
3+ using avaness . PluginLoader . GUI ;
34using avaness . PluginLoader . Network ;
45using ProtoBuf ;
56using Sandbox . Graphics . GUI ;
@@ -61,6 +62,8 @@ public override bool LoadData(ref PluginDataConfig config, bool enabled)
6162 return true ;
6263 }
6364
65+ this . config = null ;
66+
6467 if ( config != null )
6568 {
6669 config = null ;
@@ -132,7 +135,7 @@ public override Assembly GetAssembly()
132135
133136 string dllFile = Path . Combine ( cacheDir , pluginFile ) ;
134137 string commitFile = Path . Combine ( cacheDir , commitHashFile ) ;
135- string selectedCommit = GetSelectedCommit ( ) ;
138+ string selectedCommit = GetSelectedVersion ( ) ? . Commit ?? Commit ;
136139 if ( ! File . Exists ( dllFile ) || ! File . Exists ( commitFile ) || File . ReadAllText ( commitFile ) != selectedCommit || Main . Instance . Config . GameVersionChanged )
137140 {
138141 var lbl = Main . Instance . Splash ;
@@ -153,14 +156,11 @@ public override Assembly GetAssembly()
153156 return a ;
154157 }
155158
156- private string GetSelectedCommit ( )
159+ private Branch GetSelectedVersion ( )
157160 {
158- if ( config == null || string . IsNullOrWhiteSpace ( config . SelectedVersion ) || AlternateVersions == null )
159- return Commit ;
160- Branch branch = AlternateVersions . FirstOrDefault ( x => x . Name . Equals ( config . SelectedVersion , StringComparison . OrdinalIgnoreCase ) ) ;
161- if ( branch == null )
162- return Commit ;
163- return branch . Commit ;
161+ if ( config == null || string . IsNullOrWhiteSpace ( config . SelectedVersion ) )
162+ return null ;
163+ return AlternateVersions ? . FirstOrDefault ( x => x . Name . Equals ( config . SelectedVersion , StringComparison . OrdinalIgnoreCase ) ) ;
164164 }
165165
166166 public byte [ ] CompileFromSource ( string commit , Action < float > callback = null )
@@ -236,6 +236,61 @@ public override void InvalidateCache()
236236 catch { }
237237 }
238238
239+ public override void AddDetailControls ( PluginDetailMenu screen , MyGuiControlBase bottomControl , out MyGuiControlBase topControl )
240+ {
241+ if ( AlternateVersions == null || AlternateVersions . Length == 0 )
242+ {
243+ topControl = null ;
244+ return ;
245+ }
246+
247+ string selectedCommit = GetSelectedVersion ( ) ? . Commit ?? Commit ;
248+ MyGuiControlCombobox versionDropdown = new MyGuiControlCombobox ( ) ;
249+ versionDropdown . AddItem ( - 1 , "Default" ) ;
250+ int selectedKey = - 1 ;
251+ for ( int i = 0 ; i < AlternateVersions . Length ; i ++ )
252+ {
253+ Branch version = AlternateVersions [ i ] ;
254+ versionDropdown . AddItem ( i , version . Name ) ;
255+ if ( version . Commit == selectedCommit )
256+ selectedKey = i ;
257+ }
258+ versionDropdown . SelectItemByKey ( selectedKey ) ;
259+ versionDropdown . ItemSelected += ( ) =>
260+ {
261+ PluginConfig mainConfig = Main . Instance . Config ;
262+
263+ int selectedKey = ( int ) versionDropdown . GetSelectedKey ( ) ;
264+ string newVersion = selectedKey >= 0 ? AlternateVersions [ selectedKey ] . Name : null ;
265+ string currentVersion = GetSelectedVersion ( ) ? . Name ;
266+ if ( currentVersion == newVersion )
267+ return ;
268+
269+ if ( config == null )
270+ {
271+ config = new GitHubPluginConfig ( )
272+ {
273+ Id = Id ,
274+ } ;
275+
276+ mainConfig . SavePluginData ( config ) ;
277+ }
278+
279+ config . SelectedVersion = newVersion ;
280+ mainConfig . Save ( ) ;
281+ if ( mainConfig . IsEnabled ( Id ) )
282+ screen . InvokeOnRestartRequired ( ) ;
283+ } ;
284+
285+ screen . PositionAbove ( bottomControl , versionDropdown , MyAlignH . Left ) ;
286+ screen . Controls . Add ( versionDropdown ) ;
287+
288+ MyGuiControlLabel lblVersion = new MyGuiControlLabel ( text : "Installed Version" ) ;
289+ screen . PositionAbove ( versionDropdown , lblVersion , align : MyAlignH . Left , spacing : 0 ) ;
290+ screen . Controls . Add ( lblVersion ) ;
291+ topControl = lblVersion ;
292+ }
293+
239294 [ ProtoContract ]
240295 public class Branch
241296 {
0 commit comments