- //完整代码,xml那边多加了一些条目,可以一次性显示多个数据
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using TaleWorlds.Core;
- using TaleWorlds.GauntletUI;
- using TaleWorlds.Library;
- using TaleWorlds.MountAndBlade;
- using TaleWorlds.MountAndBlade.GauntletUI;
- using TaleWorlds.MountAndBlade.GauntletUI.Mission;
- using TaleWorlds.MountAndBlade.GauntletUI.Widgets.Mission;
- using TaleWorlds.MountAndBlade.View.MissionViews;
- using TaleWorlds.MountAndBlade.View;
- using TaleWorlds.ScreenSystem;
- using TaleWorlds.MountAndBlade.ViewModelCollection;
- using TaleWorlds.Engine.GauntletUI;
- using TaleWorlds.Engine;
- namespace WoW
- {
- internal class WoW_MainAgentStatus : MissionGauntletBattleUIBase
- {
- private WoW_MainAgentStatusVM _dataSource;
- private GauntletLayer _gauntletLayer;
- protected override void OnCreateView()
- {
- this._dataSource = new WoW_MainAgentStatusVM(base.Mission, base.MissionScreen.CombatCamera, new Func<float>(base.MissionScreen.GetCameraToggleProgress));
- this._gauntletLayer = new GauntletLayer(this.ViewOrderPriority, "GauntletLayer", false);
- this._gauntletLayer.LoadMovie("WoW_AgentStatus", this._dataSource);
- base.MissionScreen.AddLayer(this._gauntletLayer);
- }
- protected override void OnDestroyView()
- {
- MissionScreen.RemoveLayer(this._gauntletLayer);
- _dataSource = null;
- _gauntletLayer = null;
- }
- public override void OnMissionScreenTick(float dt)
- {
- base.OnMissionScreenTick(dt);
- if (_dataSource!=null)
- _dataSource?.UpdateAgentStatuses();
- }
- }
- public class WoW_MainAgentStatusVM : ViewModel
- {
- private Mission mission;
- private Camera combatCamera;
- private Func<float> func;
- private int _Stamina;
- private int _Mana;
- private int _Time;
- public bool IsInDeployement { get; set; }
- public WoW_MainAgentStatusVM(Mission mission, Camera combatCamera, Func<float> func)
- {
- this.mission = mission;
- this.combatCamera = combatCamera;
- this.func = func;
-
- }
- [DataSourceProperty]
- public int Stamina
- {
- get
- {
- return this._Stamina;
- }
- set
- {
- if (value != this._Stamina)
- {
- this._Stamina = value;
- base.OnPropertyChangedWithValue(value, "Stamina");
- }
- }
- }
- [DataSourceProperty]
- public int Mana
- {
- get
- {
- return this._Mana;
- }
- set
- {
- if (value != this._Mana)
- {
- this._Mana = value;
- base.OnPropertyChangedWithValue(value, "Mana");
- }
- }
- }
- [DataSourceProperty]
- public int Time
- {
- get
- {
- return this._Time;
- }
- set
- {
- if (value != this._Time)
- {
- this._Time = value;
- base.OnPropertyChangedWithValue(value, "Time");
- }
- }
- }
- internal void UpdateAgentStatuses()
- {
- if (this.mission != null && this.mission.MainAgent == null)
- {
- this._Stamina = 0;
- this._Mana = 0;
- return;
- }
- if (this.mission != null)
- {
- this._Stamina = (int)Mission.Current.CurrentTime;
- }
- if (this.mission != null && WoW_MissionSetting.WoW_Agents.TryGetValue(mission.MainAgent.Index, out var MainAgent))
- {
- this.Stamina = (int)MainAgent.Stamina;
- this.Mana = (int)MainAgent.Mana;
- this.Time = (int)Mission.Current.CurrentTime;
- }
- }
- }
- }
复制代码- <Prefab>
- <Window>
- <Widget Id="Canvas" WidthSizePolicy="Fixed" HeightSizePolicy="Fixed" SuggestedWidth="500" SuggestedHeight="1500" HorizontalAlignment="Left" VerticalAlignment="Center" >
- <Children>
- <TextWidget WidthSizePolicy="Fixed" HeightSizePolicy="Fixed" SuggestedWidth="500" SuggestedHeight="400" MarginLeft="500" MarginRight="500" MaxWidth="380" HorizontalAlignment="Left" VerticalAlignment="Top" IntText="@Stamina" PositionYOffset="0"/>
- <TextWidget WidthSizePolicy="Fixed" HeightSizePolicy="Fixed" SuggestedWidth="500" SuggestedHeight="400" MarginLeft="0" MarginRight="0" MaxWidth="380" HorizontalAlignment="Left" VerticalAlignment="Top" Text="Stamina:" PositionXOffset="5" PositionYOffset="0"/>
- <TextWidget WidthSizePolicy="Fixed" HeightSizePolicy="Fixed" SuggestedWidth="500" SuggestedHeight="400" MarginLeft="500" MarginRight="500" MaxWidth="380" HorizontalAlignment="Left" VerticalAlignment="Top" IntText="@Mana" PositionYOffset="50"/>
- <TextWidget WidthSizePolicy="Fixed" HeightSizePolicy="Fixed" SuggestedWidth="500" SuggestedHeight="400" MarginLeft="0" MarginRight="0" MaxWidth="380" HorizontalAlignment="Left" VerticalAlignment="Top" Text="Mana:" PositionXOffset="5" PositionYOffset="50"/>
-
- <TextWidget WidthSizePolicy="Fixed" HeightSizePolicy="Fixed" SuggestedWidth="500" SuggestedHeight="400" MarginLeft="500" MarginRight="500" MaxWidth="380" HorizontalAlignment="Left" VerticalAlignment="Top" IntText="@Mana" PositionXOffset="10" PositionYOffset="100"/>
- <TextWidget WidthSizePolicy="Fixed" HeightSizePolicy="Fixed" SuggestedWidth="500" SuggestedHeight="400" MarginLeft="0" MarginRight="0" MaxWidth="380" HorizontalAlignment="Left" VerticalAlignment="Top" Text="time:" PositionXOffset="5" PositionYOffset="100"/>
- </Children>
- </Widget>
- </Window>
-
- </Prefab>
复制代码
|