Skip to content

Commit

Permalink
did some work on the gui
Browse files Browse the repository at this point in the history
- had to edit miyagi's xml importer a bit so it wouldn't look for skins and fonts
- had to add two properties to two classes in miyagi (SkinName and FontName)
- UIs are now completely made from the serialized file

git-svn-id: svn://svn.code.sf.net/p/ponykart/code/trunk@299 ba97e771-f6de-4074-9afc-763755853dd4
  • Loading branch information
pyritie committed Sep 27, 2011
1 parent b02c7f6 commit 4fa715c
Show file tree
Hide file tree
Showing 27 changed files with 455 additions and 394 deletions.
10 changes: 5 additions & 5 deletions Ponykart/Core/InputSwallowerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ public void AddSwallower(Func<bool> condition, object swallower) {
/// </summary>
/// <param name="querier">
/// For the most part, just use the keyword "this".
/// The thing asking whether the input it swallowed or not.
/// The thing asking whether the input is swallowed or not.
/// This is needed because otherwise nothing would be able to do anything if the input was swallowed.
/// So when we're checking the conditions, we excude any that are managed by the querier.
/// </param>
/// <returns>Returns whether or not the input is swallowed by something else.</returns>
/// <returns>Returns true if the input is swallowed by something else, false otherwise.</returns>
public bool IsSwallowed(object querier) {
bool result = false;
// we go through our conditions to check
foreach (Func<bool> f in ThingsToCheck.Keys.Where((f, i) => ThingsToCheck[f] != querier)) {
foreach (KeyValuePair<Func<bool>, object> pair in ThingsToCheck.Where((p) => p.Value != querier)) {
// and we don't count things that are managed by the querier
// We OR the conditions with the result. If any of the conditions are true, the input is swallowed.
result |= f.Invoke();
result |= pair.Key.Invoke();
}
return result;
}
Expand All @@ -58,7 +58,7 @@ public bool IsSwallowed(object querier) {
/// Is the current input swallowed or not? This method is the same as IsSwallowed(object) but without the extra condition.
/// This should be used by objects that do not swallow input themselves.
/// </summary>
/// <returns>Returns whether or not the input is swallowed.</returns>
/// <returns>Returns true if the input is swallowed by something, false otherwise.</returns>
public bool IsSwallowed() {
bool result = false;
// we go through our conditions to check
Expand Down
3 changes: 2 additions & 1 deletion Ponykart/Handlers/MiscKeyboardHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ void OnKeyboardPress_Anything(KeyEvent ke) {
LKernel.GetG<SoundMain>().Play2D("Sweet Apple Acres 128bpm.ogg", true);
break;
case KeyCode.KC_U:
LKernel.GetG<PlayerManager>().MainPlayer.Body.ApplyForce(new Vector3(0, 100000, 0), Vector3.ZERO);
//LKernel.GetG<PlayerManager>().MainPlayer.Body.ApplyForce(new Vector3(0, 100000, 0), Vector3.ZERO);
LKernel.GetG<PlayerManager>().MainPlayer.Body.LinearVelocity += new Vector3(0, 10, 0);
break;
case KeyCode.KC_F:
LKernel.GetG<PlayerManager>().MainPlayer.Kart.Body.LinearVelocity *= 2f;
Expand Down
20 changes: 10 additions & 10 deletions Ponykart/Handlers/Per-level/SAA_WheelParticleHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class SAA_WheelParticleHandler : ILevelHandler {
float defaultDirtEmissionRate = -1;
float defaultGrassEmissionRate = -1;
// woo microimprovements
static readonly string hyphen = "-";
static readonly string _hyphen = "-";

/// <summary>
/// I mostly put this in C# because running a lua function 10 times every second per kart seemed like it could cause some slowdowns
Expand All @@ -39,8 +39,8 @@ public SAA_WheelParticleHandler() {
// create particles for each wheel
foreach (Player p in LKernel.GetG<PlayerManager>().Players) {
for (int a = 0; a < 4; a++) {
var dirt = sceneMgr.CreateParticleSystem(string.Concat("wheelDirtParticle", p.ID, hyphen, a), "dirt");
var grass = sceneMgr.CreateParticleSystem(string.Concat("wheelGrassParticle", p.ID, hyphen, a), "grass");
var dirt = sceneMgr.CreateParticleSystem(string.Concat("wheelDirtParticle", p.ID, _hyphen, a), "dirt");
var grass = sceneMgr.CreateParticleSystem(string.Concat("wheelGrassParticle", p.ID, _hyphen, a), "grass");

dirt.Emitting = false;
grass.Emitting = false;
Expand All @@ -49,8 +49,8 @@ public SAA_WheelParticleHandler() {
wheel.Node.AttachObject(dirt);
wheel.Node.AttachObject(grass);

dirtParticles[string.Concat(p.ID, hyphen, a)] = dirt;
grassParticles[string.Concat(p.ID, hyphen, a)] = grass;
dirtParticles[string.Concat(p.ID, _hyphen, a)] = dirt;
grassParticles[string.Concat(p.ID, _hyphen, a)] = grass;

if (defaultDirtEmissionRate == -1)
defaultDirtEmissionRate = dirt.GetEmitter(0).EmissionRate;
Expand Down Expand Up @@ -80,7 +80,7 @@ bool IsGrass(string objName) {
/// Sets all of the emission states of the dirt particles of a kart
/// </summary>
void DirtEmitting(int kartID, bool isEmitting) {
string idWithHyphen = kartID + hyphen;
string idWithHyphen = kartID + _hyphen;
for (int a = 0; a < 4; a++) {
dirtParticles[idWithHyphen + a].Emitting = isEmitting;
}
Expand All @@ -90,7 +90,7 @@ void DirtEmitting(int kartID, bool isEmitting) {
/// Sets all of the emission states of the grass particles of a kart
/// </summary>
void GrassEmitting(int kartID, bool isEmitting) {
string idWithHyphen = kartID + hyphen;
string idWithHyphen = kartID + _hyphen;
for (int a = 0; a < 4; a++) {
grassParticles[idWithHyphen + a].Emitting = isEmitting;
}
Expand All @@ -100,7 +100,7 @@ void GrassEmitting(int kartID, bool isEmitting) {
/// Sets all of the emission states of both the dirt and grass particles of a kart
/// </summary>
void BothEmitting(int kartID, bool isEmitting) {
string idWithHyphen = kartID + hyphen;
string idWithHyphen = kartID + _hyphen;
for (int a = 0; a < 4; a++) {
dirtParticles[idWithHyphen + a].Emitting = isEmitting;
grassParticles[idWithHyphen + a].Emitting = isEmitting;
Expand Down Expand Up @@ -174,7 +174,7 @@ void OnGround(Kart kart, CollisionWorld.ClosestRayResultCallback callback) {
}

// update the particles
string idWithHypen = kart.OwnerID + hyphen;
string idWithHypen = kart.OwnerID + _hyphen;
// make some new emission rates
float dirtEmissionRate = (speed / 150) * defaultDirtEmissionRate;
float grassEmissionRate = (speed / 150) * defaultGrassEmissionRate;
Expand All @@ -189,7 +189,7 @@ void OnGround(Kart kart, CollisionWorld.ClosestRayResultCallback callback) {
if (kartSpeedStates[kart.OwnerID] != KartSpeedState.Fast) {
kartSpeedStates[kart.OwnerID] = KartSpeedState.Fast;

string idWithHypen = kart.OwnerID + hyphen;
string idWithHypen = kart.OwnerID + _hyphen;
for (int a = 0; a < 4; a++) {
// update all of the particles to use the default emission rate instead of whatever it was set to before
dirtParticles[idWithHypen + a].GetEmitter(0).EmissionRate = defaultDirtEmissionRate;
Expand Down
3 changes: 3 additions & 0 deletions Ponykart/Handlers/PrimitiveCreatorHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public PrimitiveCreatorHandler() {
}

void ShootPrimitive(KeyEvent ke) {
if (LKernel.GetG<InputSwallowerManager>().IsSwallowed())
return;

if (ke.key == KeyCode.KC_B) {
string type;
switch ((int) Math.RangeRandom(0, 5)) {
Expand Down
28 changes: 7 additions & 21 deletions Ponykart/Handlers/UI/CountdownUIHandler.cs
Original file line number Diff line number Diff line change
@@ -1,49 +1,35 @@
using Miyagi.Common;
using Miyagi.Common.Data;
using Miyagi.UI;
using Miyagi.UI;
using Miyagi.UI.Controls;
using Ponykart.Core;
using Ponykart.Levels;
using Ponykart.Properties;
using Ponykart.UI;

namespace Ponykart.Handlers {
[Handler(HandlerScope.Global)]
public class CountdownUIHandler {
private Label countLabel;
private GUI countGui;

public CountdownUIHandler() {
// set up our label
GUI Gui = LKernel.GetG<UIMain>().Gui;
countGui = LKernel.GetG<UIMain>().GetGUI("countdown gui");

countLabel = new Label("countdown label") {
Location = new Point(0, 0),
Size = new Size((int) Settings.Default.WindowWidth, (int) Settings.Default.WindowHeight),
TextStyle = {
Alignment = Alignment.MiddleCenter,
ForegroundColour = Colours.Magenta,
Font = UIResources.Fonts["Celestia"],
},
Visible = false,
Text = string.Empty,
};

Gui.Controls.Add(countLabel);
countLabel = countGui.GetControl<Label>("countdown label");

// hook up to events
LKernel.GetG<RaceCountdown>().OnCountdown += new RaceCountdownEvent(OnCountdown);
LKernel.GetG<LevelManager>().OnLevelPreUnload += new LevelEvent(OnLevelPreUnload);
}

void OnLevelPreUnload(LevelChangedEventArgs eventArgs) {
countLabel.Visible = false;
countGui.Visible = false;
}


void OnCountdown(RaceCountdownState state) {
switch (state) {
case RaceCountdownState.Three:
countLabel.Visible = true;
countGui.Visible = true;
countLabel.Text = "3";
break;
case RaceCountdownState.Two:
Expand All @@ -56,7 +42,7 @@ void OnCountdown(RaceCountdownState state) {
countLabel.Text = "Go!";
break;
case RaceCountdownState.OneSecondAfterGo:
countLabel.Visible = false;
countGui.Visible = false;
break;
}
}
Expand Down
Loading

0 comments on commit 4fa715c

Please sign in to comment.