• entries
    707
  • comments
    1173
  • views
    434026

Untitled

Sign in to follow this  
Programmer16

74 views

That was fun. Found a bunch of flaws in my GUI system. One of the biggest being I wasn't using my own font class right lol. Another important one being that I wasn't using the control's font color or formatting.

I added a new GUI widget, but I'm going to change it to make it more useable. At the moment it's named KeyMapInput, has it's own skin and whatnot. Originally I was going to just use a button and a label, but once I got into doing that I realized how much of a pain it was going to be (actually, it was looking near impossible to do without using tons of extra variables.) So, I made the new class and it actually works really well.

I also had to fix a few kinks in my config class system, add some saving functions, and add some setting functions (I've only used it for loading and retrieving so I didn't code any setting or saving stuff into it lol.)

Anyway, here's a screenshot of my first attempt:


And here's one of the final system:


And here's one with a different layout:


The new screenshots show off my GUI's multi-font capability nicely. The HUD does a good job as well. Any control can use any font that's currently loaded into the environment; as you can see it's pretty useful.

Tomorrow I'm going to go through and figure out everything that needs to be finished before I move on. I'll update then and we'll go from there.

Thanks to everybody that tested it for me!

-edit-
Btw, I found a pretty bad bug earlier while playing around. If you walk at an angle and hit an enemy, it's REALLY easy to get instant death. That should be pretty easy to fix and while I'm doing that I'll make sure to fix it so you don't have to worry about the domino effect (get hit, which throws you into a different monster which hurts you and throws you into another monster, etc.)



I was asked about one of my design practices earlier, so I figured I'd discuss it real quick. Here's a quick example:

class FontFormatting
{
static int QuickFromString(const std::string &String, int Default = Left)
{
if(String == "") return Default;
if(String == "Left") return Left;
if(String == "Center") return Center;
if(String == "Right") return Right;
if(String == "Top") return Top;
if(String == "VCenter") return VCenter;
if(String == "Bottom") return Bottom;
if(String == "WordBreak") return WordBreak;

return Default;
}

public:
static const int Left = 1;
static const int Center = 2;
static const int Right = 4;
static const int Top = 8;
static const int VCenter = 16;
static const int Bottom = 32;
static const int WordBreak = 64;

static bool IsValid(int Type) // Type is only valid if it is a single choice. Fixing this is on my to-do list.
{
return Type == Left || Type == Center || Type == Right || Type == Top || Type == VCenter || Type == Bottom || Type == WordBreak;
}

static int FromString(const std::string &String, int Default = Left)
{
std::vector Chunks;
std::string Temp = dft::StringOps::Remove(String, ' ');
dft::StringOps::Split(Chunks, Temp, '|');

int Results = 0;
for(std::vector::iterator Itor = Chunks.begin(); Itor != Chunks.end(); ++Itor)
Results |= QuickFromString(*Itor, Default);
return Results;
}

static std::string ToString(int Type, int Default)
{
if(!IsValid(Type))
{
if(!IsValid(Default))
return "";
return ToString(Default, Default);
}

switch(Type)
{
case Left: return "Left";
case Center: return "Center";
case Right: return "Right";
case Top: return "Top";
case VCenter: return "VCenter";
case Bottom: return "Bottom";
case WordBreak: return "WordBreak";
}
return "";
}

class Enumerator
{
int CurrentValue;
bool FirstPass;
public:
Enumerator()
{
CurrentValue = FontFormatting::Left;
FirstPass = true;
}

bool MoveNext()
{
if(FirstPass)
{
FirstPass = false;
return true;
}

switch(CurrentValue)
{
case FontFormatting::Left: CurrentValue = FontFormatting::Center; break;
case FontFormatting::Center: CurrentValue = FontFormatting::Right; break;
case FontFormatting::Right: CurrentValue = FontFormatting::Top; break;
case FontFormatting::Top: CurrentValue = FontFormatting::VCenter; break;
case FontFormatting::VCenter: CurrentValue = FontFormatting::Bottom; break;
case FontFormatting::Bottom: CurrentValue = FontFormatting::WordBreak; break;
case FontFormatting::WordBreak: CurrentValue = FontFormatting::Left; return false;
}
return true;
}

void Reset()
{
FirstPass = true;
CurrentValue = FontFormatting::Left;
}

int operator *() const
{
return CurrentValue;
}

std::string ToString() const
{
return FontFormatting::ToString(CurrentValue, FontFormatting::Left);
}
};
};





Whenever I need an enum, it's made like this. This isn't the best example seeing as how it's somewhat broken (IsValid() won't work if you combine more than one option; working on this), but it'll do. This design actually ties into my file loading designs as well. I can have a single function like so:

template
static bool ConditionalAssignmentAttribute(Type &Destination, const char* Text, const Type &Default)
{
if(Text)
{
Destination = TypeConverter::FromString(Text);
return true;
}
Destination = Default;
return false;
}





There are better examples, but I'm kind of in a rush lol. Anyway, this design has made my life tons easier. I use it for my key-mapping (yes, my Keys enum has all of the above for every key), for loading my GUI skin file and layout file (font formatting and such.)

I also use a similiar design for my math classes (they all have a ToString() and FromString() function.)

Now, I've been told by some people that it's bad (haven't really been told any reasons), but I haven't had a single problem with it and it's saved me tons of time.

Anyway, bedtime now. kthxbai

-edit-
Btw, I put my download link thing back up at the top of the page. I'm going to expand it a little and update the download real quick so the key-mapping is in.
Sign in to follow this  


3 Comments


Recommended Comments

Hey, Ima little late to the party, but I just gave your demo from last post a run through. Ran great and actually, killing a bunch of static entities is more fun than one would think =D

My only suggestion would be with the movement: If you are holding right/left and then press down/up, you move diagonal and stay facing right/left, but if you are moving down/up and the press right/left you will again moving diagonal but your direction will change from the orignal.

That is a pretty minor qualm and should be an easy fix. The ui has an elegant foundation and overall its looking like a solid [and fun] project.

Nice work =)

Share this comment


Link to comment
Quote:
Original post by shadowcomplex
Hey, Ima little late to the party, but I just gave your demo from last post a run through. Ran great and actually, killing a bunch of static entities is more fun than one would think =D

My only suggestion would be with the movement: If you are holding right/left and then press down/up, you move diagonal and stay facing right/left, but if you are moving down/up and the press right/left you will again moving diagonal but your direction will change from the orignal.

That is a pretty minor qualm and should be an easy fix. The ui has an elegant foundation and overall its looking like a solid [and fun] project.

Nice work =)

Lol, indeed. I've spent a couple hours myself just running around and killing things XD.

I noticed that as well and I think I know of a way to fix it. I'll put it on my todo list. I should (hopefully) be able to get to it before the night is over.

Thanks, I appreciate the comments and thanks for trying it!

Share this comment


Link to comment
I trust you also have joypad mapping -- my big problem right now is designing my input UI so joypad mapping works great too. [grin]

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now