From 0a9c611dfd2356e99cb13486319de8f698d02467 Mon Sep 17 00:00:00 2001 From: Siana Gearz Date: Tue, 4 Oct 2011 06:07:52 +0200 Subject: [PATCH] Merge back the ability to select the tree (not just random, from Imprudence). Conflicts: indra/newview/app_settings/settings.xml indra/newview/llfloatertools.cpp --- indra/newview/app_settings/settings.xml | 22 +++++++ indra/newview/llfloatertools.cpp | 82 +++++++++++++++++++++++++ indra/newview/llfloatertools.h | 4 ++ indra/newview/lltoolplacer.cpp | 17 ++++- indra/newview/lltoolplacer.h | 1 + indra/newview/llvograss.cpp | 7 +++ indra/newview/llvograss.h | 3 + indra/newview/llvotree.cpp | 7 +++ indra/newview/llvotree.h | 4 ++ 9 files changed, 144 insertions(+), 3 deletions(-) diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml index a6f883670..3cb5445cd 100644 --- a/indra/newview/app_settings/settings.xml +++ b/indra/newview/app_settings/settings.xml @@ -14538,5 +14538,27 @@ Value 1 + LastGrass + + Comment + The last grass selected in the create dialog + Persist + 1 + Type + String + Value + Random + + LastTree + + Comment + The last tree selected in the create dialog + Persist + 1 + Type + String + Value + Random + diff --git a/indra/newview/llfloatertools.cpp b/indra/newview/llfloatertools.cpp index 0a9b5dd1d..54b7f6729 100644 --- a/indra/newview/llfloatertools.cpp +++ b/indra/newview/llfloatertools.cpp @@ -31,6 +31,7 @@ */ #include "llviewerprecompiledheaders.h" +indra/newview/llfloatertools.cpp #include "llfloatertools.h" @@ -87,6 +88,8 @@ #include "qtoolalign.h" //Thank Qarl! +#include "llvograss.h" +#include "llvotree.h" // Globals LLFloaterTools *gFloaterTools = NULL; @@ -295,6 +298,8 @@ BOOL LLFloaterTools::postBuild() llwarns << "Tool button not found! DOA Pending." << llendl; } } + mComboTreesGrass = getChild("trees_grass"); + childSetCommitCallback("trees_grass", onSelectTreesGrass, (void*)0); mCheckCopySelection = getChild("checkbox copy selection"); childSetValue("checkbox copy selection",(BOOL)gSavedSettings.getBOOL("CreateToolCopySelection")); mCheckSticky = getChild("checkbox sticky"); @@ -392,6 +397,7 @@ LLFloaterTools::LLFloaterTools() mBtnDuplicate(NULL), mBtnDuplicateInPlace(NULL), + mComboTreesGrass(NULL), mCheckSticky(NULL), mCheckCopySelection(NULL), mCheckCopyCenters(NULL), @@ -721,6 +727,8 @@ void LLFloaterTools::updatePopup(LLCoordGL center, MASK mask) mBtnCreate ->setToggleState( tool == LLToolCompCreate::getInstance() ); + updateTreeGrassCombo(create_visible); + if (mCheckCopySelection && mCheckCopySelection->get()) { @@ -1058,3 +1066,77 @@ void LLFloaterTools::onFocusReceived() LLToolMgr::getInstance()->setCurrentToolset(gBasicToolset); LLFloater::onFocusReceived(); } + +// static +void LLFloaterTools::onSelectTreesGrass(LLUICtrl*, void*) +{ + const std::string &selected = gFloaterTools->mComboTreesGrass->getValue(); + LLPCode pcode = LLToolPlacer::getObjectType(); + if (pcode == LLToolPlacerPanel::sTree) + { + gSavedSettings.setString("LastTree", selected); + } + else if (pcode == LLToolPlacerPanel::sGrass) + { + gSavedSettings.setString("LastGrass", selected); + } +} + +void LLFloaterTools::updateTreeGrassCombo(bool visible) +{ + LLTextBox* tree_grass_label = getChild("tree_grass_label"); + if (visible) + { + LLPCode pcode = LLToolPlacer::getObjectType(); + std::map::iterator it, end; + std::string selected; + if (pcode == LLToolPlacerPanel::sTree) + { + tree_grass_label->setVisible(visible); + LLButton* button = getChild("ToolTree"); + tree_grass_label->setText(button->getToolTip()); + + selected = gSavedSettings.getString("LastTree"); + it = LLVOTree::sSpeciesNames.begin(); + end = LLVOTree::sSpeciesNames.end(); + } + else if (pcode == LLToolPlacerPanel::sGrass) + { + tree_grass_label->setVisible(visible); + LLButton* button = getChild("ToolGrass"); + tree_grass_label->setText(button->getToolTip()); + + selected = gSavedSettings.getString("LastGrass"); + it = LLVOGrass::sSpeciesNames.begin(); + end = LLVOGrass::sSpeciesNames.end(); + } + else + { + mComboTreesGrass->removeall(); + mComboTreesGrass->setLabel(LLStringExplicit("")); // LLComboBox::removeall() does not clear the label + mComboTreesGrass->setEnabled(false); + mComboTreesGrass->setVisible(false); + tree_grass_label->setVisible(false); + return; + } + + mComboTreesGrass->removeall(); + mComboTreesGrass->add("Random"); + + int select = 0, i = 0; + + while (it != end) + { + const std::string &species = it->first; + mComboTreesGrass->add(species); ++i; + if (species == selected) select = i; + ++it; + } + // if saved species not found, default to "Random" + mComboTreesGrass->selectNthItem(select); + mComboTreesGrass->setEnabled(true); + } + + mComboTreesGrass->setVisible(visible); + tree_grass_label->setVisible(visible); +} diff --git a/indra/newview/llfloatertools.h b/indra/newview/llfloatertools.h index 85308315f..a06e2728c 100644 --- a/indra/newview/llfloatertools.h +++ b/indra/newview/llfloatertools.h @@ -155,6 +155,7 @@ public: LLButton *mBtnDuplicateInPlace; // Create buttons + LLComboBox *mComboTreesGrass; LLCheckBoxCtrl *mCheckSticky; LLCheckBoxCtrl *mCheckCopySelection; LLCheckBoxCtrl *mCheckCopyCenters; @@ -194,6 +195,9 @@ private: BOOL mDirty; std::map mStatusText; + + void updateTreeGrassCombo(bool visible); + static void onSelectTreesGrass(LLUICtrl*, void*); }; extern LLFloaterTools *gFloaterTools; diff --git a/indra/newview/lltoolplacer.cpp b/indra/newview/lltoolplacer.cpp index db49bbdd7..9e59b9cc4 100644 --- a/indra/newview/lltoolplacer.cpp +++ b/indra/newview/lltoolplacer.cpp @@ -175,7 +175,18 @@ BOOL LLToolPlacer::raycastForNewObjPos( S32 x, S32 y, LLViewerObject** hit_obj, return TRUE; } - +S32 LLToolPlacer::getTreeGrassSpecies(std::map &table, const char *control, S32 max) +{ + const std::string &species = gSavedSettings.getString(control); + std::map::iterator it; + it = table.find(species); + if (it != table.end()) { + return it->second; + } else { + // if saved species not found, default to "Random" + return (rand() % max); + } +} BOOL LLToolPlacer::addObject( LLPCode pcode, S32 x, S32 y, U8 use_physics ) { LLVector3 ray_start_region; @@ -220,13 +231,13 @@ BOOL LLToolPlacer::addObject( LLPCode pcode, S32 x, S32 y, U8 use_physics ) case LL_PCODE_LEGACY_GRASS: // Randomize size of grass patch scale.setVec(10.f + ll_frand(20.f), 10.f + ll_frand(20.f), 1.f + ll_frand(2.f)); - state = rand() % LLVOGrass::sMaxGrassSpecies; + state = getTreeGrassSpecies(LLVOGrass::sSpeciesNames, "LastGrass", LLVOGrass::sMaxGrassSpecies); break; case LL_PCODE_LEGACY_TREE: case LL_PCODE_TREE_NEW: - state = rand() % LLVOTree::sMaxTreeSpecies; + state = getTreeGrassSpecies(LLVOTree::sSpeciesNames, "LastTree", LLVOTree::sMaxTreeSpecies); break; case LL_PCODE_SPHERE: diff --git a/indra/newview/lltoolplacer.h b/indra/newview/lltoolplacer.h index d478f7b1c..702fc1f50 100644 --- a/indra/newview/lltoolplacer.h +++ b/indra/newview/lltoolplacer.h @@ -62,6 +62,7 @@ protected: private: BOOL addObject( LLPCode pcode, S32 x, S32 y, U8 use_physics ); + S32 getTreeGrassSpecies(std::map &table, const char *control, S32 max); BOOL raycastForNewObjPos( S32 x, S32 y, LLViewerObject** hit_obj, S32* hit_face, BOOL* b_hit_land, LLVector3* ray_start_region, LLVector3* ray_end_region, LLViewerRegion** region ); BOOL addDuplicate(S32 x, S32 y); diff --git a/indra/newview/llvograss.cpp b/indra/newview/llvograss.cpp index 1d350d635..25337f0ef 100644 --- a/indra/newview/llvograss.cpp +++ b/indra/newview/llvograss.cpp @@ -74,6 +74,8 @@ F32 w_mod[GRASS_MAX_BLADES]; // Factor to modulate wind movement by to rand LLVOGrass::SpeciesMap LLVOGrass::sSpeciesTable; S32 LLVOGrass::sMaxGrassSpecies = 0; +LLVOGrass::SpeciesNames LLVOGrass::sSpeciesNames; + LLVOGrass::LLVOGrass(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp) : LLAlphaObject(id, pcode, regionp) @@ -198,6 +200,11 @@ void LLVOGrass::initClass() if (species >= sMaxGrassSpecies) sMaxGrassSpecies = species + 1; + std::string name; + static LLStdStringHandle name_string = LLXmlTree::addAttributeString("name"); + success &= grass_def->getFastAttributeString(name_string, name); + sSpeciesNames[name] = species; + if (!success) { std::string name; diff --git a/indra/newview/llvograss.h b/indra/newview/llvograss.h index 6a6fcc31c..8519d02cd 100644 --- a/indra/newview/llvograss.h +++ b/indra/newview/llvograss.h @@ -117,6 +117,9 @@ public: F32 mBladeWindAngle; F32 mBWAOverlap; + typedef std::map SpeciesNames; + static SpeciesNames sSpeciesNames; + protected: ~LLVOGrass(); diff --git a/indra/newview/llvotree.cpp b/indra/newview/llvotree.cpp index 08dbc4df5..8ab942851 100644 --- a/indra/newview/llvotree.cpp +++ b/indra/newview/llvotree.cpp @@ -83,6 +83,8 @@ F32 LLVOTree::sTreeFactor = 1.f; LLVOTree::SpeciesMap LLVOTree::sSpeciesTable; S32 LLVOTree::sMaxTreeSpecies = 0; +LLVOTree::SpeciesNames LLVOTree::sSpeciesNames; + // Tree variables and functions LLVOTree::LLVOTree(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp): @@ -242,6 +244,11 @@ void LLVOTree::initClass() sSpeciesTable[species] = newTree; if (species >= sMaxTreeSpecies) sMaxTreeSpecies = species + 1; + + std::string name; + static LLStdStringHandle name_string = LLXmlTree::addAttributeString("name"); + success &= tree_def->getFastAttributeString(name_string, name); + sSpeciesNames[name] = species; if (!success) { diff --git a/indra/newview/llvotree.h b/indra/newview/llvotree.h index 7e961471f..befe3665c 100644 --- a/indra/newview/llvotree.h +++ b/indra/newview/llvotree.h @@ -153,6 +153,10 @@ public: }; static F32 sTreeFactor; // Tree level of detail factor + + typedef std::map SpeciesNames; + static SpeciesNames sSpeciesNames; + static const S32 sMAX_NUM_TREE_LOD_LEVELS ; friend class LLDrawPoolTree;