summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Boffey <DougABoffey@netscape.net>2008-09-04 17:05:27 +0000
committerDouglas Boffey <DougABoffey@netscape.net>2008-09-04 17:05:27 +0000
commitc57fdaf3c18f34678cf4753a1fae0e6d622839a7 (patch)
tree3a183f500fa8b9f1679b420e0894496fad1299f5
parent7946cd875877870e7cab002cba099d21cf9fc063 (diff)
downloadmana-client-c57fdaf3c18f34678cf4753a1fae0e6d622839a7.tar.gz
mana-client-c57fdaf3c18f34678cf4753a1fae0e6d622839a7.tar.bz2
mana-client-c57fdaf3c18f34678cf4753a1fae0e6d622839a7.tar.xz
mana-client-c57fdaf3c18f34678cf4753a1fae0e6d622839a7.zip
Added omitted files from rev 405
-rw-r--r--ChangeLog10
-rw-r--r--src/gui/colour.cpp137
-rw-r--r--src/gui/colour.h130
-rw-r--r--src/gui/setup_colours.cpp208
-rw-r--r--src/gui/setup_colours.h76
5 files changed, 558 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index deebf57c..99952782 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2008-09-04 Douglas Boffey ("Scraggy") <scraggy@aethyra.com>
+
+ * Added code to change colours in the chatlog
+
2008-08-30 kevin Day ("blame") <blame@aethyra.com>
* Updated the in game help files "/trunk/data/help"
@@ -7,7 +11,7 @@
* Patch to prevent crash if a map layer has too many
tiles (From TMW svn, r4544)
-2008-08-26 Douglas Boffey ("Scraggy") <DougABoffey@netscape.net>
+2008-08-26 Douglas Boffey ("Scraggy") <DougABoffey@netscape.net>
* Corrected position of registration dialogs
@@ -22,7 +26,7 @@
2008-08-17 Lloyd Bryant ("Sanga") <sanga@aethyra.com>
* Set the wallpaper based on the screen width.
- * Added a usleep to the login sequence loop to
+ * Added a usleep to the login sequence loop to
prevent it from unnecessarily maxing out the CPU
2008-08-17 Lloyd Bryant ("Sanga") <sanga@aethyra.com>
@@ -59,7 +63,7 @@
2008-07-25 Lloyd Bryant ("Sanga") <sanga@aethyra.com>
- * Added feature to remember window locations from one
+ * Added feature to remember window locations from one
session to the next (patch from TMW by ElvenProgrammer)
2008-07-24 Lloyd Bryant ("Sanga") <sanga@aethyra.com>
diff --git a/src/gui/colour.cpp b/src/gui/colour.cpp
new file mode 100644
index 00000000..d1782e1c
--- /dev/null
+++ b/src/gui/colour.cpp
@@ -0,0 +1,137 @@
+/***************************************************************************
+ * Copyright (C) 2008 by Douglas Boffey *
+ * *
+ * DougABoffey@netscape.net *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed with The Mana Experiment *
+ * in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#include "colour.h"
+
+#include <cstdio>
+
+#include "../configuration.h"
+
+Colour::Colour()
+{
+ addColour('C', 0x000000, "Chat");
+ addColour('G', 0xff0000, "GM");
+ addColour('Y', 0x1fa052, "Player");
+ addColour('W', 0x0000ff, "Whisper");
+ addColour('I', 0xf1dc27, "Is");
+ addColour('P', 0xff00d8, "Party");
+ addColour('S', 0x8415e2, "Server");
+ addColour('L', 0x919191, "Logger");
+ addColour('<', 0xe50d0d, "Hyperlink");
+ commit();
+}
+
+Colour::~Colour()
+{
+ for (ColVector::iterator col = mColVector.begin(),
+ colEnd = mColVector.end();
+ col != colEnd;
+ ++col)
+ {
+ char buffer[20];
+ std::sprintf(buffer, "0x%06x", col->rgb);
+ config.setValue("Colour" + col->text, buffer);
+ }
+}
+
+void Colour::setColour(const char c, const int rgb)
+{
+ for (ColVector::iterator col = mColVector.begin(),
+ colEnd = mColVector.end();
+ col != colEnd;
+ ++col)
+ {
+ if (col->ch == c)
+ {
+ col->rgb = rgb;
+ return;
+ }
+ }
+}
+
+int Colour::getColour(const char c, bool &valid) const
+{
+ for (ColVector::const_iterator col = mColVector.begin(),
+ colEnd = mColVector.end();
+ col != colEnd;
+ ++col)
+ {
+ if (col->ch == c)
+ {
+ valid = true;
+ return col->rgb;
+ }
+ }
+ valid = false;
+ return 0x000000;
+}
+
+std::string Colour::getElementAt(int i)
+{
+ if (i < 0 || i >= getNumberOfElements())
+ {
+ return "";
+ }
+ return mColVector[i].text;
+}
+
+void Colour::addColour(const char c, const int rgb, const std::string &text)
+{
+ int trueRgb = config.getValue("Colour" + text, rgb);
+ mColVector.push_back(ColourElem(c, trueRgb, text));
+}
+
+int Colour::getColourAt(int i)
+{
+ if (i < 0 || i >= getNumberOfElements())
+ {
+ return 0;
+ }
+ return mColVector[i].rgb;
+}
+
+void Colour::setColourAt(int i, int rgb)
+{
+ if (i >= 0 && i < getNumberOfElements())
+ {
+ mColVector[i].rgb = rgb;
+ }
+}
+
+void Colour::commit()
+{
+ for (ColVector::iterator i = mColVector.begin(), iEnd = mColVector.end();
+ i != iEnd;
+ ++i)
+ {
+ i->committedRgb = i->rgb;
+ }
+}
+
+void Colour::rollback()
+{
+ for (ColVector::iterator i = mColVector.begin(), iEnd = mColVector.end();
+ i != iEnd;
+ ++i)
+ {
+ i->rgb = i->committedRgb;
+ }
+}
diff --git a/src/gui/colour.h b/src/gui/colour.h
new file mode 100644
index 00000000..69253f95
--- /dev/null
+++ b/src/gui/colour.h
@@ -0,0 +1,130 @@
+/***************************************************************************
+ * Copyright (C) 2008 by Douglas Boffey *
+ * *
+ * DougABoffey@netscape.net *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed with The Mana Experiment *
+ * in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#ifndef _COLOUR_H
+#define _COLOUR_H
+#include <cstdio>
+#include <vector>
+#include <string>
+
+#include <guichan/listmodel.hpp>
+
+class Colour : public gcn::ListModel
+{
+ public:
+ /**
+ * Constructor
+ */
+ Colour();
+
+ /**
+ * Destructor
+ */
+ ~Colour();
+
+ /**
+ * Define the colour replacement for a character
+ *
+ * @param c charater to be replaced
+ * @param rgb colour to replace character
+ */
+ void setColour(const char c, const int rgb);
+
+ /**
+ * Define the colour replacement for a character
+ *
+ * @param c character to be replaced
+ * @param r red component
+ * @param g green component
+ * @param b blue component
+ */
+ void setColour(const char c, const int r, const int g, const int b)
+ {
+ setColour(c, (r << 16) | (g << 8) | b);
+ }
+
+ /**
+ * Return the colour associated with a character, if exists
+ *
+ * @param c character requested
+ * @param valid indicate whether character is known
+ */
+ int getColour(const char c, bool &valid) const;
+
+ /**
+ * Return the number of colours known
+ */
+ int getNumberOfElements() {return mColVector.size(); }
+
+ /**
+ * Return the name of the ith colour
+ *
+ * @param i index of colour interested in
+ */
+ std::string getElementAt(int i);
+
+ /**
+ * Get the colour for the element at index i in the current colour
+ * model
+ */
+ int getColourAt(int i);
+
+ /**
+ * Set the colour for the element at index i
+ */
+ void setColourAt(int i, int rgb);
+
+ /**
+ * Commit the colours
+ */
+ void commit();
+
+ /**
+ * Rollback the colours
+ */
+ void rollback();
+
+ private:
+ struct ColourElem
+ {
+ ColourElem(const char c, const int rgb, const std::string &text) :
+ ch(c), rgb(rgb), text(text) {}
+ char ch;
+ int rgb;
+ int committedRgb;
+ std::string text;
+ };
+ typedef std::vector<ColourElem> ColVector;
+ ColVector mColVector;
+
+ /**
+ * Initialise colour
+ *
+ * @param c character that needs initialising
+ * @param rgb default colour if not found in config
+ * @param text identifier of colour
+ */
+ void addColour(const char c, const int rgb, const std::string &text);
+};
+
+extern Colour *textColour;
+
+#endif
diff --git a/src/gui/setup_colours.cpp b/src/gui/setup_colours.cpp
new file mode 100644
index 00000000..2c6d7aa9
--- /dev/null
+++ b/src/gui/setup_colours.cpp
@@ -0,0 +1,208 @@
+/***************************************************************************
+ * Copyright (C) 2008 by Douglas Boffey *
+ * *
+ * DougABoffey@netscape.net *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed with The Mana Experiment *
+ * in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#include "setup_colours.h"
+
+#include <vector>
+
+#include <guichan/listmodel.hpp>
+#include <guichan/widgets/label.hpp>
+#include <guichan/widgets/slider.hpp>
+
+#include "colour.h"
+#include "scrollarea.h"
+#include "slider.h"
+
+#include "../configuration.h"
+
+Setup_Colours::Setup_Colours() :
+ mColourLabel("Colour:"),
+ mSelected(-1)
+{
+ mColourBox = new gcn::ListBox(textColour);
+ mScroll = new ScrollArea(mColourBox);
+
+ mColourLabel.setX(5);
+ mColourLabel.setY(5);
+
+ mColourBox->setDimension(gcn::Rectangle(0, 10 + mColourLabel.getHeight(),
+ 80,
+ 115 - mColourLabel.getHeight()));
+ mScroll->setDimension(gcn::Rectangle(5, 10 + mColourLabel.getHeight(),
+ 100, 115 - mColourLabel.getHeight()));
+ mColourBox->setSelected(-1);
+ mColourBox->setActionEventId("colour_box");
+ mColourBox->addActionListener(this);
+
+ setOpaque(false);
+
+ add(&mColourLabel);
+ add(mScroll);
+
+ setupPlacer(140, mLabel1, mSlider1, mText1, "R", "1");
+ setupPlacer(165, mLabel2, mSlider2, mText2, "G", "2");
+ setupPlacer(190, mLabel3, mSlider3, mText3, "B", "3");
+
+}
+
+Setup_Colours::~Setup_Colours()
+{
+ delete mLabel1;
+ delete mSlider1;
+ delete mText1;
+
+ delete mLabel2;
+ delete mSlider2;
+ delete mText2;
+
+ delete mLabel3;
+ delete mSlider3;
+ delete mText3;
+
+ delete mScroll;
+}
+
+void Setup_Colours::action(const gcn::ActionEvent &event)
+{
+ if (event.getId() == "colour_box")
+ {
+ mSelected = mColourBox->getSelected();
+ int col = textColour->getColourAt(mSelected);
+ setEntry(mSlider1, mText1, col >> 16);
+ setEntry(mSlider2, mText2, (col >> 8) & 0xff);
+ setEntry(mSlider3, mText3, col & 0xff);
+ return;
+ }
+
+ if (event.getId() == "slider1")
+ {
+ char buffer[30];
+ std::sprintf(buffer, "%d", static_cast<int>(mSlider1->getValue()));
+ mText1->setText(buffer);
+ updateColour();
+ return;
+ }
+
+ if (event.getId() == "slider2")
+ {
+ char buffer[30];
+ std::sprintf(buffer, "%d", static_cast<int>(mSlider2->getValue()));
+ mText2->setText(buffer);
+ updateColour();
+ return;
+ }
+
+ if (event.getId() == "slider3")
+ {
+ char buffer[30];
+ std::sprintf(buffer, "%d", static_cast<int>(mSlider3->getValue()));
+ mText3->setText(buffer);
+ updateColour();
+ return;
+ }
+}
+
+void Setup_Colours::setEntry(Slider *s, TextField *t, int value)
+{
+ s->setValue(value);
+ char buffer[100];
+ sprintf(buffer, "%d", value);
+ t->setText(buffer);
+}
+
+void Setup_Colours::apply()
+{
+ textColour->commit();
+}
+
+void Setup_Colours::cancel()
+{
+ textColour->rollback();
+ int col = textColour->getColourAt(mSelected);
+ setEntry(mSlider1, mText1, col >> 16);
+ setEntry(mSlider2, mText2, (col >> 8) & 0xff);
+ setEntry(mSlider3, mText3, col & 0xff);
+}
+
+void Setup_Colours::setupPlacer(int v, gcn::Label *&l, Slider *&s,
+ TextField *&t, std::string lbl,
+ std::string sfx)
+{
+ l = new gcn::Label(lbl + ":");
+ l->setX(5);
+ l->setY(v - l->getHeight() / 2);
+
+ s = new Slider(0, 255);
+ s->setHeight(10);
+ s->setX(25);
+ s->setY(v - s->getHeight() / 2);
+ s->setWidth(128);
+ s->setScale(0, 255);
+
+ t = new TextField();
+ t->setX(165);
+ t->setY(v - t->getHeight() / 2);
+ t->setWidth(40);
+ t->setNumeric(true);
+ t->setRange(0, 255);
+ t->addListener(this);
+
+ s->setActionEventId("slider" + sfx);
+ s->addActionListener(this);
+
+ add(l);
+ add(s);
+ add(t);
+}
+
+void Setup_Colours::listen(const TextField *tf)
+{
+ if (tf == mText1)
+ {
+ mSlider1->setValue(tf->getValue());
+ updateColour();
+ return;
+ }
+ if (tf == mText2)
+ {
+ mSlider2->setValue(tf->getValue());
+ updateColour();
+ return;
+ }
+ if (tf == mText3)
+ {
+ mSlider3->setValue(tf->getValue());
+ updateColour();
+ return;
+ }
+}
+
+void Setup_Colours::updateColour()
+{
+ if (mSelected == -1)
+ {
+ return;
+ }
+ int rgb = static_cast<int>(mSlider1->getValue()) << 16 |
+ static_cast<int>(mSlider2->getValue()) << 8 |
+ static_cast<int>(mSlider3->getValue());
+ textColour->setColourAt(mSelected, rgb);
+}
diff --git a/src/gui/setup_colours.h b/src/gui/setup_colours.h
new file mode 100644
index 00000000..566bed37
--- /dev/null
+++ b/src/gui/setup_colours.h
@@ -0,0 +1,76 @@
+/***************************************************************************
+ * Copyright (C) 2008 by Douglas Boffey *
+ * *
+ * DougABoffey@netscape.net *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed with The Mana Experiment *
+ * in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+#ifndef _SETUP_COLOURS_H
+#define _SETUP_COLOURS_H
+
+#include <vector>
+#include <string>
+
+#include <guichan/actionlistener.hpp>
+#include <guichan/widgets/listbox.hpp>
+#include <guichan/widgets/label.hpp>
+
+#include "setuptab.h"
+#include "slider.h"
+#include "textfield.h"
+#include "scrollarea.h"
+
+#include "../guichanfwd.h"
+
+class Setup_Colours : public SetupTab, public gcn::ActionListener,
+ public TextFieldListener
+{
+ public:
+ Setup_Colours();
+ ~Setup_Colours();
+ void apply();
+ void cancel();
+ void action(const gcn::ActionEvent &event);
+
+ void listen(const TextField *tf);
+ private:
+ gcn::ListBox *mColourBox;
+ gcn::Label mColourLabel;
+ ScrollArea *mScroll;
+ int mSelected;
+
+ gcn::Label *mLabel1;
+ Slider *mSlider1;
+ TextField *mText1;
+ int mValue1;
+
+ gcn::Label *mLabel2;
+ Slider *mSlider2;
+ TextField *mText2;
+ int mValue2;
+
+ gcn::Label *mLabel3;
+ Slider *mSlider3;
+ TextField *mText3;
+ int mValue3;
+
+ void setupPlacer(int v, gcn::Label *&l, Slider *&s, TextField *&t,
+ std::string lbl, std::string sfx);
+ void setEntry(Slider *s, TextField *t, int value);
+ void updateColour();
+};
+#endif