void Project::CreateSettings(const std::string &path, const std::string& name) { GameWorld world; GameObject* root = world.CreateRoot(); root->AddComponent<ProjectSettings>()->name = name; std::ofstream file; file.open(path); root->ToJson(file); file.close(); }
void Project::CreateNewWorld(const std::string &worldPath) { GameWorld world; GameObject* root = world.CreateRoot(); GameObject* cube = root->CreateObject(); cube->AddComponent<Transform>(); cube->AddComponent<Mesh>()->GetMesh<Vertex>().AddCube(0, 1); cube->AddComponent<Renderable>(); std::ofstream file; file.open(worldPath); root->ToJson(file); file.close(); }
void Initialize() { GameObject* root = world.CreateRoot(); Gui* gui = root->CreateSystem<Gui>(); root->CreateSystem<LayoutSystem>(); gui->Setup("images.png", "images.xml", Context().Viewport()); box = gui->CreateControl(root, "Box", 100, 300); box->AddComponent<Draggable>(); box->AddComponent<Layouter>()->ChildrenLayoutMode = Layouter::LayoutMode::Vertical; box->GetComponent<Layouter>()->SetAll(300); for(int i=0; i<4; i++) { GameObject* row = gui->CreateControl(box, "Box"); row->AddComponent<Layouter>()->Min = {300, 1}; row->GetComponent<Layouter>()->Max = {300.0f, static_cast<float>((i == 1 ? 60 : 20))}; row->GetComponent<Layouter>()->Desired = {300.0f, static_cast<float>((i == 1 ? 60 : 20))}; row->GetComponent<Layouter>()->ChildrenLayoutMode = Layouter::LayoutMode::Horizontal; AddTextBox(row, gui, {50, 20}, {50,20}); AddTextBox(row, gui, {100, 20}, {5000,20}); //AddTextBox(row, gui, {200, 20}, {300,20}); } dragger = gui->CreateControl(root, "Box", 100, 30); dragger->AddComponent<Draggable>(); //auto font = gui->CreateFont("Font.fnt", "Font"); //gui->CreateClipper(box, true); //auto label = gui->CreateLabel(box, 100, 200, font, "Hej med dig", 50); //gui->CreateClipper(box, false); /* GameObject* root = world.CreateRoot(); Selectable* sel1 = 0; { GameObject* object = root->CreateChild(); sel1 = object->AddComponent<Selectable>(); sel1->Selected.Changed.Bind(this, &Game::SelectedChanged, object); std::cout << "1. empty = " << (sel1->Selected.Changed.Empty() ? "true" : "false") << std::endl; object->Remove(); } world.Update(0); Selectable* sel2 = 0; { GameObject* object = root->CreateChild(); sel2 = object->AddComponent<Selectable>(); //sel2->Selected.Changed.Bind(this, &Game::SelectedChanged, object); std::cout << "2. empty = " << (sel2->Selected.Changed.Empty() ? "true" : "false") << std::endl; object->Remove(); } if (sel1 == sel2) { std::cout << "Same" << std::endl; } Component cDefault = Component(); //cDefault.Value = 123; Component comp1 = cDefault; comp1.Value.Changed.Bind(this, &Game::SelectedChanged, (GameObject*)0); comp1.Value = cDefault.Value; comp1 = cDefault; { } */ }
void Initialize() { root = world.CreateRoot(); root->CreateSystem<RenderSystem>(); root->CreateSystem<FontTextureSystem>(); root->CreateSystem<FirstPersonMoverSystem>(); root->CreateSystem<LabelMeshSystem>(); root->CreateSystem<ColorSystem>(); GameObject* camera = root->CreateObject(); camera->AddComponent<Camera>(); camera->AddComponent<Transform>()->Position = {0,0,5}; camera->AddComponent<FirstPersonMover>(); GameObject* font = root->CreateObject(); bool succes = font->AddComponent<Font>()->LoadTTF("/Library/Fonts/Times New Roman.ttf");//"/Users/Jeppe/Library/Fonts/NuevaStd-Bold_ttf.ttf"); if (!succes) { std::cout << "Font could not be loaded"<<std::endl; } //font->GetComponent<Font>()->CharacterSetEverySize = 2; font->AddComponent<TextureComponent>(); font->AddComponent<Renderable>()->BlendMode = BlendModeType::Alpha; font->AddComponent<Mesh>()->GetMesh<Vertex>().AddQuad(0, 40, Colour::White()); //font->AddComponent<Transform>()->Position = {0,0,1}; { label = root->CreateObject(); label->AddComponent<Transform>(); label->AddComponent<Sizeable>()->Size = {64,64}; label->AddComponent<Renderable>()->BlendMode = BlendModeType::Alpha; label->AddComponent<TextureComponent>(font); label->AddComponent<Mesh>(); label->AddComponent<Font>(font); label->AddComponent<Label>()->Text = "Testing"; label->GetComponent<Label>()->FontSize = 12; label->GetComponent<Label>()->WordWrap = false; label->GetComponent<Label>()->HAlignment = Font::HAlignment::Center; label->GetComponent<Label>()->VAlignment = Font::VAlignment::Middle; label->AddComponent<Colorable>()->Color = Colour::Black(); } { label2 = root->CreateObject(); label2->AddComponent<Transform>()->Position = {0,12}; label2->AddComponent<Sizeable>()->Size = {120,64}; label2->AddComponent<Renderable>()->BlendMode = BlendModeType::Alpha; label2->AddComponent<TextureComponent>(font); //label2->AddComponent<Mesh>(); label2->AddComponent<Font>(font); //label2->AddComponent<Label>()->Text = "Cubism, is a new puzzle game from Jeppe Nielsen"; //label2->GetComponent<Label>()->FontSize = 64; //label2->GetComponent<Label>()->WordWrap = true; } { GameObject* cube = root->CreateObject(); cube->AddComponent<Transform>()->Position = {32,32,-1}; cube->AddComponent<Mesh>()->GetMesh<Vertex>().AddCube(0, {32,32,0.02f}); cube->AddComponent<Renderable>(); } { GameObject* cube = root->CreateObject(); cube->AddComponent<Transform>()->Position = {1,0,0}; cube->AddComponent<Mesh>()->GetMesh<Vertex>().AddCube(0, {0.02f,6.0f,0.02f}); cube->AddComponent<Renderable>(); } counter = 0; timer = 2.0f; Input.ButtonDown.Bind([font] (std::string button) { font->GetComponent<Font>()->Clear(); //std::string path = "/Projects/PocketEngine/Games/TestFreeType/test.png"; //font->GetComponent<TextureComponent>()->Texture().SaveToPng(path, GL_RGBA); }); }