Skip to content

Commit

Permalink
v1.3.5 adds zoom-to-mouse and other improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
pardeike committed Jul 5, 2019
1 parent 8f11dac commit e77f92a
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 8 deletions.
Binary file modified Assemblies/CameraPlus.dll
Binary file not shown.
1 change: 1 addition & 0 deletions Languages/English/Keyed/Text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<HideNamesWhenZoomedOut>Hide name labels when zoomed out</HideNamesWhenZoomedOut>
<DollyPercentLabel>Scroll speed</DollyPercentLabel>
<DollyFrictionLabel>Scroll friction</DollyFrictionLabel>
<ZoomToMouse>Zoom to mouse</ZoomToMouse>
<ZoomedIn>Fully zoomed in</ZoomedIn>
<ZoomedOut>Fully zoomed out</ZoomedOut>
</LanguageData>
7 changes: 7 additions & 0 deletions Languages/Japanese/Keyed/Text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@
<ZoomedOutPercent>最大ズームアウト倍率</ZoomedOutPercent>
<Exponentiality>指数関数スケーリング:</Exponentiality>
<SoundNearness>付近の音が聞こえるズーム倍率</SoundNearness>
<ZoomLevelPixelSizes>ズームレベルを定義するピクセルサイズ:</ZoomLevelPixelSizes>
<ClosestZoom>最も近いズーム</ClosestZoom>
<CloseZoom>近いズーム</CloseZoom>
<MiddleZoom>中ズーム</MiddleZoom>
<FarZoom>遠いズーム</FarZoom>
<ScalePawnNames>名前ラベルを拡大縮小する</ScalePawnNames>
<HideNamesWhenZoomedOut>ズームアウトした時名前を非表示にする</HideNamesWhenZoomedOut>
<DollyPercentLabel>スクロールの速度</DollyPercentLabel>
<DollyFrictionLabel>スクロール摩擦</DollyFrictionLabel>
<ZoomToMouse>マウスにズーム</ZoomToMouse>
<ZoomedIn>完全にズームイン</ZoomedIn>
<ZoomedOut>完全にズームアウト</ZoomedOut>
</LanguageData>
7 changes: 7 additions & 0 deletions Languages/Spanish/Keyed/Text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@
<ZoomedOutPercent>Factor máximo de alejamiento (zoom out)</ZoomedOutPercent>
<Exponentiality>Escalado exponencial:</Exponentiality>
<SoundNearness>Acercar los sonidos locales</SoundNearness>
<ZoomLevelPixelSizes>Tamaños de píxeles que definen los niveles de zoom:</ZoomLevelPixelSizes>
<ClosestZoom>Más cercano</ClosestZoom>
<CloseZoom>Cercano</CloseZoom>
<MiddleZoom>Medio</MiddleZoom>
<FarZoom>Lejos</FarZoom>
<ScalePawnNames>Escala las etiquetas de nombre</ScalePawnNames>
<HideNamesWhenZoomedOut>Ocultar etiquetas de nombre cuando la cámara se aleja</HideNamesWhenZoomedOut>
<DollyPercentLabel>Velocidad de desplazamiento</DollyPercentLabel>
<DollyFrictionLabel>Fricción de desplazamiento</DollyFrictionLabel>
<ZoomToMouse>Acercar al mouse</ZoomToMouse>
<ZoomedIn>Completamente ampliado</ZoomedIn>
<ZoomedOut>Completamente alejado</ZoomedOut>
</LanguageData>
7 changes: 7 additions & 0 deletions Languages/SpanishLatin/Keyed/Text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@
<ZoomedOutPercent>Factor máximo de alejamiento (zoom out)</ZoomedOutPercent>
<Exponentiality>Escalado exponencial:</Exponentiality>
<SoundNearness>Acercar los sonidos locales</SoundNearness>
<ZoomLevelPixelSizes>Tamaños de píxeles que definen los niveles de zoom:</ZoomLevelPixelSizes>
<ClosestZoom>Más cercano</ClosestZoom>
<CloseZoom>Cercano</CloseZoom>
<MiddleZoom>Medio</MiddleZoom>
<FarZoom>Lejos</FarZoom>
<ScalePawnNames>Escala las etiquetas de nombre</ScalePawnNames>
<HideNamesWhenZoomedOut>Ocultar etiquetas de nombre cuando la cámara se aleja</HideNamesWhenZoomedOut>
<DollyPercentLabel>Velocidad de desplazamiento</DollyPercentLabel>
<DollyFrictionLabel>Fricción de desplazamiento</DollyFrictionLabel>
<ZoomToMouse>Acercar al mouse</ZoomToMouse>
<ZoomedIn>Completamente ampliado</ZoomedIn>
<ZoomedOut>Completamente alejado</ZoomedOut>
</LanguageData>
56 changes: 54 additions & 2 deletions Source/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,57 @@ static void Postfix()
}
}

[HarmonyPatch(typeof(CameraDriver))]
[HarmonyPatch("Update")]
static class CameraDriver_Update_Patch
{
static readonly FieldRef<CameraDriver, Vector3> rootPosRef = FieldRefAccess<CameraDriver, Vector3>("rootPos");
static readonly FieldRef<CameraDriver, float> rootSizeRef = FieldRefAccess<CameraDriver, float>("rootSize");
static readonly MethodInfo m_ApplyPositionToGameObject = Method(typeof(CameraDriver), "ApplyPositionToGameObject");
static readonly FastInvokeHandler applyPositionToGameObjectInvoker = MethodInvoker.GetHandler(m_ApplyPositionToGameObject);

static void SetRootSize(CameraDriver driver, float rootSize)
{
if (Event.current.shift || CameraPlusMain.Settings.zoomToMouse == false)
{
rootSizeRef(driver) = rootSize;
return;
}
var rootPos = rootPosRef(driver);
applyPositionToGameObjectInvoker(driver, new object[0]);
var oldMousePos = UI.MouseMapPosition();
rootSizeRef(driver) = rootSize;
applyPositionToGameObjectInvoker(driver, new object[0]);
rootPos += oldMousePos - UI.MouseMapPosition();
rootPosRef(driver) = rootPos;
}

static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
var f_CameraDriver_rootSize = Field(typeof(CameraDriver), "rootSize");
if (f_CameraDriver_rootSize == null)
Log.Error("Cannot find field CameraDriver.rootSize");

var m_SetRootSize = SymbolExtensions.GetMethodInfo(() => SetRootSize(null, 0f));
var found = false;
foreach (var instruction in instructions)
{
if (instruction.opcode == OpCodes.Stfld && instruction.operand == f_CameraDriver_rootSize)
{
instruction.opcode = OpCodes.Call;
instruction.operand = m_SetRootSize;
found = true;
}
yield return instruction;
}
if (found == false)
Log.Error("Cannot find field Stdfld rootSize in CameraDriver.Update");
}
}

// open Camera+ preferences by pressing Shift-Tab
// (for now disabled because this might conflict with other usages of that key combo)
/*
[HarmonyPatch(typeof(MainTabsRoot))]
[HarmonyPatch(nameof(MainTabsRoot.HandleLowPriorityShortcuts))]
static class MainTabsRoot_HandleLowPriorityShortcuts_Patch
Expand All @@ -79,6 +130,7 @@ static void Postfix()
stack.Add(dialog);
}
}
*/

[HarmonyPatch(typeof(MoteMaker))]
[HarmonyPatch("ThrowText")]
Expand Down Expand Up @@ -231,7 +283,7 @@ static bool Prefix(ref CameraZoomRange __result)
static class CameraDriver_ApplyPositionToGameObject_Patch
{
static readonly MethodInfo m_ApplyZoom = SymbolExtensions.GetMethodInfo(() => ApplyZoom(null, null));
static readonly MethodInfo m_get_MyCamera = AccessTools.Method(typeof(CameraDriver), "get_MyCamera");
static readonly MethodInfo m_get_MyCamera = Method(typeof(CameraDriver), "get_MyCamera");

static void ApplyZoom(CameraDriver driver, Camera camera)
{
Expand Down Expand Up @@ -293,7 +345,7 @@ static IEnumerable<CodeInstruction> Postfix_Awake(IEnumerable<CodeInstruction> i
[HarmonyPatch("CurrentViewRect", MethodType.Getter)]
static class CameraDriver_CurrentViewRect_Patch
{
static readonly FieldInfo f_CameraDriver_rootSize = AccessTools.Field(typeof(CameraDriver), "rootSize");
static readonly FieldInfo f_CameraDriver_rootSize = Field(typeof(CameraDriver), "rootSize");
static readonly MethodInfo m_Main_LerpRootSize = SymbolExtensions.GetMethodInfo(() => CameraPlusSettings.LerpRootSize(0f));

[HarmonyTranspiler]
Expand Down
15 changes: 9 additions & 6 deletions Source/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class CameraPlusSettings : ModSettings
public float zoomedInDollyPercent = 1;
public float zoomedOutDollyFrictionPercent = 0.15f;
public float zoomedInDollyFrictionPercent = 0.15f;
public bool zoomToMouse = true;
public float soundNearness = 0;
public bool scalePawnNames = true;
public bool hideNamesWhenZoomedOut = true;
Expand Down Expand Up @@ -41,6 +42,7 @@ public override void ExposeData()
Scribe_Values.Look(ref zoomedInDollyPercent, "zoomedInDollyPercent", 1);
Scribe_Values.Look(ref zoomedOutDollyFrictionPercent, "zoomedOutDollySpeedDecayPercent", 0.15f);
Scribe_Values.Look(ref zoomedInDollyFrictionPercent, "zoomedInDollySpeedDecayPercent", 0.15f);
Scribe_Values.Look(ref zoomToMouse, "zoomToMouse", true);
Scribe_Values.Look(ref soundNearness, "soundNearness", 0);
Scribe_Values.Look(ref scalePawnNames, "scalePawnNames", true);
Scribe_Values.Look(ref hideNamesWhenZoomedOut, "hideNamesWhenZoomedOut", true);
Expand Down Expand Up @@ -89,7 +91,7 @@ public void DoWindowContents(Rect inRect)
var list = new Listing_Standard { ColumnWidth = (inRect.width - 34f) / 2f };
list.Begin(inRect);

list.Gap(12f);
list.Gap(16f);

list.Label("ZoomedInPercent".Translate() + ": " + Math.Round(zoomedInPercent, 1) + "%", -1f);
previous = zoomedInPercent;
Expand Down Expand Up @@ -144,11 +146,6 @@ public void DoWindowContents(Rect inRect)
list.Gap(-4f);
}

list.Gap(12f);

list.CheckboxLabeled("ScalePawnNames".Translate(), ref scalePawnNames);
list.CheckboxLabeled("HideNamesWhenZoomedOut".Translate(), ref hideNamesWhenZoomedOut);

list.NewColumn();
list.Gap(12f);

Expand All @@ -172,6 +169,12 @@ public void DoWindowContents(Rect inRect)

list.Gap(12f);

list.CheckboxLabeled("ScalePawnNames".Translate(), ref scalePawnNames);
list.CheckboxLabeled("HideNamesWhenZoomedOut".Translate(), ref hideNamesWhenZoomedOut);
list.CheckboxLabeled("ZoomToMouse".Translate(), ref zoomToMouse);

list.Gap(12f);

if (list.ButtonText("RestoreToDefaultSettings".Translate()))
{
zoomedOutPercent = 65;
Expand Down

0 comments on commit e77f92a

Please sign in to comment.