JANK MODE: Messy / broken commit - in progress
Needed to make a checkpoint, gods forgive me for committing known broken code straight to master. The jam has in a sense already begun. I tested a smaller solution in the xplat_concept repo earlier today. In short, I'm going to build a janky method to add new + report existing UI elements. After that's done, the UI building should be done from python modules, hastening the UI design. This is ugly and bad, I am truly sorry. We just need to get through 7DRL, so I can't make it pretty today.
This commit is contained in:
parent
2c1946c29b
commit
1e9fd77a13
7 changed files with 147 additions and 101 deletions
|
|
@ -20,7 +20,7 @@ void setSpriteTexture(int ti)
|
|||
}
|
||||
|
||||
UITestScene::UITestScene(GameEngine* g)
|
||||
: Scene(g), grid(30, 10, 16, 20, 20, 400, 320)
|
||||
: Scene(g), grid(150, 150, 16, 20, 20, 800, 520)
|
||||
{
|
||||
// demo sprites from texture file
|
||||
texture.loadFromFile("./assets/kenney_tinydungeon.png");
|
||||
|
|
@ -33,22 +33,14 @@ UITestScene::UITestScene(GameEngine* g)
|
|||
setSpriteTexture(0);
|
||||
|
||||
// random for this test
|
||||
//std::default_random_engine generator(42);
|
||||
//std::normal_distribution<double> distribution(0, 131);
|
||||
std::random_device rd; // Will be used to obtain a seed for the random number engine
|
||||
std::mt19937 gen(rd()); // Standard mersenne_twister_engine seeded with rd()
|
||||
std::uniform_int_distribution<> distrib(0, 131);
|
||||
// Use distrib to transform the random unsigned int
|
||||
// generated by gen into an int in [1, 6]
|
||||
//for (int n = 0; n != 10; ++n)
|
||||
// std::cout << distrib(gen) << ' ';
|
||||
// std::cout << '\n';
|
||||
|
||||
std::uniform_int_distribution<> distrib(84, 100);
|
||||
|
||||
// Test grid with random sprite noise
|
||||
|
||||
for (int _x = 0; _x < 30; _x++)
|
||||
for (int _y = 0; _y < 10; _y++)
|
||||
for (int _x = 0; _x < 150; _x++)
|
||||
for (int _y = 0; _y < 150; _y++)
|
||||
//grid.at(_x, _y).tilesprite = _y*11 + _x;
|
||||
//if (!_x % 2 || _y == 0) grid.at(_x, _y).tilesprite = 121;
|
||||
//else
|
||||
|
|
@ -95,7 +87,7 @@ UITestScene::UITestScene(GameEngine* g)
|
|||
test_menu.visible = false;
|
||||
test_menu.box.setSize(sf::Vector2f(350, 200));
|
||||
test_menu.add_caption("debug to stdout", 16, sf::Color(255, 255, 0));
|
||||
test_menu.add_button(Button(0, 0, 130, 40, sf::Color(0, 0, 192), sf::Color(0,0,0), "view", game->getFont(), "showviewport"));
|
||||
test_menu.add_button(Button(0, 0, 130, 40, sf::Color(0, 0, 192), sf::Color(0,0,0), "REPL", game->getFont(), "startrepl"));
|
||||
|
||||
test_menu2.visible = true;
|
||||
test_menu2.box.setPosition(150, 180);
|
||||
|
|
@ -112,10 +104,12 @@ UITestScene::UITestScene(GameEngine* g)
|
|||
menus.push_back(test_menu);
|
||||
menus.push_back(test_menu2);
|
||||
|
||||
/*
|
||||
test_ship.miner();
|
||||
test_ship.angle = 180.0;
|
||||
test_ship.position.x = 250;
|
||||
test_ship.position.y = 120;
|
||||
*/
|
||||
//std::cout << menus.size() << std::endl;
|
||||
|
||||
}
|
||||
|
|
@ -148,10 +142,11 @@ void UITestScene::update()
|
|||
|
||||
void UITestScene::doButton(std::string b_action)
|
||||
{
|
||||
if (!b_action.compare("showviewport"))
|
||||
if (!b_action.compare("startrepl"))
|
||||
{
|
||||
std::cout << viewport.getSize().x << ", " << viewport.getSize().y << ": "
|
||||
<< viewport.getCenter().x << ", " << viewport.getCenter().y << std::endl;
|
||||
McRFPy_API::REPL();
|
||||
//std::cout << viewport.getSize().x << ", " << viewport.getSize().y << ": "
|
||||
// << viewport.getCenter().x << ", " << viewport.getCenter().y << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -218,39 +213,30 @@ void UITestScene::doAction(std::string name, std::string type)
|
|||
if (ACTION("sound_test", "start")) { sound.play(); }
|
||||
|
||||
if (ACTION("left", "start")) {
|
||||
//viewport.move(-10, 0);
|
||||
grid.center_x -= 0.5;
|
||||
}
|
||||
if (ACTION("right", "start")) {
|
||||
//viewport.move(10, 0);
|
||||
grid.center_x += 0.5;
|
||||
}
|
||||
if (ACTION("up", "start")) {
|
||||
//viewport.move(0, -10);
|
||||
grid.center_y -= 0.5;
|
||||
}
|
||||
if (ACTION("down", "start")) {
|
||||
//viewport.move(0, 10);
|
||||
grid.center_y += 0.5;
|
||||
}
|
||||
//if (ACTION("down", "start")) {
|
||||
// viewport.move(0, 10);
|
||||
//}
|
||||
if (ACTION("zoom_down", "start")) {
|
||||
//if (zoom > 0.2f) zoom -= 0.1f; viewport.zoom(zoom);
|
||||
if (grid.zoom > 0.75f) grid.zoom -= 0.25f;
|
||||
}
|
||||
if (ACTION("zoom_up", "start")) {
|
||||
//if (zoom < 10.0f) zoom += 0.1f; viewport.zoom(zoom);
|
||||
if (grid.zoom < 5.0f) grid.zoom += 0.25f;
|
||||
}
|
||||
//std::cout << "viewport: " << viewport.getCenter().x << ", " << viewport.getCenter().y << std::endl;
|
||||
//
|
||||
|
||||
|
||||
if (type.compare("resize")) // get center coordinate from game coordinate viewport, apply to new window viewport, restore zoom level
|
||||
{
|
||||
auto center = viewport.getCenter();
|
||||
//auto w = viewport.getSize().x;
|
||||
//auto h = viewport.getSize().y;
|
||||
viewport = game->getView();
|
||||
viewport.setCenter(center);
|
||||
viewport.zoom(zoom);
|
||||
|
|
@ -268,67 +254,18 @@ void UITestScene::sRender()
|
|||
// Scrolling Viewport Objects (under the UI) --- entities, etc.
|
||||
game->getWindow().setView(viewport);
|
||||
|
||||
int width = viewport.getSize().x;
|
||||
int height = viewport.getSize().y;
|
||||
int top = viewport.getCenter().y - (height/2);
|
||||
int left = viewport.getCenter().x - (width/2);
|
||||
|
||||
int vline_count = height / grid_spacing * 2;
|
||||
sf::VertexArray v_lines(sf::Lines, vline_count*2);
|
||||
int index = 0;
|
||||
for (int x = left - (left % grid_spacing); index < vline_count*2; x += grid_spacing)
|
||||
{
|
||||
v_lines[index] = sf::Vector2f(x, top);
|
||||
v_lines[index + 1] = sf::Vector2f(x, top+height);
|
||||
v_lines[index].color = sf::Color(0, 40, 0);
|
||||
v_lines[index + 1].color = sf::Color(0, 40, 0);
|
||||
index += 2;
|
||||
|
||||
}
|
||||
game->getWindow().draw(v_lines);
|
||||
|
||||
int hline_count = width / grid_spacing * 2;
|
||||
sf::VertexArray h_lines(sf::Lines, hline_count*2);
|
||||
//std::cout << "Width: " << v.width << " Lines:" << vline_count <<
|
||||
// " Point array length: " << vline_count * 2 << std::endl;
|
||||
index = 0;
|
||||
for (int y = top - (top % grid_spacing); index < hline_count * 2; y += grid_spacing)
|
||||
{
|
||||
//std::cout << "(" << v.left << ", " << y << ") -> " << "(" << v.left + v.width << ", " << y << ")" << std::endl;
|
||||
h_lines[index] = sf::Vector2f(left, y);
|
||||
h_lines[index + 1] = sf::Vector2f(left+width, y);
|
||||
h_lines[index].color = sf::Color(0, 40, 0);
|
||||
h_lines[index + 1].color = sf::Color(0, 40, 0);
|
||||
index += 2;
|
||||
}
|
||||
|
||||
game->getWindow().draw(h_lines);
|
||||
/*for (int i = 0; i < total_lines; i++)
|
||||
{
|
||||
sf::Vertex p = lines[i];
|
||||
std::cout << p.position.x << ", " << p.position.y << std::endl;
|
||||
}*/
|
||||
|
||||
|
||||
for (auto e : entities.getEntities())
|
||||
{
|
||||
//game->getWindow().draw(e->cShape->circle);
|
||||
}
|
||||
test_ship.render(game->getWindow());
|
||||
|
||||
|
||||
//draw grid
|
||||
grid.render(game->getWindow());
|
||||
|
||||
// Fixed position objects
|
||||
game->getWindow().setView(game->getView());
|
||||
game->getWindow().draw(text);
|
||||
|
||||
|
||||
//draw grid
|
||||
grid.render(game->getWindow());
|
||||
|
||||
//test_button.render(game->getWindow());
|
||||
//if (test_menu.visible) test_menu.render(game->getWindow());
|
||||
//if (test_menu2.visible) test_menu2.render(game->getWindow());
|
||||
for ( auto ui : menus)
|
||||
{
|
||||
//std::cout << ui.buttons[0].getAction() << std::endl;
|
||||
|
|
@ -338,12 +275,7 @@ void UITestScene::sRender()
|
|||
}
|
||||
|
||||
// test Python sprite code
|
||||
McRFPy_API::executePyString("mcrfpy.drawSprite(123, 36, 10)");
|
||||
//McRFPy_API::executePyString("mcrfpy.drawSprite(121, 15, 15)");
|
||||
|
||||
//game->api->executePyString("mcrfpy.drawSprite(123, 10, 10)")
|
||||
//game->api->executePyString("mcrfpy.drawSprite(121, 15, 15)")
|
||||
|
||||
//McRFPy_API::executePyString("mcrfpy.drawSprite(123, 36, 10)");
|
||||
|
||||
// draw test sprite on top of everything
|
||||
game->getWindow().draw(test_sprite);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue