<commit_before>/* bzflag
 * Copyright (c) 1993 - 2004 <NAME>
 *
 * This package is free software;  you can redistribute it and/or
 * modify it under the terms of the license found in the file
 * named COPYING that should have accompanied this file.
 *
 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

#include "common.h"

/* interface header */
#include "SaveWorldMenu.h"

/* system implementation headers */
#include <vector>
#include <string>

/* common implementation headers */
#include "BzfDisplay.h"
#include "BzfWindow.h"
#include "OpenGLTexture.h"
#include "SceneRenderer.h"
#include "StateDatabase.h"
#include "FontManager.h"
#include "DirectoryNames.h"

/* local implementation headers */
#include "MenuDefaultKey.h"
#include "World.h"
#include "FormatMenu.h"
#include "KeyboardMapMenu.h"
#include "GUIOptionsMenu.h"
#include "SaveWorldMenu.h"
#include "ServerListCache.h"
#include "MainMenu.h"
#include "HUDDialog.h"
#include "HUDuiControl.h"
#include "HUDuiLabel.h"
#include "HUDuiTypeIn.h"


SaveWorldMenu::SaveWorldMenu()
{
  // add controls
  std::vector<HUDuiControl*>& list = getControls();

  HUDuiLabel* label = new HUDuiLabel;
  label->setFontFace(MainMenu::getFontFace());
  label->setString("Save World");
  list.push_back(label);

  filename = new HUDuiTypeIn;
  filename->setFontFace(MainMenu::getFontFace());
  filename->setLabel("File Name:");
  filename->setMaxLength(255);
  list.push_back(filename);

  status = new HUDuiLabel;
  status->setFontFace(MainMenu::getFontFace());
  status->setString("");
  status->setPosition(0.5f * (float)width, status->getY());
  list.push_back(status);

  // only navigate to the file name
  initNavigation(list, 1,1);
}

SaveWorldMenu::~SaveWorldMenu()
{
}


HUDuiDefaultKey* SaveWorldMenu::getDefaultKey()
{ 
  return MenuDefaultKey::getInstance(); 
}

void SaveWorldMenu::execute()
{
  World *pWorld = World::getWorld();
  if (pWorld == NULL) {
    status->setString("No world loaded to save");
  } else {
    std::string fullname = getWorldDirName();
    fullname += filename->getString();
    fullname += ".bzw";
    bool success = World::getWorld()->writeWorld(fullname);
    if (success) {
      std::string newLabel = "File Saved: ";
      newLabel += fullname;
      status->setString(newLabel);
    } else {
      std::string newLabel = "Error Saving: ";
      newLabel += fullname;
      status->setString(newLabel);
    }<commit_msg>do not add ".bzw" if it already is part of the name.<commit_after>/* bzflag
 * Copyright (c) 1993 - 2004 <NAME>
 *
 * This package is free software;  you can redistribute it and/or
 * modify it under the terms of the license found in the file
 * named COPYING that should have accompanied this file.
 *
 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 */

#include "common.h"

/* interface header */
#include "SaveWorldMenu.h"

/* system implementation headers */
#include <vector>
#include <string>

/* common implementation headers */
#include "BzfDisplay.h"
#include "BzfWindow.h"
#include "OpenGLTexture.h"
#include "SceneRenderer.h"
#include "StateDatabase.h"
#include "FontManager.h"
#include "DirectoryNames.h"

/* local implementation headers */
#include "MenuDefaultKey.h"
#include "World.h"
#include "FormatMenu.h"
#include "KeyboardMapMenu.h"
#include "GUIOptionsMenu.h"
#include "SaveWorldMenu.h"
#include "ServerListCache.h"
#include "MainMenu.h"
#include "HUDDialog.h"
#include "HUDuiControl.h"
#include "HUDuiLabel.h"
#include "HUDuiTypeIn.h"


SaveWorldMenu::SaveWorldMenu()
{
  // add controls
  std::vector<HUDuiControl*>& list = getControls();

  HUDuiLabel* label = new HUDuiLabel;
  label->setFontFace(MainMenu::getFontFace());
  label->setString("Save World");
  list.push_back(label);

  filename = new HUDuiTypeIn;
  filename->setFontFace(MainMenu::getFontFace());
  filename->setLabel("File Name:");
  filename->setMaxLength(255);
  list.push_back(filename);

  status = new HUDuiLabel;
  status->setFontFace(MainMenu::getFontFace());
  status->setString("");
  status->setPosition(0.5f * (float)width, status->getY());
  list.push_back(status);

  // only navigate to the file name
  initNavigation(list, 1,1);
}

SaveWorldMenu::~SaveWorldMenu()
{
}


HUDuiDefaultKey* SaveWorldMenu::getDefaultKey()
{ 
  return MenuDefaultKey::getInstance(); 
}

void SaveWorldMenu::execute()
{
  World *pWorld = World::getWorld();
  if (pWorld == NULL) {
    status->setString("No world loaded to save");
  } else {
    std::string fullname = getWorldDirName();
    fullname += filename->getString();
    if (strstr(fullname.c_str(), ".bzw") == NULL)
    	fullname += ".bzw";
    bool success = World::getWorld()->writeWorld(fullname);
    if (success) {
      std::string newLabel = "File Saved: ";
      newLabel += fullname;
      status->setString(newLabel);
    } else {
      std::string newLabel = "Error Saving: ";
      newLabel += fullname;
      status->setString(newLabel);
    }
{'fraction_non_alphanumeric': 0.14113366526235158, 'fraction_numerical': 0.005744925315970892, 'mean_word_length': 4.580128205128205, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5297498', 'n_tokens_mistral': 1697, 'n_tokens_neox': 1665, 'n_words': 427}