Worked on it for 2 days : no success. I can't figure out what broke the templates. Don't think I've seen a template change/code update that broke code quite so effectively in a long time. I am (well ... was) using it with MMO as a really crude way to jump around to different worlds and places within the worlds. The code is not pretty but it did work. Teleport.h is added to the list of <includes> in Main.h in the Client folder of MMO.
Code:
#include "StdAfx.h"
#include "Main.h"
extern Game::ObjMemx<Player> Players;
static JumpBoxElm gm_island_003[]=
{
{"Start", "gmi003_start", 0, 0},
{"End", "gmi003_end", 0, 0},
};
static JumpBoxElm guild_hall_island_001[]=
{
{"Start", "start", 0, 0},
{"End", "ghi001_end", 0, 0},
};
static JumpAreaElm jumpAreaElms[]=
{
{"GM Island", "gm_island_003", 256, 256, gm_island_003, Elms(gm_island_003)},
{"Guild Hall Island 001", "guild_hall_island_001", 256, 256, guild_hall_island_001, Elms(guild_hall_island_001)},
};
Teleport::Teleport(void)
{
isInited = false;
}
Teleport::~Teleport(void)
{
}
Str Teleport::ComboBoxElmFunc(JumpBoxElm &elm)
{
Int area = ar ? (*ar)() : -1;
Int sel = cmb ? (*cmb)() : -1;
if ((area < 0) | (sel < 0))
bJump->disabled(true);
else
bJump->disabled(false);
return S + elm.name;
}
Str Teleport::ComboBoxAreaFunc(JumpAreaElm &elm)
{
Int area = ar ? (*ar)() : -1;
Int sel = cmb ? (*cmb)() : -1;
if (area >= 0 && sel >= 0)
{
C JumpBoxElm *jb = jumpAreaElms[area].jumpBox;
cmb->setData(jb, jumpAreaElms[area].nLocs);
}
if ((area < 0) | (sel < 0))
bJump->disabled(true);
else
bJump->disabled(false);
return S + elm.name;
}
void Teleport::jumpAreaElmChanged(Ptr user)
{
Int area = ar ? (*ar)() : -1;
Int sel = cmb ? (*cmb)() : -1;
//area = area < 0 ? 0 : area;
if (area >= 0 && sel >= 0)
{
C JumpBoxElm *jb = jumpAreaElms[area].jumpBox;
cmb->setData(jb, jumpAreaElms[area].nLocs);
sel = 0;
cmb->set(sel);
}
if ((area < 0) | (sel < 0))
bJump->disabled(true);
else
bJump->disabled(false);
}
void Teleport::bCancelFunc(Ptr user)
{
if (true)
{
gui_jumpbox.hide();
bJump->disabled(true);
}
}
void Teleport::bJumpFunc(Ptr user)
{
Int area = ar ? (*ar)() : -1;
Int sel = cmb ? (*cmb)() : -1;
if ((area < 0) | (sel < 0))
{
// cannot jump if the things are out of range
area = area < 0 ? 0 : area;
sel = sel < 0 ? 0 : sel;
bJump->disabled(true);
return;
}
C JumpBoxElm *jb = jumpAreaElms[area].jumpBox;
Str wp = jb[sel].waypoint;
//need to be sure we have the correct world
C Str wdp = Game::World.worldDir();
Str wd = GetBase(GetExtNot(wdp));
if (wd != jumpAreaElms[area].worldName)
{
// here to load a new world if needed
C Str wn = S + "world/" + jumpAreaElms[area].worldName + ".world";
Net::World *world = Net::Worlds(wn);
Game::Waypoint *waypoint = world->getWaypoint(wp);
if(!waypoint->points.elms())
Exit(S +"No points in starting waypoint in new world:" + wn);
current_world = world;
Flt scale = ChrData.scale;
ChrData.setWorld(world, waypoint->points[0].pos+Vec(0,0.5f*scale,0)); // set world and position
}
Game::Waypoint *waypoint = Game::World.getWaypoint(wp);
if(!waypoint->points.elms())
{
// here if the waypoint is invalid -- some sort of error
Exit(S+"Cannot find waypoint:" + wp + " in world: " + wd);
}
gui_jumpbox.hide();
if (Players.elms())
{
tempSave.writeMem();
Players[0].save(tempSave);
Players.removeValid(0);
newPos.x = waypoint->points[0].pos.x;
newPos.y = waypoint->points[0].pos.y + .5f;
newPos.z = waypoint->points[0].pos.z;
Cam.at = newPos;
Game::World.update(newPos);
Cam.setFromAt(newPos, newPos);
InjectPlayer();
}
}
bool Teleport::Init()
{
static ListColumn lg[] =
{
ListColumn(ComboBoxElmFunc, 0.5f, L"Function"), // make it .5 wide to show the major part of the line in the dropdown box width
};
static ListColumn alg[]=
{
ListColumn(ComboBoxAreaFunc, 0.5f, L"Function"),
};
if (isInited)
return true;
if (gui_jumpbox.load("gui/jump table.gobj"))
{
Gui += gui_jumpbox;
gui_jumpbox.hide();
cmb = &gui_jumpbox.getComboBox("comboJumpList");
ar = &gui_jumpbox.getComboBox("comboAreaList");
bJump = &gui_jumpbox.getButton("btnJump");
bCancel = &gui_jumpbox.getButton("btnCancel");
ar->setColumns(alg, Elms(alg));
ar->setData(jumpAreaElms, Elms(jumpAreaElms));
ar->func(jumpAreaElmChanged);
cmb->setColumns(lg, Elms(lg));
cmb->setData(guild_hall_island_001, Elms(guild_hall_island_001));
bJump->func(bJumpFunc);
bCancel->func(bCancelFunc);
bJump->disabled(true);
isInited = true;
return true;
}
return false;
};
void Teleport::InjectPlayer()
{
tempSave.pos(0);
Game::World.objInject(OBJ_PLAYER, tempSave, &newPos);
tempSave.reset();
};
void Teleport::Update(void)
{
//do the jump box
if (Kb.b(KB_RALT) & Kb.bp(KB_NPDEL))
{
gui_jumpbox.show();
}
}
GuiObjs Teleport::GetJumpbox()
{
return gui_jumpbox;
}
Net::World *Teleport::GetCurrentWorld()
{
return current_world;
}