From c96afda71bd39e69e1b26849ac5e956d0fd97072 Mon Sep 17 00:00:00 2001 From: McCabe Maxsted Date: Thu, 23 Jun 2011 20:47:21 -0700 Subject: Created new window for inworld dice rolling in advanced > UI. Todo: add button for 'rocks fall, everybody dies' --- linden/indra/newview/CMakeLists.txt | 2 + linden/indra/newview/app_settings/settings.xml | 38 ++++++++ linden/indra/newview/floaterdice.cpp | 108 +++++++++++++++++++++ linden/indra/newview/floaterdice.h | 50 ++++++++++ linden/indra/newview/llviewermenu.cpp | 29 ++++++ .../skins/default/xui/en-us/floater_dice.xml | 15 +++ .../skins/default/xui/en-us/menu_viewer.xml | 7 +- 7 files changed, 248 insertions(+), 1 deletion(-) create mode 100644 linden/indra/newview/floaterdice.cpp create mode 100644 linden/indra/newview/floaterdice.h create mode 100644 linden/indra/newview/skins/default/xui/en-us/floater_dice.xml (limited to 'linden/indra/newview') diff --git a/linden/indra/newview/CMakeLists.txt b/linden/indra/newview/CMakeLists.txt index b0cb366..46da492 100644 --- a/linden/indra/newview/CMakeLists.txt +++ b/linden/indra/newview/CMakeLists.txt @@ -78,6 +78,7 @@ set(viewer_SOURCE_FILES floaterao.cpp floaterbusy.cpp floatercommandline.cpp + floaterdice.cpp floatergriddefault.cpp floatergridmanager.cpp floaterlocalassetbrowse.cpp @@ -535,6 +536,7 @@ set(viewer_HEADER_FILES floaterao.h floaterbusy.h floatercommandline.h + floaterdice.h floatergriddefault.h floatergridmanager.h floaterlocalassetbrowse.h diff --git a/linden/indra/newview/app_settings/settings.xml b/linden/indra/newview/app_settings/settings.xml index a6b782d..eb59254 100644 --- a/linden/indra/newview/app_settings/settings.xml +++ b/linden/indra/newview/app_settings/settings.xml @@ -399,6 +399,44 @@ Value 3 + DiceLastCount + + Comment + Last entered dice count + Persist + 1 + Type + S32 + Value + 1 + + DiceLastSides + + Comment + Last entered dice sides + Persist + 1 + Type + S32 + Value + 6 + + DiceFloaterRect + + Comment + Rectangle for dice window + Persist + 1 + Type + Rect + Value + + 0 + 100 + 100 + 100 + + DisableInternalFlyUpAnimation Comment 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 @@ +/** +* @file floaterdice.cpp +* @brief Dice window for Imprudence +* +* $LicenseInfo:firstyear=2009&license=viewergpl$ +* +* Copyright (c) 2011, McCabe Maxsted +* +* Imprudence Viewer Source Code +* The source code in this file ("Source Code") is provided to you +* under the terms of the GNU General Public License, version 2.0 +* ("GPL"). Terms of the GPL can be found in doc/GPL-license.txt in +* this distribution, or online at +* http://secondlifegrid.net/programs/open_source/licensing/gplv2 +* +* There are special exceptions to the terms and conditions of the GPL as +* it is applied to this Source Code. View the full text of the exception +* in the file doc/FLOSS-exception.txt in this software distribution, or +* online at http://secondlifegrid.net/programs/open_source/licensing/flossexception +* +* By copying, modifying or distributing this software, you acknowledge +* that you have read and understood your obligations described above, +* and agree to abide by those obligations. +* +* ALL SOURCE CODE IS PROVIDED "AS IS." THE AUTHOR MAKES NO +* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, +* COMPLETENESS OR PERFORMANCE. +* $/LicenseInfo$ +*/ + +#include "llviewerprecompiledheaders.h" + +#include "floaterdice.h" + +#include "llspinctrl.h" +#include "lluictrlfactory.h" + +#include "llchat.h" +#include "llchatbar.h" +#include "llkeyboard.h" +#include "llviewercontrol.h" + + +FloaterDice::FloaterDice(const LLSD& seed) : LLFloater("Roll Dice") +{ + LLUICtrlFactory::getInstance()->buildFloater(this, "floater_dice.xml"); +} + +FloaterDice::~FloaterDice() +{ +} + +BOOL FloaterDice::postBuild() +{ + childSetAction("btn_roll", onClickRoll, this); + + return TRUE; +} + +// static +void FloaterDice::onClickRoll(void* data) +{ + FloaterDice* self = (FloaterDice*)data; + if (self) + { + S32 dice_count = (S32)(self->getChild("spin_dice_count")->getValue()); + S32 dice_sides = (S32)(self->getChild("spin_dice_sides")->getValue()); + + if (dice_count <= 0 || dice_sides <= 3) + { + llwarns << "Invalid dice roll! Someone's trying to cheat, perhaps?" << llendl; + return; + } + else + { + S32 dice_total = 0; + std::ostringstream rolls; + for (S32 i = 0; i < dice_count; ++i) + { + S32 roll = ll_rand(dice_sides); + dice_total += roll; + rolls << roll; + if (i < dice_count - 1) rolls << ", "; + } + + std::string roll_text = llformat("/me rolled %dd%d for a total of %d", dice_count, dice_sides, dice_total); + if (dice_count > 1) + { + roll_text += " (" + rolls.str() + ")"; + } + gChatBar->sendChatFromViewer(roll_text, CHAT_TYPE_NORMAL, FALSE); + } + } +} + +// virtual +BOOL FloaterDice::handleKeyHere(KEY key, MASK mask) +{ + BOOL handled = FALSE; + + if ((KEY_RETURN == key) && (mask == MASK_NONE)) + { + onClickRoll(this); + handled = TRUE; + } + + return handled; +} diff --git a/linden/indra/newview/floaterdice.h b/linden/indra/newview/floaterdice.h new file mode 100644 index 0000000..57a664b --- /dev/null +++ b/linden/indra/newview/floaterdice.h @@ -0,0 +1,50 @@ +/** +* @file floaterdice.h +* @brief Dice window for Imprudence +* +* $LicenseInfo:firstyear=2009&license=viewergpl$ +* +* Copyright (c) 2011, McCabe Maxsted +* +* Imprudence Viewer Source Code +* The source code in this file ("Source Code") is provided to you +* under the terms of the GNU General Public License, version 2.0 +* ("GPL"). Terms of the GPL can be found in doc/GPL-license.txt in +* this distribution, or online at +* http://secondlifegrid.net/programs/open_source/licensing/gplv2 +* +* There are special exceptions to the terms and conditions of the GPL as +* it is applied to this Source Code. View the full text of the exception +* in the file doc/FLOSS-exception.txt in this software distribution, or +* online at http://secondlifegrid.net/programs/open_source/licensing/flossexception +* +* By copying, modifying or distributing this software, you acknowledge +* that you have read and understood your obligations described above, +* and agree to abide by those obligations. +* +* ALL SOURCE CODE IS PROVIDED "AS IS." THE AUTHOR MAKES NO +* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, +* COMPLETENESS OR PERFORMANCE. +* $/LicenseInfo$ +*/ + +#ifndef floaterdice_h +#define floaterdice_h + +#include "llfloater.h" + +class FloaterDice : public LLFloater, public LLFloaterSingleton +{ +public: + + FloaterDice(const LLSD& seed); + virtual ~FloaterDice(); + BOOL postBuild(); + +private: + + static void onClickRoll(void* data); + virtual BOOL handleKeyHere(KEY key, MASK mask); +}; + +#endif //floaterdice_h diff --git a/linden/indra/newview/llviewermenu.cpp b/linden/indra/newview/llviewermenu.cpp index c336c3a..a83c11b 100644 --- a/linden/indra/newview/llviewermenu.cpp +++ b/linden/indra/newview/llviewermenu.cpp @@ -84,6 +84,7 @@ #include "llfirstuse.h" #include "llfloater.h" #include "floaterao.h" +#include "floaterdice.h" #include "llfloaterabout.h" #include "llfloaterbuycurrency.h" #include "llfloateractivespeakers.h" @@ -9601,6 +9602,32 @@ class LLAdvancedReloadBalance : public view_listener_t } }; + +///////////////// +// DICE WINDOW // +///////////////// + + +class LLAdvancedToggleDice : public view_listener_t +{ + bool handleEvent(LLPointer event, const LLSD& userdata) + { + FloaterDice::toggleInstance(); + return true; + } +}; + +class LLAdvancedCheckDice : public view_listener_t +{ + bool handleEvent(LLPointer event, const LLSD& userdata) + { + bool new_value = FloaterDice::instanceVisible(); + std::string control_name = userdata["control"].asString(); + gMenuHolder->findControl(control_name)->setValue(new_value); + return true; + } +}; + ///////////////////// // DUMP SELECT MGR // ///////////////////// @@ -11421,6 +11448,8 @@ void initialize_menus() addMenu(new LLAdvancedWebBrowserTest(), "Advanced.WebBrowserTest"); addMenu(new LLAdvancedToggleEditableUI(), "Advanced.ToggleEditableUI"); addMenu(new LLAdvancedReloadBalance(), "Advanced.ReloadBalance"); + addMenu(new LLAdvancedToggleDice(), "Advanced.ToggleDice"); + addMenu(new LLAdvancedCheckDice(), "Advanced.CheckDice"); //addMenu(new LLAdvancedCheckEditableUI(), "Advanced.CheckEditableUI"); addMenu(new LLAdvancedDumpSelectMgr(), "Advanced.DumpSelectMgr"); addMenu(new LLAdvancedDumpInventory(), "Advanced.DumpInventory"); diff --git a/linden/indra/newview/skins/default/xui/en-us/floater_dice.xml b/linden/indra/newview/skins/default/xui/en-us/floater_dice.xml new file mode 100644 index 0000000..4a70c1c --- /dev/null +++ b/linden/indra/newview/skins/default/xui/en-us/floater_dice.xml @@ -0,0 +1,15 @@ + + + + +