Hi!
I need to create a window in a window for my game. (Confirmation and message dialogs.)
So I've just created this class :
OptionPane::OptionPane(math::Vec3f position, math::Vec3f size, const Font* font, sf::String t, TYPE type) :
LightComponent (position, size, size * 0.5f, false),
rw (sf::VideoMode(size.x, size.y), "Option Pane", sf::Style::Default, sf::ContextSettings(0, 0, 4, 3, 0)),
type(type) {
rw.getView().move(size.x * 0.5f, size.y * 0.5f, size.z * 0.5f);
if (type == CONFIRMATION_DIALOG) {
yes = new Button(math::Vec2f(size.x / 100 * 70, size.y - 100), math::Vec2f(100, 50), font, "Yes", rw);
no = new Button(math::Vec2f(size.x / 100 * 10, size.y - 100), math::Vec2f(100, 50), font, "No", rw);
core::FastDelegate<bool> trigger1(&Button::isMouseInButton, yes);
core::FastDelegate<bool> trigger2(&Button::isMouseInButton, no);
core::FastDelegate<void> slot1(&OptionPane::onYesOption, this);
core::FastDelegate<void> slot2(&OptionPane::onNoOption, this);
core::Action a (core::Action::MOUSE_BUTTON_PRESSED_ONCE,sf::Mouse::Left);
core::Command cmd1 (a, trigger1, slot1);
core::Command cmd2 (a, trigger2, slot2);
getListener().connect("YESOPTION", cmd1);
getListener().connect("NOOPTION", cmd2);
} else {
yes = nullptr;
no = nullptr;
core::Action a (core::Action::KEY_PRESSED_ONCE, sf::Keyboard::Return);
core::FastDelegate<void> slot(&OptionPane::onEnter, this);
core::Command cmd (a, slot);
getListener().connect("ONENTER", cmd);
}
rw.setPosition(sf::Vector2i(position.x, position.y));
option = UNDEFINED;
text.setFont(*font);
text.setString(t);
text.setColor(sf::Color::Black);
text.setPosition(math::Vec3f(10, 10, position.z));
text.setSize(size);
backgroundColor = sf::Color::White;
}
void OptionPane::onVisibilityChanged(bool visible) {
rw.setVisible(visible);
}
OptionPane::OPTION OptionPane::getOption() {
OPTION choosenOption = option;
option = UNDEFINED;
return choosenOption;
}
void OptionPane::clear() {
rw.clear(backgroundColor);
}
void OptionPane::draw(RenderTarget& target, RenderStates states) {
if (rw.isOpen()) {
rw.draw(text, states);
if (type == CONFIRMATION_DIALOG) {
rw.draw(*yes, states);
rw.draw(*no, states);
}
rw.display();
}
}
void OptionPane::update() {
sf::Event event;
while(rw.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
rw.setVisible(false);
}
getListener().pushEvent(event);
}
}
void OptionPane::onEnter() {
setVisible(false);
setEventContextActivated(false);
rw.setVisible(false);
}
void OptionPane::onYesOption() {
rw.setVisible(false);
setEventContextActivated(false);
option = YES_OPTION;
}
void OptionPane::onNoOption() {
rw.setVisible(false);
setEventContextActivated(false);
option = NO_OPTION;
}
void OptionPane::setText(std::string t) {
text.setString(sf::String(t.c_str()));
}
OptionPane::~OptionPane() {
rw.close();
if (CONFIRMATION_DIALOG) {
delete yes;
delete no;
}
}
It works fine except for one point, here, I want to create two sub-windows :
m_pseudoUsed = new gui::OptionPane(Vec2f(200, 200), Vec2f(200, 100), fm.getResourceByAlias("FreeSerif"),"Pseudo already used!",gui::OptionPane::TYPE::MESSAGE_DIALOG);
m_pseudoUsed->setVisible(false);
m_pseudoUsed->setEventContextActivated(false);
m_confirmInvitation = new gui::OptionPane(Vec2f(200, 200), Vec2f(200, 100), fm.getResourceByAlias("FreeSerif"),"",gui::OptionPane::TYPE::CONFIRMATION_DIALOG);
m_confirmInvitation->setVisible(false);
m_confirmInvitation->setEventContextActivated(false);
I set the visibility of my sub-windows to false, so the windows shouldn't be shown, but it's not what I see.
I see a transparent window on the main window, and the title is not always the title of my sub-windows..., this is really strange. :/