From: <ma...@us...> - 2013-04-09 15:53:39
|
Revision: 8687 http://planeshift.svn.sourceforge.net/planeshift/?rev=8687&view=rev Author: magodra Date: 2013-04-09 15:53:30 +0000 (Tue, 09 Apr 2013) Log Message: ----------- - Added /brigness command and preserve setting through restart. (PS#5968) Modified Paths: -------------- trunk/data/help.xml trunk/src/client/cmdusers.cpp trunk/src/client/pscharcontrol.cpp trunk/src/client/psengine.cpp trunk/src/client/psengine.h trunk/src/common/util/strutil.h Modified: trunk/data/help.xml =================================================================== --- trunk/data/help.xml 2013-04-09 12:50:16 UTC (rev 8686) +++ trunk/data/help.xml 2013-04-09 15:53:30 UTC (rev 8687) @@ -2189,6 +2189,15 @@ <content type="text">This command lists the available admin commands for your account. As I assume your are no GM or Dev this won't do anything for you.</content> </Contents> </topic> + <topic name="/brightness"> + <Contents> + <content type="text">This command allow you to change the brightness level. + +Usage: /brightness [<value>|increase|decrease|reset] + +Setting a brigness value between -1.0 and 3.0. You can do /brighness increase or decrease to change by 0.1 or reset to set back to 0.0. By default F10 will reset, F11 decrease and F12 increase brigness as well.</content> + </Contents> + </topic> <topic name="/buddy"> <Contents> <content type="text">This command allows you to manage your buddy-list. Modified: trunk/src/client/cmdusers.cpp =================================================================== --- trunk/src/client/cmdusers.cpp 2013-04-09 12:50:16 UTC (rev 8686) +++ trunk/src/client/cmdusers.cpp 2013-04-09 15:53:30 UTC (rev 8687) @@ -73,6 +73,7 @@ cmdsource->Subscribe("/attack", this); cmdsource->Subscribe("/away", this); cmdsource->Subscribe("/bank", this); + cmdsource->Subscribe("/brightness", this); cmdsource->Subscribe("/buddy", this); // add named player to buddy list cmdsource->Subscribe("/buy", this); cmdsource->Subscribe("/storage", this); //allows to access the storage of an npc. @@ -151,6 +152,7 @@ cmdsource->Unsubscribe("/attack", this); cmdsource->Unsubscribe("/away", this); cmdsource->Unsubscribe("/bank", this); + cmdsource->Unsubscribe("/brightness", this); cmdsource->Unsubscribe("/buddy", this); cmdsource->Unsubscribe("/buy", this); cmdsource->Unsubscribe("/storage", this); @@ -429,6 +431,58 @@ psGUIMerchantMessage exchange(psGUIMerchantMessage::REQUEST,buff); exchange.SendMessage(); } + else if ( words[0] == "/brightness" ) + { + const char* usage = "Usage: /brightness [<value>|increase|decrease|reset]"; + if (words.GetCount() != 2) //if there were no arguments open the buddy window + { + return usage; + } + else //else send the data to the server for parsing + { + if (csStrNCaseCmp(words[1].GetDataSafe(), "increase", 1) == 0) // Only need to compare first to make uniq + { + psengine->AdjustBrightnessCorrectionUp(); + } + else if (csStrNCaseCmp(words[1].GetDataSafe(), "decrease", 1) == 0) // Only need to compare first to make uniq + { + psengine->AdjustBrightnessCorrectionDown(); + } + else if (csStrNCaseCmp(words[1].GetDataSafe(), "reset", 1) == 0) // Only need to compare first to make uniq + { + psengine->ResetBrightnessCorrection(); + } + else if (words.IsFloat(1)) + { + csString sysMsg; + + float brightnessCorrection = words.GetFloat(1); + + // Cap values + if (brightnessCorrection > 3.0) + { + brightnessCorrection = 3.0; + } + else if (brightnessCorrection < -1.0) + { + brightnessCorrection = -1.0; + } + + // Update engine + psengine->SetBrightnessCorrection(brightnessCorrection); + psengine->UpdateLights(); + + // Inform user + sysMsg.Format("Brightness correction: %0.1f",brightnessCorrection); + psSystemMessage ackMsg(0, MSG_OK, sysMsg); + ackMsg.FireEvent(); + } + else + { + return usage; + } + } + } else if ( words[0] == "/buddy" ) { if (words.GetCount() < 2) //if there were no arguments open the buddy window Modified: trunk/src/client/pscharcontrol.cpp =================================================================== --- trunk/src/client/pscharcontrol.cpp 2013-04-09 12:50:16 UTC (rev 8686) +++ trunk/src/client/pscharcontrol.cpp 2013-04-09 15:53:30 UTC (rev 8687) @@ -413,46 +413,17 @@ void psTriggerHandler::HandleBrightnessUp(const psControl* /*trigger*/, bool /*value*/) { - csString sysmsg; - - float BrightnessCorrection = psengine->GetBrightnessCorrection(); - - if(BrightnessCorrection < 3.0f) - BrightnessCorrection += 0.1f; - - psengine->SetBrightnessCorrection(BrightnessCorrection); - psengine->UpdateLights(); - - sysmsg.Format("Brightness correction: %0.1f.",BrightnessCorrection); - psSystemMessage ackmsg(0, MSG_OK, sysmsg); - ackmsg.FireEvent(); + psengine->AdjustBrightnessCorrectionUp(); } void psTriggerHandler::HandleBrightnessDown(const psControl* /*trigger*/, bool /*value*/) { - csString sysmsg; - - float BrightnessCorrection = psengine->GetBrightnessCorrection(); - - if(BrightnessCorrection > -1.0f) - BrightnessCorrection -= 0.1f; - - psengine->SetBrightnessCorrection(BrightnessCorrection); - psengine->UpdateLights(); - - sysmsg.Format("Brightness correction: %0.1f.",BrightnessCorrection); - psSystemMessage ackmsg(0, MSG_OK, sysmsg); - ackmsg.FireEvent(); + psengine->AdjustBrightnessCorrectionDown(); } - void psTriggerHandler::HandleBrightnessReset(const psControl* /*trigger*/, bool /*value*/) +void psTriggerHandler::HandleBrightnessReset(const psControl* /*trigger*/, bool /*value*/) { - psengine->SetBrightnessCorrection(0.0f); - psengine->UpdateLights(); - - - psSystemMessage ackmsg(0, MSG_OK, "Brightness Reset!"); - ackmsg.FireEvent(); + psengine->ResetBrightnessCorrection(); } void psTriggerHandler::HandleMovement(const psControl* trigger, bool value) Modified: trunk/src/client/psengine.cpp =================================================================== --- trunk/src/client/psengine.cpp 2013-04-09 12:50:16 UTC (rev 8686) +++ trunk/src/client/psengine.cpp 2013-04-09 15:53:30 UTC (rev 8687) @@ -621,6 +621,9 @@ PS_PAUSEEXIT(1); } + BrightnessCorrection = options->GetOption("engine","brightness", 0.0f); + UpdateLights(); + // Init the main widget mainWidget->SetupMain(); @@ -1611,6 +1614,70 @@ return modehandler->GetTime(); } +void psEngine::SetBrightnessCorrection(float B) +{ + BrightnessCorrection = B; + + options->SetOption("engine","brightness", BrightnessCorrection); +} + +void psEngine::AdjustBrightnessCorrectionUp() +{ + csString sysMsg; + + float brightnessCorrection = psengine->GetBrightnessCorrection(); + + if(brightnessCorrection < 3.0f) + { + brightnessCorrection += 0.1f; + } + if (brightnessCorrection > 3.0) + { + brightnessCorrection = 3.0; + } + + psengine->SetBrightnessCorrection(brightnessCorrection); + psengine->UpdateLights(); + + sysMsg.Format("Brightness correction: %0.1f", brightnessCorrection); + psSystemMessage ackMsg(0, MSG_OK, sysMsg); + ackMsg.FireEvent(); +} + +void psEngine::AdjustBrightnessCorrectionDown() +{ + csString sysMsg; + + float brightnessCorrection = psengine->GetBrightnessCorrection(); + + if(brightnessCorrection > -1.0f) + { + brightnessCorrection -= 0.1f; + } + if (brightnessCorrection < -1.0f) + { + brightnessCorrection = -1.0f; + } + + psengine->SetBrightnessCorrection(brightnessCorrection); + psengine->UpdateLights(); + + sysMsg.Format("Brightness correction: %0.1f", brightnessCorrection); + psSystemMessage ackMsg(0, MSG_OK, sysMsg); + ackMsg.FireEvent(); +} + +void psEngine::ResetBrightnessCorrection() +{ + psengine->SetBrightnessCorrection(0.0f); + psengine->UpdateLights(); + + + psSystemMessage ackmsg(0, MSG_OK, "Brightness Reset!"); + ackmsg.FireEvent(); +} + + void psEngine::UpdateLights() { modehandler->UpdateLights(); Modified: trunk/src/client/psengine.h =================================================================== --- trunk/src/client/psengine.h 2013-04-09 12:50:16 UTC (rev 8686) +++ trunk/src/client/psengine.h 2013-04-09 15:53:30 UTC (rev 8687) @@ -341,14 +341,34 @@ size_t GetTime(); + /** + * Get the current brightness correlation value. + */ float GetBrightnessCorrection() { return BrightnessCorrection; } - void SetBrightnessCorrection(float B) - { - BrightnessCorrection = B; - } + + /** + * Set the current brightness correlation value. + */ + void SetBrightnessCorrection(float B); + + /** + * Adjust brightness up and inform user. + */ + void AdjustBrightnessCorrectionUp(); + + /** + * Adjust brightness down and inform user. + */ + void AdjustBrightnessCorrectionDown(); + + /** + * Reset brightness and inform user. + */ + void ResetBrightnessCorrection(); + void UpdateLights(); float GetKFactor() Modified: trunk/src/common/util/strutil.h =================================================================== --- trunk/src/common/util/strutil.h 2013-04-09 12:50:16 UTC (rev 8686) +++ trunk/src/common/util/strutil.h 2013-04-09 15:53:30 UTC (rev 8687) @@ -56,7 +56,9 @@ csString& GetWordNumber(const csString& str, int number, size_t * startpos = NULL); -/** WordArray is class that parses text command (e.g. "/newguild Insomniac Developers") to words */ +/** + * WordArray is class that parses text command (e.g. "/newguild Insomniac Developers") to words. + */ class WordArray : protected csStringArray { public: @@ -67,7 +69,9 @@ return GetSize(); } - /* Returns given word, or empty string if it does not exist */ + /** + * Returns given word, or empty string if it does not exist. + */ csString Get(size_t wordNum) const { if(wordNum < GetSize()) @@ -99,6 +103,25 @@ return true; } + /** + * Check if the word is an interger. + */ + bool IsInt(size_t wordNum) const + { + const char* toConvert = Get(wordNum).GetDataSafe(); + char* endPtr = const_cast<char*>(toConvert); + + errno = 0; /* To distinguish success/failure after call */ + strtol(toConvert, &endPtr, 10); // 10 base + + // Check for error situations + if (errno != 0) return false; + if (toConvert == endPtr) return false; + if (*endPtr != '\0') return false; // Further characters after number + + return true; + } + int GetInt(size_t wordNum) const { return atoi(Get(wordNum).GetData()); @@ -129,6 +152,25 @@ return false; } + /** + * Check if the word is a float. + */ + bool IsFloat(size_t wordNum) const + { + const char* toConvert = Get(wordNum).GetDataSafe(); + char* endPtr = const_cast<char*>(toConvert); + + errno = 0; /* To distinguish success/failure after call */ + strtof(toConvert, &endPtr); + + // Check for error situations + if (errno != 0) return false; + if (toConvert == endPtr) return false; + if (*endPtr != '\0') return false; // Further characters after number + + return true; + } + float GetFloat(size_t wordNum) const { return atof(Get(wordNum).GetData()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |