-
Notifications
You must be signed in to change notification settings - Fork 1
/
PartyInfoLayerViewModel.cs
141 lines (129 loc) · 4.71 KB
/
PartyInfoLayerViewModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using System.Numerics;
using JetBrains.Annotations;
using SandBox.View.Map;
using TaleWorlds.CampaignSystem;
using TaleWorlds.Engine;
using TaleWorlds.InputSystem;
using TaleWorlds.Library;
using TaleWorlds.Localization;
namespace Accompany
{
internal class PartyInfoLayerViewModel : ViewModel
{
private PartyBase _clickedParty;
private Vector2 _mousePosition;
private int _positionX, _positionY;
private bool _isVisible, _isShowInEncyclopediaVisible;
public void Tick()
{
if (!PartyInfoLayer.Added) return;
if (MapScreen.Instance != null && Input.IsKeyPressed(InputKey.LeftMouseButton))
{
_mousePosition.X = Input.MousePositionPixel.X;
_mousePosition.Y = Input.MousePositionPixel.Y;
if (!PartyInfoLayer.Instance.Movie.RootView.Target.IsPointInsideMeasuredArea(_mousePosition))
{
IsVisible = false;
}
}
else if (Input.IsKeyPressed(InputKey.Escape))
{
IsVisible = false;
}
}
[UsedImplicitly]
private void ExecuteAccompany()
{
MobileParty.MainParty.SetMoveEscortParty(ClickedParty.MobileParty);
if (Campaign.Current.GetSimplifiedTimeControlMode() == CampaignTimeControlMode.Stop)
{
Campaign.Current.SetTimeSpeed(1);
}
MapScreen.Instance.CurrentCameraFollowMode = MapScreen.CameraFollowMode.FollowParty;
Campaign.Current.CameraFollowParty = PartyBase.MainParty;
IsVisible = false;
}
[UsedImplicitly]
private void ExecuteShowInEncyclopedia()
{
if (ClickedParty.IsMobile && ClickedParty.MobileParty.IsLordParty)
{
Campaign.Current.EncyclopediaManager.GoToLink(ClickedParty.MobileParty.LeaderHero.EncyclopediaLink);
}
}
public PartyBase ClickedParty
{
get => _clickedParty;
set
{
if (value == _clickedParty) return;
_clickedParty = value;
OnPropertyChanged(nameof(PartyName));
}
}
[DataSourceProperty]
public int PositionX
{
get => (int) (_positionX / (PartyInfoLayer.Instance == null ? 1f : PartyInfoLayer.Instance.Movie.Context.Scale));
set
{
if (value == _positionX) return;
_positionX = value;
var rootSize = Screen.RealScreenResolution;
var size = PartyInfoLayer.Instance.Movie.RootView.Target.MeasuredSize;
if (_positionX + size.X > rootSize.X)
{
_positionX = (int) (rootSize.X - size.X);
}
PartyInfoLayer.Instance.Layer.UpdateLayout();
}
}
[DataSourceProperty]
public int PositionY
{
get => (int) (_positionY / (PartyInfoLayer.Instance == null ? 1f : PartyInfoLayer.Instance.Movie.Context.Scale));
set
{
if (value == _positionY) return;
_positionY = value;
var rootSize = Screen.RealScreenResolution;
var size = PartyInfoLayer.Instance.Movie.RootView.Target.MeasuredSize;
if (_positionY + size.Y > rootSize.Y)
{
_positionY = (int)(rootSize.Y - size.Y);
}
PartyInfoLayer.Instance.Layer.UpdateLayout();
}
}
[DataSourceProperty]
public bool IsVisible
{
get => _isVisible;
set
{
if (value == _isVisible) return;
_isVisible = value;
OnPropertyChanged(nameof(IsVisible));
}
}
[DataSourceProperty]
public bool IsShowInEncyclopediaVisible
{
get => _isShowInEncyclopediaVisible;
set
{
if (value == _isShowInEncyclopediaVisible) return;
_isShowInEncyclopediaVisible = value;
OnPropertyChanged(nameof(IsShowInEncyclopediaVisible));
}
}
[DataSourceProperty]
public string PartyName => ClickedParty == null
? new TextObject("{=BINjcIsY}Unknown Party").ToString()
: ClickedParty.Name.ToString();
[DataSourceProperty]
public string AccompanyText => new TextObject("{=LxdXABCM}Accompany").ToString();
[DataSourceProperty]
public string ShowInEncyclopediaText => new TextObject("{=68lxzu0R}Show in Encyclopedia").ToString();
}
}