Skip to content

Commit 79fc6cd

Browse files
committed
Force update transformation matrix for modules when screen size changes
1 parent 2fc4ee7 commit 79fc6cd

File tree

7 files changed

+97
-4
lines changed

7 files changed

+97
-4
lines changed

OpenTibia/Assets/Scripts/Core/Components/SplitStackWindow.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ public class SplitStackWindowButtonEvent : UnityEvent<SplitStackWindow> { }
2020
private Appearances.ObjectInstance _objectInstance = null;
2121
private int _objectAmount = 0;
2222
private int _selectedAmount = 0;
23-
23+
24+
private int _screenWidth = 0;
25+
private int _screenHeight = 0;
26+
private Vector2 _screenZoom;
27+
2428
private RenderTexture _renderTexture = null;
2529

2630
public SplitStackWindowButtonEvent onOk;
@@ -85,6 +89,16 @@ protected override void Start() {
8589
onOk = new SplitStackWindowButtonEvent();
8690
}
8791

92+
protected void Update() {
93+
if (Screen.width != _screenWidth || Screen.height != _screenHeight) {
94+
_screenWidth = Screen.width;
95+
_screenHeight = Screen.height;
96+
_screenZoom = new Vector2(Screen.width / (float)Constants.FieldSize, Screen.height / (float)Constants.FieldSize);
97+
if (!!_objectInstance)
98+
_objectInstance.InvalidateTRS();
99+
}
100+
}
101+
88102
protected void TriggerOk() {
89103
onOk.Invoke(this);
90104
Hide();
@@ -123,8 +137,8 @@ protected void OnGUI() {
123137
if (_objectInstance == null || _objectInstance.Id != _objectType.Id)
124138
_objectInstance = OpenTibiaUnity.AppearanceStorage.CreateObjectInstance(_objectType.Id, _objectAmount);
125139

126-
var zoom = new Vector2(Screen.width / (float)_renderTexture.width, Screen.height / (float)_renderTexture.height);
127-
_objectInstance.Draw(commandBuffer, Vector2Int.zero, zoom, 0, 0, 0);
140+
141+
_objectInstance.Draw(commandBuffer, Vector2Int.zero, _screenZoom, 0, 0, 0);
128142
}
129143

130144
Graphics.ExecuteCommandBuffer(commandBuffer);

OpenTibia/Assets/Scripts/Modules/Container/ContainerWindow.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ protected override void Awake() {
3737
_upButton.onClick.AddListener(OnUpButtonClick);
3838
}
3939

40+
protected override void Start() {
41+
base.Start();
42+
43+
OpenTibiaUnity.GameManager.GetModule<GameWindow.GameMapContainer>().onInvalidateTRS.AddListener(OnInvalidateTRS);
44+
}
45+
4046
protected void OnGUI() {
4147
if (Event.current.type != EventType.Repaint)
4248
return;
@@ -83,6 +89,20 @@ protected override void OnDestroy() {
8389
_slotsRenderTexture.Release();
8490
_slotsRenderTexture = null;
8591
}
92+
93+
var gameMapContainer = OpenTibiaUnity.GameManager?.GetModule<GameWindow.GameMapContainer>();
94+
if (gameMapContainer)
95+
gameMapContainer.onInvalidateTRS.RemoveListener(OnInvalidateTRS);
96+
}
97+
98+
protected void OnInvalidateTRS() {
99+
if (_containerView != null) {
100+
for (int i = 0; i < _containerView.NumberOfTotalObjects; i++) {
101+
var @object = _containerView.GetObject(i + _containerView.IndexOfFirstObject);
102+
if (!!@object)
103+
@object.InvalidateTRS();
104+
}
105+
}
86106
}
87107

88108
protected void OnMouseUp(Event e, MouseButton mouseButton, bool repeat) {

OpenTibia/Assets/Scripts/Modules/GameWindow/GameMapContainer.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using OpenTibiaUnity.Core.Game;
66
using OpenTibiaUnity.Core.Input.GameAction;
77
using UnityEngine;
8+
using UnityEngine.Events;
89
using UnityEngine.UI;
910
using PlayerAction = OpenTibiaUnity.Protobuf.Shared.PlayerAction;
1011

@@ -33,6 +34,14 @@ public class GameMapContainer : GamePanelContainer, IMoveWidget, IUseWidget, IWi
3334

3435
private RectTransform worldMapRectTransform { get => _gameWorldMap.rectTransform; }
3536

37+
public UnityEvent onInvalidateTRS;
38+
39+
protected override void Awake() {
40+
base.Awake();
41+
42+
onInvalidateTRS = new UnityEvent();
43+
}
44+
3645
protected override void Start() {
3746
base.Start();
3847

@@ -55,6 +64,8 @@ protected void Update() {
5564

5665
if (OpenTibiaUnity.WorldMapStorage != null)
5766
OpenTibiaUnity.WorldMapStorage.InvalidateFieldsTRS();
67+
68+
onInvalidateTRS.Invoke();
5869
}
5970
}
6071

OpenTibia/Assets/Scripts/Modules/GameWindow/GamePanelContainer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace OpenTibiaUnity.Modules.GameWindow
44
{
55
[ExecuteInEditMode]
66
[DisallowMultipleComponent]
7-
public class GamePanelContainer : Core.Components.Base.AbstractComponent
7+
public class GamePanelContainer : Core.Components.Base.Module
88
{
99
protected override void OnRectTransformDimensionsChange() {
1010
base.OnRectTransformDimensionsChange();

OpenTibia/Assets/Scripts/Modules/Hotkeys/HotkeysWindow.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ protected override void Start() {
108108
UpdateHotkeyPanelWithAction(hotkeysActionPanel, _lists[eventModifiers][i]);
109109
}
110110
}
111+
112+
OpenTibiaUnity.GameManager.GetModule<GameWindow.GameMapContainer>().onInvalidateTRS.AddListener(OnInvalidateTRS);
111113
}
112114

113115
protected void OnGUI() {
@@ -155,6 +157,19 @@ protected override void OnEnable() {
155157
_hotkeyTextInputField.MoveTextEnd(false);
156158
}
157159

160+
protected override void OnDestroy() {
161+
base.OnDestroy();
162+
163+
var gameMapContainer = OpenTibiaUnity.GameManager?.GetModule<GameWindow.GameMapContainer>();
164+
if (gameMapContainer)
165+
gameMapContainer.onInvalidateTRS.RemoveListener(OnInvalidateTRS);
166+
}
167+
168+
private void OnInvalidateTRS() {
169+
if (!!_objectInstance)
170+
_objectInstance.InvalidateTRS();
171+
}
172+
158173
private void OnLoadedGameAssets() {
159174
var clientVersion = OpenTibiaUnity.GameManager.ClientVersion;
160175
string jsonData = OpenTibiaUnity.OptionStorage.LoadCustomOptions(clientVersion + "_" + Core.Options.OptionStorage.LegacyHotkeysFileName);

OpenTibia/Assets/Scripts/Modules/Inventory/InventoryWindow.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ protected override void Start() {
179179

180180
_storeInboxButton.onClick.AddListener(OnStoreInboxButtonClick);
181181
_storeInboxLegacyButton.onClick.AddListener(OnStoreInboxButtonClick);
182+
183+
OpenTibiaUnity.GameManager.GetModule<GameWindow.GameMapContainer>().onInvalidateTRS.AddListener(OnInvalidateTRS);
182184
}
183185

184186
private void OnGUI() {
@@ -212,6 +214,18 @@ protected override void OnDestroy() {
212214

213215
_slotsRenderTexture.Release();
214216
_slotsRenderTexture = null;
217+
218+
var gameMapContainer = OpenTibiaUnity.GameManager?.GetModule<GameWindow.GameMapContainer>();
219+
if (gameMapContainer)
220+
gameMapContainer.onInvalidateTRS.RemoveListener(OnInvalidateTRS);
221+
}
222+
223+
private void OnInvalidateTRS() {
224+
for (int i = 0; i < (int)ClothSlots.Hip; i++) {
225+
var @object = BodyContainerView.Objects[i];
226+
if (@object)
227+
@object.InvalidateTRS();
228+
}
215229
}
216230

217231
public void OnMouseUp(Event e, MouseButton mouseButton, bool repeat) {

OpenTibia/Assets/Scripts/Modules/Outfit/OutfitWindow.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ protected override void Start() {
105105
_initialized = true;
106106
if (_currentOutfit)
107107
OnFirstShow();
108+
109+
110+
OpenTibiaUnity.GameManager.GetModule<GameWindow.GameMapContainer>().onInvalidateTRS.AddListener(OnInvalidateTRS);
108111
}
109112

110113
protected void OnGUI() {
@@ -172,6 +175,22 @@ protected override void OnEnable() {
172175
OnFirstShow();
173176
}
174177

178+
protected override void OnDestroy() {
179+
base.OnDestroy();
180+
181+
var gameMapContainer = OpenTibiaUnity.GameManager?.GetModule<GameWindow.GameMapContainer>();
182+
if (gameMapContainer)
183+
gameMapContainer.onInvalidateTRS.RemoveListener(OnInvalidateTRS);
184+
}
185+
186+
protected void OnInvalidateTRS() {
187+
if (!!_currentOutfit)
188+
_currentOutfit.InvalidateTRS();
189+
190+
if (!!_currentMount)
191+
_currentMount.InvalidateTRS();
192+
}
193+
175194
private void OnFirstShow() {
176195
_toggleWrapperHead.toggle.isOn = true;
177196
if (_currentOutfit is OutfitInstance outfitInstance)

0 commit comments

Comments
 (0)