diff options
Diffstat (limited to 'linden/indra/newview/floaterdice.cpp')
-rw-r--r-- | linden/indra/newview/floaterdice.cpp | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/linden/indra/newview/floaterdice.cpp b/linden/indra/newview/floaterdice.cpp new file mode 100644 index 0000000..203878c --- /dev/null +++ b/linden/indra/newview/floaterdice.cpp | |||
@@ -0,0 +1,100 @@ | |||
1 | /** | ||
2 | * @file floaterdice.cpp | ||
3 | * @brief Dice window for Imprudence | ||
4 | * | ||
5 | * $LicenseInfo:firstyear=2009&license=viewergpl$ | ||
6 | * | ||
7 | * Copyright (c) 2011, McCabe Maxsted | ||
8 | * | ||
9 | * Imprudence Viewer Source Code | ||
10 | * The source code in this file ("Source Code") is provided to you | ||
11 | * under the terms of the GNU General Public License, version 2.0 | ||
12 | * ("GPL"). Terms of the GPL can be found in doc/GPL-license.txt in | ||
13 | * this distribution, or online at | ||
14 | * http://secondlifegrid.net/programs/open_source/licensing/gplv2 | ||
15 | * | ||
16 | * There are special exceptions to the terms and conditions of the GPL as | ||
17 | * it is applied to this Source Code. View the full text of the exception | ||
18 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
19 | * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
20 | * | ||
21 | * By copying, modifying or distributing this software, you acknowledge | ||
22 | * that you have read and understood your obligations described above, | ||
23 | * and agree to abide by those obligations. | ||
24 | * | ||
25 | * ALL SOURCE CODE IS PROVIDED "AS IS." THE AUTHOR MAKES NO | ||
26 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
27 | * COMPLETENESS OR PERFORMANCE. | ||
28 | * $/LicenseInfo$ | ||
29 | */ | ||
30 | |||
31 | #include "llviewerprecompiledheaders.h" | ||
32 | |||
33 | #include "floaterdice.h" | ||
34 | |||
35 | #include "llspinctrl.h" | ||
36 | #include "lluictrlfactory.h" | ||
37 | |||
38 | #include "llchat.h" | ||
39 | #include "llchatbar.h" | ||
40 | #include "llviewercontrol.h" | ||
41 | |||
42 | |||
43 | FloaterDice::FloaterDice(const LLSD& seed) : LLFloater("Roll Dice") | ||
44 | { | ||
45 | LLUICtrlFactory::getInstance()->buildFloater(this, "floater_dice.xml"); | ||
46 | } | ||
47 | |||
48 | FloaterDice::~FloaterDice() | ||
49 | { | ||
50 | } | ||
51 | |||
52 | BOOL FloaterDice::postBuild() | ||
53 | { | ||
54 | childSetAction("btn_roll", onClickRoll, this); | ||
55 | |||
56 | return TRUE; | ||
57 | } | ||
58 | |||
59 | // static | ||
60 | void FloaterDice::onClickRoll(void* data) | ||
61 | { | ||
62 | FloaterDice* self = (FloaterDice*)data; | ||
63 | if (self) | ||
64 | { | ||
65 | S32 dice_count = (S32)(self->getChild<LLSpinCtrl>("spin_dice_count")->getValue()); | ||
66 | S32 dice_sides = (S32)(self->getChild<LLSpinCtrl>("spin_dice_sides")->getValue()); | ||
67 | |||
68 | if (dice_count <= 0 || dice_sides <= 3) | ||
69 | { | ||
70 | llwarns << "Invalid dice roll! Someone's trying to cheat, perhaps?" << llendl; | ||
71 | return; | ||
72 | } | ||
73 | else | ||
74 | { | ||
75 | S32 dice_total = 0; | ||
76 | std::ostringstream rolls; | ||
77 | S32 i = 0; | ||
78 | do | ||
79 | { | ||
80 | // see the clamping rules for ll_rand | ||
81 | S32 roll = ll_rand(dice_sides+1); | ||
82 | if (roll > 0) | ||
83 | { | ||
84 | dice_total += roll; | ||
85 | rolls << roll; | ||
86 | if (i < dice_count - 1) rolls << ", "; | ||
87 | ++i; | ||
88 | } | ||
89 | } | ||
90 | while (i < dice_count); | ||
91 | |||
92 | std::string roll_text = llformat("/me rolled %dd%d for a total of %d", dice_count, dice_sides, dice_total); | ||
93 | if (dice_count > 1) | ||
94 | { | ||
95 | roll_text += " (" + rolls.str() + ")"; | ||
96 | } | ||
97 | gChatBar->sendChatFromViewer(roll_text, CHAT_TYPE_NORMAL, FALSE); | ||
98 | } | ||
99 | } | ||
100 | } | ||