[6475138] | 1 | #include "chat.h"
|
---|
| 2 |
|
---|
| 3 | chat::chat(void)
|
---|
| 4 | {
|
---|
| 5 | }
|
---|
| 6 |
|
---|
| 7 | chat::~chat(void)
|
---|
| 8 | {
|
---|
| 9 | }
|
---|
| 10 |
|
---|
| 11 | string chat::getInput()
|
---|
| 12 | {
|
---|
| 13 | string temp = strEnteredInput;
|
---|
| 14 | strEnteredInput.clear();
|
---|
| 15 | return temp;
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 | void chat::draw(ALLEGRO_FONT *font, ALLEGRO_COLOR color)
|
---|
| 19 | {
|
---|
[4c202e0] | 20 | for(unsigned int x=0; x<vctChat.size(); x++)
|
---|
[9b1e12c] | 21 | al_draw_text(font, color, 5, 100+x*15, ALLEGRO_ALIGN_LEFT, vctChat[x].c_str());
|
---|
[6475138] | 22 |
|
---|
[9b1e12c] | 23 | // I think this might never be used
|
---|
| 24 | al_draw_text(font, color, 5, 460, ALLEGRO_ALIGN_LEFT, strPrompt.c_str());
|
---|
[6475138] | 25 | }
|
---|
| 26 |
|
---|
| 27 | void chat::addLine(string s)
|
---|
| 28 | {
|
---|
| 29 | vctChat.push_back(s);
|
---|
| 30 | }
|
---|
| 31 |
|
---|
[bc70282] | 32 | void chat::clear() {
|
---|
| 33 | vctChat.clear();
|
---|
| 34 | }
|
---|
| 35 |
|
---|
[6475138] | 36 | // returns true if the event was consumed, false if it should be passed on
|
---|
[87b3ee2] | 37 | bool chat::handleEvent(ALLEGRO_EVENT e)
|
---|
[6475138] | 38 | {
|
---|
| 39 | ALLEGRO_KEYBOARD_STATE keys;
|
---|
| 40 | al_get_keyboard_state(&keys);
|
---|
| 41 |
|
---|
[87b3ee2] | 42 | if (e.type == ALLEGRO_EVENT_KEY_DOWN) {
|
---|
[6475138] | 43 | char newChar = 0;
|
---|
| 44 |
|
---|
[87b3ee2] | 45 | if (ALLEGRO_KEY_A <= e.keyboard.keycode && e.keyboard.keycode <= ALLEGRO_KEY_Z) {
|
---|
| 46 | newChar = 'a'+e.keyboard.keycode-ALLEGRO_KEY_A;
|
---|
[6475138] | 47 | if (al_key_down(&keys, ALLEGRO_KEY_LSHIFT) || al_key_down(&keys, ALLEGRO_KEY_RSHIFT))
|
---|
| 48 | newChar -= 32;
|
---|
| 49 | }
|
---|
[87b3ee2] | 50 | if (ALLEGRO_KEY_0 <= e.keyboard.keycode && e.keyboard.keycode <= ALLEGRO_KEY_9)
|
---|
| 51 | newChar = '0'+e.keyboard.keycode-ALLEGRO_KEY_0;
|
---|
[6475138] | 52 |
|
---|
| 53 | if (newChar != 0) {
|
---|
| 54 | strPrompt.append(1, newChar);
|
---|
| 55 | return true;
|
---|
| 56 | }
|
---|
| 57 |
|
---|
[87b3ee2] | 58 | if (e.keyboard.keycode == ALLEGRO_KEY_ENTER) {
|
---|
[6475138] | 59 | strEnteredInput = strPrompt;
|
---|
| 60 | strPrompt.clear();
|
---|
| 61 | return true;
|
---|
| 62 | }
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | return false;
|
---|
| 66 | }
|
---|