From 09428d243d46ba31483278e1497bca89f702181a Mon Sep 17 00:00:00 2001 From: hashashin Date: Sat, 26 Sep 2015 17:27:15 +0200 Subject: [PATCH] Reorganice Reorganice and add notesRPM --- .gitattributes | 63 ++++++++ .gitignore | 156 ++++++++++++++++++ notes.sln | 32 ++++ notes/Properties/AssemblyInfo.cs | 35 ++++ notes.cs => notes/notes.cs | 51 +++--- notes/notes.csproj | 91 +++++++++++ toolbarwrapper.cs => notes/toolbarwrapper.cs | 4 +- notesRPM/Properties/AssemblyInfo.cs | 36 +++++ notesRPM/notesRPM.cs | 158 +++++++++++++++++++ notesRPM/notesRPM.csproj | 61 +++++++ 10 files changed, 667 insertions(+), 20 deletions(-) create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 notes.sln create mode 100644 notes/Properties/AssemblyInfo.cs rename notes.cs => notes/notes.cs (98%) create mode 100644 notes/notes.csproj rename toolbarwrapper.cs => notes/toolbarwrapper.cs (99%) create mode 100644 notesRPM/Properties/AssemblyInfo.cs create mode 100644 notesRPM/notesRPM.cs create mode 100644 notesRPM/notesRPM.csproj diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1bc915c --- /dev/null +++ b/.gitignore @@ -0,0 +1,156 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results + +[Dd]ebug/ +[Rr]elease/ +x64/ +build/ +[Bb]in/ +[Oo]bj/ + +# Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets +!packages/*/build/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +*_i.c +*_p.c +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.log +*.scc + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +*.ncrunch* +.*crunch*.local.xml + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.Publish.xml + +# NuGet Packages Directory +## TODO: If you have NuGet Package Restore enabled, uncomment the next line +#packages/ + +# Windows Azure Build Output +csx +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +sql/ +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.[Pp]ublish.xml +*.pfx +*.publishsettings + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +App_Data/*.mdf +App_Data/*.ldf + + +#LightSwitch generated files +GeneratedArtifacts/ +_Pvt_Extensions/ +ModelManifest.xml + +# ========================= +# Windows detritus +# ========================= + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Mac desktop service store files +.DS_Store diff --git a/notes.sln b/notes.sln new file mode 100644 index 0000000..f184006 --- /dev/null +++ b/notes.sln @@ -0,0 +1,32 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.31101.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "notes", "notes\notes.csproj", "{2C8D5E92-19CD-499C-916D-BCB41FBC42FC}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "notesRPM", "notesRPM\notesRPM.csproj", "{8B2F9614-11C3-45E3-AA5C-FBEDBFDA3B2D}" + ProjectSection(ProjectDependencies) = postProject + {2C8D5E92-19CD-499C-916D-BCB41FBC42FC} = {2C8D5E92-19CD-499C-916D-BCB41FBC42FC} + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2C8D5E92-19CD-499C-916D-BCB41FBC42FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2C8D5E92-19CD-499C-916D-BCB41FBC42FC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2C8D5E92-19CD-499C-916D-BCB41FBC42FC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2C8D5E92-19CD-499C-916D-BCB41FBC42FC}.Release|Any CPU.Build.0 = Release|Any CPU + {2C8D5E92-19CD-499C-916D-BCB41FBC42FC}.Release|Any CPU.Deploy.0 = Release|Any CPU + {8B2F9614-11C3-45E3-AA5C-FBEDBFDA3B2D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8B2F9614-11C3-45E3-AA5C-FBEDBFDA3B2D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8B2F9614-11C3-45E3-AA5C-FBEDBFDA3B2D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8B2F9614-11C3-45E3-AA5C-FBEDBFDA3B2D}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/notes/Properties/AssemblyInfo.cs b/notes/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..acac60c --- /dev/null +++ b/notes/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// La información general sobre un ensamblado se controla mediante el siguiente +// conjunto de atributos. Cambie estos atributos para modificar la información +// asociada con un ensamblado. +[assembly: AssemblyTitle("Notes")] +[assembly: AssemblyDescription("Notes plugin for KSP")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Notes plugin for KSP")] +[assembly: AssemblyCopyright("Copyright © 2015 hashashin")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Si establece ComVisible como false, los tipos de este ensamblado no estarán visibles +// para los componentes COM. Si necesita obtener acceso a un tipo de este ensamblado desde +// COM, establezca el atributo ComVisible como true en este tipo. +[assembly: ComVisible(false)] + +// El siguiente GUID sirve como identificador de typelib si este proyecto se expone a COM +[assembly: Guid("b90cc487-aa41-4cc9-83e9-cda9f63e293b")] + +// La información de versión de un ensamblado consta de los cuatro valores siguientes: +// +// Versión principal +// Versión secundaria +// Número de compilación +// Revisión +// +// Puede especificar todos los valores o establecer como predeterminados los números de compilación y de revisión +// mediante el carácter '*', como se muestra a continuación: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("0.12.0.0")] +[assembly: AssemblyFileVersion("0.12.0.0")] diff --git a/notes.cs b/notes/notes.cs similarity index 98% rename from notes.cs rename to notes/notes.cs index b8602e7..819eb04 100644 --- a/notes.cs +++ b/notes/notes.cs @@ -1,5 +1,5 @@ // ------------------------------------------------------------------------------------------------- -// notes.cs 0.11 +// notes.cs 0.12 // // Simple KSP plugin to take notes ingame. // Copyright (C) 2015 Iván Atienza @@ -92,7 +92,7 @@ public class Notes : MonoBehaviour // true to show the notes list window, false to hide. private bool _showList; - + // The reload icon texture. private WWW _reloadIconTex; @@ -110,7 +110,7 @@ public class Notes : MonoBehaviour private int _selectDirGridInt; // The text of the note. - public static string _text; + public string _text; // true to show delete button, false to hide. private bool _toggleDel; @@ -131,10 +131,10 @@ public class Notes : MonoBehaviour private string _versionLastRun; // The vessel info. - public static string _vesselInfo; + public string _vesselInfo; // The vessel name. - private static string _vesselName; + private string _vesselName; // true to show the plugin window, false to hide. private bool _visible; @@ -254,7 +254,7 @@ private void DelDirWindow(int windowId) } // Get vessel log information. - public static void GetLogInfo() + public void GetLogInfo() { if (!HighLogic.LoadedSceneIsFlight || !HighLogic.LoadedSceneHasPlanetarium) return; double _seconds = Planetarium.GetUniversalTime(); @@ -555,22 +555,12 @@ private void NotesWindow(int windowId) } if (GUI.Button(new Rect(260f, 2f, 15f, 15f), "<")) { - GetNotes(); - if (_selectFileGridInt == 0) return; - _selectFileGridInt--; - Save(); - _file = _fileNames[_selectFileGridInt]; - Load(); + SelectNote(false); } GUI.Label(new Rect(275f, 0f, 60f, 20f), "Note"); if (GUI.Button(new Rect(305f, 2f, 15f, 15f), ">")) { - GetNotes(); - if (_selectFileGridInt == _fileNames.Count - 1) return; - _selectFileGridInt++; - Save(); - _file = _fileNames[_selectFileGridInt]; - Load(); + SelectNote(true); } GUI.Label(new Rect(340f, 0f, 60, 20f), _version); // If we are on flight show the vessel logs buttons @@ -776,12 +766,14 @@ private void Toggle() { _visible = false; _showList = false; + if (!ToolbarManager.ToolbarAvailable) return; _button.TexturePath = _btextureOff; _button.ToolTip = _tooltipOff; } else { _visible = true; + if (!ToolbarManager.ToolbarAvailable) return; _button.TexturePath = _btextureOn; _button.ToolTip = _tooltipOn; } @@ -833,5 +825,28 @@ private void VersionCheck() if (_version == _versionLastRun || !File.Exists(_notesDir + "config.xml")) return; File.Delete(_notesDir + "config.xml"); } + + public void SelectNote(bool direction) + { + if (!direction) + { + GetNotes(); + if (_selectFileGridInt == 0) return; + _selectFileGridInt--; + Save(); + _file = _fileNames[_selectFileGridInt]; + Load(); + } + GUI.Label(new Rect(275f, 0f, 60f, 20f), "Note"); + if (direction) + { + GetNotes(); + if (_selectFileGridInt == _fileNames.Count - 1) return; + _selectFileGridInt++; + Save(); + _file = _fileNames[_selectFileGridInt]; + Load(); + } + } } } \ No newline at end of file diff --git a/notes/notes.csproj b/notes/notes.csproj new file mode 100644 index 0000000..f256233 --- /dev/null +++ b/notes/notes.csproj @@ -0,0 +1,91 @@ + + + + + Debug + AnyCPU + {2C8D5E92-19CD-499C-916D-BCB41FBC42FC} + Library + Properties + notes + notes + v3.5 + 512 + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + false + + + pdbonly + true + bin\Release\ + TRACE + prompt + 3 + false + AnyCPU + + + + + + + x64 + bin\x64\Debug\ + + + AnyCPU + bin\x64\Release\ + + + x86 + bin\x86\Debug\ + + + x86 + bin\x86\Release\ + + + false + + + + + + + + + + + + + False + D:\Kerbal Space Program\KSP_Data\Managed\Assembly-CSharp.dll + + + + False + D:\Kerbal Space Program\KSP_Data\Managed\UnityEngine.dll + + + + + + + + + \ No newline at end of file diff --git a/toolbarwrapper.cs b/notes/toolbarwrapper.cs similarity index 99% rename from toolbarwrapper.cs rename to notes/toolbarwrapper.cs index 5f0b385..c448313 100644 --- a/toolbarwrapper.cs +++ b/notes/toolbarwrapper.cs @@ -1,4 +1,4 @@ -/* +/* Copyright (c) 2013-2014, Maik Schreiber All rights reserved. @@ -430,7 +430,7 @@ bool Visible /// /// /// IButton button = ... - /// button.Visibility = new GameScenesVisibility(GameScenes.EDITOR, GameScenes.SPH); + /// button.Visibility = new GameScenesVisibility(GameScenes.EDITOR, GameScenes.FLIGHT); /// /// /// diff --git a/notesRPM/Properties/AssemblyInfo.cs b/notesRPM/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..12546ff --- /dev/null +++ b/notesRPM/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// La información general sobre un ensamblado se controla mediante el siguiente +// conjunto de atributos. Cambie estos atributos para modificar la información +// asociada con un ensamblado. +[assembly: AssemblyTitle("notesRPM")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("notesRPM")] +[assembly: AssemblyCopyright("Copyright © 2015 hashashin")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Si establece ComVisible como false, los tipos de este ensamblado no estarán visibles +// para los componentes COM. Si necesita obtener acceso a un tipo de este ensamblado desde +// COM, establezca el atributo ComVisible como true en este tipo. +[assembly: ComVisible(false)] + +// El siguiente GUID sirve como identificador de typelib si este proyecto se expone a COM +[assembly: Guid("9eed1e7a-ae2d-48a1-847c-2555bdeb4487")] + +// La información de versión de un ensamblado consta de los cuatro valores siguientes: +// +// Versión principal +// Versión secundaria +// Número de compilación +// Revisión +// +// Puede especificar todos los valores o establecer como predeterminados los números de compilación y de revisión +// mediante el carácter '*', como se muestra a continuación: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("0.1")] +[assembly: AssemblyFileVersion("0.1")] diff --git a/notesRPM/notesRPM.cs b/notesRPM/notesRPM.cs new file mode 100644 index 0000000..a9625b3 --- /dev/null +++ b/notesRPM/notesRPM.cs @@ -0,0 +1,158 @@ +// ------------------------------------------------------------------------------------------------- +// notesRPM.cs 0.1 +// +// Simple KSP plugin to take notes ingame. +// Copyright (C) 2015 Iván Atienza +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see http://www.gnu.org/licenses/. +// +// Email: mecagoenbush at gmail dot com +// Freenode & EsperNet: hashashin +// +// ------------------------------------------------------------------------------------------------- + + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text.RegularExpressions; +using notes; + +namespace notesRPM +{ + public class notesRPM : InternalModule + { + //Buttons + [KSPField] + public int noteButton = 0; + [KSPField] + public int downButton = 1; + [KSPField] + public int infoButton = 2; + + [KSPField] public int nextnoteButton = 7; + [KSPField] public int prevnoteButton = 8; + + + //kOS Fields + [KSPField] + public string textTint = "[#009900ff]"; + [KSPField] + public string textTintUnpowered = "[#ffffff3e]"; + [KSPField] + public int consoleWidth = 40; + [KSPField] + public int consoleHeight = 20; + + //General State Variables + private string response = "Notes terminal"; + private bool started = false; + private Notes notes; + + + public string ContentProcessor(int screenWidth, int screenHeight) + { + if (started) + { + return (response); + } + //Check for initialization + notes = FindObjectOfType(); + response = textFormat(notes._text); + started = true; + return response; + } + + public void ButtonProcessor(int buttonID) + { + if (buttonID == noteButton) + { + response = + textFormat(notes._text); + } + else if (buttonID == downButton) + { + godowntext(response); + } + else if (buttonID == infoButton) + { + notes.GetLogInfo(); + response = textFormat(notes._vesselInfo); + } + else if (buttonID == nextnoteButton) + { + notes.SelectNote(true); + response = + textFormat(notes._text); + } + else if (buttonID == prevnoteButton) + { + notes.SelectNote(false); + response = + textFormat(notes._text); + } + } + + private string textFormat(string sentence) + { + var responsetext = string.Empty; + string[] lines = Regex.Split(sentence, "[\r\n]+"); + foreach (var line in lines) + { + string[] words = line.Split(' '); + var parts = new Dictionary(); + string parttext = string.Empty; + int partCounter = 0; + + foreach (var word in words) + { + if (parttext.Length + word.Length < consoleWidth) + { + parttext += string.IsNullOrEmpty(parttext) ? word : " " + word; + } + else + { + parts.Add(partCounter, parttext); + parttext = word; + partCounter++; + } + } + parts.Add(partCounter, parttext); + responsetext = parts.Aggregate(responsetext, + (current, item) => current + (item.Value + Environment.NewLine)); + } + return (responsetext); + } + + private void godowntext(string sentence) + { + string[] lines = Regex.Split(sentence, "[\r\n]+"); + if (lines.Count() > consoleHeight - 1) + { + var responsetext = String.Empty; + var text = lines.Skip(consoleHeight - 1); + foreach (var line in text) + { + responsetext += line + Environment.NewLine; + } + response = textFormat(responsetext); + } + } + } + + public class RPMConsole : InternalModule + { + } +} + diff --git a/notesRPM/notesRPM.csproj b/notesRPM/notesRPM.csproj new file mode 100644 index 0000000..7455dff --- /dev/null +++ b/notesRPM/notesRPM.csproj @@ -0,0 +1,61 @@ + + + + + Debug + AnyCPU + {8B2F9614-11C3-45E3-AA5C-FBEDBFDA3B2D} + Library + Properties + notesRPM + notesRPM + v3.5 + 512 + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + D:\Kerbal Space Program\KSP_Data\Managed\Assembly-CSharp.dll + + + + + D:\Kerbal Space Program\KSP_Data\Managed\UnityEngine.dll + + + + + + + + + {2c8d5e92-19cd-499c-916d-bcb41fbc42fc} + notes + + + + + \ No newline at end of file