Skip to content

Commit

Permalink
Added buddy system.
Browse files Browse the repository at this point in the history
  • Loading branch information
Miguel Angel Blanch Lardin committed Mar 28, 2006
1 parent 453582f commit 165ec23
Show file tree
Hide file tree
Showing 9 changed files with 208 additions and 8 deletions.
Binary file added data/gui/buddy_offline.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/gui/buddy_online.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/sprites/ideas/pk.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions src/games/stendhal/client/StendhalClient.java
Expand Up @@ -22,6 +22,7 @@
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import javax.swing.JTextField;
import java.io.*;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -58,6 +59,7 @@ public class StendhalClient extends ariannexp
private boolean keepRunning=true;
private GameLogDialog gameDialog;
private InGameGUI gameGUI;
private JTextField textLineGUI;
private JFrame frame;
private Configuration conf;

Expand Down Expand Up @@ -157,6 +159,16 @@ public InGameGUI getGameGUI()
return gameGUI;
}

public void setTextLineGUI(JTextField line)
{
textLineGUI=line;
}

public JTextField getTextLineGUI()
{
return textLineGUI;
}

public OutfitDialog getOutfitDialog()
{
// int total_hairs, int total_heads, int total_bodies, int total_clothes) {
Expand Down
4 changes: 3 additions & 1 deletion src/games/stendhal/client/gui/j2DClient.java
Expand Up @@ -162,6 +162,8 @@ public void focusLost(FocusEvent e)
// add a key input system (defined below) to our canvas so we can respond to key pressed
playerChatText.addKeyListener(inGameGUI);

client.setTextLineGUI(playerChatText);

client.setGameLogDialog(new GameLogDialog(this, playerChatText));

addComponentListener(new ComponentAdapter()
Expand Down Expand Up @@ -192,7 +194,7 @@ public void componentShown(ComponentEvent e)
// using the actual main thread to run the game.
gameLoop();
} // constructor

public void gameLoop()
{
long lastLoopTime = System.currentTimeMillis();
Expand Down
158 changes: 158 additions & 0 deletions src/games/stendhal/client/gui/wt/Buddies.java
@@ -0,0 +1,158 @@
/* $Id$ */
/***************************************************************************
* (C) Copyright 2005 - Marauroa *
***************************************************************************
***************************************************************************
* *
* 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. *
* *
***************************************************************************/
/*
* Buddies.java
*
* Created on 19. Oktober 2005, 21:06
*/

package games.stendhal.client.gui.wt;

import games.stendhal.client.*;
import games.stendhal.client.entity.Player;
import games.stendhal.client.gui.j2DClient;
import games.stendhal.client.gui.wt.core.Panel;
import games.stendhal.client.gui.wt.core.TextPanel;
import games.stendhal.client.gui.wt.core.List;

import java.awt.Graphics;
import java.awt.Point;
import java.awt.Color;
import java.util.LinkedList;


import marauroa.common.game.RPObject;
import marauroa.common.game.RPAction;
import marauroa.common.game.RPSlot;

/**
* This is the panel where the character can be outfittet.
*
* @author mtotz
*/
public class Buddies extends Panel
{
/** cached player entity */
private RPSlot playerBuddies;

private Sprite online;
private Sprite offline;

private LinkedList<String> buddies;


/** Creates a new instance of Buddies */
public Buddies(GameObjects gameObjects)
{
super("Buddies", j2DClient.SCREEN_WIDTH-132, 265, 132, 200);
setTitleBar(true);
setFrame(true);
setMoveable(true);
setMinimizeable(true);

SpriteStore st=SpriteStore.get();
online=st.getSprite("data/gui/buddy_online.png");
offline=st.getSprite("data/gui/buddy_offline.png");

buddies=new LinkedList<String>();
}

/** we're using the window manager */
protected boolean useWindowManager()
{
return true;
}

public synchronized boolean onMouseRightClick(Point p)
{
String[] actions={"Talk", "Where", "Remove"};

int i=((int)p.getY()-2)/20-1;
System.out.println (i);

if(i<buddies.size() && i>=0)
{
List list = new List(buddies.get(i),actions,-100,0,100,100)
{
public void onClick(String name, boolean pressed)
{
StendhalClient client = StendhalClient.get();

if(name.equals("Talk"))
{
client.getTextLineGUI().setText("/tell "+getName()+" ");
}
else if(name.equals("Where"))
{
RPAction where = new RPAction();
where.put("type","where");
where.put("target",getName());
client.send(where);
}
else if(name.equals("Remove"))
{
RPAction where = new RPAction();
where.put("type","removebuddy");
where.put("target",getName());
client.send(where);
}
}
};
setContextMenu(list);
}

return true;
}

/** refreshes the player stats and draws them */
public Graphics draw(Graphics g)
{
Graphics clientg = super.draw(g);

int i=0;

RPObject object=StendhalClient.get().getPlayer();
if(object!=null)
{
RPSlot slot=object.getSlot("!buddy");
RPObject buddy=slot.getFirst();

buddies.clear();

for(String key: buddy)
{
if(key.startsWith("_"))
{
buddies.add(key.substring(1));

if(buddy.getInt(key)==0)
{
clientg.setColor(Color.RED);
offline.draw(clientg, 3, 2+i*20);
clientg.drawString(key.substring(1),24, 16+i*20);
}
else
{
clientg.setColor(Color.GREEN);
online.draw(clientg, 3, 2+i*20);
clientg.drawString(key.substring(1),24, 16+i*20);
}

i++;
}
}
}

return clientg;
}
}
7 changes: 6 additions & 1 deletion src/games/stendhal/client/gui/wt/Character.java
Expand Up @@ -131,6 +131,11 @@ private void refreshPlayerStats()
{
String slotName = slot.getName();

if(slotName.equals("!buddy"))
{
continue;
}

EntitySlot entitySlot = slotPanels.get(slotName);
if (entitySlot != null)
{
Expand All @@ -145,7 +150,7 @@ private void refreshPlayerStats()

// count all money
for (RPObject content : slot)
{
{
if (content.get("class").equals("money") && content.has("quantity"))
{
money += content.getInt("quantity");
Expand Down
24 changes: 18 additions & 6 deletions src/games/stendhal/server/actions/Buddy.java
Expand Up @@ -67,8 +67,19 @@ private void onAddBuddy(RPWorld world, StendhalRPRuleProcessor rules, Player pla
slot.assignValidID(listBuddies);
slot.add(listBuddies);
}

listBuddies.put("_"+who,"");

int online=0;

for(Player p: rules.getPlayers())
{
if(p.getName().equals(who))
{
online=1;
break;
}
}

listBuddies.put("_"+who,online);
}

Log4J.finishMethod(logger,"addBuddy");
Expand All @@ -77,7 +88,7 @@ private void onAddBuddy(RPWorld world, StendhalRPRuleProcessor rules, Player pla
private void onRemoveBuddy(RPWorld world, StendhalRPRuleProcessor rules, Player player, RPAction action)
{
Log4J.startMethod(logger,"removeBuddy");

if(action.has("target"))
{
String who="_"+action.get("target");
Expand All @@ -87,10 +98,11 @@ private void onRemoveBuddy(RPWorld world, StendhalRPRuleProcessor rules, Player

if(slot.size()>0)
{
listBuddies=slot.iterator().next();
if(listBuddies.has("_"+who))
listBuddies=slot.getFirst();

if(listBuddies.has(who))
{
listBuddies.remove("_"+who);
listBuddies.remove(who);
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/games/stendhal/server/entity/Player.java
Expand Up @@ -176,6 +176,17 @@ public static Player create(RPObject object)
{
object.addSlot(new RPSlot("bank"));
}

if(object.hasSlot("!buddy"))
{
RPSlot buddy=object.getSlot("!buddy");
if(buddy.size()==0)
{
RPObject data=new RPObject();
buddy.assignValidID(data);
buddy.add(data);
}
}


Player player=new Player(object);
Expand Down

0 comments on commit 165ec23

Please sign in to comment.