aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/floaterdice.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/newview/floaterdice.cpp')
-rw-r--r--linden/indra/newview/floaterdice.cpp108
1 files changed, 108 insertions, 0 deletions
diff --git a/linden/indra/newview/floaterdice.cpp b/linden/indra/newview/floaterdice.cpp
new file mode 100644
index 0000000..f16a6ca
--- /dev/null
+++ b/linden/indra/newview/floaterdice.cpp
@@ -0,0 +1,108 @@
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 "llkeyboard.h"
41#include "llviewercontrol.h"
42
43
44FloaterDice::FloaterDice(const LLSD& seed) : LLFloater("Roll Dice")
45{
46 LLUICtrlFactory::getInstance()->buildFloater(this, "floater_dice.xml");
47}
48
49FloaterDice::~FloaterDice()
50{
51}
52
53BOOL FloaterDice::postBuild()
54{
55 childSetAction("btn_roll", onClickRoll, this);
56
57 return TRUE;
58}
59
60// static
61void FloaterDice::onClickRoll(void* data)
62{
63 FloaterDice* self = (FloaterDice*)data;
64 if (self)
65 {
66 S32 dice_count = (S32)(self->getChild<LLSpinCtrl>("spin_dice_count")->getValue());
67 S32 dice_sides = (S32)(self->getChild<LLSpinCtrl>("spin_dice_sides")->getValue());
68
69 if (dice_count <= 0 || dice_sides <= 3)
70 {
71 llwarns << "Invalid dice roll! Someone's trying to cheat, perhaps?" << llendl;
72 return;
73 }
74 else
75 {
76 S32 dice_total = 0;
77 std::ostringstream rolls;
78 for (S32 i = 0; i < dice_count; ++i)
79 {
80 S32 roll = ll_rand(dice_sides);
81 dice_total += roll;
82 rolls << roll;
83 if (i < dice_count - 1) rolls << ", ";
84 }
85
86 std::string roll_text = llformat("/me rolled %dd%d for a total of %d", dice_count, dice_sides, dice_total);
87 if (dice_count > 1)
88 {
89 roll_text += " (" + rolls.str() + ")";
90 }
91 gChatBar->sendChatFromViewer(roll_text, CHAT_TYPE_NORMAL, FALSE);
92 }
93 }
94}
95
96// virtual
97BOOL FloaterDice::handleKeyHere(KEY key, MASK mask)
98{
99 BOOL handled = FALSE;
100
101 if ((KEY_RETURN == key) && (mask == MASK_NONE))
102 {
103 onClickRoll(this);
104 handled = TRUE;
105 }
106
107 return handled;
108}