12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634 |
- #ifdef PLATFORM_CONSOLE
- enum ConsoleActionToolbarMask
- {
- EMPTY = 0,
- TO_HANDS_SWAP_VICINITY = 1,
- TO_HANDS_SWAP_INVENTORY = 2,
- DROP = 4,
- EQUIP = 8,
- SPLIT = 16,
- TO_INVENTORY = 32,
- OPEN_CLOSE_CONTAINER = 64,
- MICROMANAGMENT = 128,
- QUICKSLOT = 256,
- COMBINE = 512,
- }
- #endif
- enum Direction
- {
- RIGHT,
- LEFT,
- UP,
- DOWN
- }
- class Inventory: LayoutHolder
- {
- protected ref LeftArea m_LeftArea;
- protected ref RightArea m_RightArea;
- protected ref HandsArea m_HandsArea;
- protected ref PlayerPreview m_PlayerPreview;
- protected ref InventoryQuickbar m_Quickbar;
-
- protected Widget m_QuickbarWidget;
- protected Widget m_TopConsoleToolbarVicinity;
- protected Widget m_TopConsoleToolbarHands;
- protected Widget m_TopConsoleToolbarEquipment;
- protected Widget m_BottomConsoleToolbar;
- protected RichTextWidget m_BottomConsoleToolbarRichText;
- protected ref ContextMenu m_ContextMenu;
- protected static ref map<string, int> m_PlayerAttachmentsIndexes;
-
- protected bool m_HadFastTransferred;
- protected bool m_HadInspected;
- protected bool m_NeedUpdateConsoleToolbar;
-
- protected static Inventory m_Instance;
-
- protected int m_ControllerAngle;
- protected int m_ControllerTilt;
- protected bool m_ControllerRightStickTimerEnd = true;
- protected ref Timer m_ControllerRightStickTimer;
-
- protected bool m_HoldingQB;
- protected InventoryItem m_QBHoveredItems;
-
- ////////////////////
- const float BT_REPEAT_DELAY = 0.35; //delay from first press to begin tick repeat state
- const float BT_REPEAT_TIME = 0.09; //tick repeat frequency time
- const float BT_THRESHOLD_VALUE = 0.8; //threshold values for analog inputs
- const int INV_MOV_LEFT = 0;
- const int INV_MOV_RIGHT = 1;
- const int INV_MOV_UP = 2;
- const int INV_MOV_DOWN = 3;
- protected ref array<string> m_InvInputNames = {"UAUILeftInventory","UAUIRightInventory","UAUIUpInventory","UAUIDownInventory"};
- protected ref array<UAIDWrapper> m_InvInputWrappers;
- protected ref array<float> m_InvInputTimes;
- protected int m_InvInputWrappersCount;
- protected float m_SensitivityThreshold = 0.0;
- UAInput m_InvUAInput;
- int m_InvInputActive = 0;
-
- void Inventory(LayoutHolder parent)
- {
- m_Instance = this;
- LoadPlayerAttachmentIndexes();
-
- m_ControllerRightStickTimer = new Timer();
- new ItemManager(GetMainWidget());
- new ColorManager();
-
- m_LeftArea = new LeftArea(this);
- m_RightArea = new RightArea(this);
- m_HandsArea = new HandsArea(this);
- m_PlayerPreview = new PlayerPreview(this);
- m_QuickbarWidget = GetMainWidget().FindAnyWidget("QuickbarGrid");
- m_Quickbar = new InventoryQuickbar(m_QuickbarWidget);
- m_Quickbar.UpdateItems(m_QuickbarWidget);
-
- WidgetEventHandler.GetInstance().RegisterOnDropReceived(GetMainWidget().FindAnyWidget("LeftBackground"), this, "OnLeftPanelDropReceived");
- WidgetEventHandler.GetInstance().RegisterOnDraggingOver(GetMainWidget().FindAnyWidget("LeftBackground"), this, "DraggingOverLeftPanel");
- WidgetEventHandler.GetInstance().RegisterOnDropReceived(GetMainWidget().FindAnyWidget("LeftPanel").FindAnyWidget("Scroller"), this, "OnLeftPanelDropReceived");
- WidgetEventHandler.GetInstance().RegisterOnDraggingOver(GetMainWidget().FindAnyWidget("LeftPanel").FindAnyWidget("Scroller"), this, "DraggingOverLeftPanel");
-
- WidgetEventHandler.GetInstance().RegisterOnDropReceived(GetMainWidget().FindAnyWidget("RightBackground"), this, "OnRightPanelDropReceived");
- WidgetEventHandler.GetInstance().RegisterOnDraggingOver(GetMainWidget().FindAnyWidget("RightBackground"), this, "DraggingOverRightPanel");
- WidgetEventHandler.GetInstance().RegisterOnDropReceived(GetMainWidget().FindAnyWidget("RightPanel").FindAnyWidget("Scroller"), this, "OnRightPanelDropReceived");
- WidgetEventHandler.GetInstance().RegisterOnDraggingOver(GetMainWidget().FindAnyWidget("RightPanel").FindAnyWidget("Scroller"), this, "DraggingOverRightPanel");
-
- WidgetEventHandler.GetInstance().RegisterOnDropReceived(GetMainWidget().FindAnyWidget("CharacterPanel"), this, "OnCenterPanelDropReceived");
- WidgetEventHandler.GetInstance().RegisterOnDraggingOver(GetMainWidget().FindAnyWidget("CharacterPanel"), this, "DraggingOverCenterPanel");
-
- WidgetEventHandler.GetInstance().RegisterOnDropReceived(GetMainWidget().FindAnyWidget("HandsPanel"), this, "OnHandsPanelDropReceived");
- WidgetEventHandler.GetInstance().RegisterOnDraggingOver(GetMainWidget().FindAnyWidget("HandsPanel"), this, "DraggingOverHandsPanel");
-
- #ifdef PLATFORM_CONSOLE
- PluginDiagMenu plugin_diag_menu = PluginDiagMenu.Cast(GetPlugin(PluginDiagMenu));
- GetGame().GetUIManager().ShowUICursor(false);
- ResetFocusedContainers();
- GetMainWidget().FindAnyWidget("CursorCharacter").Show(false);
- //console inventory toolbar
- m_TopConsoleToolbarVicinity = GetRootWidget().FindAnyWidget("LBRB_Vicinity");
- m_TopConsoleToolbarHands = GetRootWidget().FindAnyWidget("LBRB_Hands");
- m_TopConsoleToolbarEquipment = GetRootWidget().FindAnyWidget("LBRB_Equipment");
- RichTextWidget.Cast(m_TopConsoleToolbarVicinity.FindAnyWidget("LBRB_Vicinity_LBIcon")).SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUIInventoryTabLeft", "", EUAINPUT_DEVICE_CONTROLLER));
- RichTextWidget.Cast(m_TopConsoleToolbarVicinity.FindAnyWidget("LBRB_Vicinity_RBIcon")).SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUIInventoryTabRight", "", EUAINPUT_DEVICE_CONTROLLER));
- RichTextWidget.Cast(m_TopConsoleToolbarHands.FindAnyWidget("LBRB_Hands_LBIcon")).SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUIInventoryTabLeft", "", EUAINPUT_DEVICE_CONTROLLER));
- RichTextWidget.Cast(m_TopConsoleToolbarHands.FindAnyWidget("LBRB_Hands_RBIcon")).SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUIInventoryTabRight", "", EUAINPUT_DEVICE_CONTROLLER));
- RichTextWidget.Cast(m_TopConsoleToolbarEquipment.FindAnyWidget("LBRB_Equipment_LBIcon")).SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUIInventoryTabLeft", "", EUAINPUT_DEVICE_CONTROLLER));
- RichTextWidget.Cast(m_TopConsoleToolbarEquipment.FindAnyWidget("LBRB_Equipment_RBIcon")).SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUIInventoryTabRight", "", EUAINPUT_DEVICE_CONTROLLER));
-
- m_BottomConsoleToolbar = GetRootWidget().FindAnyWidget("BottomConsoleToolbar");
- m_BottomConsoleToolbarRichText = RichTextWidget.Cast(GetRootWidget().FindAnyWidget("ContextToolbarText"));
-
- m_NeedUpdateConsoleToolbar = false;
-
- GetGame().GetMission().GetOnInputPresetChanged().Insert(OnInputPresetChanged);
- GetGame().GetMission().GetOnInputDeviceChanged().Insert(OnInputDeviceChanged);
-
- UpdateConsoleToolbar();
- InitInputWrapperData();
- #endif
- }
-
- void InitInputWrapperData()
- {
- int namesCount = m_InvInputNames.Count();
- m_InvInputWrappers = new array<UAIDWrapper>;
- m_InvInputTimes = new array<float>;
-
- for (int i = 0; i < namesCount; i++)
- {
- m_InvInputWrappers.Insert(GetUApi().GetInputByName(m_InvInputNames[i]).GetPersistentWrapper());
- m_InvInputTimes.Insert(0);
- }
-
- m_InvInputWrappersCount = m_InvInputWrappers.Count();
- }
-
- protected void OnInputPresetChanged()
- {
- #ifdef PLATFORM_CONSOLE
- UpdateConsoleToolbar();
- #endif
- }
-
- protected void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
- {
- switch (pInputDeviceType)
- {
- case EInputDeviceType.CONTROLLER:
- m_BottomConsoleToolbar.Show(true);
- UpdateConsoleToolbar();
- break;
-
- default:
- if (GetGame().GetInput().IsEnabledMouseAndKeyboardEvenOnServer())
- {
- m_BottomConsoleToolbar.Show(false);
- m_TopConsoleToolbarVicinity.Show(false);
- m_TopConsoleToolbarHands.Show(false);
- m_TopConsoleToolbarEquipment.Show(false);
- }
- break;
- }
- }
-
- static Inventory GetInstance()
- {
- return m_Instance;
- }
-
- void Serialize()
- {
- ItemManager.GetInstance().SerializeDefaultOpenStates();
- ItemManager.GetInstance().SerializeDefaultHeaderOpenStates();
- GetGame().SaveProfile();
- }
- void Deserialize()
- {
- ItemManager.GetInstance().DeserializeDefaultOpenStates();
- ItemManager.GetInstance().DeserializeDefaultHeaderOpenStates();
- }
- static int GetPlayerAttachmentIndex(string slot_name)
- {
- return m_PlayerAttachmentsIndexes[slot_name];
- }
-
- static int GetPlayerAttachmentIndex(int slot_id)
- {
- return GetPlayerAttachmentIndex(InventorySlots.GetSlotName(slot_id));
- }
-
- protected void LoadPlayerAttachmentIndexes()
- {
- int i;
- string data, errorMessage;
-
- m_PlayerAttachmentsIndexes = new map<string, int>();
- if (GetGame().GetProfileString("INV_AttIndexes", data))
- {
- if (!JsonFileLoader<map<string, int>>.LoadData(data, m_PlayerAttachmentsIndexes, errorMessage))
- ErrorEx(errorMessage);
- }
-
- string configPathGhostSlots = "CfgVehicles SurvivorBase InventoryEquipment playerSlots";
- array<string> playerGhostSlots = new array<string>();
- GetGame().ConfigGetTextArray(configPathGhostSlots, playerGhostSlots);
-
- foreach (string slotName : playerGhostSlots)
- {
- slotName.Replace("Slot_", "");
- if (!m_PlayerAttachmentsIndexes.Contains(slotName) && InventorySlots.GetSlotIdFromString(slotName) != -1)
- {
- m_PlayerAttachmentsIndexes.Insert(slotName, m_PlayerAttachmentsIndexes.Count());
- }
- }
-
- if (!JsonFileLoader<map<string, int>>.MakeData(m_PlayerAttachmentsIndexes, data, errorMessage))
- ErrorEx(errorMessage);
- GetGame().SetProfileString("INV_AttIndexes", data);
- }
-
- static void MoveAttachmentUp(int slot_id)
- {
- int curr = GetPlayerAttachmentIndex(slot_id);
-
- int next_offset = 0;
- string next_item = "init";
- int next_id;
- EntityAI next_ent;
-
- while(!next_ent && next_item != "")
- {
- next_item = m_PlayerAttachmentsIndexes.GetKeyByValue(curr + --next_offset);
- next_id = InventorySlots.GetSlotIdFromString(next_item);
- next_ent = GetGame().GetPlayer().GetInventory().FindAttachment(next_id);
- if (next_ent && !m_Instance.m_RightArea.HasEntityContainerVisible(next_ent))
- next_ent = null;
- }
-
- if (next_item != "" && next_ent)
- {
- int next = GetPlayerAttachmentIndex(next_item);
- m_PlayerAttachmentsIndexes.Set(InventorySlots.GetSlotName(slot_id), next);
- m_PlayerAttachmentsIndexes.Set(next_item, curr);
- if (m_Instance)
- m_Instance.m_RightArea.SwapItemsInOrder(next_id, slot_id);
- }
- }
-
- static void MoveAttachmentDown(int slot_id)
- {
- int curr = GetPlayerAttachmentIndex(slot_id);
-
- int next_offset = 0;
- string next_item = "init";
- int next_id;
- EntityAI next_ent;
-
- while(!next_ent && next_item != "")
- {
- next_item = m_PlayerAttachmentsIndexes.GetKeyByValue(curr + ++next_offset);
- next_id = InventorySlots.GetSlotIdFromString(next_item);
- next_ent = GetGame().GetPlayer().GetInventory().FindAttachment(next_id);
- if (next_ent && !m_Instance.m_RightArea.HasEntityContainerVisible(next_ent))
- next_ent = null;
- }
-
- if (next_item != "" && next_ent)
- {
- int next = GetPlayerAttachmentIndex(next_item);
- m_PlayerAttachmentsIndexes.Set(InventorySlots.GetSlotName(slot_id), next);
- m_PlayerAttachmentsIndexes.Set(next_item, curr);
- if (m_Instance)
- m_Instance.m_RightArea.SwapItemsInOrder(next_id, slot_id);
- }
- }
- protected int GetProperControllerStickAngle(int angle)
- {
- int proper_angle = (360 - angle) % 360;
- return proper_angle;
- }
- protected int AngleToDirection(int angle)
- {
- if (angle < 45 || angle > 315)
- {
- return Direction.RIGHT;
- }
- else if (angle < 135 && angle > 45)
- {
- return Direction.DOWN;
- }
- else if (angle < 225 && angle > 135)
- {
- return Direction.LEFT;
- }
- else if (angle < 315 && angle > 225)
- {
- return Direction.UP;
- }
- return -1;
- }
- void TimerEnd()
- {
- m_ControllerRightStickTimerEnd = true;
- m_ControllerRightStickTimer.Stop();
- }
- bool Controller(Widget w, int control, int value)
- {
- #ifdef PLATFORM_CONSOLE
-
- //Right stick
- if (control == ControlID.CID_RADIALMENU)
- {
- m_ControllerAngle = value >> 4; // <0,360>
- m_ControllerTilt = value & 0xF; // <0,10>
- m_ControllerAngle = GetProperControllerStickAngle(m_ControllerAngle);
- m_ControllerAngle = AngleToDirection(m_ControllerAngle);
- if (m_ControllerTilt>5)
- {
- if (m_ControllerRightStickTimerEnd)
- {
- m_ControllerRightStickTimerEnd = false;
- m_ControllerRightStickTimer.Run(0.1, this, "TimerEnd");
- }
- }
- return true;
- }
-
- UpdateConsoleToolbar();
- #endif
- return false;
- }
- void DraggingOverHandsPanel(Widget w, int x, int y, Widget receiver)
- {
- ItemManager.GetInstance().HideDropzones();
- m_HandsArea.DraggingOverHandsPanel(w, x, y, receiver);
- }
-
- void OnHandsPanelDropReceived(Widget w, int x, int y, Widget receiver)
- {
- m_HandsArea.OnHandsPanelDropReceived(w, x, y, receiver);
- }
- void OnLeftPanelDropReceived(Widget w, int x, int y, Widget receiver)
- {
- m_LeftArea.OnLeftPanelDropReceived(w, x, y, receiver);
- }
- void OnRightPanelDropReceived(Widget w, int x, int y, Widget receiver)
- {
- if (w)
- {
- ItemPreviewWidget ipw = ItemPreviewWidget.Cast(w.FindAnyWidget("Render"));
- if (!ipw)
- {
- string name = w.GetName();
- name.Replace("PanelWidget", "Render");
- ipw = ItemPreviewWidget.Cast(w.FindAnyWidget(name));
- if (!ipw)
- {
- ipw = ItemPreviewWidget.Cast(w);
- if (!ipw)
- {
- return;
- }
- }
- }
-
- EntityAI item = ipw.GetItem();
- if (item)
- {
- PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
- InventoryLocation il = new InventoryLocation;
- if (player && player.GetInventory().FindFreeLocationFor(item, FindInventoryLocationType.CARGO | FindInventoryLocationType.ATTACHMENT, il))
- {
- SplitItemUtils.TakeOrSplitToInventory(player, player, item);
- }
- }
- }
- }
-
- void OnCenterPanelDropReceived(Widget w, int x, int y, Widget receiver)
- {
- if (w)
- {
- ItemPreviewWidget ipw = ItemPreviewWidget.Cast(w.FindAnyWidget("Render"));
- if (!ipw)
- {
- string name = w.GetName();
- name.Replace("PanelWidget", "Render");
- ipw = ItemPreviewWidget.Cast(w.FindAnyWidget(name));
- if (!ipw)
- {
- ipw = ItemPreviewWidget.Cast(w);
- if (!ipw)
- {
- return;
- }
- }
- }
-
- EntityAI item = ipw.GetItem();
- if (item)
- {
- if (!item.GetInventory().CanRemoveEntity())
- return;
- PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
-
- bool found = false;
-
- InventoryLocation inv_loc = new InventoryLocation;
-
- if (player)
- {
- int index = player.GetHumanInventory().FindUserReservedLocationIndex(item);
- if (index>=0)
- {
- player.GetHumanInventory().GetUserReservedLocation(index, inv_loc);
- if (player.GetInventory().LocationCanAddEntity(inv_loc))
- {
- SplitItemUtils.TakeOrSplitToInventoryLocation(player, inv_loc);
- }
- return;
- }
-
- }
-
- if (player && (player.GetInventory().CanAddAttachment(item)))
- {
- float stackable = item.GetTargetQuantityMax(-1);
-
- if (stackable == 0 || stackable >= item.GetQuantity())
- {
- player.PredictiveTakeEntityAsAttachment(item);
- }
- else
- {
- InventoryLocation il = new InventoryLocation;
- player.GetInventory().FindFreeLocationFor(item, FindInventoryLocationType.ATTACHMENT, il);
- ItemBase.Cast(item).SplitIntoStackMaxToInventoryLocationClient(il);
- }
- }
- else
- {
- int slot_id = item.GetInventory().GetSlotId(0);
- EntityAI slot_item = player.GetInventory().FindAttachment(slot_id);
- if (slot_item && player.GetInventory().CanSwapEntitiesEx(item, slot_item))
- {
- player.PredictiveSwapEntities(item, slot_item);
- }
- else if (player.CanReceiveItemIntoCargo(item))
- {
- InventoryLocation dst = new InventoryLocation;
- player.GetInventory().FindFreeLocationFor(item, FindInventoryLocationType.ANY, dst);
- if (dst.IsValid())
- {
- if (dst.GetType() == InventoryLocationType.HANDS && item.IsHeavyBehaviour())
- {
- ActionManagerClient mngr_client;
- CastTo(mngr_client, player.GetActionManager());
-
- ActionTarget atrg = new ActionTarget(item, null, -1, vector.Zero, -1.0);
- if (mngr_client.GetAction(ActionTakeItemToHands).Can(player, atrg, null))
- mngr_client.PerformActionStart(mngr_client.GetAction(ActionTakeItemToHands), atrg, null);
-
- return;
- }
-
- SplitItemUtils.TakeOrSplitToInventoryLocation(player, dst);
- }
- }
- }
- }
- }
- }
- void DraggingOverLeftPanel(Widget w, int x, int y, Widget receiver)
- {
- m_LeftArea.DraggingOverHeader(w, x, y, receiver);
- }
- void DraggingOverRightPanel(Widget w, int x, int y, Widget receiver)
- {
- m_RightArea.DraggingOverHeader(w, x, y, receiver);
- }
-
- void DraggingOverCenterPanel(Widget w, int x, int y, Widget receiver)
- {
- if (w)
- {
- ItemPreviewWidget ipw = ItemPreviewWidget.Cast(w.FindAnyWidget("Render"));
- if (!ipw)
- {
- string name = w.GetName();
- name.Replace("PanelWidget", "Render");
- ipw = ItemPreviewWidget.Cast(w.FindAnyWidget(name));
- if (!ipw)
- {
- ipw = ItemPreviewWidget.Cast(w);
- if (!ipw)
- {
- return;
- }
- }
- }
-
- EntityAI item = ipw.GetItem();
- PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
-
- if (player && item)
- {
- int slot_id = item.GetInventory().GetSlotId(0);
- EntityAI slot_item = player.GetInventory().FindAttachment(slot_id);
- bool found = false;
-
- InventoryLocation inv_loc = new InventoryLocation;
-
- int index = player.GetHumanInventory().FindUserReservedLocationIndex(item);
- if (index>=0)
- {
- player.GetHumanInventory().GetUserReservedLocation(index, inv_loc);
- if (player.GetInventory().LocationCanAddEntity(inv_loc))
- found = true;
- }
-
- if (!found)
- {
- player.GetInventory().FindFreeLocationFor(item, FindInventoryLocationType.ANY, inv_loc);
- }
-
-
- if (inv_loc.IsValid())
- {
- ItemManager.GetInstance().HideDropzones();
- GetMainWidget().FindAnyWidget("RightPanel").FindAnyWidget("DropzoneX").SetAlpha(1);
- if (inv_loc.GetType() == 4)
- {
- ItemManager.GetInstance().HideDropzones();
- GetMainWidget().FindAnyWidget("HandsPanel").FindAnyWidget("DropzoneX").SetAlpha(1);
- }
-
- ColorManager.GetInstance().SetColor(w, ColorManager.GREEN_COLOR);
- }
- else
- {
- ItemManager.GetInstance().ShowSourceDropzone(item);
- ColorManager.GetInstance().SetColor(w, ColorManager.RED_COLOR);
- }
- }
- else
- {
- ColorManager.GetInstance().SetColor(w, ColorManager.RED_COLOR);
- }
- }
- }
- void Update(float timeslice)
- {
- #ifdef PLATFORM_CONSOLE
- //inventory grid movement
- InventoryMovementButtonTickHandler(timeslice);
-
- if (m_InvInputActive & (1 << INV_MOV_RIGHT))
- {
- if (GetUApi().GetInputByID(UAUIDragNDrop).LocalValue())
- {
- EnableMicromanagement();
- }
-
- if (!GetUApi().GetInputByID(UAUIInventoryTabRight).LocalValue())
- {
- if (m_RightArea.IsActive())
- m_RightArea.MoveGridCursor(Direction.RIGHT);
- if (m_LeftArea.IsActive())
- m_LeftArea.MoveGridCursor(Direction.RIGHT);
- if (m_HandsArea.IsActive())
- m_HandsArea.MoveGridCursor(Direction.RIGHT);
- }
- }
- else if (m_InvInputActive & (1 << INV_MOV_LEFT))
- {
- if (GetUApi().GetInputByID(UAUIDragNDrop).LocalValue())
- {
- EnableMicromanagement();
- }
-
- if (!GetUApi().GetInputByID(UAUIInventoryTabLeft).LocalValue())
- {
- if (m_RightArea.IsActive())
- m_RightArea.MoveGridCursor(Direction.LEFT);
- if (m_LeftArea.IsActive())
- m_LeftArea.MoveGridCursor(Direction.LEFT);
- if (m_HandsArea.IsActive())
- m_HandsArea.MoveGridCursor(Direction.LEFT);
- }
- }
- else if (m_InvInputActive & (1 << INV_MOV_UP))
- {
- if (GetUApi().GetInputByID(UAUIDragNDrop).LocalValue())
- {
- EnableMicromanagement();
- }
-
- if (!GetUApi().GetInputByID(UAUIInventoryContainerUp).LocalValue())
- {
- if (m_RightArea.IsActive())
- m_RightArea.MoveGridCursor(Direction.UP);
- if (m_LeftArea.IsActive())
- m_LeftArea.MoveGridCursor(Direction.UP);
- if (m_HandsArea.IsActive())
- m_HandsArea.MoveGridCursor(Direction.UP);
- }
- }
- else if (m_InvInputActive & (1 << INV_MOV_DOWN))
- {
- if (GetUApi().GetInputByID(UAUIDragNDrop).LocalValue())
- {
- EnableMicromanagement();
- }
-
- if (!GetUApi().GetInputByID(UAUIInventoryContainerDown).LocalValue())
- {
- if (m_RightArea.IsActive())
- m_RightArea.MoveGridCursor(Direction.DOWN);
- if (m_LeftArea.IsActive())
- m_LeftArea.MoveGridCursor(Direction.DOWN);
- if (m_HandsArea.IsActive())
- m_HandsArea.MoveGridCursor(Direction.DOWN);
- }
- }
-
- m_InvInputActive = 0;
- #endif
-
- UpdateInterval();
- }
-
- UAInput m_InpInp = null;
- override void UpdateInterval()
- {
- PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
- InventoryItem item;
- InventoryItem handsItem
- if (GetUApi().GetInputByID(UAUIRotateInventory).LocalPress())
- {
- item = InventoryItem.Cast(ItemManager.GetInstance().GetDraggedItem());
- if (item)
- {
- int size_x, size_y;
- GetGame().GetInventoryItemSize(item, size_x, size_y);
- if (size_x != size_y)
- {
- item.GetInventory().FlipCargo();
- item.GetOnItemFlipped().Invoke(item.GetInventory().GetFlipCargo());
- }
- }
- }
-
- #ifdef PLATFORM_CONSOLE
- DayZPlayerInventory dpi;
- if (player)
- dpi = player.GetDayZPlayerInventory();
-
- // There's a second one a bit below
- if (dpi && !dpi.IsProcessing())
- {
- if (GetUApi().GetInputByID(UAUIExpandCollapseContainer).LocalPress())
- {
- if (m_RightArea.IsActive())
- {
- m_RightArea.ExpandCollapseContainer();
- }
- else if (m_LeftArea.IsActive())
- {
- m_LeftArea.ExpandCollapseContainer();
- }
- }
-
- if (GetUApi().GetInputByID(UAUIDragNDrop).LocalHoldBegin())
- {
- EnableMicromanagement();
- }
-
- if (GetUApi().GetInputByID(UAUISplit).LocalPress())
- {
- if (m_HandsArea.IsActive())
- {
- if (m_HandsArea.SplitItem())
- {
- m_HandsArea.SetActive(false);
- m_HandsArea.UnfocusGrid();
- m_RightArea.SetActive(true);
- }
- }
- else if (m_RightArea.IsActive())
- {
- m_RightArea.SplitItem();
- }
- else if (m_LeftArea.IsActive())
- {
- m_LeftArea.SplitItem();
- }
-
- HideOwnedTooltip();
- }
-
- if (GetUApi().GetInputByID(UAUIFastEquip).LocalPress())
- {
- if (m_HandsArea.IsActive())
- {
- if (m_HandsArea.EquipItem())
- {
- m_HandsArea.SetActive(false);
- m_HandsArea.UnfocusGrid();
- m_RightArea.SetActive(true);
- }
- }
- else if (m_RightArea.IsActive())
- {
- m_RightArea.EquipItem();
- }
- else if (m_LeftArea.IsActive())
- {
- m_LeftArea.EquipItem();
- }
-
- UpdateConsoleToolbar();
- HideOwnedTooltip();
- }
-
- if (ItemManager.GetInstance().IsMicromanagmentMode() && GetUApi().GetInputByID(UAUIDragNDrop).LocalRelease())
- {
- if (m_RightArea.IsActive())
- {
- m_RightArea.Select();
- }
- else if (m_LeftArea.IsActive())
- {
- m_LeftArea.Select();
- }
- else if (m_HandsArea.IsActive())
- {
- m_HandsArea.Select();
- }
-
- DisableMicromanagement();
- UpdateConsoleToolbar();
- }
- if (GetUApi().GetInputByID(UAUIPutInHandsFromVicinity).LocalPress())
- {
- if (m_LeftArea.IsActive())
- {
- if (m_LeftArea.Select())
- {
- m_LeftArea.SetActive(false);
- m_LeftArea.UnfocusGrid();
- m_HandsArea.SetActive(true);
-
- UpdateConsoleToolbar();
- }
- }
- }
- if (GetUApi().GetInputByID(UAUIPutInHandsFromInventory).LocalPress())
- {
- if (m_RightArea.IsActive())
- {
- if (m_RightArea.Select())
- {
- m_RightArea.SetActive(false);
- m_RightArea.UnfocusGrid();
- m_HandsArea.SetActive(true);
-
- UpdateConsoleToolbar();
- }
- }
- }
-
- if (GetUApi().GetInputByID(UAUIFastTransferToVicinity).LocalPress()) //item drop
- {
- if (m_HandsArea.IsActive())
- {
- item = InventoryItem.Cast(m_HandsArea.GetFocusedItem());
- if (item && item.GetInventory().CanRemoveEntity())
- {
- if (m_HandsArea.TransferItemToVicinity())
- {
- handsItem = InventoryItem.Cast(player.GetHumanInventory().GetEntityInHands());
- if (handsItem && handsItem == item)
- {
- m_HandsArea.SetActive(false);
- m_HandsArea.UnfocusGrid();
- m_LeftArea.SetActive(true);
- }
- m_HadFastTransferred = true;
- }
- }
- }
- else if (m_RightArea.IsActive())
- {
- item = InventoryItem.Cast(m_RightArea.GetFocusedItem());
- if (item && item.GetInventory().CanRemoveEntity())
- {
- if (m_RightArea.TransferItemToVicinity())
- m_HadFastTransferred = true;
- }
- }
-
- UpdateConsoleToolbar();
- HideOwnedTooltip();
- }
- }
-
- if (GetUApi().GetInputByID(UAUIInspectItem).LocalPress())
- {
- if (m_HandsArea.IsActive())
- {
- if (m_HandsArea.InspectItem())
- {
- m_HadInspected = true;
- }
- }
- else if (m_RightArea.IsActive())
- {
- if (m_RightArea.InspectItem())
- {
- m_HadInspected = true;
- }
- }
- else if (m_LeftArea.IsActive())
- {
- if (m_LeftArea.InspectItem())
- {
- m_HadInspected = true;
- }
- }
-
- UpdateConsoleToolbar();
- }
-
- if (GetUApi().GetInputByID(UAUIFastTransferItem).LocalPress())
- m_HadFastTransferred = false;
-
- if (GetUApi().GetInputByID(UAUIInspectItem).LocalPress())
- m_HadInspected = false;
-
- if (dpi && !dpi.IsProcessing())
- {
- if (!m_HadFastTransferred && GetUApi().GetInputByID(UAUIFastTransferItem).LocalPress()) //transfers item to inventory (not hands, or hands last?)
- {
- if (m_LeftArea.IsActive())
- {
- item = InventoryItem.Cast(m_LeftArea.GetFocusedItem());
- if (item && item.GetInventory().CanRemoveEntity())
- {
- m_LeftArea.TransferItem();
- }
- }
- else if (m_HandsArea.IsActive())
- {
- item = InventoryItem.Cast(m_HandsArea.GetFocusedItem());
- if (item && item.GetInventory().CanRemoveEntity())
- {
- handsItem = InventoryItem.Cast(player.GetHumanInventory().GetEntityInHands());
- if (m_HandsArea.TransferItem() && handsItem && handsItem == item)
- {
- m_HandsArea.SetActive(false);
- m_HandsArea.UnfocusGrid();
- m_RightArea.SetActive(true);
- }
-
- HideOwnedTooltip();
- }
- }
-
- UpdateConsoleToolbar();
- }
- }
-
- if (GetUApi().GetInputByID(UAUIInventoryContainerUp).LocalPress())
- {
- if (GetUApi().GetInputByID(UAUIDragNDrop).LocalValue())
- {
- EnableMicromanagement();
- }
-
- MoveFocusByContainer(Direction.UP);
- }
- if (GetUApi().GetInputByID(UAUIInventoryContainerDown).LocalPress())
- {
- if (GetUApi().GetInputByID(UAUIDragNDrop).LocalValue())
- {
- EnableMicromanagement();
- }
-
- MoveFocusByContainer(Direction.DOWN);
- }
- if (GetUApi().GetInputByID(UAUIInventoryTabLeft).LocalPress())
- {
- if (GetUApi().GetInputByID(UAUIDragNDrop).LocalValue())
- {
- EnableMicromanagement();
- }
-
- MoveFocusByArea(Direction.LEFT);
- }
- if (GetUApi().GetInputByID(UAUIInventoryTabRight).LocalPress())
- {
- if (GetUApi().GetInputByID(UAUIDragNDrop).LocalValue())
- {
- EnableMicromanagement();
- }
-
- MoveFocusByArea(Direction.RIGHT);
- }
-
- //Open Quickbar radial menu
- if (GetUApi().GetInputByID(UAUIQuickbarRadialInventoryOpen).LocalPress())
- {
- //assign item
- EntityAI item_to_assign;
-
- if (m_HandsArea.IsActive())
- {
- player = PlayerBase.Cast(GetGame().GetPlayer());
- item_to_assign = m_HandsArea.GetFocusedItem();
- m_HandsArea.AddItemToQuickbarRadial(item_to_assign);
- }
- else if (m_RightArea.IsActive())
- {
- item_to_assign = m_RightArea.GetFocusedItem();
- m_RightArea.AddItemToQuickbarRadial(item_to_assign);
- }
- }
- #endif
-
- MissionGameplay mission = MissionGameplay.Cast(GetGame().GetMission());
- if (!m_HadInspected && GetUApi().GetInputByID(UAUICombine).LocalPress())
- {
- if (GetMainWidget().IsVisible())
- {
- #ifdef PLATFORM_CONSOLE
- //DisableMicromanagement();
- if (m_RightArea.IsActive())
- {
- if (m_RightArea.CanCombine())
- {
- if (m_RightArea.Combine())
- {
- mission.HideInventory();
- }
- }
- }
- else if (m_LeftArea.IsActive())
- {
- if (m_LeftArea.CanCombine())
- {
- if (m_LeftArea.Combine())
- {
- mission.HideInventory();
- }
- }
- }
- #endif
- }
- }
-
- // controller close inventory using back action
- if (!m_HadInspected && GetUApi().GetInputByID(UAUIBack).LocalPress() && GetGame().GetInput().GetCurrentInputDevice() == EInputDeviceType.CONTROLLER)
- {
- mission.HideInventory();
- }
-
- for (int i = 0; i < 10; i++)
- {
- if (!m_HoldingQB && GetUApi().GetInputByName("UAItem" + i).LocalPress())
- {
- m_QBHoveredItems = InventoryItem.Cast(ItemManager.GetInstance().GetHoveredItem());
- m_HoldingQB = true;
- }
-
- if (m_HoldingQB && GetUApi().GetInputByName("UAItem" + i).LocalHold())
- {
-
- AddQuickbarItem(m_QBHoveredItems, i);
- m_QBHoveredItems = null;
- m_HoldingQB = false;
- }
- }
- m_LeftArea.UpdateInterval();
- m_RightArea.UpdateInterval();
- m_HandsArea.UpdateInterval();
- m_PlayerPreview.UpdateInterval();
-
- #ifdef PLATFORM_CONSOLE
- UpdateConsoleToolbarCheck();
- #endif
- }
-
- void AddQuickbarItem(InventoryItem item, int index)
- {
- PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
-
- if (item && item.GetInventory().CanRemoveEntity())
- {
- player.SetQuickBarEntityShortcut(item, index) ;
- }
-
- InventoryMenu menu = InventoryMenu.Cast(GetGame().GetUIManager().FindMenu(MENU_INVENTORY));
- if (menu)
- {
- menu.RefreshQuickbar();
- }
- }
-
- void EnableMicromanagement()
- {
- if (!ItemManager.GetInstance().IsMicromanagmentMode())
- {
- ItemManager.GetInstance().SetItemMicromanagmentMode(true);
- if (m_RightArea.IsActive())
- {
- m_RightArea.SelectItem();
- }
- else if (m_LeftArea.IsActive())
- {
- m_LeftArea.SelectItem();
- }
- else if (m_HandsArea.IsActive())
- {
- m_HandsArea.SelectItem();
- }
-
- UpdateConsoleToolbar();
- HideOwnedTooltip();
- }
- }
-
- void DisableMicromanagement()
- {
- if (ItemManager.GetInstance().IsMicromanagmentMode())
- {
- ItemManager.GetInstance().SetItemMicromanagmentMode(false);
- ItemManager.GetInstance().SetSelectedItemEx(null, null, null);
- UpdateConsoleToolbar();
- HideOwnedTooltip();
- }
- }
- override void SetLayoutName()
- {
- #ifdef PLATFORM_CONSOLE
- m_LayoutName = WidgetLayoutName.InventoryXbox;
- #else
- switch (InventoryMenu.GetWidthType())
- {
- case ScreenWidthType.NARROW:
- {
- m_LayoutName = WidgetLayoutName.InventoryNarrow;
- break;
- }
- case ScreenWidthType.MEDIUM:
- {
- m_LayoutName = WidgetLayoutName.InventoryMedium;
- break;
- }
- case ScreenWidthType.WIDE:
- {
- m_LayoutName = WidgetLayoutName.InventoryWide;
- break;
- }
- }
- #endif
- }
- void Init() {}
- void Reset()
- {
- m_LeftArea.Refresh();
- m_RightArea.Refresh();
- m_HandsArea.Refresh();
- }
-
- void ResetFocusedContainers()
- {
- #ifdef PLATFORM_CONSOLE
- m_RightArea.UnfocusGrid();
- m_LeftArea.UnfocusGrid();
- m_HandsArea.UnfocusGrid();
-
- m_LeftArea.SetActive(false);
- m_HandsArea.SetActive(false);
- m_RightArea.SetActive(false);
-
- m_RightArea.ResetFocusedContainer();
- m_LeftArea.ResetFocusedContainer();
-
- m_RightArea.SetActive(true);
- #endif
- }
- override void OnShow()
- {
- SetFocus(GetMainWidget());
- Deserialize();
-
- PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
- if (player && player.IsPlacingLocal())
- {
- GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Call(player.TogglePlacingLocal);
- }
- Mission mission = GetGame().GetMission();
- if (mission)
- {
- IngameHud hud = IngameHud.Cast(mission.GetHud());
- if (hud)
- {
- hud.ShowQuickbarUI(false);
- hud.ShowHudInventory(true);
- }
- }
-
- RefreshQuickbar();
- UpdateInterval();
- UpdateConsoleToolbar();
-
- m_HadFastTransferred = false;
- m_HadInspected = false;
-
- m_PlayerPreview.RefreshPlayerPreview();
- }
- override void OnHide()
- {
- Serialize();
- HideOwnedTooltip();
- Mission mission = GetGame().GetMission();
- if (mission)
- {
- IngameHud hud = IngameHud.Cast(mission.GetHud());
- if (hud)
- {
- hud.ShowQuickbarUI(true);
- hud.ShowHudInventory(false);
- }
- }
- ItemManager.GetInstance().SetSelectedItemEx(null, null, null);
- ResetFocusedContainers();
- }
-
- override void Refresh()
- {
- m_LeftArea.Refresh();
- m_HandsArea.Refresh();
- m_RightArea.Refresh();
-
- RefreshQuickbar();
- UpdateConsoleToolbar();
- }
-
- void RefreshQuickbar()
- {
- #ifndef PLATFORM_CONSOLE
- m_QuickbarWidget.Show(true);
- #else
- m_QuickbarWidget.Show(GetGame().GetInput().IsEnabledMouseAndKeyboardEvenOnServer());
- #endif
-
- #ifndef PLATFORM_CONSOLE
- if (m_Quickbar)
- #else
- if (m_Quickbar && GetGame().GetInput().IsEnabledMouseAndKeyboardEvenOnServer())
- #endif
- {
- m_Quickbar.UpdateItems(m_QuickbarWidget);
- }
- }
-
- #ifdef PLATFORM_CONSOLE
- protected string GetConsoleToolbarText(int mask)
- {
- string result = "";
-
- string toHandsSwapVicinity = string.Format(" %1", InputUtils.GetRichtextButtonIconFromInputAction("UAUIPutInHandsFromVicinity", GetStringVariant("UAUIPutInHandsFromVicinity",{"#STR_Controls_TakeInHandsSwap","#STR_USRACT_HoldToHandSwap",""}), EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
- string toHandsSwapInv = string.Format(" %1", InputUtils.GetRichtextButtonIconFromInputAction("UAUIPutInHandsFromInventory", GetStringVariant("UAUIPutInHandsFromInventory",{"#STR_Controls_TakeInHandsSwap","#STR_USRACT_HoldToHandSwap",""}), EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
- string drop = string.Format(" %1", InputUtils.GetRichtextButtonIconFromInputAction("UAUIFastTransferToVicinity", "#dayz_context_menu_drop", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
- string equip = string.Format(" %1", InputUtils.GetRichtextButtonIconFromInputAction("UAUIFastEquip", "#dayz_context_menu_equip", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
- string split = string.Format(" %1", InputUtils.GetRichtextButtonIconFromInputAction("UAUISplit", GetStringVariant("UAUISplit",{"#dayz_context_menu_split","#STR_Controls_HoldSplit",""}), EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
- string toInventory = string.Format(" %1", InputUtils.GetRichtextButtonIconFromInputAction("UAUIFastTransferItem", "#dayz_context_menu_to_inventory", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
- string openCloseContainer = string.Format(" %1", InputUtils.GetRichtextButtonIconFromInputAction("UAUIExpandCollapseContainer", "#dayz_context_menu_open_close", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
- string micromanagment = string.Format(" %1", InputUtils.GetRichtextButtonIconFromInputAction("UAUIDragNDrop", "#dayz_context_menu_micro", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
- string quickslot = string.Format(" %1", InputUtils.GetRichtextButtonIconFromInputAction("UAUIQuickbarRadialInventoryOpen", "#ps4_dayz_context_menu_quickslot", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
- string combine = string.Format(" %1", InputUtils.GetRichtextButtonIconFromInputAction("UAUICombine", GetStringVariant("UAUICombine",{"#dayz_context_menu_combine","#dayz_context_menu_combine_hold",""}), EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
-
- if (mask & ConsoleActionToolbarMask.OPEN_CLOSE_CONTAINER)
- {
- result += openCloseContainer;
- }
- if (mask & ConsoleActionToolbarMask.TO_HANDS_SWAP_VICINITY)
- {
- result += toHandsSwapVicinity;
- }
- if (mask & ConsoleActionToolbarMask.TO_HANDS_SWAP_INVENTORY)
- {
- result += toHandsSwapInv;
- }
- if (mask & ConsoleActionToolbarMask.TO_INVENTORY)
- {
- result += toInventory;
- }
- if (mask & ConsoleActionToolbarMask.DROP)
- {
- result += drop;
- }
- if (mask & ConsoleActionToolbarMask.SPLIT)
- {
- result += split;
- }
- if (mask & ConsoleActionToolbarMask.EQUIP)
- {
- result += equip;
- }
- if (mask & ConsoleActionToolbarMask.COMBINE)
- {
- result += combine;
- }
- if (mask & ConsoleActionToolbarMask.MICROMANAGMENT)
- {
- result += micromanagment;
- }
- if (mask & ConsoleActionToolbarMask.QUICKSLOT)
- {
- result += quickslot;
- }
- return result;
- }
- #endif
- Container GetFocusedArea()
- {
- if (m_LeftArea && m_LeftArea.IsActive())
- {
- return m_LeftArea;
- }
- else if (m_RightArea && m_RightArea.IsActive())
- {
- return m_RightArea;
- }
- else if (m_HandsArea && m_HandsArea.IsActive())
- {
- return m_HandsArea;
- }
- return null;
- }
-
- #ifdef PLATFORM_CONSOLE
- void UpdateConsoleToolbarCheck()
- {
- if ( m_NeedUpdateConsoleToolbar )
- {
- PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
- if (player.GetInventory().GetAnyInventoryReservationCount() == 0)
- {
- m_NeedUpdateConsoleToolbar = false;
- UpdateConsoleToolbar();
- }
- }
- }
- #endif
-
- //Console toolbar
- void UpdateConsoleToolbar()
- {
- #ifdef PLATFORM_CONSOLE
- int combinationFlag = 0;
- string contextualText;
- InventoryLocation il;
-
- Container focusedArea = GetFocusedArea();
- if (focusedArea)
- {
- Container focusedContainer = GetFocusedArea().GetFocusedContainer();
- EntityAI focusedItem = GetFocusedArea().GetFocusedItem();
-
- if (!(focusedItem && focusedItem.IsSetForDeletion()))
- {
- if (focusedContainer)
- {
- if (focusedItem)
- {
- il = new InventoryLocation;
- focusedItem.GetInventory().GetCurrentInventoryLocation( il );
- }
-
- bool canBeManipulated = false;
- PlayerBase player;
- PlayerBase itemPlayerOwner;
-
- player = PlayerBase.Cast(GetGame().GetPlayer());
-
- m_NeedUpdateConsoleToolbar = player.GetInventory().GetAnyInventoryReservationCount() > 0;
-
- if (focusedItem)
- {
- itemPlayerOwner = PlayerBase.Cast(focusedItem.GetHierarchyRootPlayer());
- il = new InventoryLocation;
- focusedItem.GetInventory().GetCurrentInventoryLocation( il );
-
- canBeManipulated = !player.GetInventory().HasInventoryReservation( focusedItem, null ) && !player.GetInventory().IsInventoryLocked() && !player.IsItemsToDelete();
- m_NeedUpdateConsoleToolbar |= !canBeManipulated;
- canBeManipulated = canBeManipulated && focusedItem.CanPutIntoHands(null);
- canBeManipulated = canBeManipulated && focusedItem.GetInventory().CanRemoveEntity();
-
- EntityAI parent = il.GetParent();
- if ( parent && il.GetType() == InventoryLocationType.ATTACHMENT )
- {
- canBeManipulated = canBeManipulated && AttachmentsOutOfReach.IsAttachmentReachable( parent, "", il.GetSlot() );
- canBeManipulated = canBeManipulated && !parent.GetInventory().GetSlotLock( il.GetSlot() );
- }
-
- if (canBeManipulated)
- {
- if (!ItemManager.GetInstance().IsMicromanagmentMode())
- {
- combinationFlag |= ConsoleActionToolbarMask.MICROMANAGMENT;
- }
-
- if (focusedContainer.CanEquipEx(focusedItem))
- {
- combinationFlag |= ConsoleActionToolbarMask.EQUIP;
- }
-
- if (player!= null && player == itemPlayerOwner)
- {
- if (focusedContainer.CanSwapOrTakeToHandsEx(focusedItem))
- {
- combinationFlag |= ConsoleActionToolbarMask.TO_HANDS_SWAP_INVENTORY;
- }
-
- if (focusedContainer.CanDropEx(focusedItem))
- {
- combinationFlag |= ConsoleActionToolbarMask.DROP;
- }
- }
- else
- {
- if (focusedContainer.CanSwapOrTakeToHandsEx(focusedItem))
- {
- combinationFlag |= ConsoleActionToolbarMask.TO_HANDS_SWAP_VICINITY;
- }
- }
-
- if (focusedContainer.CanCombineEx(focusedItem))
- {
- combinationFlag |= ConsoleActionToolbarMask.COMBINE;
- }
-
- if (focusedContainer.CanSplitEx(focusedItem))
- {
- combinationFlag |= ConsoleActionToolbarMask.SPLIT;
- }
-
- if (focusedArea.CanTakeToInventoryEx(focusedItem))
- {
- combinationFlag |= ConsoleActionToolbarMask.TO_INVENTORY;
- }
- }
- }
-
- if (focusedContainer.CanOpenCloseContainerEx(focusedItem))
- {
- combinationFlag |= ConsoleActionToolbarMask.OPEN_CLOSE_CONTAINER;
- }
-
- if (player!= null && focusedContainer.CanAddToQuickbarEx(focusedItem))
- {
- combinationFlag |= ConsoleActionToolbarMask.QUICKSLOT;
- }
- }
- }
- contextualText = GetConsoleToolbarText(combinationFlag);
- if (m_TopConsoleToolbarVicinity)
- m_TopConsoleToolbarVicinity.Show(m_LeftArea.IsActive());
- if (m_TopConsoleToolbarHands)
- m_TopConsoleToolbarHands.Show(m_HandsArea.IsActive());
- if (m_TopConsoleToolbarEquipment)
- m_TopConsoleToolbarEquipment.Show(m_RightArea.IsActive());
- if (m_BottomConsoleToolbarRichText)
- m_BottomConsoleToolbarRichText.SetText(contextualText + " ");
- }
- #endif
- }
-
- //! Picks from the strings by active input limiter variant in order: {click,hold,doubleclick}. Intended for inputs that check 'LocalPress' exclusively!!
- string GetStringVariant(string pInputAction, notnull array<string> variants)
- {
- if (variants.Count() != 3)
- {
- ErrorEx("wrong array count!");
- return "";
- }
-
- UAInput inp = GetUApi().GetInputByName(pInputAction);
- if (!inp.IsLimited() || inp.IsClickLimit()) //returns 'click' (no extension) variant as default
- {
- return variants[0];
- }
- if (inp.IsHoldLimit() || inp.IsHoldBeginLimit())
- {
- return variants[1];
- }
- if (inp.IsDoubleClickLimit())
- {
- return variants[2];
- }
- ErrorEx("Unhandled limiter exception!");
- return "";
- }
-
- //! Shifts between containers vertically
- void MoveFocusByContainer(int direction)
- {
- HideOwnedTooltip();
-
- if (direction == Direction.UP)
- {
- if ( m_LeftArea.IsActive() )
- {
- m_LeftArea.SetSameLevelPreviousActive();
- }
- else if ( m_RightArea.IsActive() )
- {
- m_RightArea.SetSameLevelPreviousActive();
- }
- else if ( m_HandsArea.IsActive() )
- {
- m_HandsArea.SetSameLevelPreviousActive();
- }
-
- UpdateConsoleToolbar();
- }
- else if (direction == Direction.DOWN)
- {
- if ( m_LeftArea.IsActive() )
- {
- m_LeftArea.SetSameLevelNextActive();
- }
- else if ( m_RightArea.IsActive() )
- {
- m_RightArea.SetSameLevelNextActive();
- }
- else if ( m_HandsArea.IsActive() )
- {
- m_HandsArea.SetSameLevelNextActive();
- }
-
- UpdateConsoleToolbar();
- }
- }
-
- //! Shifts between vicinity-hands-player
- void MoveFocusByArea(int direction)
- {
- HideOwnedTooltip();
- PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
-
- if (direction == Direction.LEFT)
- {
- if (m_LeftArea.IsActive())
- {
- if (!ItemManager.GetInstance().IsMicromanagmentMode())
- {
- m_LeftArea.UnfocusGrid();
- }
- m_LeftArea.SetActive(false);
- m_RightArea.SetActive(true);
-
- UpdateConsoleToolbar();
- }
- else if (m_RightArea.IsActive())
- {
- if (!ItemManager.GetInstance().IsMicromanagmentMode())
- {
- m_RightArea.UnfocusGrid();
- }
- m_RightArea.SetActive(false);
- player = PlayerBase.Cast(GetGame().GetPlayer());
- EntityAI item_in_hands = player.GetItemInHands();
- m_HandsArea.SetActive(true);
- UpdateConsoleToolbar();
- }
- else if (m_HandsArea.IsActive())
- {
- m_HandsArea.UnfocusGrid();
- m_HandsArea.SetActive(false);
- m_LeftArea.SetActive(true);
-
- UpdateConsoleToolbar();
- }
- }
- else if (direction == Direction.RIGHT)
- {
- if (m_LeftArea.IsActive())
- {
- if (!ItemManager.GetInstance().IsMicromanagmentMode())
- {
- m_LeftArea.UnfocusGrid();
- }
- m_LeftArea.SetActive(false);
- player = PlayerBase.Cast(GetGame().GetPlayer());
- item_in_hands = player.GetItemInHands();
- m_HandsArea.SetActive(true);
-
- UpdateConsoleToolbar();
- }
- else if (m_RightArea.IsActive())
- {
- if (!ItemManager.GetInstance().IsMicromanagmentMode())
- {
- m_RightArea.UnfocusGrid();
- }
- m_RightArea.SetActive(false);
- m_LeftArea.SetActive(true);
-
- UpdateConsoleToolbar();
- }
- else if (m_HandsArea.IsActive())
- {
- m_HandsArea.UnfocusGrid();
- m_HandsArea.SetActive(false);
- m_RightArea.SetActive(true);
-
- UpdateConsoleToolbar();
- }
- }
- }
-
- void InventoryMovementButtonTickHandler(float timeslice)
- {
- float tickvalue = 0;
-
- if (m_SensitivityThreshold > 0.0)
- {
- if (m_SensitivityThreshold < BT_REPEAT_TIME) //sensitivity solution...
- {
- m_SensitivityThreshold += timeslice;
- return;
- }
- else
- {
- m_SensitivityThreshold = 0.0;
- }
- }
-
- for (int i = 0; i < m_InvInputWrappersCount; i++)
- {
- m_InvUAInput = m_InvInputWrappers[i].InputP();
-
- if (m_InvUAInput.LocalValue() > BT_THRESHOLD_VALUE)
- {
- tickvalue = m_InvInputTimes[i];
- tickvalue += timeslice;
- }
- else
- {
- tickvalue = 0.0;
- }
-
- if (tickvalue < BT_REPEAT_DELAY && m_InvUAInput.LocalPress())
- {
- m_InvInputActive |= (1 << i);
- m_SensitivityThreshold += timeslice;
- }
- else if (tickvalue > (BT_REPEAT_DELAY + BT_REPEAT_TIME))
- {
- while (tickvalue > (BT_REPEAT_DELAY + BT_REPEAT_TIME))
- {
- tickvalue -= BT_REPEAT_TIME;
- }
-
- m_InvInputActive |= (1 << i);
- m_SensitivityThreshold += timeslice;
- }
- else
- {
- m_InvInputActive &= ~(1 << i);
- }
-
- m_InvInputTimes[i] = tickvalue;
- }
- }
-
- // DEPRECATED below
- protected Widget m_SpecializationPanel;
- protected Widget m_SpecializationIcon;
-
- void UpdateSpecialtyMeter();
- }
|