
declare netwrite Boolean Net_DistractionFreeMode for UI;
declare netwrite Boolean Net_DriveHideMode for UI;

declare CMlLabel HideChatLabel <=> (Page.GetFirstChild("player_hide_chat_toggle") as CMlLabel);

while(True) {
  foreach (Event in PendingEvents) {
    // Distration free mode. (F8)
    if (Event.Type == CMlScriptEvent::Type::KeyPress && Event.KeyCode == 45) {
      if (Net_DistractionFreeMode == True) {
        Net_DistractionFreeMode = False;
      } else {
        Net_DistractionFreeMode = True;
      }
    }

    // Driving widget hiding
    if (Event.Type == CMlScriptEvent::Type::KeyPress && Event.KeyCode == 46) {
      if (Net_DistractionFreeMode == True) {
        // Do nothing.
      } else {
        if (Net_DriveHideMode == True) {
          Net_DriveHideMode = False;
        } else {
          Net_DriveHideMode = True;
        }
      }
    }

    // Show/hide chat.
    if (Event.Type == CMlScriptEvent::Type::MouseClick && Event.ControlId == "player_hide_chat_toggle") {
      if (ClientUI.OverlayHideChat) {
        ClientUI.OverlayHideChat = False;
        HideChatLabel.SetText("");
        ClientUI.SendChat("Show chat");
      } else {
        ClientUI.OverlayHideChat = True;
        HideChatLabel.SetText("$f00");
        ClientUI.SendChat("Hide chat");
      }
    }
  }
  yield;
}
