1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366 |
- class Container extends LayoutHolder
- {
- protected ref array<ref LayoutHolder> m_Body;
- protected ref array<LayoutHolder> m_OpenedContainers;
- protected int m_ActiveIndex = 0;
- protected bool m_LastIndex; //deprecated
- protected bool m_Closed;
- protected Container m_FocusedContainer;
- protected float m_PrevAlpha;
- const int ITEMS_IN_ROW = 8;
-
- //protected int m_RowCount;
- protected int m_ColumnCount;
-
- protected int m_FocusedColumn = 0;
- protected bool m_ForcedHide;
- protected bool m_ForcedShow; //used to override displayability condition, but 'm_ForcedHide' takes preference
-
- protected SlotsIcon m_SlotIcon;
- protected EntityAI m_Entity;
-
- const int SORT_ATTACHMENTS_OWN = 1; //direct attachments of the parent item
- const int SORT_CARGO_OWN = 2; //cargo of the parent item
- const int SORT_ATTACHMENTS_NEXT_OFFSET = 2;
- const int SORT_CARGO_NEXT_OFFSET = 3;
- void OnDropReceivedFromHeader( Widget w, int x, int y, Widget receiver );
- void DraggingOver( Widget w, int x, int y, Widget receiver );
- void DraggingOverHeader( Widget w, int x, int y, Widget receiver );
- void UpdateSpacer();
- Header GetHeader();
- void SetHeader(Header header);
- void CheckHeaderDragability();
-
- void Container( LayoutHolder parent )
- {
- m_Body = new array<ref LayoutHolder>;
- m_OpenedContainers = new array<LayoutHolder>;
- m_PrevAlpha = m_RootWidget.GetAlpha();
- m_SlotIcon = null;
- m_ForcedHide = false;
- m_ForcedShow = false;
-
- m_ActiveIndex = 0;
- m_IsActive = false;
- }
-
- Container GetFocusedContainer()
- {
- if (m_ActiveIndex < m_OpenedContainers.Count())
- {
- return Container.Cast(m_OpenedContainers[m_ActiveIndex]);
- }
- return null;
- }
-
- Container GetContainer(int index)
- {
- if (index < m_Body.Count())
- {
- return Container.Cast( m_Body[index] );
- }
- return null;
- }
-
-
- void SetFocusedContainer( Container cont )
- {
- m_FocusedContainer = cont;
- }
-
- SlotsIcon GetFocusedSlotsIcon()
- {
- Container c = GetFocusedContainer();
- if (c)
- {
- return c.GetFocusedSlotsIcon();
- }
- return null;
- }
-
- int GetActiveIndex()
- {
- return m_ActiveIndex;
- }
-
- void SetActiveIndex( int index )
- {
- m_ActiveIndex = index;
- }
-
- ScrollWidget GetScrollWidget()
- {
- return null;
- }
-
- void UpdateRadialIcon()
- {
- if ( m_SlotIcon )
- {
- m_SlotIcon.GetRadialIconPanel().Show( false );
- }
- }
-
- void SetSlotIcon( SlotsIcon icon )
- {
- m_SlotIcon = icon;
- }
-
- void SetDefaultFocus(bool while_micromanagment_mode = false)
- {
- m_ActiveIndex = 0;
- }
-
- void SetLastFocus()
- {
- m_ActiveIndex = 0;
- m_FocusedColumn = 0;
- if ( m_OpenedContainers.Count() > 0 )
- {
- m_ActiveIndex = m_OpenedContainers.Count() - 1;
- }
- }
-
- void Unfocus()
- {
- }
-
- void MoveGridCursor(int direction)
- {
- if ( direction == Direction.UP )
- {
- SetPreviousActive();
- }
- else if ( direction == Direction.DOWN )
- {
- SetNextActive();
- }
- else if ( direction == Direction.RIGHT )
- {
- SetNextRightActive();
- }
- else if ( direction == Direction.LEFT )
- {
- SetNextLeftActive();
- }
-
- UpdateSelectionIcons();
-
- Inventory.GetInstance().UpdateConsoleToolbar();
- }
- void ScrollToActiveContainer()
- {
- ScrollWidget sw = GetScrollWidget();
- if (sw)
- {
- float x, y, y_s;
-
- sw.GetScreenPos( x, y );
- sw.GetScreenSize( x, y_s );
- float f_y,f_h;
- float amount;
- f_y = GetFocusedContainerYScreenPos( true );
- f_h = GetFocusedContainerHeight( true );
-
- float next_pos = f_y + f_h;
-
- if (next_pos > ( y + y_s ))
- {
- amount = sw.GetVScrollPos() + next_pos - ( y + y_s ) + 2;
- sw.VScrollToPos( amount );
- }
- else if (f_y < y)
- {
- amount = sw.GetVScrollPos() + f_y - y - 2;
- sw.VScrollToPos(amount);
- }
-
- //CheckScrollbarVisibility();
- }
- }
-
- void CheckScrollbarVisibility()
- {
- ScrollWidget sw = GetScrollWidget();
- if (sw)
- {
- if (!sw.IsScrollbarVisible())
- {
- sw.VScrollToPos01(0.0);
- }
- else if (sw.GetVScrollPos01() > 1.0)
- {
- sw.VScrollToPos01(1.0);
- }
- }
- }
-
- void Open()
- {
- m_Closed = false;
- UpdateSelectionIcons();
- }
-
- void Close()
- {
- m_Closed = true;
- UpdateSelectionIcons();
- }
-
- bool IsOpened()
- {
- return !m_Closed;
- }
-
- void SetOpenForSlotIcon(bool open, SlotsIcon icon = null/*m_SlotIcon*/)
- {
- if (!icon)
- {
- icon = m_SlotIcon;
- }
-
- if (icon)
- {
- icon.GetRadialIcon().Show(open);
- icon.GetRadialIconClosed().Show(!open);
- }
- /*else
- {
- ErrorEx("Dbg No Icon");
- }*/
- }
-
- void Toggle()
- {
- if (IsOpened())
- {
- Close();
- }
- else
- {
- Open();
- }
- SetOpenForSlotIcon(IsOpened());
- }
-
- float GetFocusedContainerHeight( bool contents = false )
- {
- float x, y, result;
- if( GetFocusedContainer() )
- y = GetFocusedContainer().GetFocusedContainerHeight( contents );
- else if( GetRootWidget() )
- GetRootWidget().GetScreenSize( x, y );
-
- result = y;
-
- if ( m_ActiveIndex == 0 )
- {
- if ( GetHeader() )
- {
- GetHeader().GetRootWidget().GetScreenSize( x, y );
- result += y;
- }
- }
- return result;
- }
-
- float GetFocusedContainerYPos( bool contents = false )
- {
- float x, y;
- if( GetFocusedContainer() )
- y = GetFocusedContainer().GetFocusedContainerYPos( contents );
- else if( GetRootWidget() )
- GetRootWidget().GetPos( x, y );
-
- return y;
- }
-
- float GetFocusedContainerYScreenPos( bool contents = false )
- {
- float x, y, result;
- if( GetFocusedContainer() )
- y = GetFocusedContainer().GetFocusedContainerYScreenPos( contents );
- else if( GetRootWidget() )
- GetRootWidget().GetScreenPos( x, y );
-
-
- result = y;
-
- if ( m_ActiveIndex == 0 )
- {
- if ( GetHeader() )
- {
- GetHeader().GetRootWidget().GetScreenPos( x, y );
- result = y;
- }
- }
- return result;
- }
- int Count()
- {
- return m_Body.Count();
- }
-
- bool SelectItem()
- {
- if( GetFocusedContainer() )
- return GetFocusedContainer().SelectItem();
- return false;
- }
-
- bool Select()
- {
- if( GetFocusedContainer() )
- return GetFocusedContainer().Select();
- return false;
- }
-
- bool OnSelectButton()
- {
- if(GetFocusedContainer())
- {
- return GetFocusedContainer().OnSelectButton();
- }
- return false;
- }
-
- bool Combine()
- {
- if( GetFocusedContainer() )
- return GetFocusedContainer().Combine();
- return true;
- }
-
- bool TransferItemToVicinity()
- {
- if( GetFocusedContainer() )
- return GetFocusedContainer().TransferItemToVicinity();
- return false;
- }
-
- bool TransferItem()
- {
- if( GetFocusedContainer() )
- return GetFocusedContainer().TransferItem();
- return false;
- }
-
- bool InspectItem()
- {
- if( GetFocusedContainer() )
- return GetFocusedContainer().InspectItem();
- return false;
- }
-
- bool SplitItem()
- {
- if( GetFocusedContainer() )
- return GetFocusedContainer().SplitItem();
- return false;
- }
-
- bool EquipItem()
- {
- if( GetFocusedContainer() )
- return GetFocusedContainer().EquipItem();
- return false;
- }
-
- bool CanOpenCloseContainer()
- {
- if ( ItemManager.GetInstance().IsMicromanagmentMode() )
- return false;
-
- EntityAI focusedEntity = GetFocusedItem();
- if (focusedEntity)
- {
- if (GetFocusedContainer())
- return GetFocusedContainer().CanOpenCloseContainerEx(focusedEntity);
-
- return CanOpenCloseContainerEx(focusedEntity);
- }
- return false;
- }
-
- bool CanOpenCloseContainerEx(EntityAI focusedEntity)
- {
- return false;
- }
-
- bool CanSplit()
- {
- EntityAI focusedEntity = GetFocusedItem();
- if (focusedEntity)
- {
- if (GetFocusedContainer())
- return GetFocusedContainer().CanSplitEx(focusedEntity);
-
- return CanSplitEx(focusedEntity);
- }
- return false;
- }
-
- bool CanSplitEx(EntityAI focusedEntity)
- {
- if ( ItemManager.GetInstance().IsMicromanagmentMode() )
- return false;
-
- if (focusedEntity)
- {
- return focusedEntity.CanBeSplit();
- }
- return false;
- }
-
- bool CanDrop()
- {
- EntityAI focusedEntity = GetFocusedItem();
- if (focusedEntity)
- {
- if (GetFocusedContainer())
- return GetFocusedContainer().CanDropEx(focusedEntity);
-
- return CanDropEx(focusedEntity);
-
- }
- return false;
- }
-
- bool CanDropEx(EntityAI focusedEntity)
- {
- if ( ItemManager.GetInstance().IsMicromanagmentMode() )
- return false;
-
- if (focusedEntity)
- {
- PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
-
- if (player)
- {
- return player.CanDropEntity(focusedEntity);
- }
- }
- return false;
- }
-
- bool CanSwapOrTakeToHands()
- {
- EntityAI focusedEntity = GetFocusedItem();
- if (focusedEntity)
- {
- if (GetFocusedContainer())
- return GetFocusedContainer().CanSwapOrTakeToHandsEx(focusedEntity);
-
- return CanSwapOrTakeToHandsEx(focusedEntity);
- }
- return false;
- }
-
- bool CanSwapOrTakeToHandsEx(EntityAI focusedEntity)
- {
- if ( ItemManager.GetInstance().IsMicromanagmentMode() )
- return false;
-
- if (focusedEntity)
- {
- PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
- EntityAI entityInHands = player.GetItemInHands();
- if (entityInHands)
- {
- InventoryLocation il = new InventoryLocation();
-
- if (!GameInventory.CanSwapEntitiesEx(focusedEntity, entityInHands))
- {
- return GameInventory.CanForceSwapEntitiesEx( focusedEntity, null, entityInHands, il );
- }
- else
- {
- return true;
- }
- }
- else
- {
- return player.GetInventory().CanAddEntityIntoHands(focusedEntity);
- }
- }
- return false;
- }
-
- bool CanEquip()
- {
- EntityAI focusedEntity = GetFocusedItem();
- if (focusedEntity)
- {
- if (GetFocusedContainer())
- return GetFocusedContainer().CanEquipEx(focusedEntity);
-
- return CanEquipEx(focusedEntity);
- }
- return false;
- }
-
- bool CanEquipEx(EntityAI focusedEntity)
- {
- if ( ItemManager.GetInstance().IsMicromanagmentMode() )
- return false;
-
- bool found = false;
- if (focusedEntity)
- {
- InventoryLocation il = new InventoryLocation;
- PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
- found = player.GetInventory().FindFreeLocationFor(focusedEntity,FindInventoryLocationType.ATTACHMENT, il);
-
- if (found && il.GetParent().GetInventory().FindAttachment(il.GetSlot()))
- {
- found = false;
- }
- else if (!found)
- {
- for (int i = 0; i < focusedEntity.GetInventory().GetSlotIdCount(); i++)
- {
- int slot_id = focusedEntity.GetInventory().GetSlotId(i);
- EntityAI slot_item = player.GetInventory().FindAttachment( slot_id );
- if (slot_item && player.GetInventory().CanSwapEntitiesEx( focusedEntity, slot_item ))
- {
- found = true;
- break;
- }
-
- }
- }
- }
- return found;
- }
-
- bool CanTakeToInventory()
- {
- EntityAI focusedEntity = GetFocusedItem();
- if (focusedEntity)
- {
- if (GetFocusedContainer())
- return GetFocusedContainer().CanTakeToInventoryEx(focusedEntity);
-
- return CanTakeToInventoryEx(focusedEntity);
- }
- return false;
- }
-
- bool CanTakeToInventoryEx(EntityAI focusedEntity)
- {
- if ( ItemManager.GetInstance().IsMicromanagmentMode() )
- return false;
-
- if (focusedEntity)
- {
- PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
- return player.GetInventory().CanAddEntityToInventory(focusedEntity,FindInventoryLocationType.CARGO);
- }
- return false;
- }
-
- bool CanCombine()
- {
- EntityAI focusedEntity = GetFocusedItem();
- if (focusedEntity)
- {
- if (GetFocusedContainer())
- return GetFocusedContainer().CanCombineEx(focusedEntity);
-
- return CanCombineEx(focusedEntity);
- }
- return false;
- }
-
- bool CanCombineEx(EntityAI focusedEntity)
- {
- if (ItemManager.GetInstance().IsMicromanagmentMode())
- return false;
-
- if (focusedEntity)
- {
- EntityAI entityInHands = PlayerBase.Cast(GetGame().GetPlayer()).GetItemInHands();
- if (focusedEntity != entityInHands)
- {
- return (ItemManager.GetCombinationFlags(entityInHands, focusedEntity) != 0);
- }
- }
- return false;
- }
-
- bool CanCombineAmmo()
- {
- if( GetFocusedContainer() )
- return GetFocusedContainer().CanCombineAmmo();
- return false;
- }
-
- bool CanAddToQuickbarEx(EntityAI focusedEntity)
- {
- if ( ItemManager.GetInstance().IsMicromanagmentMode() )
- return false;
-
- if (focusedEntity)
- {
- PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
- if (focusedEntity.GetHierarchyRootPlayer() == player)
- {
- return true;
- }
- }
-
- return false;
- }
-
- bool AddItemToQuickbarRadial(EntityAI itemToAssign)
- {
- if ( CanAddToQuickbarEx(itemToAssign) )
- {
- PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
- DayZPlayerInventory dpi;
- dpi = player.GetDayZPlayerInventory();
-
- if (itemToAssign && dpi && !dpi.IsProcessing())
- {
- RadialQuickbarMenu.SetItemToAssign(itemToAssign);
-
- //open radial quickbar menu
- if (!GetGame().GetUIManager().IsMenuOpen(MENU_RADIAL_QUICKBAR))
- {
- RadialQuickbarMenu.OpenMenu(GetGame().GetUIManager().FindMenu(MENU_INVENTORY));
- }
- }
- return true;
- }
- return false;
- }
-
- bool IsEmpty()
- {
- return m_OpenedContainers.Count() == 0;
- }
-
- bool IsItemActive()
- {
- if( GetFocusedContainer() )
- return GetFocusedContainer().IsItemActive();
- return false;
- }
- bool IsItemWithQuantityActive()
- {
- if( GetFocusedContainer() )
- return GetFocusedContainer().IsItemWithQuantityActive();
- return false;
- }
-
- EntityAI GetFocusedItem()
- {
- EntityAI item;
- if( GetFocusedContainer() )
- item = GetFocusedContainer().GetFocusedItem();
- return item;
- }
-
- EntityAI GetFocusedContainerEntity()
- {
- EntityAI item;
- if( GetFocusedContainer() )
- item = GetFocusedContainer().GetFocusedContainerEntity();
- return item;
- }
-
- int GetColumnCount()
- {
- return m_ColumnCount;
- }
-
- void SetColumnCount( int count )
- {
- m_ColumnCount = count;
- }
-
- int GetFocusedColumn()
- {
- return m_FocusedColumn;
- }
-
- void SetFocusedColumn( int column )
- {
- m_FocusedColumn = column;
- }
-
- override void UpdateInterval()
- {
- for ( int i = 0; i < m_Body.Count(); i++ )
- {
- if ( m_Body.Get( i ) )
- m_Body.Get( i ).UpdateInterval();
- }
-
- CheckHeaderDragability();
- }
- override void SetLastActive()
- {
- if (m_IsActive)
- {
- m_IsActive = true;
- if (m_OpenedContainers.Count())
- {
- SetLastFocus();
- if (!m_OpenedContainers[m_ActiveIndex].IsActive())
- {
- for (int i = 0; i < m_OpenedContainers.Count() - 1; i++)
- {
- if (m_OpenedContainers[i].IsActive())
- {
- m_OpenedContainers[i].SetActive(false);
- }
- }
- m_OpenedContainers[m_ActiveIndex].SetLastActive();
- }
- else
- {
- m_OpenedContainers[m_ActiveIndex].SetLastActive();
- }
- }
- }
- else
- {
- m_IsActive = true;
- if (GetHeader())
- {
- GetHeader().SetActive(m_IsActive);
- }
- SetLastFocus();
- if (m_OpenedContainers.Count())
- {
- Container c = Container.Cast(m_OpenedContainers.Get( m_ActiveIndex ));
- if (c)
- {
- c.SetLastActive( );
- }
- }
- }
- }
-
- override void SetFirstActive()
- {
- if (!m_IsActive)
- {
- SetActive(true);
- }
- else
- {
- if (m_OpenedContainers.Count())
- {
- SetDefaultFocus();
- if (!m_OpenedContainers[m_ActiveIndex].IsActive())
- {
- for (int i = 1; i < m_OpenedContainers.Count(); i++)
- {
- if (m_OpenedContainers[i].IsActive())
- {
- m_OpenedContainers[i].SetActive(false);
- }
- }
- m_OpenedContainers[m_ActiveIndex].SetActive(true);
- }
- else
- {
- m_OpenedContainers[m_ActiveIndex].SetFirstActive();
- }
- }
- }
- }
-
- override void SetActive(bool active)
- {
- if (!active)
- {
- HideOwnedTooltip();
- }
-
- if (!active && !m_IsActive)
- return;
-
- super.SetActive( active );
- if ( GetHeader() )
- {
- GetHeader().SetActive(active);
- }
- if (m_MainWidget.FindAnyWidget("SelectedContainer"))
- {
- m_MainWidget.FindAnyWidget("SelectedContainer").Show(active);
- }
-
- Container c;
- if( active )
- {
- SetDefaultFocus();
- if( m_OpenedContainers.Count() )
- {
- c = Container.Cast(m_OpenedContainers.Get( m_ActiveIndex ));
- if (c)
- {
- c.SetActive(active);
- }
- }
- }
- else
- {
- c = GetFocusedContainer();
- if (c)
- {
- GetFocusedContainer().SetActive(false);
- }
- Unfocus();
- m_ActiveIndex = 0;
- m_FocusedColumn = 0;
- }
- }
- void UnfocusAll()
- {
- for ( int i = 0; i < Count(); i++ )
- {
- for ( int j = 0; j < ITEMS_IN_ROW; j++ )
- {
- SlotsIcon icon;
- if (Get(i) && Get(i).GetMainWidget())
- Get( i ).GetMainWidget().GetUserData(icon);
-
- if (icon)
- icon.GetCursorWidget().Show( false );
- }
- }
- }
- void UnfocusGrid()
- {
- if( GetFocusedContainer() )
- {
- m_FocusedColumn = 0;
- GetFocusedContainer().UnfocusAll();
- }
- }
- bool IsLastIndex()
- {
- return m_ActiveIndex == ( m_OpenedContainers.Count() - 1 );
- }
-
- bool IsFirstIndex()
- {
- return m_ActiveIndex == 0;
- }
-
- bool IsFirstContainerFocused()
- {
- return m_ActiveIndex == 0;
- }
-
- bool IsLastContainerFocused()
- {
- return m_ActiveIndex >= ( m_OpenedContainers.Count() - 1 );
- }
-
- void ResetFocusedContainer()
- {
- if ( GetFocusedContainer() )
- {
- GetFocusedContainer().ResetFocusedContainer();
- }
-
- m_ActiveIndex == 0;
- }
- void SetNextActive()
- {
- HideOwnedTooltip();
- Container active;
- if (m_OpenedContainers.Count())
- {
- active = Container.Cast(m_OpenedContainers[m_ActiveIndex]);
- }
-
- if (active && active.IsActive())
- {
- active.SetNextActive();
- }
- if (!active || !active.IsActive())
- {
- Container next;
- if (!IsLastContainerFocused())
- {
- m_ActiveIndex++;
-
- next = Container.Cast(m_OpenedContainers[m_ActiveIndex]);
- next.SetActive(true);
- }
- else if (Container.Cast( GetParent() ))
- {
- SetActive(false);
- }
- else
- {
- SetActive(false);
- SetFirstActive();
- }
- }
- }
- void SetPreviousActive(bool force = false)
- {
- HideOwnedTooltip();
- Container active;
- if (m_OpenedContainers.Count())
- {
- active = Container.Cast(m_OpenedContainers[m_ActiveIndex]);
- }
-
- if (active && active.IsActive())
- {
- active.SetPreviousActive();
- }
-
- if (!active || !active.IsActive())
- {
- Container prev;
- if (!IsFirstContainerFocused())
- {
- m_ActiveIndex--;
-
- prev = Container.Cast(m_OpenedContainers[m_ActiveIndex]);
- prev.SetLastActive();
- }
- else if (Container.Cast( GetParent() ))
- {
- SetActive(false);
- }
- else
- {
- SetActive(false);
- SetLastActive();
- }
- }
- }
-
- void SetNextRightActive()
- {
- Container active;
- if (m_OpenedContainers.Count())
- {
- active = Container.Cast(m_OpenedContainers[m_ActiveIndex]);
- }
-
- if (active)
- {
- active.SetNextRightActive();
- }
- }
-
- void SetNextLeftActive()
- {
- Container active;
- if (m_OpenedContainers.Count())
- {
- active = Container.Cast(m_OpenedContainers[m_ActiveIndex]);
- }
-
- if (active)
- {
- active.SetNextLeftActive();
- }
- }
-
- void SetSameLevelNextActive()
- {
- Icon icon;
- Container active;
- active = Container.Cast(m_OpenedContainers[m_ActiveIndex]);
- if (ClosableContainer.Cast(active) && active.m_OpenedContainers.Count()) // Check if current active container has any opened nested containers and go through them
- {
- active.SetNextActive();
- ContainerWithCargoAndAttachments cwcaa;
- if (Class.CastTo(cwcaa, active))
- {
- if (cwcaa.GetAttachmentCargos())
- {
- bool foundActive;
- for (int i = 0; i < cwcaa.GetAttachmentCargos().Count(); i++)
- {
- Entity entA = cwcaa.GetAttachmentCargos().GetKey(i);
- CargoContainer cc = cwcaa.GetAttachmentCargos().GetElement(i);
- if (cc && cc.IsActive())
- {
- icon = cc.GetIcon(0);
- if (icon && !icon.IsActive())
- {
- cwcaa.SetActive(false);
- }
- }
- }
- }
-
- if (cwcaa.GetAttachmentAttachmentsContainers())
- {
- for (int j = 0; j < cwcaa.GetAttachmentAttachmentsContainers().Count(); j++)
- {
- Entity entB = cwcaa.GetAttachmentAttachmentsContainers().GetKey(j);
- AttachmentsWrapper aw = cwcaa.GetAttachmentAttachmentsContainers().GetElement(j);
- if (aw && aw.IsActive())
- {
- aw.SetFirstActive();
- }
- }
- }
-
- if (cwcaa && cwcaa.GetCargo() && cwcaa.GetCargo().IsActive())
- {
- icon = cwcaa.GetCargo().GetIcon(0);
- if (icon && !icon.IsActive())
- {
- cwcaa.SetActive(false);
- }
- }
- }
-
- ContainerWithCargo cwc;
- if (Class.CastTo(cwc, active) && cwc.GetCargo())
- {
- icon = cwc.GetCargo().GetIcon(0);
- if (icon && !icon.IsActive())
- {
- cwc.SetActive(false);
- }
- }
- }
- else
- {
- active.SetActive(false);
- m_ActiveIndex++;
- if (m_ActiveIndex > m_OpenedContainers.Count() - 1)
- {
- m_ActiveIndex = 0;
- }
-
- active = Container.Cast(m_OpenedContainers[m_ActiveIndex]);
- active.SetActive(true);
- }
-
- if (!active || !active.IsActive())
- {
- if (!IsLastContainerFocused())
- {
- m_ActiveIndex++;
- Container next = Container.Cast(m_OpenedContainers[m_ActiveIndex]);
-
- ContainerWithCargo cwcn;
- if (Class.CastTo(cwcn, next) && cwcn.GetCargo())
- {
- icon = cwcn.GetCargo().GetIcon(0);
- if (icon && icon.IsActive())
- {
- SetActive(false);
- }
- else
- {
- cwcn.SetFirstActive();
- }
- }
- else
- {
- next.SetActive(true);
- }
- }
- else
- {
- SetActive(false);
- SetFirstActive();
- }
- }
- }
-
- void SetSameLevelPreviousActive()
- {
- Icon icon;
- Container active;
- ContainerWithCargoAndAttachments cwcaa;
- ContainerWithCargo cwc;
- int i;
- if (m_OpenedContainers.Count())
- {
- active = Container.Cast(m_OpenedContainers[m_ActiveIndex]);
- }
-
- if (active && active.IsActive())
- {
- if (Class.CastTo(cwcaa, active))
- {
- if (cwcaa.GetAttachmentCargos())
- {
- for (i = 0; i < cwcaa.GetAttachmentCargos().Count(); i++)
- {
- Entity entA = cwcaa.GetAttachmentCargos().GetKey(i);
- CargoContainer cc = cwcaa.GetAttachmentCargos().GetElement(i);
- if (cc && cc.IsActive())
- {
- icon = cc.GetIcon(cc.GetIconsCount() - 1);
- if (icon && !icon.IsActive())
- {
- cc.SetActive(false);
- }
- }
- }
- }
-
- if (cwcaa && cwcaa.GetCargo() && cwcaa.GetCargo().IsActive())
- {
- cwcaa.SetFirstActive();
- }
- else
- {
- active.SetPreviousActive();
- }
- }
- else
- {
- if (Class.CastTo(cwc, active))
- {
- if (cwc && cwc.GetCargo() && cwc.GetCargo().IsActive())
- {
- active.SetActive(false);
- }
- }
- else
- {
- active.SetActive(false);
- m_ActiveIndex--;
- if (m_ActiveIndex < 0)
- {
- m_ActiveIndex = m_OpenedContainers.Count() - 1;
- }
-
- active = Container.Cast(m_OpenedContainers[m_ActiveIndex]);
- active.SetLastActive();
- }
- }
- }
-
- if (!active || !active.IsActive())
- {
- Container prev;
- if (!IsFirstContainerFocused())
- {
- m_ActiveIndex--;
- prev = Container.Cast(m_OpenedContainers[m_ActiveIndex]);
- if (Class.CastTo(cwc, prev))
- {
- if (cwc && cwc.GetCargo() && cwc.GetCargo().IsActive())
- {
- prev.SetActive(false);
- }
- else
- {
- prev.SetLastActive();
- }
- }
- else
- {
- prev.SetLastActive();
- }
- }
- else
- {
- SetActive(false);
- SetLastActive();
- }
- }
- }
-
- void RecomputeOpenedContainers()
- {
- m_OpenedContainers.Clear();
- int i;
- bool need_reset_focus = false;
- Container c;
- for (i = 0; i < m_Body.Count(); i++)
- {
- c = Container.Cast(m_Body.Get( i ));
- if ( c )
- {
- c.RecomputeOpenedContainers();
- if (c.IsDisplayable() && c.IsVisible())
- {
- m_OpenedContainers.Insert(c);
- }
- else if (c.IsActive())
- {
- c.SetActive(false);
- need_reset_focus = true;
- }
-
- }
- }
-
- //In case of removing focused container or change order of containers
- if (IsActive())
- {
- if (!need_reset_focus && ( m_ActiveIndex >= m_OpenedContainers.Count() || !m_OpenedContainers[m_ActiveIndex].IsActive() ))
- {
- need_reset_focus = true;
- for (i = 0; i < m_OpenedContainers.Count(); i++)
- {
- if (m_OpenedContainers[i].IsActive())
- {
- need_reset_focus = false;
- m_ActiveIndex = i;
- }
- }
- }
-
- if (need_reset_focus)
- {
- SetFirstActive();
- }
- }
- }
- override void SetLayoutName()
- {
- m_LayoutName = WidgetLayoutName.Container;
- }
- void Insert( LayoutHolder container, int pos = -1, bool immedUpdate = true )
- {
- if ( pos > -1 && pos < m_Body.Count() )
- {
- if ( pos <= m_ActiveIndex )
- m_ActiveIndex++;
- m_Body.InsertAt( container, pos );
- }
- else
- m_Body.Insert( container );
-
- if ( immedUpdate )
- Refresh();
- }
- void Remove( LayoutHolder container )
- {
- if( m_Body )
- {
- int index = m_Body.Find( container );
- if( index > -1 )
- {
- index = m_OpenedContainers.Find( container );
- if (index > -1)
- {
- if (index <= m_ActiveIndex)
- {
- if (GetFocusedContainer() == container)
- {
- SetPreviousActive( true );
- }
- else
- {
- m_ActiveIndex--;
- }
- }
- m_OpenedContainers.RemoveItem( container );
- }
- m_Body.RemoveItem( container );
- }
- }
-
- Refresh();
- }
-
- LayoutHolder Get( int x )
- {
- return m_Body.Get( x );
- }
- override void Refresh()
- {
- for ( int i = 0; i < m_Body.Count(); i++ )
- {
- if( m_Body.Get( i ) )
- m_Body.Get( i ).Refresh();
- }
- }
- void UpdateBodySpacers()
- {
- for ( int i = 0; i < m_Body.Count(); i++ )
- {
- Container c = Container.Cast( m_Body.Get( i ) );
- if( c && c.IsInherited( Container ) )
- {
- c.UpdateSpacer();
- }
- }
-
- UpdateSpacer();
- }
- void HideContent( bool force_hide = false )
- {
- if( !m_ForcedHide )
- {
- m_ForcedHide = force_hide;
- }
- for(int i = 0; i < m_Body.Count(); i++)
- {
- if( m_Body.Get( i ) )
- m_Body.Get( i ).OnHide();
- }
- }
-
- void ShowContent( bool force_show = false )
- {
- if( force_show )
- m_ForcedHide = false;
-
- if( !m_ForcedHide )
- {
- for(int i = 0; i < m_Body.Count(); i++)
- {
- if( m_Body.Get( i ) )
- m_Body.Get( i ).OnShow();
- }
- }
- }
-
- void SetForceShow(bool value)
- {
- m_ForcedShow = value;
- }
-
- override void UpdateSelectionIcons()
- {
- m_Parent.UpdateSelectionIcons();
- }
-
- void ExpandCollapseContainer(){}
- }
|