Skip to content
This repository has been archived by the owner on Mar 30, 2020. It is now read-only.

Commit

Permalink
Add tree movement adjuster (BETA)
Browse files Browse the repository at this point in the history
Current impl has less effects on far trees (on investigation)
  • Loading branch information
saki7 committed May 13, 2018
1 parent d946110 commit 7aa0cf9
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Shicho/GUI/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static UILabel AddLabel(ref UIPanel parent, string label, string tooltip

var sp = obj.AddUIComponent<UISprite>();
sp.width = sp.height = bulletSize;
sp.spriteName = "ToolbarIconBaseDisabled";
sp.spriteName = "InfoIconMaintenance";
sp.relativePosition = new Vector2(-1, 0);
}

Expand Down
8 changes: 7 additions & 1 deletion Shicho/Mod/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ public abstract class ClonableData : ICloneable
[Serializable]
public class GraphicsData : ClonableData
{
public Switchable<float> shadowBias, shadowStrength, lightIntensity;
public Switchable<float>
shadowBias, shadowStrength, lightIntensity
;

public float treeMoveFactor;
}

[Serializable]
Expand All @@ -180,6 +184,8 @@ public class AIData : ClonableData
shadowBias = new Switchable<float>{Enabled = true, Value = 0.20f},
shadowStrength = new Switchable<float>{Enabled = false, Value = 0.8f},
lightIntensity = new Switchable<float>{Enabled = false, Value = 4.2f},

treeMoveFactor = 0.0f,
};

[NonSerialized]
Expand Down
4 changes: 2 additions & 2 deletions Shicho/Mod/Mod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public void OnEnabled()
{
Bootstrapper.Instance.Bootstrap();

if (Cities.ToolsModifierControl.toolController != null) {
if (Cities.ToolsModifierControl.toolController.m_mode == Cities.ItemClass.Availability.Game) {
if (Cities::ToolsModifierControl.toolController != null) {
if (Cities::ToolsModifierControl.toolController.m_mode == Cities::ItemClass.Availability.Game) {
App.Instance.InitGameMode();
}
}
Expand Down
73 changes: 73 additions & 0 deletions Shicho/Patcher/TreeInstancePatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
extern alias Cities;

using ColossalFramework;
using UnityEngine;
using Harmony;
using System;

namespace Shicho.Patcher.TreeInstancePatch
{
using Shicho.Core;

using TreeManager = Cities::TreeManager;
using RenderManager = Cities::RenderManager;
using WeatherManager = Cities::WeatherManager;
using TreeInfo = Cities::TreeInfo;
using TreeInstance = Cities::TreeInstance;


[HarmonyPatch(typeof(TreeInstance))]
[HarmonyPatch("RenderInstance")]
[HarmonyPatch(new Type[] {
typeof(RenderManager.CameraInfo),
typeof(TreeInfo),
typeof(Vector3),
typeof(float),
typeof(float),
})]
class RenderInstance
{
static bool Prefix(RenderManager.CameraInfo cameraInfo, TreeInfo info, Vector3 position, float scale, float brightness)
{
if (info.m_prefabInitialized) {
if (cameraInfo == null || (UnityEngine.Object)info.m_lodMesh1 == (UnityEngine.Object)null || cameraInfo.CheckRenderDistance(position, info.m_lodRenderDistance)) {
var instance = Singleton<TreeManager>.instance;
if (instance == null) return false;
var materialBlock = instance.m_materialBlock;
var matrix = default(Matrix4x4);
matrix.SetTRS(position, Quaternion.identity, new Vector3(scale, scale, scale));

var color = info.m_defaultColor * brightness;
color.a = Singleton<WeatherManager>.instance.GetWindSpeed(position);
lock (App.Config.GraphicsLock) {
color.a *= App.Config.Graphics.treeMoveFactor;
}

materialBlock.Clear();
materialBlock.SetColor(instance.ID_Color, color);
instance.m_drawCallData.m_defaultCalls++;

Graphics.DrawMesh(info.m_mesh, matrix, info.m_material, info.m_prefabDataLayer, null, 0, materialBlock);

} else {
position.y += info.m_generatedInfo.m_center.y * (scale - 1f);

var color = info.m_defaultColor * brightness;
color.a = Singleton<WeatherManager>.instance.GetWindSpeed(position);
lock (App.Config.GraphicsLock) {
color.a *= App.Config.Graphics.treeMoveFactor;
}

info.m_lodLocations[info.m_lodCount] = new Vector4(position.x, position.y, position.z, scale);
info.m_lodColors[info.m_lodCount] = color.linear;
info.m_lodMin = Vector3.Min(info.m_lodMin, position);
info.m_lodMax = Vector3.Max(info.m_lodMax, position);
if (++info.m_lodCount == info.m_lodLocations.Length) {
TreeInstance.RenderLod(cameraInfo, info);
}
}
}
return false;
}
}
}
3 changes: 2 additions & 1 deletion Shicho/Shicho.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\Cities_Skylines\Cities_Data\Managed\Assembly-CSharp.dll</HintPath>
<Aliases>Cities</Aliases>
<Aliases>global,Cities</Aliases>
<Private>False</Private>
</Reference>
<Reference Include="ColossalManaged">
Expand Down Expand Up @@ -110,6 +110,7 @@
<Compile Include="Input.cs" />
<Compile Include="Patcher\CameraControllerPatch.cs" />
<Compile Include="Patcher\DayNightPropertiesPatch.cs" />
<Compile Include="Patcher\TreeInstancePatch.cs" />
<Compile Include="PropManager.cs" />
<Compile Include="Resources.cs" />
<Compile Include="Tool\SupportTool.cs" />
Expand Down
30 changes: 30 additions & 0 deletions Shicho/Tool/SupportTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ public override void Awake()
Normal = "InfoIconHappiness", // NotificationIconHappy
},
},
new TabTemplate() {
name = "Nature",
icons = new IconSet() {
Normal = "IconPolicyParksandRecreation",
},
},
//new TabTemplate() {
// name = "District",
// icons = new IconSet() {
Expand Down Expand Up @@ -402,6 +408,30 @@ public override void Start()
}
}

{
var page = TabPage("Nature");
page.padding = Helper.Padding(8, 12);

var pane = AddConfig(
ref page,
"Tree movement",
"[BETA] Sets the amount of tree branch movement.\nVanilla: maximum; Recommended: minimum",
opts: new SliderOption<float>() {
hasField = false,

minValue = 0.0f,
maxValue = 1.0f,
stepSize = 0.1f,

eventValueChanged = (c, value) => {
LockedApply(App.Config.GraphicsLock, ref App.Config.Graphics.treeMoveFactor, value);
},
},
labelPadding: 4
);
pane.slider.value = App.Config.Graphics.treeMoveFactor;
}

{
var page = TabPage("About");
page.padding = Helper.Padding(8, 12);
Expand Down
2 changes: 1 addition & 1 deletion Shicho/Tool/Watcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private void UpdateCitizen()

lock (App.Config.AILock) {
if (App.Config.AI.regenChance.Enabled) {
var mgr = Cities.CitizenManager.instance;
var mgr = Cities::CitizenManager.instance;

DataQuery.Citizens((ref Cities::Citizen c, uint id) => {
if (!c.Sick) return true;
Expand Down

1 comment on commit 7aa0cf9

@saki7
Copy link
Owner Author

@saki7 saki7 commented on 7aa0cf9 May 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

closes 7aa0cf9

Please sign in to comment.