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

Messages - texus

#1561
Installation help / Re: [MSVC 2010] Build errors
16 September 2013, 20:39:49
That means that I wrote code that VS2010 didn't support yet. You can't do anything about that.

I'm currently booting up my windows, I'll fix this as soon as possible.
#1562
Installation help / Re: [MSVC 2010] Build errors
16 September 2013, 20:20:57
Damn, I hate windows.
I am using ptr_fun for only one reason: windows.h does something strange with the to_lower function so that it can't work cross-platform. And now it seems that I can't even use it in VS2010 (which is strange because I have build precompiled VS2010 binaries without facing this problem).

For now you should change "std::ptr_fun<int, int>(std::tolower)" into "std::tolower" or even "tolower" on the places where the compiler complains (use 'replace all' on all files).

In the meantime I will look for an alternative way to convert a string to lowercase.
#1563
You are writing to the file every frame.

You should move the code that opens and writes to the file to after the "while (window.isOpen())" loop.
#1564
Installation help / Re: [MSVC 2010] Build errors
16 September 2013, 19:51:33
The first error is in Widget.cpp on line 442, so lets focus on that one first.

Could you try to add the following line to the top of the file and try again?
#include <functional>
#1565
I edited my post later because I realized that this was going to happen. VS2010 has only very limited c++11 support.

Quote from: texus on 15 September 2013, 11:55:10Edit: just realized that that for loop is only supported since VS2012. It will be like this for you:
for (auto it = items.cbegin(); it != items.cend(); ++it)
{
    ofile << it->toAnsiString() << std::endl;
}
#1566
Which part about the file handling isn't working exactly (the code looks good at first sight)? Does the text file get written correctly? What gets placed in the list box when trying to load from a file?

If you want to store the animals, even after the program has quit, then there is no other option than storing it in a text file on the hard disk.
#1567
Help requests / Re: callback not triggered
15 September 2013, 16:53:10
Callbacks can now be loaded from widget files.

The widget files need to contain lines like these:
Callback = LeftMouseClicked
CallbackId = 1


You can pass multiple callbacks by placing a comma between them:
Callback = Focused, Unfocused

Also because of how the new form builder is written, you will also be able to change the callbacks from within the form builder.
#1568
Help requests / Re: LoadFromFile() & callbacks
15 September 2013, 16:52:08
Callbacks can now be loaded from widget files.

The widget files need to contain lines like these:
Callback = LeftMouseClicked
CallbackId = 1


You can pass multiple callbacks by placing a comma between them:
Callback = Focused, Unfocused

Also because of how the new form builder is written, you will also be able to change the callbacks from within the form builder.
#1569
Quotecan i store the selected item from listBox in a character array or any character variable so that i may pass this character array in addItem() function of listBox, and it will store new animal name in the listBox !?
I have no idea what you mean with this, but lets break it down in smaller parts.

Quotecan i store the selected item from listBox in a character array
std::string selectedItem = listBox->getSelectedItem();

Quoteso that i may pass this character array in addItem() function of listBox
listBox->addItem(selectedItem);
#1570
Quotehmmm, i didn't get you !
You want to be able to keep your added animals even after the program was quit, right?

So at the beginning of the program you have something like this:
std::ifstream ifile("animals.txt");
if (ifile.is_open())
{
    // Read the contents of the file and put the read animals in the listbox with addItem
}


At the end of the program you save the animals that you have in your listbox to a file, so that the next time you start the program you will still have all animals.
std::ofstream ofile("animals.txt");
if (ifile.is_open())
{
    auto& items = listBox->getItems();
    for (auto& item : items)
    {
        ofile << item.toAnsiString() << std::endl;
    }
}


Again, this code is only for guidance and may contain mistakes. I also deliberately left out the way to load the text file so that I don't give you the complete solution.

Edit: just realized that that for loop is only supported since VS2012. It will be like this for you:
for (auto it = items.cbegin(); it != items.cend(); ++it)
{
    ofile << it->toAnsiString() << std::endl;
}
#1571
Quotebut when i close my window and compile my code again it will not show the recently added animal in the list box !
Obviously. What you want to do is save a the contents of the list in a text file and load it again when starting the program (look at std::ifstream and std::ofstream).
#1572
Adding an edit box is the same as adding a button or a list box:
tgui::EditBox::Ptr editBox(gui);
editBox->load("...");

And then look at the documentation for the other functions you can use. But you probably only need setPosition and setSize.

When the "Add animal" button gets pressed, you can use the addItem function to add the contents of the edit box to the list box (editBox->getText() for getting text in edit box).

The animal will be added to the back of the list box, but it still has to be selected.
listBox->setSelectedItem(listBox->getItems().size()-1); // Select the last item in the list box

----------
What follows below is a suggestion of what you can do to play the sound. I didn't test it as I wrote it so it might contain mistakes, and it definately isn't the only way. But you might get some ideas from it.

Now you can even make the sound load dynamically. At the beginning of the program you define this:
std::list<sf::SoundBuffer> buffers;
std::list<sf::Sound> sounds;


When adding a new item to the list box, e.g. with the "Add animal" button then you load the sound. This has the limitation that the sound needs to have the exact name as the animal though (if CAT is entered in the edit box then it will load CAT.wav).
buffers.push_back(sf::SoundBuffer());
buffers.back().loadFromFile(editBox->getText() + ".wav");

sounds.push_back(sf::Sound());
sounds.back().setBuffer(buffers.back());
sounds.back().setPitch(1.5f);
sounds.back().setVolume(80);


And then when the speak button is pressed, you play the correct sound. There are just as many sounds as there are items in the list box, and e.g. the third item in the list box matches the third sound in the list, so you can use listBox->getSelectedItemIndex().
auto it = sounds.begin();
std::advance(it, listBox->getSelectedItemIndex());
it->play();
#1573
Please post on either the sfml forum or on this forum but not on both.
There is no need to ask the same question twice, by the time one replies you might already have a reply on the other forum.

I read both forums anyway.
#1574
I guess you understand it by now with the other reply on the sfml forum?
#1575
You'll have to wait till someone responds on the sfml forum, because I can't help with that.