Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_MapCompassUI.c
Go to the documentation of this file.
3 {
4  protected static const string ICON_NAME = "compass";
5 
6  protected SCR_CompassComponent m_CompassComp;
7  protected string m_sPrefabResource;
8 
9  //------------------------------------------------------------------------------------------------
10  override void SetWidgetNames()
11  {
12  WIDGET_NAME = "CompassFrame";
13  RT_WIDGET_NAME = "CompRTW";
14  WORLD_NAME = "CompassUIWorld";
15  }
16 
17  //------------------------------------------------------------------------------------------------
18  override void InitPositionVectors()
19  {
20  m_CompassComp = SCR_CompassComponent.Cast( m_RTEntity.FindComponent(SCR_CompassComponent) );
21 
22  m_vPrefabPos = "0 0 0";
23  m_vCameraPos = m_CompassComp.GetMapCamPosition();
24  m_vCameraAngle = "0 -90 0";
25  }
26 
27  //------------------------------------------------------------------------------------------------
29  protected void UpdateCompassEntity()
30  {
31  if (m_CompassComp)
32  {
33  ChimeraCharacter player = ChimeraCharacter.Cast(SCR_PlayerController.GetLocalControlledEntity());
34  if (!player || !player.GetCharacterController())
35  return;
36 
37  vector anglesCompass = vector.Zero;
38  anglesCompass[1] = player.GetCharacterController().GetInputContext().GetHeadingAngle() * Math.RAD2DEG;
39 
40  m_RTEntity.SetAngles(anglesCompass);
41 
42  // activate, apply proc anims
43  if (m_CompassComp.GetMode() != EGadgetMode.IN_HAND)
44  m_CompassComp.SetMapMode();
45 
46  // tick the frame
47  float tick = System.GetFrameTimeS();
48  m_CompassComp.Update( tick );
49  }
50 
51  // update
52  BaseWorld previewWorld = m_RTWorld.GetRef();
53  previewWorld.UpdateEntities();
54  }
55 
56  //------------------------------------------------------------------------------------------------
57  protected void OnInputQuickBind(float value, EActionTrigger reason)
58  {
59  SetVisible(!m_bIsVisible);
60  }
61 
62  //------------------------------------------------------------------------------------------------
63  protected override string GetPrefabResource()
64  {
65  return m_sPrefabResource;
66  }
67 
68  //------------------------------------------------------------------------------------------------
69  override void SetVisible(bool visible)
70  {
71  if (visible)
72  {
73  IEntity compass = FindRelatedGadget();
74  if (!compass)
75  {
76  super.SetVisible(false);
77  return;
78  }
79 
80  SCR_CompassComponent compassComp = SCR_CompassComponent.Cast(compass.FindComponent(SCR_CompassComponent));
81  if (!compassComp)
82  return;
83 
84  m_sPrefabResource = compassComp.GetMapPrefabResource();
85 
86  super.SetVisible(visible);
87  if (!m_RTWorld || !m_RTEntity)
88  return;
89 
90  // Start anim
91  ScriptCallQueue queue = GetGame().GetCallqueue();
92  if (queue)
93  queue.CallLater(UpdateCompassEntity, 0, true);
94 
95  UpdateCompassEntity();
96  m_CompassComp.Init2DMapCompass();
97  }
98  else
99  {
100  // stop anim
101  ScriptCallQueue queue = GetGame().GetCallqueue();
102  if (queue)
103  queue.Remove(UpdateCompassEntity);
104 
105  super.SetVisible(visible);
106  }
107  }
108 
109  //------------------------------------------------------------------------------------------------
110  override void Init()
111  {
112  SCR_MapToolMenuUI toolMenu = SCR_MapToolMenuUI.Cast(m_MapEntity.GetMapUIComponent(SCR_MapToolMenuUI));
113  if (toolMenu)
114  {
115  m_ToolMenuEntry = toolMenu.RegisterToolMenuEntry(SCR_MapToolMenuUI.s_sToolMenuIcons, ICON_NAME, 11);
116  m_ToolMenuEntry.m_OnClick.Insert(ToggleVisible);
117 
118  GetGame().GetInputManager().AddActionListener("MapToolCompass", EActionTrigger.DOWN, OnInputQuickBind);
119  }
120  }
121 
122  //------------------------------------------------------------------------------------------------
123  override void Update(float timeSlice)
124  {
125  // Drag compass
126  if (m_bIsVisible && m_bIsDragged)
127  {
128  // apply shake
129  m_CompassComp.DragMapCompass();
130 
131  // save compass position for map reopen
132  WorkspaceWidget workspace = g_Game.GetWorkspace();
133  m_wFrame.GetScreenPos(m_fPosX, m_fPosY);
134  m_fPosX = workspace.DPIUnscale(m_fPosX);
135  m_fPosY = workspace.DPIUnscale(m_fPosY);
136  }
137  }
138 
139  //------------------------------------------------------------------------------------------------
140  // constructor
141  void SCR_MapCompassUI()
142  {
143  m_eGadgetType = EGadgetType.COMPASS;
144  }
145 }
ToggleVisible
protected void ToggleVisible()
Visibility toggle.
Definition: SCR_MapRTWBaseUI.c:87
SCR_CompassComponent
Compass component.
Definition: SCR_CompassComponent.c:73
m_MapEntity
protected SCR_MapEntity m_MapEntity
Definition: SCR_MapGadgetComponent.c:14
SCR_PlayerController
Definition: SCR_PlayerController.c:31
WIDGET_NAME
protected string WIDGET_NAME
Definition: SCR_MapRTWBaseUI.c:21
SCR_MapRTWBaseUI
void SCR_MapRTWBaseUI()
Definition: SCR_MapRTWBaseUI.c:300
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_ToolMenuEntry
protected SCR_MapToolEntry m_ToolMenuEntry
Definition: SCR_MapDrawingUI.c:182
FindRelatedGadget
IEntity FindRelatedGadget()
Definition: SCR_MapRTWBaseUI.c:74
m_fPosX
protected float m_fPosX
Definition: SCR_MapRTWBaseUI.c:34
m_vCameraPos
protected vector m_vCameraPos
Definition: SCR_MapRTWBaseUI.c:26
m_RTWorld
protected ref SharedItemRef m_RTWorld
Definition: SCR_MapRTWBaseUI.c:38
m_bIsDragged
protected bool m_bIsDragged
Definition: SCR_MapRTWBaseUI.c:31
RT_WIDGET_NAME
protected string RT_WIDGET_NAME
Definition: SCR_MapRTWBaseUI.c:22
m_vPrefabPos
protected vector m_vPrefabPos
Definition: SCR_MapRTWBaseUI.c:25
m_RTEntity
protected GenericEntity m_RTEntity
Definition: SCR_MapRTWBaseUI.c:37
m_vCameraAngle
protected vector m_vCameraAngle
Definition: SCR_MapRTWBaseUI.c:27
WORLD_NAME
protected string WORLD_NAME
Definition: SCR_MapRTWBaseUI.c:24
m_bIsVisible
protected bool m_bIsVisible
Definition: SCR_MapRTWBaseUI.c:29
m_fPosY
protected float m_fPosY
Definition: SCR_MapRTWBaseUI.c:34
SCR_MapCompassUI
Compass in map UI.
Definition: SCR_MapCompassUI.c:2
m_eGadgetType
protected EGadgetType m_eGadgetType
Definition: SCR_MapRTWBaseUI.c:36
SCR_MapToolMenuUI
void SCR_MapToolMenuUI()
Definition: SCR_MapToolMenuUI.c:389
m_wFrame
protected Widget m_wFrame
Definition: SCR_MapRTWBaseUI.c:42