[Tutorial] Launcher Animation
Hi,
this is a tutorial to get slide on your launcher, enjoy
https://i.gyazo.com/cfabe7697e84cc73...37e2907e88.gif
(This tutorial is made for WarZ alpha source code, works also on V3 source, just some line to find could be different or missing)
Open RSUpdate.sln
Main.cpp
Search :
Code:
static void drawServerStatus(const CUpdater& updater)
Add after this function :
Code:
// Frage: Rotator function [1/13]
static void rotatorCreateTexture(CUpdater::rotator_s& rot)
{
// create rotator texture if we downloaded data
if(rot.imgStatus_ == 2)
{
IDirect3DTexture9* d3dtex = NULL;
HRESULT hr = D3DXCreateTextureFromFileInMemory(
r3dRenderer->pd3ddev,
rot.imgData_.getBytes(),
rot.imgData_.getSize(),
&d3dtex);
if(hr == D3D_OK)
{
rot.tex_ = r3dRenderer->AllocateTexture();
rot.tex_->Create(4, 4, D3DFMT_A8R8G8B8, 1);
rot.tex_->SetNewD3DTexture(d3dtex);
}
else
{
r3dOutToLog("Rotator: failed to create texture from %s\n", rot.image_);
}
rot.imgStatus_ = 3;
}
}
static void drawRotator(CUpdater& updater)
{
static r3dRECT rRotImg = {21, 85, 745, 226};
if(updater.rotatorStatus_ != 1)
return;
if(updater.rotatorData_.size() == 0)
return;
static float TIME_IN_IMAGE = 5.0f;
static float TIME_TO_FADEIN = 1.0f;
static float TIME_TO_SHOW_DESC = 1.0f;
static int rotIdx = -1;
static r3dTexture* prevTex = NULL;
static float imgStartTime = -999;
static float descShowTime = -999;
if(r3dGetTime() > imgStartTime + TIME_IN_IMAGE)
{
// check if next image is loaded
size_t newIdx = (rotIdx + 1) % updater.rotatorData_.size();
if(updater.rotatorData_[newIdx].imgStatus_ == 0)
return;
if(newIdx != rotIdx)
{
rotatorCreateTexture(updater.rotatorData_[newIdx]);
// switch to new image
if(rotIdx >= 0)
prevTex = updater.rotatorData_[rotIdx].tex_;
rotIdx = newIdx;
imgStartTime = r3dGetTime();
}
}
r3d_assert(rotIdx >= 0 && rotIdx < (int)updater.rotatorData_.size());
CUpdater::rotator_s& rot = updater.rotatorData_[rotIdx];
if(rot.tex_ != NULL)
{
if(prevTex)
r3dDrawBox2D(21, 85, 745, 226, r3dColor(255, 255, 255), prevTex);
float a = 255.0f * R3D_MIN(1.0f, (r3dGetTime()-imgStartTime) / TIME_TO_FADEIN);
r3dDrawBox2D(21, 85, 745, 226, r3dColor(255, 255, 255, (int)a), rot.tex_);
}
else
{
r3dDrawBox2D(21, 85, 745, 226, r3dColor(0, 0, 0, 100), NULL);
}
// process click
if(g_mb && insideRect(rRotImg, g_mx, g_my))
{
char token[512];
updater.gUserProfile.CreateAuthToken(token);
char url[1024];
if(strchr(rot.url_.c_str(), '?') == NULL) {
sprintf(url, "%s?WoLogin=%s", rot.url_.c_str(), token);
} else {
sprintf(url, "%s&WoLogin=%s", rot.url_.c_str(), token);
}
ShellExecute(NULL, "open", url, "", NULL, SW_SHOW);
}
// show description
if(insideRect(rRotImg, g_mx, g_my))
{
g_hCursor = gCursorHand;
if(descShowTime < 0)
descShowTime = r3dGetTime();
if(r3dGetTime() > descShowTime + TIME_TO_SHOW_DESC)
{
g_font1->PrintF(25, 89, r3dColor(0, 0, 0), rot.desc_.c_str()); // text
g_font1->PrintF(23, 87, r3dColor(255, 255, 255), rot.desc_.c_str()); // shadow
}
}
else
{
descShowTime = -1;
}
}
Search :
Add after :
Code:
drawRotator(updater); // Frage: Rotator function [2/13]
Updater.cpp
Search :
Add after :
Code:
rotatorThread_= NULL; // Frage: Rotator function [3/13]
rotatorStatus_= 0;
Search :
Code:
InitializeCriticalSection(&csNews_);
Add after :
Code:
InitializeCriticalSection(&csRotator_); // Frage: Rotator function [4/13]
Search :
Code:
r3d_assert(newsThread_ == NULL);
Add after :
Code:
r3d_assert(rotatorThread_ == NULL); // Frage: Rotator function [5/13]
Search :
Code:
void CUpdater::ParseNewsNode(pugi::xml_node xmlNode, std::vector<news_s>& news)
Add after this function :
Code:
// Frage: Rotator function [6/13]
void CUpdater::ParseRotatorNode(pugi::xml_node xmlNode, std::vector<rotator_s>& rotator)
{
rotator.clear();
xmlNode = xmlNode.first_child();
while(!xmlNode.empty())
{
rotator_s n;
n.imgStatus_ = 0;
n.tex_ = NULL;
n.url_ = xmlNode.attribute("url").value();
n.desc_ = xmlNode.attribute("desc").value();
n.image_ = xmlNode.attribute("image").value();
rotator.push_back(n);
xmlNode = xmlNode.next_sibling();
}
return;
}
Search :
Code:
ParseNewsNode(xmlInfo.child("news"), newsData_);
Add after :
Code:
// Frage: Rotator function [7/13]
if(rotatorStatus_ == 0) // download rotator data only once
{
ParseRotatorNode(xmlInfo.child("rotator"), rotatorData_);
rotatorStatus_ = 1;
// and start picture download thread for rotator
rotatorThread_ = (HANDLE)_beginthreadex(
NULL,
0,
&CUpdater_RotatorThreadEntry,
(void *)this, // argument
0, // creation flags
NULL // thread ID
);
}
Search :
Code:
void CUpdater::NewsThreadEntry()
Add after this function :
Code:
// Frage: Rotator function [8/13]
void CUpdater::RotatorThreadEntry()
{
try
{
for(size_t i=0; i<rotatorData_.size(); i++)
{
rotator_s& r = rotatorData_[i];
const char* url = r.image_.c_str();
HttpDownload http;
if(!http.Get(url, r.imgData_)) {
// failed to download image there
r3dOutToLog("Rotator: failed to download %s\n", url);
r.imgStatus_ = 1;
continue;
}
//r3dOutToLog("Rotator: got %s\n", url);
r.imgStatus_ = 2;
}
return;
}
catch(...)
{
MessageBox(NULL, "something wrong happened in rotator", "", MB_OK);
}
return;
}
Search :
Code:
static unsigned int __stdcall CUpdater_NewsThreadEntry(LPVOID in)
Add after this function :
Code:
// Frage: Rotator function [9/13]
static unsigned int __stdcall CUpdater_RotatorThreadEntry(LPVOID in)
{
CUpdater* impl = (CUpdater*)in;
impl->RotatorThreadEntry();
return 0;
}
Search :
Code:
StopThread(newsThread_);
Add after :
Code:
StopThread(rotatorThread_); // Frage: Rotator function [10/13]
Updater.h
Search :
Code:
std::string surveyLinkOut_;
Add after :
Code:
// Frage: Rotator function [11/13]
struct rotator_s {
std::string url_;
std::string desc_;
std::string image_;
volatile DWORD imgStatus_;
CkByteData imgData_;
r3dTexture* tex_;
};
std::vector<rotator_s> rotatorData_;
volatile DWORD rotatorStatus_;
CRITICAL_SECTION csRotator_;
Search :
Code:
void ParseNewsNode(pugi::xml_node xmlNode, std::vector<news_s>& news);
Add after this function :
Code:
void ParseRotatorNode(pugi::xml_node xmlNode, std::vector<rotator_s>& rotator); // Frage: Rotator function [12/13]
Search :
Code:
HANDLE newsThread_;
Add after :
Code:
// Frage: Rotator function [13/13]
friend static unsigned int __stdcall CUpdater_RotatorThreadEntry(LPVOID in);
void RotatorThreadEntry();
HANDLE rotatorThread_;
api_getserverinfo.xml
Make the number of rotator line as you wish, this is mine for an example.
Code:
<info>
<news>
<news name="This is a news for the launcher, Frage Production ! 1" date="99.99.9999" url="http://forum.ragezone.com/members/2000206218.html"/>
<news name="This is a news for the launcher, Frage Production ! 2" date="99.99.9999" url="http://forum.ragezone.com/members/2000206218.html"/>
<news name="This is a news for the launcher, Frage Production ! 3" date="99.99.9999" url="http://forum.ragezone.com/members/2000206218.html"/>
<news name="This is a news for the launcher, Frage Production ! 3" date="99.99.9999" url="http://forum.ragezone.com/members/2000206218.html"/>
<news name="This is a news for the launcher, Frage Production ! 4" date="99.99.9999" url="http://forum.ragezone.com/members/2000206218.html"/>
</news>
<rotator>
<rotator url="https://www.google.com/" desc="Description" image="http://192.168.1.2/wz/rotator_img_1.png"/>
<rotator url="https://www.google.com/" desc="Description" image="http://192.168.1.2/wz/rotator_img_2.png"/>
</rotator>
<SurveyIn link="" />
<SurveyOut link="" />
<ServerInfo status="ONLINE" />
</info>
Their is two images for you to test if you want.
https://mega.nz/#!fAVU2QpT!v2ueE6pNo...wT_EBpdonZDRZ4
Crédit : FrageDev and WarInc devs
Re: [Tutorial] Launcher Animation
is not work :)
- - - Updated - - -
not work for all function is error 35 - 40 error :)
please check for static and void function :(
Re: [Tutorial] Launcher Animation
Quote:
Originally Posted by
Returnerzx
is not work :)
- - - Updated - - -
not work for all function is error 35 - 40 error :)
please check for static and void function :(
Well don't say "is not work" when I already test it on my launcher, so it works, maybe I made one mistake on the tutorial but I don't find it.
Can someone told me if this tutorial works or if I missed one character, or step, or idk ?
Re: [Tutorial] Launcher Animation
Quote:
Originally Posted by
FrageDev
Well don't say "is not work" when I already test it on my launcher, so it works, maybe I made one mistake on the tutorial but I don't find it.
Can someone told me if this tutorial works or if I missed one character, or step, or idk ?
Nice tutorial nice to see others actually do something unique with launcher you could always just test your tutorial on a non-edited launcher see if you get any error or not.
Re: [Tutorial] Launcher Animation
Main Post updated. Some lines was missing for no reason. I code on a VM, copy pasta didn't work well.
I don't even know how "copy pasta" my own code -_- feelsbad
Re: [Tutorial] Launcher Animation
can fix image quantity loss?
Re: [Tutorial] Launcher Animation
Quote:
Originally Posted by
zetoris
can fix image quantity loss?
No, that is scientifically, and logically impossible to do. :/
Re: [Tutorial] Launcher Animation
Thanks, i using and working, very good FrageDev.
I'm glad to know it works and I'm using it for something.
https://www.youtube.com/watch?v=AjkUnGh_7mI