summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gui/palette.cpp62
-rw-r--r--src/gui/palette.h31
-rw-r--r--src/gui/setup_colors.cpp89
-rw-r--r--src/gui/setup_colors.h4
-rw-r--r--src/shopitem.cpp1
5 files changed, 124 insertions, 63 deletions
diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp
index 92a2aea5..d06d589f 100644
--- a/src/gui/palette.cpp
+++ b/src/gui/palette.cpp
@@ -73,8 +73,6 @@ std::string Palette::getConfigName(const std::string &typeName)
DEFENUMNAMES(ColorType, COLOR_TYPE);
-const int Palette::GRADIENT_DELAY = 40;
-
Palette::Palette() :
mRainbowTime(tick_time),
mColVector(ColVector(TYPE_COUNT))
@@ -149,10 +147,12 @@ Palette::~Palette()
{
configName = &ColorTypeNames[col->type];
config.setValue(*configName + "Gradient", col->committedGrad);
+
+ if (col->grad != STATIC)
+ config.setValue(*configName + "Delay", col->delay);
+
if (col->grad == STATIC || col->grad == PULSE)
- {
config.setValue(*configName, toString(col->getRGB()));
- }
}
}
@@ -227,6 +227,7 @@ void Palette::commit(bool commitNonStatic)
i != iEnd; ++i)
{
i->committedGrad = i->grad;
+ i->committedDelay = i->delay;
if (commitNonStatic || i->grad == STATIC)
{
i->committedColor = i->color;
@@ -241,13 +242,13 @@ void Palette::commit(bool commitNonStatic)
void Palette::rollback()
{
for (ColVector::iterator i = mColVector.begin(), iEnd = mColVector.end();
- i != iEnd;
- ++i)
+ i != iEnd; ++i)
{
if (i->grad != i->committedGrad)
{
setGradient(i->type, i->committedGrad);
}
+ setGradientDelay(i->type, i->committedDelay);
setColor(i->type, i->committedColor.r, i->committedColor.g,
i->committedColor.b);
if (i->grad == PULSE)
@@ -260,24 +261,24 @@ void Palette::rollback()
}
void Palette::addColor(Palette::ColorType type, int rgb,
- Palette::GradientType grad,
- const std::string &text, char c)
+ Palette::GradientType grad, const std::string &text,
+ char c, int delay)
{
const std::string *configName = &ColorTypeNames[type];
- gcn::Color trueCol = (int)config.getValue(*configName, rgb);
- grad = (GradientType)config.getValue(*configName + "Gradient", grad);
- mColVector[type].set(type, trueCol, grad, text, c);
+ gcn::Color trueCol = (int) config.getValue(*configName, rgb);
+ grad = (GradientType) config.getValue(*configName + "Gradient", grad);
+ delay = (int) config.getValue(*configName + "Delay", delay);
+ mColVector[type].set(type, trueCol, grad, text, c, delay);
+
if (grad != STATIC)
- {
mGradVector.push_back(&mColVector[type]);
- }
}
void Palette::advanceGradient ()
{
if (get_elapsed_time(mRainbowTime) > 5)
{
- int pos, colIndex, colVal;
+ int pos, colIndex, colVal, delay, numOfColors;
// For slower systems, advance can be greater than one (advance > 1
// skips advance-1 steps). Should make gradient look the same
// independent of the framerate.
@@ -286,19 +287,25 @@ void Palette::advanceGradient ()
for (size_t i = 0; i < mGradVector.size(); i++)
{
+ delay = mGradVector[i]->delay;
+
+ if (mGradVector[i]->grad == PULSE)
+ delay = delay / 20;
+
+ numOfColors = (mGradVector[i]->grad == SPECTRUM ? 6 :
+ mGradVector[i]->grad == PULSE ? 127 :
+ RAINBOW_COLOR_COUNT);
+
mGradVector[i]->gradientIndex =
- (mGradVector[i]->gradientIndex + advance) %
- (GRADIENT_DELAY * ((mGradVector[i]->grad == SPECTRUM) ?
- (mGradVector[i]->grad == PULSE) ? 255 : 6 :
- RAINBOW_COLOR_COUNT));
+ (mGradVector[i]->gradientIndex + advance) %
+ (delay * numOfColors);
- pos = mGradVector[i]->gradientIndex % GRADIENT_DELAY;
- colIndex = mGradVector[i]->gradientIndex / GRADIENT_DELAY;
+ pos = mGradVector[i]->gradientIndex % delay;
+ colIndex = mGradVector[i]->gradientIndex / delay;
if (mGradVector[i]->grad == PULSE)
{
- colVal = (int) (255.0 * (sin(M_PI *
- (mGradVector[i]->gradientIndex) / 255) + 1) / 2);
+ colVal = (int) (255.0 * sin(M_PI * colIndex / numOfColors));
const gcn::Color* col = &mGradVector[i]->testColor;
@@ -310,13 +317,12 @@ void Palette::advanceGradient ()
{
if (colIndex % 2)
{ // falling curve
- colVal = (int)(255.0 * (cos(M_PI * pos / GRADIENT_DELAY) +
- 1) / 2);
+ colVal = (int)(255.0 * (cos(M_PI * pos / delay) + 1) / 2);
}
else
{ // ascending curve
- colVal = (int)(255.0 * (cos(M_PI * (GRADIENT_DELAY-pos) /
- GRADIENT_DELAY) + 1) / 2);
+ colVal = (int)(255.0 * (cos(M_PI * (delay - pos) / delay) +
+ 1) / 2);
}
mGradVector[i]->color.r =
@@ -333,9 +339,9 @@ void Palette::advanceGradient ()
{
const gcn::Color* startCol = &RAINBOW_COLORS[colIndex];
const gcn::Color* destCol =
- &RAINBOW_COLORS[(colIndex + 1) % RAINBOW_COLOR_COUNT];
+ &RAINBOW_COLORS[(colIndex + 1) % numOfColors];
- startColVal = (cos(M_PI * pos / GRADIENT_DELAY) + 1) / 2;
+ startColVal = (cos(M_PI * pos / delay) + 1) / 2;
destColVal = 1 - startColVal;
mGradVector[i]->color.r =(int)(startColVal * startCol->r +
diff --git a/src/gui/palette.h b/src/gui/palette.h
index 6a9fc937..1dec2a60 100644
--- a/src/gui/palette.h
+++ b/src/gui/palette.h
@@ -42,6 +42,9 @@
#define DEFENUMNAMES(name,def)\
const std::string Palette::name ## Names[] = { def(ECONFIGSTR,ECONFIGSTR) "" }
+// Default Gradient Delay
+#define GRADIENT_DELAY 40
+
/**
* Class controlling the game's color palette.
*/
@@ -196,6 +199,16 @@ class Palette : public gcn::ListModel
}
/**
+ * Gets the gradient delay for the specified type.
+ *
+ * @param type the color type of the color
+ *
+ * @return the gradient delay of the color with the given index
+ */
+ inline int getGradientDelay(ColorType type)
+ { return mColVector[type].delay; }
+
+ /**
* Get the character used by the specified color.
*
* @param type the color type of the color
@@ -225,6 +238,14 @@ class Palette : public gcn::ListModel
void setGradient(ColorType type, GradientType grad);
/**
+ * Sets the gradient delay for the specified color.
+ *
+ * @param grad gradient type to set
+ */
+ void setGradientDelay(ColorType type, int delay)
+ { mColVector[type].delay = delay; }
+
+ /**
* Returns the number of colors known.
*
* @return the number of colors known
@@ -275,8 +296,6 @@ class Palette : public gcn::ListModel
/** Colors used for the rainbow gradient */
static const gcn::Color RAINBOW_COLORS[];
static const int RAINBOW_COLOR_COUNT;
- /** Parameter to control the speed of the gradient */
- static const int GRADIENT_DELAY;
/** Time tick, that gradient-type colors were updated the last time. */
int mRainbowTime;
@@ -307,9 +326,11 @@ class Palette : public gcn::ListModel
GradientType grad;
GradientType committedGrad;
int gradientIndex;
+ int delay;
+ int committedDelay;
void set(ColorType type, gcn::Color& color, GradientType grad,
- const std::string &text, char c)
+ const std::string &text, char c, int delay)
{
ColorElem::type = type;
ColorElem::color = color;
@@ -317,6 +338,7 @@ class Palette : public gcn::ListModel
ColorElem::text = text;
ColorElem::ch = c;
ColorElem::grad = grad;
+ ColorElem::delay = delay;
ColorElem::gradientIndex = rand();
}
@@ -339,7 +361,8 @@ class Palette : public gcn::ListModel
* @param text identifier of color
*/
void addColor(ColorType type, int rgb, GradientType grad,
- const std::string &text, char c = 0);
+ const std::string &text, char c = 0,
+ int delay = GRADIENT_DELAY);
/**
* Prefixes the given string with "Color", lowercases all letters but
diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp
index 4d8c1e1d..80c425e5 100644
--- a/src/gui/setup_colors.cpp
+++ b/src/gui/setup_colors.cpp
@@ -71,7 +71,7 @@ Setup_Colors::Setup_Colors() :
mGradTypeLabel = new Label(_("Type: "));
mGradTypeSlider = new Slider(0, 3);
- mGradTypeSlider->setWidth(160);
+ mGradTypeSlider->setWidth(200);
mGradTypeSlider->setActionEventId("slider_grad");
mGradTypeSlider->setValue(0);
mGradTypeSlider->addActionListener(this);
@@ -79,6 +79,22 @@ Setup_Colors::Setup_Colors() :
mGradTypeText = new Label;
+ mGradDelayLabel = new Label(_("Delay: "));
+
+ mGradDelayText = new TextField();
+ mGradDelayText->setWidth(40);
+ mGradDelayText->setRange(20, 400);
+ mGradDelayText->setNumeric(true);
+ mGradDelayText->addListener(this);
+ mGradDelayText->setEnabled(false);
+
+ mGradDelaySlider = new Slider(20, 400);
+ mGradDelaySlider->setWidth(200);
+ mGradDelaySlider->setValue(mGradDelayText->getValue());
+ mGradDelaySlider->setActionEventId("slider_graddelay");
+ mGradDelaySlider->addActionListener(this);
+ mGradDelaySlider->setEnabled(false);
+
mRedLabel = new Label(_("Red: "));
mRedText = new TextField;
@@ -89,7 +105,7 @@ Setup_Colors::Setup_Colors() :
mRedText->setEnabled(false);
mRedSlider = new Slider(0, 255);
- mRedSlider->setWidth(160);
+ mRedSlider->setWidth(200);
mRedSlider->setValue(mRedText->getValue());
mRedSlider->setActionEventId("slider_red");
mRedSlider->addActionListener(this);
@@ -105,7 +121,7 @@ Setup_Colors::Setup_Colors() :
mGreenText->setEnabled(false);
mGreenSlider = new Slider(0, 255);
- mGreenSlider->setWidth(160);
+ mGreenSlider->setWidth(200);
mGreenSlider->setValue(mGreenText->getValue());
mGreenSlider->setActionEventId("slider_green");
mGreenSlider->addActionListener(this);
@@ -121,7 +137,7 @@ Setup_Colors::Setup_Colors() :
mBlueText->setEnabled(false);
mBlueSlider = new Slider(0, 255);
- mBlueSlider->setWidth(160);
+ mBlueSlider->setWidth(200);
mBlueSlider->setValue(mBlueText->getValue());
mBlueSlider->setActionEventId("slider_blue");
mBlueSlider->addActionListener(this);
@@ -138,15 +154,18 @@ Setup_Colors::Setup_Colors() :
place(0, 7, mGradTypeLabel, 2);
place(2, 7, mGradTypeSlider);
place(3, 7, mGradTypeText);
- place(0, 8, mRedLabel, 2);
- place(2, 8, mRedSlider);
- place(3, 8, mRedText).setPadding(1);
- place(0, 9, mGreenLabel, 2);
- place(2, 9, mGreenSlider);
- place(3, 9, mGreenText).setPadding(1);
- place(0, 10, mBlueLabel, 2);
- place(2, 10, mBlueSlider);
- place(3, 10, mBlueText).setPadding(1);
+ place(0, 8, mGradDelayLabel, 2);
+ place(2, 8, mGradDelaySlider);
+ place(3, 8, mGradDelayText);
+ place(0, 9, mRedLabel, 2);
+ place(2, 9, mRedSlider);
+ place(3, 9, mRedText).setPadding(1);
+ place(0, 10, mGreenLabel, 2);
+ place(2, 10, mGreenSlider);
+ place(3, 10, mGreenText).setPadding(1);
+ place(0, 11, mBlueLabel, 2);
+ place(2, 11, mBlueSlider);
+ place(3, 11, mBlueText).setPadding(1);
setDimension(gcn::Rectangle(0, 0, 325, 280));
}
@@ -167,9 +186,10 @@ void Setup_Colors::action(const gcn::ActionEvent &event)
Palette::ColorType type = guiPalette->getColorTypeAt(mSelected);
const gcn::Color *col = &guiPalette->getColor(type);
Palette::GradientType grad = guiPalette->getGradientType(type);
+ const int delay = guiPalette->getGradientDelay(type);
std::string msg;
- char ch = guiPalette->getColorChar(type);
+ const char ch = guiPalette->getColorChar(type);
mPreview->clearRows();
mPreviewBox->setContent(mTextPreview);
@@ -300,6 +320,7 @@ void Setup_Colors::action(const gcn::ActionEvent &event)
col = &guiPalette->getTestColor(type);
}
+ setEntry(mGradDelaySlider, mGradDelayText, delay);
setEntry(mRedSlider, mRedText, col->r);
setEntry(mGreenSlider, mGreenText, col->g);
setEntry(mBlueSlider, mBlueText, col->b);
@@ -318,6 +339,13 @@ void Setup_Colors::action(const gcn::ActionEvent &event)
return;
}
+ if (event.getId() == "slider_graddelay")
+ {
+ mGradDelayText->setText(toString(std::floor(mGradDelaySlider->getValue())));
+ updateColor();
+ return;
+ }
+
if (event.getId() == "slider_red")
{
mRedText->setText(toString(std::floor(mRedSlider->getValue())));
@@ -359,6 +387,8 @@ void Setup_Colors::cancel()
Palette::ColorType type = guiPalette->getColorTypeAt(mSelected);
const gcn::Color *col = &guiPalette->getColor(type);
mGradTypeSlider->setValue(guiPalette->getGradientType(type));
+ const int delay = guiPalette->getGradientDelay(type);
+ setEntry(mGradDelaySlider, mGradDelayText, delay);
setEntry(mRedSlider, mRedText, col->r);
setEntry(mGreenSlider, mGreenText, col->g);
setEntry(mBlueSlider, mBlueText, col->b);
@@ -366,24 +396,16 @@ void Setup_Colors::cancel()
void Setup_Colors::listen(const TextField *tf)
{
- if (tf == mRedText)
- {
+ if (tf == mGradDelayText)
+ mGradDelaySlider->setValue(tf->getValue());
+ else if (tf == mRedText)
mRedSlider->setValue(tf->getValue());
- updateColor();
- return;
- }
- if (tf == mGreenText)
- {
+ else if (tf == mGreenText)
mGreenSlider->setValue(tf->getValue());
- updateColor();
- return;
- }
- if (tf == mBlueText)
- {
+ else if (tf == mBlueText)
mBlueSlider->setValue(tf->getValue());
- updateColor();
- return;
- }
+
+ updateColor();
}
void Setup_Colors::updateGradType()
@@ -400,7 +422,12 @@ void Setup_Colors::updateGradType()
(grad == Palette::PULSE) ? _("Pulse") :
(grad == Palette::RAINBOW) ? _("Rainbow") : _("Spectrum"));
- bool enable = (grad == Palette::STATIC || grad == Palette::PULSE);
+ const bool enable = (grad == Palette::STATIC || grad == Palette::PULSE);
+ const bool delayEnable = (grad != Palette::STATIC);
+
+ mGradDelayText->setEnabled(delayEnable);
+ mGradDelaySlider->setEnabled(delayEnable);
+
mRedText->setEnabled(enable);
mRedSlider->setEnabled(enable);
mGreenText->setEnabled(enable);
@@ -417,7 +444,9 @@ void Setup_Colors::updateColor()
Palette::ColorType type = guiPalette->getColorTypeAt(mSelected);
Palette::GradientType grad =
static_cast<Palette::GradientType>((int)mGradTypeSlider->getValue());
+ int delay = (int) mGradDelaySlider->getValue();
guiPalette->setGradient(type, grad);
+ guiPalette->setGradientDelay(type, delay);
if (grad == Palette::STATIC)
{
diff --git a/src/gui/setup_colors.h b/src/gui/setup_colors.h
index 0aaf8b49..10a3437c 100644
--- a/src/gui/setup_colors.h
+++ b/src/gui/setup_colors.h
@@ -62,6 +62,10 @@ class Setup_Colors : public SetupTab, public gcn::ActionListener,
gcn::Slider *mGradTypeSlider;
gcn::Label *mGradTypeText;
+ gcn::Label *mGradDelayLabel;
+ gcn::Slider *mGradDelaySlider;
+ TextField *mGradDelayText;
+
gcn::Label *mRedLabel;
gcn::Slider *mRedSlider;
TextField *mRedText;
diff --git a/src/shopitem.cpp b/src/shopitem.cpp
index 683cef7a..2389785a 100644
--- a/src/shopitem.cpp
+++ b/src/shopitem.cpp
@@ -63,7 +63,6 @@ void ShopItem::addDuplicate(int inventoryIndex, int quantity)
mQuantity += quantity;
}
-
void ShopItem::addDuplicate()
{
DuplicateItem* di = new DuplicateItem;