123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422 |
- class InGameMenu extends UIScriptedMenu
- {
- string m_ServerInfoText;
-
- protected Widget m_ContinueButton;
- protected Widget m_SeparatorPanel;
- protected Widget m_ExitButton;
- protected Widget m_RestartButton;
- protected Widget m_RespawnButton;
- protected Widget m_RestartDeadRandomButton;
- protected Widget m_RestartDeadCustomButton;
- protected Widget m_OptionsButton;
- protected Widget m_ServerInfoPanel;
- protected Widget m_FavoriteButton;
- protected Widget m_FavoriteImage;
- protected Widget m_UnfavoriteImage;
- protected Widget m_CopyInfoButton;
- protected Widget m_FeedbackButton;
-
- protected ref TextWidget m_ModdedWarning;
- protected ref TextWidget m_ServerIP;
- protected ref TextWidget m_ServerPort;
- protected ref TextWidget m_ServerName;
-
- protected ref UiHintPanel m_HintPanel;
-
- void ~InGameMenu()
- {
- HudShow(true);
-
- Mission mission = g_Game.GetMission();
- if (mission)
- mission.Continue();
- }
- override Widget Init()
- {
- layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/day_z_ingamemenu.layout");
-
- m_ContinueButton = layoutRoot.FindAnyWidget("continuebtn");
- m_SeparatorPanel = layoutRoot.FindAnyWidget("separator_red");
- m_ExitButton = layoutRoot.FindAnyWidget("exitbtn");
- m_RestartButton = layoutRoot.FindAnyWidget("restartbtn");
- m_RespawnButton = layoutRoot.FindAnyWidget("respawn_button");
- m_RestartDeadRandomButton = layoutRoot.FindAnyWidget("respawn_button_random");
- m_RestartDeadCustomButton = layoutRoot.FindAnyWidget("respawn_button_custom");
- m_OptionsButton = layoutRoot.FindAnyWidget("optionsbtn");
- m_ModdedWarning = TextWidget.Cast(layoutRoot.FindAnyWidget("ModdedWarning"));
- m_HintPanel = new UiHintPanel(layoutRoot.FindAnyWidget("hint_frame"));
- m_ServerInfoPanel = layoutRoot.FindAnyWidget("server_info");
- m_ServerIP = TextWidget.Cast(layoutRoot.FindAnyWidget("server_ip"));
- m_ServerPort = TextWidget.Cast(layoutRoot.FindAnyWidget("server_port"));
- m_ServerName = TextWidget.Cast(layoutRoot.FindAnyWidget("server_name"));
- m_FavoriteImage = layoutRoot.FindAnyWidget("favorite_image");
- m_UnfavoriteImage = layoutRoot.FindAnyWidget("unfavorite_image");
- m_CopyInfoButton = layoutRoot.FindAnyWidget("copy_button");
- m_FeedbackButton = layoutRoot.FindAnyWidget("feedbackbtn");
-
- if (GetGame().IsMultiplayer())
- {
- ButtonSetText(m_RestartButton, "#main_menu_respawn");
- }
- else
- {
- ButtonSetText(m_RestartButton, "#main_menu_restart");
- }
-
- HudShow(false);
- SetGameVersion();
- SetServerInfoVisibility(SetServerInfo() && g_Game.GetProfileOption(EDayZProfilesOptions.SERVERINFO_DISPLAY));
- m_ModdedWarning.Show(g_Game.ReportModded());
-
- Mission mission = g_Game.GetMission();
- if (mission)
- mission.Pause();
-
- return layoutRoot;
- }
-
- protected void SetGameVersion()
- {
- TextWidget version_widget = TextWidget.Cast(layoutRoot.FindAnyWidget("version"));
- string version;
- GetGame().GetVersion(version);
- version_widget.SetText("#main_menu_version" + " " + version);
- #ifdef PREVIEW_BUILD
- version_widget.SetText("THIS IS PREVIEW");
- #endif
- }
-
- protected bool SetServerInfo()
- {
- if (GetGame().IsMultiplayer())
- {
- MenuData menu_data = g_Game.GetMenuData();
- GetServersResultRow info = OnlineServices.GetCurrentServerInfo();
-
- if (info)
- {
- m_ServerPort.SetText(info.m_HostPort.ToString());
- m_ServerIP.SetText(info.m_HostIp);
- m_ServerName.SetText(info.m_Name);
- m_UnfavoriteImage.Show(info.m_Favorite);
- m_FavoriteImage.Show(!info.m_Favorite);
- m_ServerInfoText = "" + info.GetIpPort();
-
- return true;
- }
- //temporary, incomplete solution, OnlineServices.GetCurrentServerInfo() should be working!
- else if (menu_data && menu_data.GetLastPlayedCharacter() != GameConstants.DEFAULT_CHARACTER_MENU_ID)
- {
- int char_id = menu_data.GetLastPlayedCharacter();
- int port;
- string address,name;
-
- menu_data.GetLastServerAddress(char_id,address);
- port = menu_data.GetLastServerPort(char_id);
- menu_data.GetLastServerName(char_id,name);
- m_ServerPort.SetText(port.ToString());
- m_ServerIP.SetText(address);
- m_ServerName.SetText(name);
- m_ServerInfoText = "" + address + ":" + port;
-
- return true;
- }
- else
- {
- g_Game.RefreshCurrentServerInfo();
- }
- }
- return false;
- }
-
- protected void HudShow(bool show)
- {
- Mission mission = GetGame().GetMission();
- if (mission)
- {
- IngameHud hud = IngameHud.Cast(mission.GetHud());
- if (hud)
- {
- hud.ShowHudUI(g_Game.GetProfileOption(EDayZProfilesOptions.HUD) && show);
- hud.ShowQuickbarUI(g_Game.GetProfileOption(EDayZProfilesOptions.QUICKBAR) && show);
- }
- }
- }
-
- override bool OnMouseEnter(Widget w, int x, int y)
- {
- ColorHighlight(w);
- return true;
- }
-
- override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
- {
- ColorNormal(w);
- return true;
- }
- override bool OnClick(Widget w, int x, int y, int button)
- {
- super.OnClick(w, x, y, button);
-
- if (w == m_ContinueButton)
- {
- OnClick_Continue();
- return true;
- }
- else if (w == m_RestartButton)
- {
- #ifdef DEVELOPER
- if (GetGame().IsMultiplayer() || (GetGame().GetPlayer() && GetGame().GetPlayer().IsUnconscious()))
- OnClick_Restart();
- else
- {
- PluginDeveloper plugin = PluginDeveloper.GetInstance();
- if (plugin)
- plugin.ToggleMissionLoader();
- }
- #else
- OnClick_Restart();
- #endif
- return true;
- }
- else if (w == m_RespawnButton)
- {
- OnClick_Respawn();
- return true;
- }
- else if (w == m_OptionsButton)
- {
- OnClick_Options();
- return true;
- }
- else if (w == m_ExitButton)
- {
- OnClick_Exit();
- return true;
- }
- else if (w == m_CopyInfoButton)
- {
- GetGame().CopyToClipboard(m_ServerInfoText);
- }
- else if (w == m_FeedbackButton)
- {
- OpenFeedback();
- }
- return false;
- }
-
- protected void OnClick_Continue()
- {
- GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(GetGame().GetMission().Continue);
- }
-
- protected void OnClick_Restart()
- {
- if (!GetGame().IsMultiplayer())
- {
- GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(GetGame().RestartMission);
- }
- else
- {
- OnClick_Respawn();
- }
- }
-
- protected void OnClick_Respawn()
- {
- Man player = GetGame().GetPlayer();
-
- if (player && player.IsUnconscious() && !player.IsDamageDestroyed())
- {
- GetGame().GetUIManager().ShowDialog("#main_menu_respawn", "#main_menu_respawn_question", IDC_INT_RETRY, DBT_YESNO, DBB_YES, DMT_QUESTION, this);
- }
- else
- {
- if (GetGame().GetMission().GetRespawnModeClient() == GameConstants.RESPAWN_MODE_CUSTOM)
- {
- GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(GetGame().GetUIManager().EnterScriptedMenu,MENU_RESPAWN_DIALOGUE,this);
- }
- else
- {
- GameRespawn(true);
- }
- }
- }
-
- protected void OnClick_Options()
- {
- EnterScriptedMenu(MENU_OPTIONS);
- }
-
- protected void OnClick_Exit()
- {
- GetGame().LogoutRequestTime();
- GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(GetGame().GetMission().CreateLogoutMenu, this);
- }
-
- override bool OnModalResult(Widget w, int x, int y, int code, int result)
- {
- super.OnModalResult(w, x, y, code, result);
- if (code == IDC_INT_EXIT && result == DBB_YES)
- {
- if (GetGame().IsMultiplayer())
- {
- GetGame().LogoutRequestTime();
- GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(GetGame().GetMission().CreateLogoutMenu, this);
- }
- else
- {
- // skip logout screen in singleplayer
- GetGame().GetMission().AbortMission();
- }
- g_Game.CancelLoginTimeCountdown();
- return true;
- }
- else if (code == IDC_INT_EXIT && result == DBB_NO)
- {
- g_Game.CancelLoginTimeCountdown();
- }
- else if (code == IDC_INT_RETRY && result == DBB_YES && GetGame().IsMultiplayer())
- {
- if (GetGame().GetMission().GetRespawnModeClient() == GameConstants.RESPAWN_MODE_CUSTOM)
- {
- GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(GetGame().GetUIManager().EnterScriptedMenu,MENU_RESPAWN_DIALOGUE,this);
- }
- else
- {
- GameRespawn(true);
- }
- return true;
- }
-
- return false;
- }
-
- override void Update(float timeslice)
- {
- super.Update(timeslice);
-
- UpdateGUI();
- }
-
- protected void UpdateGUI()
- {
- #ifdef BULDOZER
- m_RestartButton.Show(false);
- m_RespawnButton.Show(false);
- #else
- Man player = GetGame().GetPlayer();
- bool playerAlive = player && player.GetPlayerState() == EPlayerStates.ALIVE;
- if (GetGame().IsMultiplayer())
- {
- m_RestartButton.Show(playerAlive && player.IsUnconscious() && !CfgGameplayHandler.GetDisableRespawnInUnconsciousness());
- m_RespawnButton.Show(!playerAlive);
- }
- else
- {
- m_RestartButton.Show(true);
- m_RespawnButton.Show(false);
- m_SeparatorPanel.Show(playerAlive);
- }
- m_ContinueButton.Show(playerAlive);
- #endif
- }
-
- void MenuRequestRespawn(UIScriptedMenu menu, bool random)
- {
- if (RespawnDialogue.Cast(menu))
- GameRespawn(random);
- }
-
- protected void GameRespawn(bool random)
- {
- GetGame().GetMenuDefaultCharacterData(false).SetRandomCharacterForced(random);
- GetGame().RespawnPlayer();
-
- PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
- if (player)
- {
- player.SimulateDeath(true);
- GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(player.ShowDeadScreen, true, 0);
- }
-
- MissionGameplay missionGP = MissionGameplay.Cast(GetGame().GetMission());
- missionGP.DestroyAllMenus();
- missionGP.SetPlayerRespawning(true);
- missionGP.Continue();
- Close();
- }
-
- protected void ColorHighlight(Widget w)
- {
- if (!w)
- return;
-
- ButtonSetColor(w, ARGB(255, 0, 0, 0));
- ButtonSetTextColor(w, ARGB(255, 255, 0, 0));
- }
-
- protected void ColorNormal(Widget w)
- {
- if (!w)
- return;
-
- ButtonSetColor(w, ARGB(0, 0, 0, 0));
- ButtonSetTextColor(w, ARGB(255, 255, 255, 255));
- }
-
- protected void ColorDisable(Widget w)
- {
- if (!w)
- return;
-
- ButtonSetColor(w, ARGB(0, 0, 0, 0));
- ButtonSetTextColor(w, ColorManager.COLOR_DISABLED_TEXT);
- }
-
- protected void ButtonSetText(Widget w, string text)
- {
- if (!w)
- return;
-
- TextWidget label = TextWidget.Cast(w.FindWidget(w.GetName() + "_label"));
- if (label)
- label.SetText(text);
-
- }
- protected void ButtonSetColor(Widget w, int color)
- {
- Widget panel = w.FindWidget(w.GetName() + "_panel");
- if (panel)
- panel.SetColor(color);
- }
-
- protected void ButtonSetTextColor(Widget w, int color)
- {
- TextWidget label = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_label"));
- if (label)
- label.SetColor(color);
- }
-
- void SetServerInfoVisibility(bool show)
- {
- m_ServerInfoPanel.Show(show);
- }
-
- protected void OpenFeedback()
- {
- GetGame().OpenURL("https://feedback.bistudio.com/project/view/2/");
- }
-
- //! DEPRECATED
- void ToggleFavoriteServer();
- }
|