Skip to content
Permalink
Browse files
Added interaction HUD.
  • Loading branch information
crabmusket committed Nov 10, 2014
1 parent e6e2d30 commit 327f2da7378d37961aaffec61c3eda79e70a6328
@@ -4,7 +4,7 @@
horizSizing = "right";
vertSizing = "bottom";
position = "0 0";
extent = "1024 768";
extent = "800 600";
minExtent = "8 8";
canSave = true;
visible = true;
@@ -0,0 +1,39 @@
GameViewGui.add(new GuiControl(HUD) {
profile = InvisibleProfile;
horizSizing = Right;
vertSizing = Bottom;
position = "0 0";
extent = "800 600";
visible = false;

new GuiControl([Interaction]) {
profile = BackgroundProfile;
position = "-350 50";
extent = "350 50";

new GuiBitmapCtrl([InteractionIcon]) {
visible = false;
};

new GuiTextCtrl([InteractionString]) {
profile = SmallTitleProfile;
position = "50 10";
extent = "300 30";
};
};
});

HUD.Tweens = Twillex::create();
HUD.Tweens.startUpdates();

function clientCmdInteraction(%text) {
HUD-->InteractionString.setText(%text);
%textW = getWord(HUD-->InteractionString.extent, 0);
HUD-->Interaction.extent = 100 + %textW SPC 50;
HUD.Tweens.toOnce(200, HUD-->Interaction, "position: 0 50", "ease:sine_out");
}

function clientCmdNoInteraction() {
%pos = -1 * getWord(Hud-->Interaction.extent, 0) SPC 50;
HUD.Tweens.toOnce(200, HUD-->Interaction, "position:" SPC %pos, "ease:sine_in");
}
@@ -20,3 +20,4 @@
exec("./menus/loading.cs");
exec("./ingame/gameView.cs");
exec("./ingame/inGameMenu.cs");
exec("./ingame/hud.cs");
@@ -182,7 +182,7 @@ 0 SPC (getWord(%level.extent, 1) * 0.5)
%levels = %this-->Levels;
%levels.add(new GuiButtonCtrl() {
class = LevelListButton;
profile = LevelListProfile;
profile = SmallTitleProfile;
text = %level.levelName;
command = "GuiEvents.postEvent(EvtSelectLevel, \""@%level.levelName@"\");";
useMouseEvents = true;
@@ -198,9 +198,9 @@ class = LevelListButton;
}
function LevelListButton::onEvtSelectLevel(%this, %title) {
if (%this.text $= %title) {
%this.profile = LevelListInvertedProfile;
%this.profile = SmallTitleProfileInverted;
} else {
%this.profile = LevelListProfile;
%this.profile = SmallTitleProfile;
}
}
function LevelListButton::onMouseEnter(%this) {
@@ -84,7 +84,7 @@ class = JoinButton;
%servers = %this-->Servers;
%servers.add(new GuiButtonCtrl() {
class = LevelListButton;
profile = LevelListProfile;
profile = SmallTitleProfile;
text = %info;
command = "GuiEvents.postEvent(EvtSelectServer, \""@%level.levelName@"\");";
useMouseEvents = true;
@@ -99,9 +99,9 @@ class = LevelListButton;
}
function ServerListButton::onEvtSelectLevel(%this, %title) {
if (%this.text $= %title) {
%this.profile = LevelListInvertedProfile;
%this.profile = SmallTitleProfileInverted;
} else {
%this.profile = LevelListProfile;
%this.profile = SmallTitleProfile;
}
}
function ServerListButton::onMouseEnter(%this) {
@@ -10,18 +10,19 @@
fontColorHL = "White";
fillColor = "Black";
fillColorHL = "Black";
autoSizeWidth = true;
};

new GuiControlProfile(TitleProfile : TextProfile) {
fontType = "basic title font";
fontSize = 36;
};

new GuiControlProfile(LevelListProfile : TitleProfile) {
new GuiControlProfile(SmallTitleProfile : TitleProfile) {
fontSize = 26;
};

new GuiControlProfile(LevelListInvertedProfile : LevelListProfile) {
new GuiControlProfile(SmallTitleProfileInverted : SmallTitleProfile) {
fontColor = "Black";
fontColorHL = "Black";
fillColor = "White";
@@ -163,9 +163,9 @@
{
// no need to return it if you named it!
if (%name !$= "")
new ScriptObject(%name) { class = Twillex; };
new ScriptTickObject(%name) { class = Twillex; };
else
return new ScriptObject() { class = Twillex; };
return new ScriptTickObject() { class = Twillex; };
}

function Twillex::onAdd(%this)
@@ -528,6 +528,11 @@ class = Tween;

%this.onUpdate();
%this.schedule(%millis, startUpdates);
%this.callOnAdvanceTime = true;
}

function Twillex::onAdvanceTime(%this) {
%this.onUpdate();
}

// ---------------------------------------------
@@ -1,3 +1,62 @@
datablock PlayerData(PlayerSoldier) {
class = SoldierShape;
shapeFile = "art/characters/soldier.dae";

cameraMaxDist = 2;
};

function PlayerSoldier::onAdd(%this, %obj) {
// Start looking for items to interact with.
%this.itemSearch(%obj);
}

function PlayerSoldier::onRemove(%this, %obj) {
cancel(%obj.itemSearch);
}

// Search for items in front of the character. If we see one, we'll notify the
// GameConnection in control of this player. This function runs every 100ms (i.e.
// 10 times/second). The search takes the form of a big sphere in front of the
// player's eye (imagine holding an exercise ball in front of your face).
function PlayerSoldier::itemSearch(%this, %obj) {
%obj.itemSearch = %this.schedule(100, itemSearch, %obj);
%radius = 1.2;
%eye = %obj.getEyePoint();
%dir = %obj.getEyeVector();
%pos = VectorAdd(%eye, VectorScale(%dir, %radius));

InitContainerRadiusSearch(%pos, %radius, $TypeMasks::ItemObjectType);
%best = 0;
%bestDot = -1;
while((%item = ContainerSearchNext()) != 0) {
%diff = VectorSub(%item.getPosition(), %eye);
%diffn = VectorNormalize(%diff);
%dot = VectorDot(%dir, %diffn);
if (%dot > %bestDot) {
%bestDot = %dot;
%best = %item;
}
}

if (isObject(%obj.client)) {
%obj.client.lookingAtItem(%best);
}
}

function PlayerSoldier::getInteraction(%this, %obj, %item) {
%db = %item.getDataBlock();
switch$ (%db.type) {
case "pickup":
%empty = "pick up";
%full = "swap for";

case "device":
%empty = "use";
%full = "use";
}

%msg = (%obj.getMountedImage(0) == 0 ? %empty : %full)
SPC %db.itemName;

return %msg;
}
@@ -28,7 +28,56 @@ class = ClientConnectionState;

function ClientConnectionState::enterObserving(%this) {
%this.connection.setControlObject(%this.connection.camera);
%this.observeThroughCam(0);
commandToClient(%this.connection, 'enterObserving');
}

function ClientConnectionState::observeThroughCam(%this, %idx) {
if (!isObject(ObserverCamGroup)) {
return;
}

%markers = ObserverCamGroup.getCount();
if (%idx < 0) {
%idx = %markers - 1;
} else if (%idx >= %markers) {
%idx = 0;
}
%marker = ObserverCamGroup.getObject(%idx);
if (isObject(%marker)) {
%transform = %marker.getTransform();
%this.connection.camera.setTransform(%transform);
%this.observerCamIndex = %idx;
}
}

function ClientConnectionState::enterPlaying(%this) {
if (!isObject(%this.connection.character)) {
%this.connection.character = new Player() {
datablock = PlayerSoldier;
client = %this.connection;
};
MissionCleanup.add(%this.connection.character);
LevelEvents.postEvent(EvtSpawn, %this.connection);
}
%this.connection.setControlObject(%this.connection.character);
commandToClient(%this.connection, 'enterPlaying');
}

function serverCmdShiftObserverCam(%this, %dir) {
if (%this.state.state $= observing) {
%this.state.observeThroughCam(%this.state.observerCamIndex + %dir);
}
}

function GameConnection::lookingAtItem(%this, %item) {
if (%item !$= %this.currentItem) {
%this.currentItem = %item;
if (isObject(%item)) {
commandToClient(%this, 'interaction',
%this.character.getDataBlock().getInteraction(%this.character, %item));
} else {
commandToClient(%this, 'noInteraction');
}
}
}
@@ -30,6 +30,8 @@ class = Weapon;
image = MachineGunImage;
elasticity = 0.05;
mass = 15;
type = "pickup";
itemName = "machine gun";
};

datablock ProjectileData(MachineGunProjectile) {

0 comments on commit 327f2da

Please sign in to comment.