Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class TRA_Map_Manager : SCR_MapUIBaseComponent
- {
- //protected Widget m_WidgetLayer;
- //protected ImageWidget m_UnitImage;
- protected SCR_MapEntity m_MapUnitEntity;
- protected float m_iCycleDuration = 0.1;
- protected float m_fWaitingTime = float.MAX;
- protected bool m_isMapOpen = false;
- protected ref array<Widget> UnitWidgets = {};
- protected ref array<Widget> ObjWidgets = {};
- protected ref array<SCR_PlayerScoreInfoFiringRange> m_aAllPlayersInfo = new ref array<SCR_PlayerScoreInfoFiringRange>;
- //------------------------------------------------------------------------------------------------
- //! GetPlayer faction
- protected Faction GetPlayerFaction(IEntity player)
- {
- if (!player)
- return null;
- if (!ChimeraCharacter.Cast(player))
- return null;
- auto foundComponent = ChimeraCharacter.Cast(player).FindComponent(FactionAffiliationComponent);
- Faction faction;
- if (foundComponent)
- {
- auto castedComponent = FactionAffiliationComponent.Cast(foundComponent);
- faction = castedComponent.GetAffiliatedFaction();
- };
- return faction;
- }
- //------------------------------------------------------------------------------------------------
- override void OnMapOpen(MapConfiguration config)
- {
- super.OnMapOpen(config);
- Print("--------------------MAPOPEN----------------", LogLevel.NORMAL);
- m_MapUnitEntity = SCR_MapEntity.GetMapInstance();
- if (!m_MapUnitEntity) return;
- array<string> types = {"village"};
- //array<string> types = {"factory", "village", "radio", "military", "city"};
- m_isMapOpen = true;
- ObjWidgets = {};
- for (int i; i < types.Count(); i++)
- {
- int count = GetObjCount(types[i]);
- for (int j; j < count; j++)
- {
- //Widget m_WidgetLayer = GetGame().GetWorkspace().CreateWidgets(("{06BB0A503B49FBAA}UI/layouts/Map/Opfor_" + types[i] + ".layout"), m_RootWidget);
- Widget m_WidgetLayer = GetGame().GetWorkspace().CreateWidgets("{06BB0A503B49FBAA}UI/layouts/Map/Opfor_Military.layout", m_RootWidget);
- ObjWidgets.Insert(m_WidgetLayer);
- };
- }
- m_MapUnitEntity.GetOnMapPan().Insert(TR_OnMapPan);
- m_MapUnitEntity.GetOnMapZoom().Insert(TR_OnMapZoom);
- UpdatePosition();
- }
- //------------------------------------------------------------------------------------------------
- override protected void OnMapClose(MapConfiguration config)
- {
- //m_MapUnitEntity.GetOnMapPan().Remove(TR_OnMapPan);
- //m_MapUnitEntity.GetOnMapZoom().Remove(TR_OnMapZoom);
- //m_isMapOpen = false;
- super.OnMapClose(config);
- }
- //------------------------------------------------------------------------------------------------
- override void Update(float timeSlice)
- {
- if (!m_isMapOpen)
- return;
- m_fWaitingTime += timeSlice;
- if (m_fWaitingTime < m_iCycleDuration)
- return;
- m_fWaitingTime = 0;
- UpdatePosition();
- }
- //------------------------------------------------------------------------------------------------
- protected void TR_OnMapPan(float x, float y, bool adjustedPan)
- {
- UpdatePosition();
- }
- //------------------------------------------------------------------------------------------------
- protected void TR_OnMapZoom(float zoomVal)
- {
- UpdatePosition();
- }
- //------------------------------------------------------------------------------------------------
- protected void UpdatePosition()
- {
- int milCount = GetObjCount("military");
- int factCount = GetObjCount("factory");
- int radioCount = GetObjCount("radio");
- int cityCount = GetObjCount("city");
- int vilCount = GetObjCount("village");
- array<IEntity> factObjs = GetObjs("factory");
- array<IEntity> milObjs = GetObjs("military");
- array<IEntity> radioObjs = GetObjs("radio");
- array<IEntity> cityObjs = GetObjs("city");
- array<IEntity> vilObjs = GetObjs("village");
- int objCount = (milCount + factCount + radioCount + cityCount + vilCount);
- int LObjID = 0;
- for (int i; i < milCount; i++)
- {
- vector ObjPos = milObjs[i].GetOrigin();
- vector ObjAngles = milObjs[i].GetAngles();
- float screenPosX, screenPosY;
- float mapZoom = m_MapUnitEntity.GetCurrentZoom();
- m_MapUnitEntity.WorldToScreen(ObjPos[0], ObjPos[2], screenPosX, screenPosY, true, mapZoom);
- ImageWidget m_ObjImage = ImageWidget.Cast(ObjWidgets[i].FindAnyWidget("Image"));
- screenPosX = GetGame().GetWorkspace().DPIUnscale(screenPosX);
- screenPosY = GetGame().GetWorkspace().DPIUnscale(screenPosY);
- if(m_ObjImage)
- {
- m_ObjImage.LoadImageTexture(0, "{9F41E9C8FDFD2BC8}Images/Opfor_Military.edds");
- // Eventually set the color according to faction in control here:
- //if ( characterDamageManager.GetIsUnconscious() )
- //{
- // if (characterDamageManager.GetState() == EDamageState.DESTROYED)
- // {
- // m_ObjImage.SetColor(Color.Black);
- // //Print("PlayerDead", LogLevel.NORMAL);
- // }else{
- // m_ObjImage.SetColor(Color.Orange);
- // //Print("PlayerUnconscious", LogLevel.NORMAL);
- // }
- //}else{
- // m_ObjImage.SetColor(LocalPlayerFaction.GetFactionColor());
- //}
- m_ObjImage.SetColor(Color.Blue);
- m_ObjImage.SetVisible(true);
- FrameSlot.SetPos(
- m_ObjImage,
- screenPosX,
- screenPosY
- );
- m_ObjImage.SetRotation(ObjAngles[1]);
- }
- TextWidget m_ObjText = TextWidget.Cast(ObjWidgets[i].FindAnyWidget("Text"));
- if(m_ObjText)
- {
- m_ObjText.SetColor(Color.FromRGBA(0, 0, 0, 255));
- //m_ObjText.SetText(playerManager.GetPlayerName(playerId));
- string objName = milObjs[i].GetName();
- m_ObjText.SetText(objName);
- m_ObjText.SetVisible(true);
- FrameSlot.SetPos(
- m_ObjText,
- screenPosX,
- screenPosY
- );
- }
- LObjID = i;
- }
- for (int i=(LObjID+1); i < milCount; i++)
- {
- ImageWidget m_ObjImage = ImageWidget.Cast(ObjWidgets[i].FindAnyWidget("Image"));
- if(m_ObjImage)
- {
- m_ObjImage.LoadImageTexture(0, "{9F41E9C8FDFD2BC8}Images/Opfor_Military.edds");
- m_ObjImage.SetVisible(false);
- }
- TextWidget m_ObjText = TextWidget.Cast(ObjWidgets[i].FindAnyWidget("Text"));
- if(m_ObjText)
- {
- m_ObjText.SetVisible(false);
- }
- };
- /* for (int i; i < 5; i++)
- {
- ImageWidget m_UnitImage = ImageWidget.Cast(UnitWidgets[i].FindAnyWidget("Image"));
- if(m_UnitImage)
- {
- m_UnitImage.LoadImageTexture(0, "{9731965B995D0B76}UI/Textures/Icons/iconman_ca.edds");
- m_UnitImage.SetColor(Color.FromRGBA(180, 0, 0, 255));
- }
- m_UnitImage.SetVisible(true);
- FrameSlot.SetPos(
- m_UnitImage,
- 100*i,
- 100*i
- );
- };
- */
- }
- //------------------------------------------------------------------------------------------------
- // type = "military" || "village" || "city" || "factory" || "radio"
- static int GetObjCount(string type)
- {
- IEntity objectives = GetGame().GetWorld().FindEntityByName((type + "_objectives"));
- IEntity child = objectives.GetChildren();
- int count = 0;
- while (child)
- {
- count++;
- child = child.GetSibling();
- }
- return count;
- }
- //------------------------------------------------------------------------------------------------
- // type = "military" || "village" || "city" || "factory" || "radio"
- static array<IEntity> GetObjs(string type)
- {
- array<IEntity> allObjectives = new array<IEntity>;
- IEntity objectives = GetGame().GetWorld().FindEntityByName((type + "_objectives"));
- IEntity child = objectives.GetChildren();
- while (child)
- {
- allObjectives.Insert(child);
- child = child.GetSibling();
- }
- return allObjectives;
- }
- //------------------------------------------------------------------------------------------------
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement