Main Menu
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Topics - Dincio

#1
I've been playing around with layouts and I've found a possible bug. First, I compiled this code (and it worked as expected, drawing both the panel and the text box on the window in the right positions):

Code (cpp) Select

/*! constructor inside a class that handles a text based interface */
mDialogInterface = std::make_shared<tgui::Panel>();
mDialogInterface->setPosition(0, mWindow->getSize().y / 4.f * 3.f);
mDialogInterface->setSize(mWindow->getSize().x, mWindow->getSize().y / 4.f);
mDialogInterface->setBackgroundColor(sf::Color::Red);
auto dialogBox = std::make_shared<tgui::TextBox>();
dialogBox->setText("hello there!");
dialogBox->setSize("parent.width / 4 * 3", "parent.height");
dialogBox->setPosition("parent.left", "parent.top");
mDialogInterface->add(dialogBox, "dialog");


Code (cpp) Select

/*! function that handles drawing (from the same class) */
void *::handleDrawing()
{
    ... //draw other stuff using views
    mWindow->setView(mWindow->getDefaultView());
    mWindow->draw(*mDialogInterface);
}


outcome shown in "right.png"


The problem is that when I change the eighth line of the first segment of code from this:
Code (cpp) Select
dialogBox->setPosition("parent.left", "parent.top");
to this:
Code (cpp) Select
dialogBox->setPosition("parent.width / 4", "parent.top");
which is what I want to do, but really I could change i 8)t to whatever inolves any type of calculation, like:
Code (cpp) Select
dialogBox->setPosition("parent.left + 1", "parent.top");
and still the problem will persist. The problem is that the text box becomes invisible (outcome shown in "wrong.png").

The only way I can seem to solve the issue is by drawing the textbox directly to the window, but this seems just some kind of workaround... so is this a bug or am I doing something wrong?

Also, as a side note, I've tryed receiving input from the panel via panel->handleInput(const sf::Event& event) but the compiler tells me that the function is protected. Is there any other way of doing this without relying on guis (aka, in my case, using panels)?
#2
Help requests / Alternative to copying Guis
05 March 2017, 17:10:15
Hello  :)

I'm in the process of making a little game and I decided to use tgui for managing the user interface. The game manages multiple entities, each with its own hp/att/def/(you get it) and moves the entities around in a board each turn. I was thinking of giving an interface to each entity holding multiple ProgressBars (possibly wrapped nicely in a VerticalLayout) to show their life parameters to the player. My first approach was storing a Gui object inside the entity class, so that each entity could manage its gui the right way (drawing it when it is visible, requesting input only if the entity can be analyzed, allocate/deallocate it, etc...) but to my great despair, I found out that the copy constructor for the Gui class had been deleted... and so storing a Gui inside an entity would make it uncopyable (which is very important for multiple game systems, such as spawning). The only solution I can come up with is using a global Gui (maybe a static variable in entity) and using it as a sort of helper for showing widgets inside entities. In other words: every entity would generate a unique id (even just using a static spawn counter) and hold a VirtualLayout containing the ProgressBars (or even an whole new object component dedicated to the widgets used by the entity's interface), which will be added/removed to this global Gui when the entity is spawned/despawned using the unique id of the widgets. This approach would solve my problem , but it seems to like some sort of workaround... So my question is, why are guis uncopyable objects? Is there some fundamental reason that I am missing, or am I just using the system wrong? And what should I do in a situation like this one (which appears to be very likely)?

I hope I've made myself clear :) have a good day.