Skip to content

Commit

Permalink
Force update transformation matrix for modules when screen size changes
Browse files Browse the repository at this point in the history
  • Loading branch information
slavidodo committed Nov 5, 2019
1 parent 2fc4ee7 commit 79fc6cd
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 4 deletions.
20 changes: 17 additions & 3 deletions OpenTibia/Assets/Scripts/Core/Components/SplitStackWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ public class SplitStackWindowButtonEvent : UnityEvent<SplitStackWindow> { }
private Appearances.ObjectInstance _objectInstance = null;
private int _objectAmount = 0;
private int _selectedAmount = 0;


private int _screenWidth = 0;
private int _screenHeight = 0;
private Vector2 _screenZoom;

private RenderTexture _renderTexture = null;

public SplitStackWindowButtonEvent onOk;
Expand Down Expand Up @@ -85,6 +89,16 @@ protected override void Start() {
onOk = new SplitStackWindowButtonEvent();
}

protected void Update() {
if (Screen.width != _screenWidth || Screen.height != _screenHeight) {
_screenWidth = Screen.width;
_screenHeight = Screen.height;
_screenZoom = new Vector2(Screen.width / (float)Constants.FieldSize, Screen.height / (float)Constants.FieldSize);
if (!!_objectInstance)
_objectInstance.InvalidateTRS();
}
}

protected void TriggerOk() {
onOk.Invoke(this);
Hide();
Expand Down Expand Up @@ -123,8 +137,8 @@ protected void OnGUI() {
if (_objectInstance == null || _objectInstance.Id != _objectType.Id)
_objectInstance = OpenTibiaUnity.AppearanceStorage.CreateObjectInstance(_objectType.Id, _objectAmount);

var zoom = new Vector2(Screen.width / (float)_renderTexture.width, Screen.height / (float)_renderTexture.height);
_objectInstance.Draw(commandBuffer, Vector2Int.zero, zoom, 0, 0, 0);

_objectInstance.Draw(commandBuffer, Vector2Int.zero, _screenZoom, 0, 0, 0);
}

Graphics.ExecuteCommandBuffer(commandBuffer);
Expand Down
20 changes: 20 additions & 0 deletions OpenTibia/Assets/Scripts/Modules/Container/ContainerWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ protected override void Awake() {
_upButton.onClick.AddListener(OnUpButtonClick);
}

protected override void Start() {
base.Start();

OpenTibiaUnity.GameManager.GetModule<GameWindow.GameMapContainer>().onInvalidateTRS.AddListener(OnInvalidateTRS);
}

protected void OnGUI() {
if (Event.current.type != EventType.Repaint)
return;
Expand Down Expand Up @@ -83,6 +89,20 @@ protected override void OnDestroy() {
_slotsRenderTexture.Release();
_slotsRenderTexture = null;
}

var gameMapContainer = OpenTibiaUnity.GameManager?.GetModule<GameWindow.GameMapContainer>();
if (gameMapContainer)
gameMapContainer.onInvalidateTRS.RemoveListener(OnInvalidateTRS);
}

protected void OnInvalidateTRS() {
if (_containerView != null) {
for (int i = 0; i < _containerView.NumberOfTotalObjects; i++) {
var @object = _containerView.GetObject(i + _containerView.IndexOfFirstObject);
if (!!@object)
@object.InvalidateTRS();
}
}
}

protected void OnMouseUp(Event e, MouseButton mouseButton, bool repeat) {
Expand Down
11 changes: 11 additions & 0 deletions OpenTibia/Assets/Scripts/Modules/GameWindow/GameMapContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using OpenTibiaUnity.Core.Game;
using OpenTibiaUnity.Core.Input.GameAction;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using PlayerAction = OpenTibiaUnity.Protobuf.Shared.PlayerAction;

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

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

public UnityEvent onInvalidateTRS;

protected override void Awake() {
base.Awake();

onInvalidateTRS = new UnityEvent();
}

protected override void Start() {
base.Start();

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

if (OpenTibiaUnity.WorldMapStorage != null)
OpenTibiaUnity.WorldMapStorage.InvalidateFieldsTRS();

onInvalidateTRS.Invoke();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace OpenTibiaUnity.Modules.GameWindow
{
[ExecuteInEditMode]
[DisallowMultipleComponent]
public class GamePanelContainer : Core.Components.Base.AbstractComponent
public class GamePanelContainer : Core.Components.Base.Module
{
protected override void OnRectTransformDimensionsChange() {
base.OnRectTransformDimensionsChange();
Expand Down
15 changes: 15 additions & 0 deletions OpenTibia/Assets/Scripts/Modules/Hotkeys/HotkeysWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ protected override void Start() {
UpdateHotkeyPanelWithAction(hotkeysActionPanel, _lists[eventModifiers][i]);
}
}

OpenTibiaUnity.GameManager.GetModule<GameWindow.GameMapContainer>().onInvalidateTRS.AddListener(OnInvalidateTRS);
}

protected void OnGUI() {
Expand Down Expand Up @@ -155,6 +157,19 @@ protected override void OnEnable() {
_hotkeyTextInputField.MoveTextEnd(false);
}

protected override void OnDestroy() {
base.OnDestroy();

var gameMapContainer = OpenTibiaUnity.GameManager?.GetModule<GameWindow.GameMapContainer>();
if (gameMapContainer)
gameMapContainer.onInvalidateTRS.RemoveListener(OnInvalidateTRS);
}

private void OnInvalidateTRS() {
if (!!_objectInstance)
_objectInstance.InvalidateTRS();
}

private void OnLoadedGameAssets() {
var clientVersion = OpenTibiaUnity.GameManager.ClientVersion;
string jsonData = OpenTibiaUnity.OptionStorage.LoadCustomOptions(clientVersion + "_" + Core.Options.OptionStorage.LegacyHotkeysFileName);
Expand Down
14 changes: 14 additions & 0 deletions OpenTibia/Assets/Scripts/Modules/Inventory/InventoryWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ protected override void Start() {

_storeInboxButton.onClick.AddListener(OnStoreInboxButtonClick);
_storeInboxLegacyButton.onClick.AddListener(OnStoreInboxButtonClick);

OpenTibiaUnity.GameManager.GetModule<GameWindow.GameMapContainer>().onInvalidateTRS.AddListener(OnInvalidateTRS);
}

private void OnGUI() {
Expand Down Expand Up @@ -212,6 +214,18 @@ protected override void OnDestroy() {

_slotsRenderTexture.Release();
_slotsRenderTexture = null;

var gameMapContainer = OpenTibiaUnity.GameManager?.GetModule<GameWindow.GameMapContainer>();
if (gameMapContainer)
gameMapContainer.onInvalidateTRS.RemoveListener(OnInvalidateTRS);
}

private void OnInvalidateTRS() {
for (int i = 0; i < (int)ClothSlots.Hip; i++) {
var @object = BodyContainerView.Objects[i];
if (@object)
@object.InvalidateTRS();
}
}

public void OnMouseUp(Event e, MouseButton mouseButton, bool repeat) {
Expand Down
19 changes: 19 additions & 0 deletions OpenTibia/Assets/Scripts/Modules/Outfit/OutfitWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ protected override void Start() {
_initialized = true;
if (_currentOutfit)
OnFirstShow();


OpenTibiaUnity.GameManager.GetModule<GameWindow.GameMapContainer>().onInvalidateTRS.AddListener(OnInvalidateTRS);
}

protected void OnGUI() {
Expand Down Expand Up @@ -172,6 +175,22 @@ protected override void OnEnable() {
OnFirstShow();
}

protected override void OnDestroy() {
base.OnDestroy();

var gameMapContainer = OpenTibiaUnity.GameManager?.GetModule<GameWindow.GameMapContainer>();
if (gameMapContainer)
gameMapContainer.onInvalidateTRS.RemoveListener(OnInvalidateTRS);
}

protected void OnInvalidateTRS() {
if (!!_currentOutfit)
_currentOutfit.InvalidateTRS();

if (!!_currentMount)
_currentMount.InvalidateTRS();
}

private void OnFirstShow() {
_toggleWrapperHead.toggle.isOn = true;
if (_currentOutfit is OutfitInstance outfitInstance)
Expand Down

0 comments on commit 79fc6cd

Please sign in to comment.