File size: 10,424 Bytes
24b81cb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 |
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 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");
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);
}
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);
}
//! DEPRECATED
void ToggleFavoriteServer();
}
|