text: // Copyright 2019 Google LLC & Bastiaan Konings
  // Licensed under the Apache License, Version 2.0 (the "License");
  // you may not use this file except in compliance with the License.
  // You may obtain a copy of the License at
  //
  //     http://www.apache.org/licenses/LICENSE-2.0
  //
  // Unless required by applicable law or agreed to in writing, software
  // distributed under the License is distributed on an "AS IS" BASIS,
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  // See the License for the specific language governing permissions and
  // limitations under the License.
  
  // written by bastiaan konings schuiling 2008 - 2015
  // this work is public domain. the code is undocumented, scruffy, untested, and should generally not be used for anything important.
  // i do not offer support, so don't ask. to be used for inspiration :)
  
  #include "ingame.hpp"
  
  #include "../../main.hpp"
  #include "../gameplan.hpp"
  #include "../controllerselect.hpp"
  #include "../pagefactory.hpp"
  
  #include "../settings.hpp"
  
  using namespace blunted;
  
  IngamePage::IngamePage(Gui2WindowManager *windowManager, const Gui2PageData &pageData) : Gui2Page(windowManager, pageData) {
  
    teamID = pageData.properties->GetInt("teamID", 0);
  
    GetGameTask()->GetMatch()->Pause(true);
  
    Gui2Root *root = windowManager->GetRoot();
  
    Gui2Button *buttonGamePlan = new Gui2Button(windowManager, "button_gameplan", 0, 0, 30, 3, "game plan");
    Gui2Button *buttonControllerSelect = new Gui2Button(windowManager, "button_controllerselect", 0, 0, 30, 3, "controller select");
    Gui2Button *buttonCameraSettings = new Gui2Button(windowManager, "button_camerasettings", 0, 0, 30, 3, "camera settings");
    Gui2Button *buttonVisualOptions = new Gui2Button(windowManager, "button_visualoptions", 0, 0, 30, 3, "visual options");
    Gui2Button *buttonSystemSettings = new Gui2Button(windowManager, "button_systemsettings", 0, 0, 30, 3, "system settings");
    Gui2Button *buttonPreQuit = new Gui2Button(windowManager, "button_quit", 0, 0, 30, 3, "forfeit match");
  
    buttonGamePlan->sig_OnClick.connect(boost::bind(&IngamePage::GoGamePlan, this));
    buttonControllerSelect->sig_OnClick.connect(boost::bind(&IngamePage::GoControllerSelect, this));
    buttonCameraSettings->sig_OnClick.connect(boost::bind(&IngamePage::GoCameraSettings, this));
    buttonVisualOptions->sig_OnClick.connect(boost::bind(&IngamePage::GoVisualOptions, this));
    buttonSystemSettings->sig_OnClick.connect(boost::bind(&IngamePage::GoSystemSettings, this));
    buttonPreQuit->sig_OnClick.connect(boost::bind(&IngamePage::GoPreQuit, this));
  
  
    Gui2Grid *grid = new Gui2Grid(windowManager, "grid", 10, 10, 80, 80);
  
    grid->AddView(buttonGamePlan, 0, 0);
    grid->AddView(buttonControllerSelect, 1, 0);
    grid->AddView(buttonCameraSettings, 2, 0);
    grid->AddView(buttonVisualOptions, 3, 0);
    grid->AddView(buttonSystemSettings, 4, 0);
    grid->AddView(buttonPreQuit, 6, 0);
  
    grid->UpdateLayout(0.5);
  
    this->AddView(grid);
    grid->Show();
  
    buttonGamePlan->SetFocus();
  
    this->Show();
  }
  
  IngamePage::~IngamePage() {
  }
  
  void IngamePage::GoGamePlan() {
    Properties properties;
    properties.Set("teamID", teamID);
    CreatePage(e_PageID_GamePlan, properties);
  }
  
  void IngamePage::GoControllerSelect() {
    Properties properties;
    properties.SetBool("isInGame", true);
    CreatePage(e_PageID_ControllerSelect, properties);
  }
  
  void IngamePage::GoCameraSettings() {
    CreatePage(e_PageID_Camera);
  }
  
  void IngamePage::GoVisualOptions() {
    CreatePage(e_PageID_VisualOptions);
  }
  
  void IngamePage::GoSystemSettings() {
    CreatePage(e_PageID_Settings);
  }
  
  void IngamePage::GoPreQuit() {
    CreatePage(e_PageID_PreQuit);
  }
  
  
  void IngamePage::ProcessWindowingEvent(WindowingEvent *event) {
    if (event->IsEscape()) {
      GetMenuTask()->ReleaseAllButtons();
      GetGameTask()->GetMatch()->Pause(false);
    }
    Gui2Page::ProcessWindowingEvent(event);
  }
  
  
  
  PreQuitPage::PreQuitPage(Gui2WindowManager *windowManager, const Gui2PageData &pageData) : Gui2Page(windowManager, pageData) {
    Gui2Root *root = windowManager->GetRoot();
    Gui2Image *bg = new Gui2Image(windowManager, "image_prequit_bg", 30, 42.5, 40, 15);
    bg->LoadImage("media/menu/backgrounds/black.png");
    this->AddView(bg);
  
    Gui2Caption *restartCaption = new Gui2Caption(windowManager, "caption_prequit_info", 0, 0, 100, 3, "are you sure you want to forfeit?");
    Gui2Button *okButton = new Gui2Button(windowManager, "button_prequit_ok", 10, 0, 30, 3, "OK, forfeit");
    Gui2Button *cancelButton = new Gui2Button(windowManager, "button_prequit_cancel", 10, 0, 30, 3, "Continue match");
    okButton->sig_OnClick.connect(boost::bind(&PreQuitPage::GoMenu, this));
    cancelButton->sig_OnClick.connect(boost::bind(&PreQuitPage::GoBack, this));
  
    Gui2Grid *grid = new Gui2Grid(windowManager, "grid_prequit", 30, 42.5, 40, 15);
  
    grid->AddView(restartCaption, 0, 0);
    grid->AddView(okButton, 1, 0);
    grid->AddView(cancelButton, 2, 0);
  
    grid->UpdateLayout(0.5);
  
    this->AddView(grid);
    grid->Show();
  
    cancelButton->SetFocus();
  
    this->Show();
  }
  
  PreQuitPage::~PreQuitPage() {
  }
  
  void PreQuitPage::GoMenu() {
    this->Exit();
    GetMenuTask()->SetMenuAction(e_MenuAction_Menu);
    delete this;
  }
  