File: caplayersettingsdialog.cpp

package info (click to toggle)
trophy 2.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 48,568 kB
  • sloc: cpp: 7,285; sh: 1,032; xml: 277; makefile: 94
file content (110 lines) | stat: -rw-r--r-- 2,573 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "caplayersettingsdialog.h"
#include "caimagehueselector.h"
#include "catrophy.h"

#define DEFAULT_CARTYPE 0

std::string priceToString(const int price)
{
    std::ostringstream ossPrice;
    ossPrice << "$" << price;
    return ossPrice.str();
}

/** Constructor.
*/
CAPlayerSettingsDialog::CAPlayerSettingsDialog()
        : CADialog(),
          nameInput("", 10, CAWidget::Left, CA_RES->font_normal_14_white),
          carImage(CA_APP->carType[DEFAULT_CARTYPE].name.c_str(),
                   priceToString(CA_APP->carType[DEFAULT_CARTYPE].price),
                   CA_APP->carType[DEFAULT_CARTYPE].surface3d,
                   true,
                   CAImageView::Vertical )
{
    if( CA_APP->debug ) std::cout << "CAPlayerSettingsDialog() begin" << std::endl;

    resize( 480, 200 );

    std::ostringstream ossPrice;
    ossPrice << "$" << CA_APP->carType[DEFAULT_CARTYPE].price;



    nameInput.move( left + 32, (top+bottom)/2 - nameInput.getHeight()/2 );


    carImage.move( right - carImage.getWidth() - 32,
                    (top+bottom)/2 - carImage.getHeight()/2 );

    help = "Type your Nickname and use the Arrow Keys to change your Color.";

    if( CA_APP->debug ) std::cout << "CAPlayerSettingsDialog() end" << std::endl;
}


/** Builds the dialog screen.
*/
void
CAPlayerSettingsDialog::buildScreen() {
    CADialog::buildScreen();

    CA_RES->font_normal_14_white->set_alignment(origin_top_left, 0, 0);
    CA_RES->font_normal_14_white->draw( left+32, top+58, "Please enter your nickname:" );

    nameInput.display();
    carImage.display();

    displayHelp();
}

/** Called on key release.
*/
void
CAPlayerSettingsDialog::on_key_released (const CL_InputEvent &key) 
{
    switch( key.id ) 
    {
        case CL_KEY_ENTER:
        {
            if (nameInput.getText()=="")
            {
                if( CA_APP->sound ) CA_RES->effectHorn->play( 2 );
            }
            else
                done = true;
            break;
        }

        case CL_KEY_ESCAPE:
            done = true;
            cancel = true;
            break;

        case CL_KEY_UP:
        case CL_KEY_DOWN:
            carImage.handleKey( key );
            break;

        default:
            nameInput.handleKey( key );
            break;
    }

}

/** Returns the player's name the user has entered.
*/
const std::string
CAPlayerSettingsDialog::getPlayerName() {
    return nameInput.getText();
}

/** Returns the player's color the user has chosen.
*/
int
CAPlayerSettingsDialog::getPlayerHue() {
    return carImage.getHue();
}

// EOF