コード例 #1
0
ファイル: basepage.cpp プロジェクト: leshkajou/bookrate
void BasePage::addBook(){
	WContainerWidget *container = new WContainerWidget();
	Wt::WTemplate *t = new Wt::WTemplate(Wt::WString::tr("addBookForm"));
	
	WLineEdit *editTitle = new WLineEdit(container);
	editTitle->setPlaceholderText("title");
	t->bindWidget("title", editTitle);
	
	WLineEdit *editAuthor = new WLineEdit(container);
	editAuthor->setPlaceholderText("author");
	t->bindWidget("author", editAuthor);
	
	WLineEdit *editAuthorYears = new WLineEdit(container);
	editAuthorYears->setPlaceholderText("years of life");
	t->bindWidget("years", editAuthorYears);
	
	WLineEdit *editGenre = new WLineEdit(container);
	editGenre->setPlaceholderText("genre");
	t->bindWidget("genre", editGenre);
	
	WLineEdit *editYear = new WLineEdit(container);
	editYear->setPlaceholderText("year");
	t->bindWidget("year", editYear);
	
	WLineEdit *editSeria = new WLineEdit(container);
	editSeria->setPlaceholderText("seria");
	t->bindWidget("seria", editSeria);
	
	WLineEdit *editNumOfBooks = new WLineEdit(container);
	editNumOfBooks->setPlaceholderText("num of books");
	t->bindWidget("numOfBooks", editNumOfBooks);
	
	WLineEdit *editNumInSeria = new WLineEdit(container);
	editNumInSeria->setPlaceholderText("number in seria");
	t->bindWidget("numInSeria", editNumInSeria);
	
	WLineEdit *editMark = new WLineEdit(container);
	editMark->setPlaceholderText("mark");
	editMark->setValidator(new Wt::WIntValidator(1, 10));
	t->bindWidget("mark", editMark);
	
	WPushButton *button = new WPushButton("Add book", container);
	button->setMargin(10, Top | Bottom);

	button->clicked().connect(std::bind([=] () {BookManager bm; bm.addBook(editTitle->valueText().toUTF8(),
																		   editAuthor->valueText().toUTF8(),
																		   editAuthorYears->valueText().toUTF8(),
																		   editGenre->valueText().toUTF8(),
																		   intoInt(editYear),
																		   editSeria->valueText().toUTF8(),
																		   intoInt(editNumOfBooks),
																		   intoInt(editNumInSeria),
																		   intoInt(editMark)); }));
	
	t->bindWidget("button", button);
	_pagecontent->addWidget(t);	
}
コード例 #2
0
/** @brief loads collision spheres from a file based on mesh name
 */
void Corpus::loadCollision(const string& a_collision_name)
{

  // TEMP!!! fake, only works for crusaders for now
  if (a_collision_name == "bullet") {
    RelBSPosition = Vector3::ZERO;
    BoundingSphere = Sphere(RelBSPosition, 2);
    CollisionSpheres.push_back(Sphere(RelBSPosition, 2));
    RelCSPositions.push_back(Vector3::ZERO);
    CSAreas.push_back(0);
    // debug
    displayCollision(true);
    return;
  } else if (a_collision_name == "ground") {
    RelBSPosition = Vector3::ZERO;
    BoundingSphere = Sphere(RelBSPosition, GROUND_COLLISION_RADIUS);
    CollisionSpheres.push_back(Sphere(RelBSPosition, GROUND_COLLISION_RADIUS));
    RelCSPositions.push_back(Vector3::ZERO);
    CSAreas.push_back(0);
    // debug
    displayCollision(true);
    return;
  }

  string a_filename = a_collision_name + "_collision";

  map<string, string> pairs;
  assert(FilesHandler::getPairs(a_filename, COLLISION_DIR, pairs));

  // bounding sphere
  vector<string> bs_sphere_string;
  FilesHandler::getStringArray(bs_sphere_string, pairs["bs"]);

  // makes sure the are enough values
  if (bs_sphere_string.size() < 4) {
    Game::kill(a_collision_name + " collision file is corrupt, missing bounding sphere");
  }

  // read in the bounding sphere
  BoundingSphere.Centre = Vector3(FilesHandler::getReal(bs_sphere_string[0]),
                                  FilesHandler::getReal(bs_sphere_string[1]),
                                  FilesHandler::getReal(bs_sphere_string[2]));
  BoundingSphere.Radius = FilesHandler::getReal(bs_sphere_string[3]);

  Sphere sphere;
  int i = 0;

  // check to see if a collision sphere with a consecutive id exists
  while (pairs.find(string("cs.") + intoString(i)) != pairs.end() && i < MAX_NUM_CS) {
    // load the cs definition string
    vector<string> cs_sphere_string;
    FilesHandler::getStringArray(cs_sphere_string, pairs["cs." + intoString(i)]);

    // makes sure the are enough values
    if (cs_sphere_string.size() < 5) {
      Game::kill(a_collision_name + " collision file is corrupt, collision sphere garbled");
    }

    // collision sphere area (to place hits)
    CSAreas.push_back(intoInt(cs_sphere_string[0]));

    // read in the collision sphere
    sphere.Centre = Vector3(FilesHandler::getReal(cs_sphere_string[1]),
                            FilesHandler::getReal(cs_sphere_string[2]),
                            FilesHandler::getReal(cs_sphere_string[3]));
    sphere.Radius = FilesHandler::getReal(cs_sphere_string[4]);
    // put the sphere in the vector
    CollisionSpheres.push_back(sphere);

    ++i;
  }

  // same for collision spheres
  for (size_t i = 0, for_size = CollisionSpheres.size(); i < for_size; ++i) {
    RelCSPositions.push_back(CollisionSpheres[i].Centre);
  }
  // and the bounding sphere
  RelBSPosition = BoundingSphere.Centre;

  // debug
  displayCollision(true);
}