package net.nova.habbo.catalog;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import net.nova.core.NovaEnvironment;
import net.nova.habbo.message.ISerializableObject;
import net.nova.habbo.message.ServerMessage;
import net.verticode.hailstorm.storage.StorageQuery;
public class CatalogPage implements ISerializableObject {
private int mID, mParent, mTree;
private boolean mVisible, mComingSoon;
private int mIconColor, mIconImage;
private String mName, mLayout
;
private Vector<CatalogHeader> mHeaders;
private Vector<CatalogWidget> mWidgets;
private int mCatagorie;
public CatalogPage
(int ID,
int Parent,
int Tree,
int Visible,
int ComingSoon,
String Name,
int IconColor,
int IconImage,
String Layout,
int Catagorie
)
{
if (Catagorie == 1)
ID = -1;
mCatagorie = Catagorie;
mID = ID;
mParent = Parent;
mTree = Tree;
mVisible = (Visible == 1);
mComingSoon = (ComingSoon == 1);
mIconColor = IconColor;
mIconImage = IconImage;
mLayout = Layout;
mHeaders = new Vector<CatalogHeader>();
StorageQuery Query = new StorageQuery("SELECT * FROM catalog_headers WHERE page = ? ORDER BY sort ASC;");
Query.addParam(mID);
try
{
while (Result.next())
{
mHeaders.add(new CatalogHeader(Result.getInt("type"), Result.getString("object")));
}
}
{
NovaEnvironment.GetLog().WriteError(e.getMessage());
}
mWidgets = new Vector<CatalogWidget>();
Query = new StorageQuery("SELECT * FROM catalog_widgets WHERE page = ? ORDER BY sort ASC;");
Query.addParam(mID);
Result = Query.getResult();
try
{
while (Result.next())
{
mWidgets.add(new CatalogWidget(Result.getInt("type"), Result.getString("content")));
}
}
{
NovaEnvironment.GetLog().WriteError(e.getMessage());
}
}
@Override
public void Serialize(ServerMessage message)
{
message.AppendInt(mID);
message.AppendString(mLayout);
//message.AppendInt(mHeaders.size());
for (CatalogHeader Header : mHeaders)
message.AppendObject(Header);
message.AppendInt(mWidgets.size());
for (CatalogWidget Widget : mWidgets)
message.AppendObject(Widget);
message.AppendInt(0); //TODO ITEM COUNT
}
class CatalogHeader implements ISerializableObject
{
private int mType;
public CatalogHeader
(int Type,
String Header
)
{
mType = Type;
mHeader = Header;
}
@Override
public void Serialize(ServerMessage message)
{
switch(mType)
{
case 0:
message.AppendString(mHeader);
break;
case 1:
message.
AppendInt(Integer.
parseInt(mHeader
));
break;
}
}
}
class CatalogWidget implements ISerializableObject
{
private int mType;
public CatalogWidget
(int type,
String content
)
{
mType = type;
mContent = content;
}
@Override
public void Serialize(ServerMessage message)
{
switch(mType)
{
case 0:
message.AppendString(mContent);
break;
case 1:
message.
AppendInt(Integer.
parseInt(mContent
));
break;
}
}
}
/**
* @param mID the mID to set
*/
public void setID(int mID) {
this.mID = mID;
}
/**
* @return the mID
*/
public int getID() {
return mID;
}
/**
* @param mParent the mParent to set
*/
public void setParent(int mParent) {
this.mParent = mParent;
}
/**
* @return the mParent
*/
public int getParent() {
return mParent;
}
/**
* @param mTree the mTree to set
*/
public void setTree(int mTree) {
this.mTree = mTree;
}
/**
* @return the mTree
*/
public int getTree() {
return mTree;
}
/**
* @param mVisible the mVisible to set
*/
public void setVisible(boolean mVisible) {
this.mVisible = mVisible;
}
/**
* @return the mVisible
*/
public boolean isVisible() {
return mVisible;
}
/**
* @param mComingSoon the mComingSoon to set
*/
public void setComingSoon(boolean mComingSoon) {
this.mComingSoon = mComingSoon;
}
/**
* @return the mComingSoon
*/
public boolean isComingSoon() {
return mComingSoon;
}
/**
* @param mIconColor the mIconColor to set
*/
public void setIconColor(byte mIconColor) {
this.mIconColor = mIconColor;
}
/**
* @return the mIconColor
*/
public int getIconColor() {
return mIconColor;
}
/**
* @param mIconImage the mIconImage to set
*/
public void setIconImage(byte mIconImage) {
this.mIconImage = mIconImage;
}
/**
* @return the mIconImage
*/
public int getIconImage() {
return mIconImage;
}
/**
* @param mName the mName to set
*/
public void setName
(String mName
) {
this.mName = mName;
}
/**
* @return the mName
*/
return mName;
}
public boolean isCatagorie() {
return (mCatagorie == 1);
}
}