Commit 725ad5cb authored by wind2009's avatar wind2009

Merge commit 'e84e059b'

parents ee1fdf5b e84e059b
Pipeline #33738 passed with stages
in 9 minutes and 35 seconds
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef __C_GUI_BUTTON_H_INCLUDED__
#define __C_GUI_BUTTON_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_GUI_
#include "IGUIButton.h"
#include "IGUISpriteBank.h"
#include "SColor.h"
namespace irr
{
namespace gui
{
class CGUIButton : public IGUIButton
{
public:
//! constructor
CGUIButton(IGUIEnvironment* environment, IGUIElement* parent,
s32 id, core::rect<s32> rectangle, bool noclip=false);
//! destructor
virtual ~CGUIButton();
//! called if an event happened.
virtual bool OnEvent(const SEvent& event);
//! draws the element and its children
virtual void draw();
//! sets another skin independent font. if this is set to zero, the button uses the font of the skin.
virtual void setOverrideFont(IGUIFont* font=0);
//! Gets the override font (if any)
virtual IGUIFont* getOverrideFont() const;
//! Get the font which is used right now for drawing
virtual IGUIFont* getActiveFont() const;
//! Sets an image which should be displayed on the button when it is in normal state.
virtual void setImage(video::ITexture* image=0);
//! Sets an image which should be displayed on the button when it is in normal state.
virtual void setImage(video::ITexture* image, const core::rect<s32>& pos);
//! Sets an image which should be displayed on the button when it is in pressed state.
virtual void setPressedImage(video::ITexture* image=0);
//! Sets an image which should be displayed on the button when it is in pressed state.
virtual void setPressedImage(video::ITexture* image, const core::rect<s32>& pos);
//! Sets the sprite bank used by the button
virtual void setSpriteBank(IGUISpriteBank* bank=0);
//! Sets the animated sprite for a specific button state
/** \param index: Number of the sprite within the sprite bank, use -1 for no sprite
\param state: State of the button to set the sprite for
\param index: The sprite number from the current sprite bank
\param color: The color of the sprite
*/
virtual void setSprite(EGUI_BUTTON_STATE state, s32 index,
video::SColor color=video::SColor(255,255,255,255), bool loop=false);
//! Sets if the button should behave like a push button. Which means it
//! can be in two states: Normal or Pressed. With a click on the button,
//! the user can change the state of the button.
virtual void setIsPushButton(bool isPushButton=true);
//! Checks whether the button is a push button
virtual bool isPushButton() const;
//! Sets the pressed state of the button if this is a pushbutton
virtual void setPressed(bool pressed=true);
//! Returns if the button is currently pressed
virtual bool isPressed() const;
//! Sets if the button should use the skin to draw its border
virtual void setDrawBorder(bool border=true);
//! Checks if the button face and border are being drawn
virtual bool isDrawingBorder() const;
//! Sets if the alpha channel should be used for drawing images on the button (default is false)
virtual void setUseAlphaChannel(bool useAlphaChannel=true);
//! Checks if the alpha channel should be used for drawing images on the button
virtual bool isAlphaChannelUsed() const;
//! Sets if the button should scale the button images to fit
virtual void setScaleImage(bool scaleImage=true);
//! Checks whether the button scales the used images
virtual bool isScalingImage() const;
//! Writes attributes of the element.
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const;
//! Reads attributes of the element
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options);
protected:
struct ButtonSprite
{
s32 Index;
video::SColor Color;
bool Loop;
};
ButtonSprite ButtonSprites[EGBS_COUNT];
IGUISpriteBank* SpriteBank;
IGUIFont* OverrideFont;
video::ITexture* Image;
video::ITexture* PressedImage;
core::rect<s32> ImageRect;
core::rect<s32> PressedImageRect;
u32 ClickTime, HoverTime, FocusTime;
bool IsPushButton;
bool Pressed;
bool UseAlphaChannel;
bool DrawBorder;
bool ScaleImage;
};
} // end namespace gui
} // end namespace irr
#endif // _IRR_COMPILE_WITH_GUI_
#endif // __C_GUI_BUTTON_H_INCLUDED__
This diff is collapsed.
// Copyright (C) 2002-2012 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#ifndef _C_GUI_IMAGE_BUTTON_H_ #ifndef _C_GUI_IMAGE_BUTTON_H_
#define _C_GUI_IMAGE_BUTTON_H_ #define _C_GUI_IMAGE_BUTTON_H_
#include <irrlicht.h> #include <IrrCompileConfig.h>
#include "CGUIButton.h" #ifdef _IRR_COMPILE_WITH_GUI_
#include <IGUIButton.h>
#include <SColor.h>
namespace irr { namespace irr {
namespace video {
class IVideoDriver;
class ITexture;
}
namespace gui { namespace gui {
class IGUISpriteBank;
void Draw2DImageRotation(video::IVideoDriver* driver, video::ITexture* image, core::rect<s32> sourceRect, void Draw2DImageRotation(video::IVideoDriver* driver, video::ITexture* image, core::rect<s32> sourceRect,
core::position2d<s32> position, core::position2d<s32> rotationPoint, f32 rotation = 0.0f, core::vector2d<s32> position, core::vector2d<s32> rotationPoint, f32 rotation = 0.0f,
core::vector2df scale = core::vector2df(1.0, 1.0), bool useAlphaChannel = true, video::SColor color = 0xffffffff); core::vector2df scale = core::vector2df(1.0, 1.0), bool useAlphaChannel = true, video::SColor color = 0xffffffff);
void Draw2DImageQuad(video::IVideoDriver* driver, video::ITexture* image, core::rect<s32> sourceRect, void Draw2DImageQuad(video::IVideoDriver* driver, video::ITexture* image, core::rect<s32> sourceRect,
core::position2d<s32> corner[4], bool useAlphaChannel = true, video::SColor color = 0xffffffff); core::vector2d<s32> corner[4], bool useAlphaChannel = true, video::SColor color = 0xffffffff);
class CGUIImageButton : public CGUIButton {
class CGUIImageButton : public IGUIButton {
public: public:
CGUIImageButton(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle); static CGUIImageButton* addImageButton(IGUIEnvironment* env, const core::rect<s32>& rectangle, IGUIElement* parent, s32 id);
static CGUIImageButton* addImageButton(IGUIEnvironment *env, const core::rect<s32>& rectangle, IGUIElement* parent, s32 id);
virtual void draw(); //! constructor
virtual void setImage(video::ITexture* image = 0); CGUIImageButton(IGUIEnvironment* environment, IGUIElement* parent,
virtual void setDrawImage(bool b); s32 id, core::rect<s32> rectangle, bool noclip = false);
virtual void setImageRotation(f32 r);
virtual void setImageScale(core::vector2df s); //! destructor
virtual void setImageSize(core::dimension2di s); ~CGUIImageButton() override;
virtual IGUIFont* getOverrideFont(void) const;
virtual IGUIFont* getActiveFont() const; //! called if an event happened.
bool OnEvent(const SEvent& event) override;
private:
//! draws the element and its children
void draw() override;
//! sets another skin independent font. if this is set to zero, the button uses the font of the skin.
void setOverrideFont(IGUIFont* font = 0) override;
//! Gets the override font (if any)
IGUIFont* getOverrideFont() const override;
//! Get the font which is used right now for drawing
IGUIFont* getActiveFont() const override;
//! Sets an image which should be displayed on the button when it is in normal state.
void setImage(video::ITexture* image = 0) override;
//! Sets an image which should be displayed on the button when it is in normal state.
void setImage(video::ITexture* image, const core::rect<s32>& pos) override;
//! Sets an image which should be displayed on the button when it is in pressed state.
void setPressedImage(video::ITexture* image = 0) override;
//! Sets an image which should be displayed on the button when it is in pressed state.
void setPressedImage(video::ITexture* image, const core::rect<s32>& pos) override;
//! Sets the sprite bank used by the button
void setSpriteBank(IGUISpriteBank* bank = 0) override;
//! Sets the animated sprite for a specific button state
/** \param index: Number of the sprite within the sprite bank, use -1 for no sprite
\param state: State of the button to set the sprite for
\param index: The sprite number from the current sprite bank
\param color: The color of the sprite
*/
void setSprite(EGUI_BUTTON_STATE state, s32 index,
video::SColor color = video::SColor(255, 255, 255, 255), bool loop = false) override;
//! Sets if the button should behave like a push button. Which means it
//! can be in two states: Normal or Pressed. With a click on the button,
//! the user can change the state of the button.
void setIsPushButton(bool isPushButton = true) override;
//! Checks whether the button is a push button
bool isPushButton() const override;
//! Sets the pressed state of the button if this is a pushbutton
void setPressed(bool pressed = true) override;
//! Returns if the button is currently pressed
bool isPressed() const override;
//! Sets if the button should use the skin to draw its border
void setDrawBorder(bool border = true) override;
//! Checks if the button face and border are being drawn
bool isDrawingBorder() const override;
//! Sets if the alpha channel should be used for drawing images on the button (default is false)
void setUseAlphaChannel(bool useAlphaChannel = true) override;
//! Checks if the alpha channel should be used for drawing images on the button
bool isAlphaChannelUsed() const override;
//! Sets if the button should scale the button images to fit
void setScaleImage(bool scaleImage = true) override;
//! Checks whether the button scales the used images
bool isScalingImage() const override;
//! Writes attributes of the element.
void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const override;
//! Reads attributes of the element
void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) override;
// from ygopro
void setDrawImage(bool b);
void setImageRotation(f32 r);
void setImageScale(core::vector2df s);
void setImageSize(core::dimension2di s);
protected:
struct ButtonSprite
{
s32 Index;
video::SColor Color;
bool Loop;
};
ButtonSprite ButtonSprites[EGBS_COUNT];
IGUISpriteBank* SpriteBank;
IGUIFont* OverrideFont;
video::ITexture* Image;
video::ITexture* PressedImage;
core::rect<s32> ImageRect;
core::rect<s32> PressedImageRect;
bool IsPushButton;
bool Pressed;
bool UseAlphaChannel;
bool DrawBorder;
bool ScaleImage;
// from ygopro
bool isDrawImage; bool isDrawImage;
bool isFixedSize; bool isFixedSize;
f32 imageRotation; f32 imageRotation;
...@@ -36,4 +155,6 @@ private: ...@@ -36,4 +155,6 @@ private:
} }
} }
#endif // _IRR_COMPILE_WITH_GUI_
#endif //_C_GUI_IMAGE_BUTTON_H_ #endif //_C_GUI_IMAGE_BUTTON_H_
...@@ -505,7 +505,7 @@ void CGUITTFont::drawUstring(const core::ustring& utext, const core::rect<s32>&p ...@@ -505,7 +505,7 @@ void CGUITTFont::drawUstring(const core::ustring& utext, const core::rect<s32>&p
// Set up some variables. // Set up some variables.
core::dimension2d<s32> textDimension; core::dimension2d<s32> textDimension;
core::position2d<s32> offset = position.UpperLeftCorner; core::vector2d<s32> offset = position.UpperLeftCorner;
// Determine offset positions. // Determine offset positions.
if (hcenter || vcenter) { if (hcenter || vcenter) {
...@@ -561,7 +561,7 @@ void CGUITTFont::drawUstring(const core::ustring& utext, const core::rect<s32>&p ...@@ -561,7 +561,7 @@ void CGUITTFont::drawUstring(const core::ustring& utext, const core::rect<s32>&p
// Determine rendering information. // Determine rendering information.
SGUITTGlyph& glyph = Glyphs[n - 1]; SGUITTGlyph& glyph = Glyphs[n - 1];
CGUITTGlyphPage* const page = Glyph_Pages[glyph.glyph_page]; CGUITTGlyphPage* const page = Glyph_Pages[glyph.glyph_page];
page->render_positions.push_back(core::position2di(offset.X + offx, offset.Y + offy)); page->render_positions.push_back(irr::core::vector2di(offset.X + offx, offset.Y + offy));
page->render_source_rects.push_back(glyph.source_rect); page->render_source_rects.push_back(glyph.source_rect);
Render_Map.set(glyph.glyph_page, page); Render_Map.set(glyph.glyph_page, page);
} }
...@@ -832,7 +832,7 @@ video::IImage* CGUITTFont::createTextureFromChar(const uchar32_t& ch) { ...@@ -832,7 +832,7 @@ video::IImage* CGUITTFont::createTextureFromChar(const uchar32_t& ch) {
// Copy the image data out of the page texture. // Copy the image data out of the page texture.
core::dimension2du glyph_size(glyph.source_rect.getSize()); core::dimension2du glyph_size(glyph.source_rect.getSize());
video::IImage* image = Driver->createImage(format, glyph_size); video::IImage* image = Driver->createImage(format, glyph_size);
pageholder->copyTo(image, core::position2di(0, 0), glyph.source_rect); pageholder->copyTo(image, irr::core::vector2di(0, 0), glyph.source_rect);
tex->unlock(); tex->unlock();
return image; return image;
...@@ -854,17 +854,14 @@ void CGUITTFont::createSharedPlane() { ...@@ -854,17 +854,14 @@ void CGUITTFont::createSharedPlane() {
0---1 0---1
*/ */
using namespace core; video::S3DVertex vertices[4];
using namespace video;
using namespace scene;
S3DVertex vertices[4];
u16 indices[6] = {0, 2, 3, 3, 1, 0}; u16 indices[6] = {0, 2, 3, 3, 1, 0};
vertices[0] = S3DVertex(vector3df(0, -1, 0), vector3df(0, 0, -1), SColor(255, 255, 255, 255), vector2df(0, 1)); vertices[0] = video::S3DVertex(core::vector3df(0, -1, 0), core::vector3df(0, 0, -1), video::SColor(255, 255, 255, 255), core::vector2df(0, 1));
vertices[1] = S3DVertex(vector3df(1, -1, 0), vector3df(0, 0, -1), SColor(255, 255, 255, 255), vector2df(1, 1)); vertices[1] = video::S3DVertex(core::vector3df(1, -1, 0), core::vector3df(0, 0, -1), video::SColor(255, 255, 255, 255), core::vector2df(1, 1));
vertices[2] = S3DVertex(vector3df(0, 0, 0), vector3df(0, 0, -1), SColor(255, 255, 255, 255), vector2df(0, 0)); vertices[2] = video::S3DVertex(core::vector3df(0, 0, 0), core::vector3df(0, 0, -1), video::SColor(255, 255, 255, 255), core::vector2df(0, 0));
vertices[3] = S3DVertex(vector3df(1, 0, 0), vector3df(0, 0, -1), SColor(255, 255, 255, 255), vector2df(1, 0)); vertices[3] = video::S3DVertex(core::vector3df(1, 0, 0), core::vector3df(0, 0, -1), video::SColor(255, 255, 255, 255), core::vector2df(1, 0));
SMeshBuffer* buf = new SMeshBuffer(); scene::SMeshBuffer* buf = new scene::SMeshBuffer();
buf->append(vertices, 4, indices, 6); buf->append(vertices, 4, indices, 6);
shared_plane_.addMeshBuffer( buf ); shared_plane_.addMeshBuffer( buf );
...@@ -882,11 +879,7 @@ core::dimension2d<u32> CGUITTFont::getDimensionUntilEndOfLine(const wchar_t* p) ...@@ -882,11 +879,7 @@ core::dimension2d<u32> CGUITTFont::getDimensionUntilEndOfLine(const wchar_t* p)
} }
core::array<scene::ISceneNode*> CGUITTFont::addTextSceneNode(const wchar_t* text, scene::ISceneManager* smgr, scene::ISceneNode* parent, const video::SColor& color, bool center) { core::array<scene::ISceneNode*> CGUITTFont::addTextSceneNode(const wchar_t* text, scene::ISceneManager* smgr, scene::ISceneNode* parent, const video::SColor& color, bool center) {
using namespace core; core::array<scene::ISceneNode*> container;
using namespace video;
using namespace scene;
array<scene::ISceneNode*> container;
if (!Driver || !smgr) return container; if (!Driver || !smgr) return container;
if (!parent) if (!parent)
...@@ -897,8 +890,8 @@ core::array<scene::ISceneNode*> CGUITTFont::addTextSceneNode(const wchar_t* text ...@@ -897,8 +890,8 @@ core::array<scene::ISceneNode*> CGUITTFont::addTextSceneNode(const wchar_t* text
if (!shared_plane_ptr_) //this points to a static mesh that contains the plane if (!shared_plane_ptr_) //this points to a static mesh that contains the plane
createSharedPlane(); //if it's not initialized, we create one. createSharedPlane(); //if it's not initialized, we create one.
dimension2d<s32> text_size(getDimension(text)); //convert from unsigned to signed. core::dimension2d<s32> text_size(getDimension(text)); //convert from unsigned to signed.
vector3df start_point(0, 0, 0), offset; core::vector3df start_point(0, 0, 0), offset;
/** NOTICE: /** NOTICE:
Because we are considering adding texts into 3D world, all Y axis vectors are inverted. Because we are considering adding texts into 3D world, all Y axis vectors are inverted.
...@@ -912,7 +905,7 @@ core::array<scene::ISceneNode*> CGUITTFont::addTextSceneNode(const wchar_t* text ...@@ -912,7 +905,7 @@ core::array<scene::ISceneNode*> CGUITTFont::addTextSceneNode(const wchar_t* text
} }
// the default font material // the default font material
SMaterial mat; video::SMaterial mat;
mat.setFlag(video::EMF_LIGHTING, true); mat.setFlag(video::EMF_LIGHTING, true);
mat.setFlag(video::EMF_ZWRITE_ENABLE, false); mat.setFlag(video::EMF_ZWRITE_ENABLE, false);
mat.setFlag(video::EMF_NORMALIZE_NORMALS, true); mat.setFlag(video::EMF_NORMALIZE_NORMALS, true);
...@@ -924,7 +917,7 @@ core::array<scene::ISceneNode*> CGUITTFont::addTextSceneNode(const wchar_t* text ...@@ -924,7 +917,7 @@ core::array<scene::ISceneNode*> CGUITTFont::addTextSceneNode(const wchar_t* text
wchar_t current_char = 0, previous_char = 0; wchar_t current_char = 0, previous_char = 0;
u32 n = 0; u32 n = 0;
array<u32> glyph_indices; core::array<u32> glyph_indices;
while (*text) { while (*text) {
current_char = *text; current_char = *text;
...@@ -957,23 +950,23 @@ core::array<scene::ISceneNode*> CGUITTFont::addTextSceneNode(const wchar_t* text ...@@ -957,23 +950,23 @@ core::array<scene::ISceneNode*> CGUITTFont::addTextSceneNode(const wchar_t* text
s32 offy = (font_metrics.ascender / 64) - glyph.offset.Y; s32 offy = (font_metrics.ascender / 64) - glyph.offset.Y;
// Apply kerning. // Apply kerning.
vector2di k = getKerning(current_char, previous_char); core::vector2di k = getKerning(current_char, previous_char);
offset.X += k.X; offset.X += k.X;
offset.Y += k.Y; offset.Y += k.Y;
vector3df current_pos(offset.X + offx, offset.Y - offy, 0); core::vector3df current_pos(offset.X + offx, offset.Y - offy, 0);
dimension2d<u32> letter_size = dimension2d<u32>(texw, texh); core::dimension2d<u32> letter_size = core::dimension2d<u32>(texw, texh);
// Now we copy planes corresponding to the letter size. // Now we copy planes corresponding to the letter size.
IMeshManipulator* mani = smgr->getMeshManipulator(); scene::IMeshManipulator* mani = smgr->getMeshManipulator();
IMesh* meshcopy = mani->createMeshCopy(shared_plane_ptr_); scene::IMesh* meshcopy = mani->createMeshCopy(shared_plane_ptr_);
mani->scale(meshcopy, vector3df((f32)letter_size.Width, (f32)letter_size.Height, 1)); mani->scale(meshcopy, core::vector3df((f32)letter_size.Width, (f32)letter_size.Height, 1));
ISceneNode* current_node = smgr->addMeshSceneNode(meshcopy, parent, -1, current_pos); scene::ISceneNode* current_node = smgr->addMeshSceneNode(meshcopy, parent, -1, current_pos);
meshcopy->drop(); meshcopy->drop();
current_node->getMaterial(0) = mat; current_node->getMaterial(0) = mat;
current_node->setAutomaticCulling(EAC_OFF); current_node->setAutomaticCulling(scene::EAC_OFF);
current_node->setIsDebugObject(true); //so the picking won't have any effect on individual letter current_node->setIsDebugObject(true); //so the picking won't have any effect on individual letter
//current_node->setDebugDataVisible(EDS_BBOX); //de-comment this when debugging //current_node->setDebugDataVisible(EDS_BBOX); //de-comment this when debugging
...@@ -991,7 +984,7 @@ core::array<scene::ISceneNode*> CGUITTFont::addTextSceneNode(const wchar_t* text ...@@ -991,7 +984,7 @@ core::array<scene::ISceneNode*> CGUITTFont::addTextSceneNode(const wchar_t* text
for (u32 i = 0; i < glyph_indices.size(); ++i) { for (u32 i = 0; i < glyph_indices.size(); ++i) {
u32 n = glyph_indices[i]; u32 n = glyph_indices[i];
SGUITTGlyph const& glyph = Glyphs[n - 1]; SGUITTGlyph const& glyph = Glyphs[n - 1];
ITexture* current_tex = Glyph_Pages[glyph.glyph_page]->texture; video::ITexture* current_tex = Glyph_Pages[glyph.glyph_page]->texture;
f32 page_texture_size = (f32)current_tex->getSize().Width; f32 page_texture_size = (f32)current_tex->getSize().Width;
//Now we calculate the UV position according to the texture size and the source rect. //Now we calculate the UV position according to the texture size and the source rect.
// //
...@@ -1007,15 +1000,15 @@ core::array<scene::ISceneNode*> CGUITTFont::addTextSceneNode(const wchar_t* text ...@@ -1007,15 +1000,15 @@ core::array<scene::ISceneNode*> CGUITTFont::addTextSceneNode(const wchar_t* text
f32 v2 = v1 + (glyph.source_rect.getHeight() / page_texture_size); f32 v2 = v1 + (glyph.source_rect.getHeight() / page_texture_size);
//we can be quite sure that this is IMeshSceneNode, because we just added them in the above loop. //we can be quite sure that this is IMeshSceneNode, because we just added them in the above loop.
IMeshSceneNode* node = static_cast<IMeshSceneNode*>(container[i]); scene::IMeshSceneNode* node = static_cast<scene::IMeshSceneNode*>(container[i]);
S3DVertex* pv = static_cast<S3DVertex*>(node->getMesh()->getMeshBuffer(0)->getVertices()); video::S3DVertex* pv = static_cast<video::S3DVertex*>(node->getMesh()->getMeshBuffer(0)->getVertices());
//pv[0].TCoords.Y = pv[1].TCoords.Y = (letter_size.Height - 1) / static_cast<f32>(letter_size.Height); //pv[0].TCoords.Y = pv[1].TCoords.Y = (letter_size.Height - 1) / static_cast<f32>(letter_size.Height);
//pv[1].TCoords.X = pv[3].TCoords.X = (letter_size.Width - 1) / static_cast<f32>(letter_size.Width); //pv[1].TCoords.X = pv[3].TCoords.X = (letter_size.Width - 1) / static_cast<f32>(letter_size.Width);
pv[0].TCoords = vector2df(u1, v2); pv[0].TCoords = core::vector2df(u1, v2);
pv[1].TCoords = vector2df(u2, v2); pv[1].TCoords = core::vector2df(u2, v2);
pv[2].TCoords = vector2df(u1, v1); pv[2].TCoords = core::vector2df(u1, v1);
pv[3].TCoords = vector2df(u2, v1); pv[3].TCoords = core::vector2df(u2, v1);
container[i]->getMaterial(0).setTexture(0, current_tex); container[i]->getMaterial(0).setTexture(0, current_tex);
} }
......
...@@ -56,7 +56,7 @@ void ClientCard::UpdateInfo(unsigned char* buf) { ...@@ -56,7 +56,7 @@ void ClientCard::UpdateInfo(unsigned char* buf) {
} }
if(flag & QUERY_POSITION) { if(flag & QUERY_POSITION) {
int pdata = (BufferIO::ReadInt32(buf) >> 24) & 0xff; int pdata = (BufferIO::ReadInt32(buf) >> 24) & 0xff;
if((location & (LOCATION_EXTRA | LOCATION_REMOVED)) && (u8)pdata != position) { if((location & (LOCATION_EXTRA | LOCATION_REMOVED)) && pdata != position) {
position = pdata; position = pdata;
mainGame->dField.MoveCard(this, 1); mainGame->dField.MoveCard(this, 1);
} else } else
......
...@@ -15,9 +15,9 @@ public: ...@@ -15,9 +15,9 @@ public:
irr::core::vector3df curRot; irr::core::vector3df curRot;
irr::core::vector3df dPos; irr::core::vector3df dPos;
irr::core::vector3df dRot; irr::core::vector3df dRot;
u32 curAlpha{ 255 }; irr::u32 curAlpha{ 255 };
u32 dAlpha{ 0 }; irr::u32 dAlpha{ 0 };
u32 aniFrame{ 0 }; irr::u32 aniFrame{ 0 };
bool is_moving{ false }; bool is_moving{ false };
bool is_fading{ false }; bool is_fading{ false };
bool is_hovered{ false }; bool is_hovered{ false };
......
...@@ -143,6 +143,16 @@ void ClientField::Initial(int player, int deckc, int extrac) { ...@@ -143,6 +143,16 @@ void ClientField::Initial(int player, int deckc, int extrac) {
GetCardLocation(pcard, &pcard->curPos, &pcard->curRot, true); GetCardLocation(pcard, &pcard->curPos, &pcard->curRot, true);
} }
} }
void ClientField::ResetSequence(std::vector<ClientCard*>& list, bool reset_height) {
unsigned char seq = 0;
for (auto& pcard : list) {
pcard->sequence = seq++;
if (reset_height) {
pcard->curPos.Z = 0.01f + 0.01f * pcard->sequence;
pcard->mTransform.setTranslation(pcard->curPos);
}
}
}
ClientCard* ClientField::GetCard(int controler, int location, int sequence, int sub_seq) { ClientCard* ClientField::GetCard(int controler, int location, int sequence, int sub_seq) {
std::vector<ClientCard*>* lst = 0; std::vector<ClientCard*>* lst = 0;
bool is_xyz = (location & LOCATION_OVERLAY) != 0; bool is_xyz = (location & LOCATION_OVERLAY) != 0;
...@@ -194,13 +204,10 @@ void ClientField::AddCard(ClientCard* pcard, int controler, int location, int se ...@@ -194,13 +204,10 @@ void ClientField::AddCard(ClientCard* pcard, int controler, int location, int se
case LOCATION_DECK: { case LOCATION_DECK: {
if (sequence != 0 || deck[controler].size() == 0) { if (sequence != 0 || deck[controler].size() == 0) {
deck[controler].push_back(pcard); deck[controler].push_back(pcard);
pcard->sequence = (unsigned char)(deck[controler].size() - 1);
} else { } else {
for (auto& pcard : deck[controler])
pcard->sequence++;
deck[controler].insert(deck[controler].begin(), pcard); deck[controler].insert(deck[controler].begin(), pcard);
pcard->sequence = 0;
} }
ResetSequence(deck[controler], true);
pcard->is_reversed = false; pcard->is_reversed = false;
pcard->ClearData(); pcard->ClearData();
pcard->ClearTarget(); pcard->ClearTarget();
...@@ -209,7 +216,7 @@ void ClientField::AddCard(ClientCard* pcard, int controler, int location, int se ...@@ -209,7 +216,7 @@ void ClientField::AddCard(ClientCard* pcard, int controler, int location, int se
} }
case LOCATION_HAND: { case LOCATION_HAND: {
hand[controler].push_back(pcard); hand[controler].push_back(pcard);
pcard->sequence = (unsigned char)(hand[controler].size() - 1); ResetSequence(hand[controler], false);
break; break;
} }
case LOCATION_MZONE: { case LOCATION_MZONE: {
...@@ -222,28 +229,22 @@ void ClientField::AddCard(ClientCard* pcard, int controler, int location, int se ...@@ -222,28 +229,22 @@ void ClientField::AddCard(ClientCard* pcard, int controler, int location, int se
} }
case LOCATION_GRAVE: { case LOCATION_GRAVE: {
grave[controler].push_back(pcard); grave[controler].push_back(pcard);
pcard->sequence = (unsigned char)(grave[controler].size() - 1); ResetSequence(grave[controler], false);
break; break;
} }
case LOCATION_REMOVED: { case LOCATION_REMOVED: {
remove[controler].push_back(pcard); remove[controler].push_back(pcard);
pcard->sequence = (unsigned char)(remove[controler].size() - 1); ResetSequence(remove[controler], false);
break; break;
} }
case LOCATION_EXTRA: { case LOCATION_EXTRA: {
if(extra_p_count[controler] == 0 || (pcard->position & POS_FACEUP)) { if(extra_p_count[controler] == 0 || (pcard->position & POS_FACEUP)) {
extra[controler].push_back(pcard); extra[controler].push_back(pcard);
pcard->sequence = (unsigned char)(extra[controler].size() - 1);
} else { } else {
int p = extra[controler].size() - extra_p_count[controler] - 1; size_t faceup_begin = extra[controler].size() - extra_p_count[controler];
for(int i = extra[controler].size() - 1; i > p; --i) { extra[controler].insert(extra[controler].begin() + faceup_begin, pcard);
extra[controler][i]->sequence++;
extra[controler][i]->curPos += irr::core::vector3df(0, 0, 0.01f);
extra[controler][i]->mTransform.setTranslation(extra[controler][i]->curPos);
}
extra[controler].insert(extra[controler].begin() + p, pcard);
pcard->sequence = p;
} }
ResetSequence(extra[controler], true);
if (pcard->position & POS_FACEUP) if (pcard->position & POS_FACEUP)
extra_p_count[controler]++; extra_p_count[controler]++;
break; break;
...@@ -252,28 +253,17 @@ void ClientField::AddCard(ClientCard* pcard, int controler, int location, int se ...@@ -252,28 +253,17 @@ void ClientField::AddCard(ClientCard* pcard, int controler, int location, int se
} }
ClientCard* ClientField::RemoveCard(int controler, int location, int sequence) { ClientCard* ClientField::RemoveCard(int controler, int location, int sequence) {
ClientCard* pcard = nullptr; ClientCard* pcard = nullptr;
auto erase_card = [](std::vector<ClientCard*>& lst, int seq) {
for (int i = seq; i < (int)lst.size() - 1; ++i) {
lst[i] = lst[i + 1];
lst[i]->sequence--;
lst[i]->curPos -= irr::core::vector3df(0, 0, 0.01f);
lst[i]->mTransform.setTranslation(lst[i]->curPos);
}
lst.pop_back();
};
switch (location) { switch (location) {
case LOCATION_DECK: { case LOCATION_DECK: {
pcard = deck[controler][sequence]; pcard = deck[controler][sequence];
erase_card(deck[controler], sequence); deck[controler].erase(deck[controler].begin() + sequence);
ResetSequence(deck[controler], true);
break; break;
} }
case LOCATION_HAND: { case LOCATION_HAND: {
pcard = hand[controler][sequence]; pcard = hand[controler][sequence];
for (int i = sequence; i < (int)hand[controler].size() - 1; ++i) { hand[controler].erase(hand[controler].begin() + sequence);
hand[controler][i] = hand[controler][i + 1]; ResetSequence(hand[controler], false);
hand[controler][i]->sequence--;
}
hand[controler].pop_back();
break; break;
} }
case LOCATION_MZONE: { case LOCATION_MZONE: {
...@@ -288,21 +278,26 @@ ClientCard* ClientField::RemoveCard(int controler, int location, int sequence) { ...@@ -288,21 +278,26 @@ ClientCard* ClientField::RemoveCard(int controler, int location, int sequence) {
} }
case LOCATION_GRAVE: { case LOCATION_GRAVE: {
pcard = grave[controler][sequence]; pcard = grave[controler][sequence];
erase_card(grave[controler], sequence); grave[controler].erase(grave[controler].begin() + sequence);
ResetSequence(grave[controler], true);
break; break;
} }
case LOCATION_REMOVED: { case LOCATION_REMOVED: {
pcard = remove[controler][sequence]; pcard = remove[controler][sequence];
erase_card(remove[controler], sequence); remove[controler].erase(remove[controler].begin() + sequence);
ResetSequence(remove[controler], true);
break; break;
} }
case LOCATION_EXTRA: { case LOCATION_EXTRA: {
pcard = extra[controler][sequence]; pcard = extra[controler][sequence];
erase_card(extra[controler], sequence); extra[controler].erase(extra[controler].begin() + sequence);
ResetSequence(extra[controler], true);
if (pcard->position & POS_FACEUP) if (pcard->position & POS_FACEUP)
extra_p_count[controler]--; extra_p_count[controler]--;
break; break;
} }
default:
return nullptr;
} }
pcard->location = 0; pcard->location = 0;
return pcard; return pcard;
...@@ -436,7 +431,7 @@ void ClientField::ShowSelectCard(bool buttonok, bool chain) { ...@@ -436,7 +431,7 @@ void ClientField::ShowSelectCard(bool buttonok, bool chain) {
mainGame->imageLoading.insert(std::make_pair(mainGame->btnCardSelect[i], selectable_cards[i]->chain_code)); mainGame->imageLoading.insert(std::make_pair(mainGame->btnCardSelect[i], selectable_cards[i]->chain_code));
else else
mainGame->btnCardSelect[i]->setImage(imageManager.tCover[selectable_cards[i]->controler + 2]); mainGame->btnCardSelect[i]->setImage(imageManager.tCover[selectable_cards[i]->controler + 2]);
mainGame->btnCardSelect[i]->setRelativePosition(rect<s32>(startpos + i * 125, 55, startpos + 120 + i * 125, 225)); mainGame->btnCardSelect[i]->setRelativePosition(irr::core::rect<irr::s32>(startpos + i * 125, 55, startpos + 120 + i * 125, 225));
mainGame->btnCardSelect[i]->setPressed(false); mainGame->btnCardSelect[i]->setPressed(false);
mainGame->btnCardSelect[i]->setVisible(true); mainGame->btnCardSelect[i]->setVisible(true);
if(mainGame->dInfo.curMsg != MSG_SORT_CARD) { if(mainGame->dInfo.curMsg != MSG_SORT_CARD) {
...@@ -491,7 +486,7 @@ void ClientField::ShowSelectCard(bool buttonok, bool chain) { ...@@ -491,7 +486,7 @@ void ClientField::ShowSelectCard(bool buttonok, bool chain) {
mainGame->stCardPos[i]->setBackgroundColor(0xffffffff); mainGame->stCardPos[i]->setBackgroundColor(0xffffffff);
} }
mainGame->stCardPos[i]->setVisible(true); mainGame->stCardPos[i]->setVisible(true);
mainGame->stCardPos[i]->setRelativePosition(rect<s32>(startpos + i * 125, 30, startpos + 120 + i * 125, 50)); mainGame->stCardPos[i]->setRelativePosition(irr::core::rect<irr::s32>(startpos + i * 125, 30, startpos + 120 + i * 125, 50));
} }
if(selectable_cards.size() <= 5) { if(selectable_cards.size() <= 5) {
for(int i = selectable_cards.size(); i < 5; ++i) { for(int i = selectable_cards.size(); i < 5; ++i) {
...@@ -524,7 +519,7 @@ void ClientField::ShowChainCard() { ...@@ -524,7 +519,7 @@ void ClientField::ShowChainCard() {
mainGame->imageLoading.insert(std::make_pair(mainGame->btnCardSelect[i], selectable_cards[i]->code)); mainGame->imageLoading.insert(std::make_pair(mainGame->btnCardSelect[i], selectable_cards[i]->code));
else else
mainGame->btnCardSelect[i]->setImage(imageManager.tCover[selectable_cards[i]->controler + 2]); mainGame->btnCardSelect[i]->setImage(imageManager.tCover[selectable_cards[i]->controler + 2]);
mainGame->btnCardSelect[i]->setRelativePosition(rect<s32>(startpos + i * 125, 55, startpos + 120 + i * 125, 225)); mainGame->btnCardSelect[i]->setRelativePosition(irr::core::rect<irr::s32>(startpos + i * 125, 55, startpos + 120 + i * 125, 225));
mainGame->btnCardSelect[i]->setPressed(false); mainGame->btnCardSelect[i]->setPressed(false);
mainGame->btnCardSelect[i]->setVisible(true); mainGame->btnCardSelect[i]->setVisible(true);
wchar_t formatBuffer[2048]; wchar_t formatBuffer[2048];
...@@ -543,7 +538,7 @@ void ClientField::ShowChainCard() { ...@@ -543,7 +538,7 @@ void ClientField::ShowChainCard() {
else mainGame->stCardPos[i]->setBackgroundColor(0xffffffff); else mainGame->stCardPos[i]->setBackgroundColor(0xffffffff);
} }
mainGame->stCardPos[i]->setVisible(true); mainGame->stCardPos[i]->setVisible(true);
mainGame->stCardPos[i]->setRelativePosition(rect<s32>(startpos + i * 125, 30, startpos + 120 + i * 125, 50)); mainGame->stCardPos[i]->setRelativePosition(irr::core::rect<irr::s32>(startpos + i * 125, 30, startpos + 120 + i * 125, 50));
} }
if(selectable_cards.size() <= 5) { if(selectable_cards.size() <= 5) {
for(int i = selectable_cards.size(); i < 5; ++i) { for(int i = selectable_cards.size(); i < 5; ++i) {
...@@ -579,7 +574,7 @@ void ClientField::ShowLocationCard() { ...@@ -579,7 +574,7 @@ void ClientField::ShowLocationCard() {
mainGame->imageLoading.insert(std::make_pair(mainGame->btnCardDisplay[i], display_cards[i]->code)); mainGame->imageLoading.insert(std::make_pair(mainGame->btnCardDisplay[i], display_cards[i]->code));
else else
mainGame->btnCardDisplay[i]->setImage(imageManager.tCover[display_cards[i]->controler + 2]); mainGame->btnCardDisplay[i]->setImage(imageManager.tCover[display_cards[i]->controler + 2]);
mainGame->btnCardDisplay[i]->setRelativePosition(rect<s32>(startpos + i * 125, 55, startpos + 120 + i * 125, 225)); mainGame->btnCardDisplay[i]->setRelativePosition(irr::core::rect<irr::s32>(startpos + i * 125, 55, startpos + 120 + i * 125, 225));
mainGame->btnCardDisplay[i]->setPressed(false); mainGame->btnCardDisplay[i]->setPressed(false);
mainGame->btnCardDisplay[i]->setVisible(true); mainGame->btnCardDisplay[i]->setVisible(true);
wchar_t formatBuffer[2048]; wchar_t formatBuffer[2048];
...@@ -612,7 +607,7 @@ void ClientField::ShowLocationCard() { ...@@ -612,7 +607,7 @@ void ClientField::ShowLocationCard() {
mainGame->stDisplayPos[i]->setBackgroundColor(0xffffffff); mainGame->stDisplayPos[i]->setBackgroundColor(0xffffffff);
} }
mainGame->stDisplayPos[i]->setVisible(true); mainGame->stDisplayPos[i]->setVisible(true);
mainGame->stDisplayPos[i]->setRelativePosition(rect<s32>(startpos + i * 125, 30, startpos + 120 + i * 125, 50)); mainGame->stDisplayPos[i]->setRelativePosition(irr::core::rect<irr::s32>(startpos + i * 125, 30, startpos + 120 + i * 125, 50));
} }
if(display_cards.size() <= 5) { if(display_cards.size() <= 5) {
for(int i = display_cards.size(); i < 5; ++i) { for(int i = display_cards.size(); i < 5; ++i) {
...@@ -657,7 +652,7 @@ void ClientField::ShowSelectOption(int select_hint) { ...@@ -657,7 +652,7 @@ void ClientField::ShowSelectOption(int select_hint) {
mainGame->btnOptionOK->setVisible(false); mainGame->btnOptionOK->setVisible(false);
for(int i = 0; i < 5; i++) for(int i = 0; i < 5; i++)
mainGame->btnOption[i]->setVisible(i < count); mainGame->btnOption[i]->setVisible(i < count);
recti pos = mainGame->wOptions->getRelativePosition(); irr::core::recti pos = mainGame->wOptions->getRelativePosition();
int newheight = 30 + 40 * (scrollbar ? 5 : count); int newheight = 30 + 40 * (scrollbar ? 5 : count);
int oldheight = pos.LowerRightCorner.Y - pos.UpperLeftCorner.Y; int oldheight = pos.LowerRightCorner.Y - pos.UpperLeftCorner.Y;
pos.UpperLeftCorner.Y = pos.UpperLeftCorner.Y + (oldheight - newheight) / 2; pos.UpperLeftCorner.Y = pos.UpperLeftCorner.Y + (oldheight - newheight) / 2;
...@@ -672,7 +667,7 @@ void ClientField::ShowSelectOption(int select_hint) { ...@@ -672,7 +667,7 @@ void ClientField::ShowSelectOption(int select_hint) {
mainGame->btnOptionOK->setVisible(true); mainGame->btnOptionOK->setVisible(true);
for(int i = 0; i < 5; i++) for(int i = 0; i < 5; i++)
mainGame->btnOption[i]->setVisible(false); mainGame->btnOption[i]->setVisible(false);
recti pos = mainGame->wOptions->getRelativePosition(); irr::core::recti pos = mainGame->wOptions->getRelativePosition();
pos.LowerRightCorner.Y = pos.UpperLeftCorner.Y + 140; pos.LowerRightCorner.Y = pos.UpperLeftCorner.Y + 140;
mainGame->wOptions->setRelativePosition(pos); mainGame->wOptions->setRelativePosition(pos);
} }
......
...@@ -96,6 +96,7 @@ public: ...@@ -96,6 +96,7 @@ public:
~ClientField(); ~ClientField();
void Clear(); void Clear();
void Initial(int player, int deckc, int extrac); void Initial(int player, int deckc, int extrac);
void ResetSequence(std::vector<ClientCard*>& list, bool reset_height);
ClientCard* GetCard(int controler, int location, int sequence, int sub_seq = 0); ClientCard* GetCard(int controler, int location, int sequence, int sub_seq = 0);
void AddCard(ClientCard* pcard, int controler, int location, int sequence); void AddCard(ClientCard* pcard, int controler, int location, int sequence);
ClientCard* RemoveCard(int controler, int location, int sequence); ClientCard* RemoveCard(int controler, int location, int sequence);
...@@ -144,8 +145,8 @@ public: ...@@ -144,8 +145,8 @@ public:
ClientCard* menu_card{ nullptr }; ClientCard* menu_card{ nullptr };
int list_command{ 0 }; int list_command{ 0 };
virtual bool OnEvent(const irr::SEvent& event); bool OnEvent(const irr::SEvent& event) override;
virtual bool OnCommonEvent(const irr::SEvent& event); bool OnCommonEvent(const irr::SEvent& event);
void GetHoverField(int x, int y); void GetHoverField(int x, int y);
void ShowMenu(int flag, int x, int y); void ShowMenu(int flag, int x, int y);
void HideMenu(); void HideMenu();
......
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
#define _IRR_STATIC_LIB_ #define _IRR_STATIC_LIB_
#define IRR_COMPILE_WITH_DX9_DEV_PACK #define IRR_COMPILE_WITH_DX9_DEV_PACK
#include <cerrno>
#ifdef _WIN32 #ifdef _WIN32
#define NOMINMAX #define NOMINMAX
...@@ -22,7 +25,6 @@ ...@@ -22,7 +25,6 @@
#else //_WIN32 #else //_WIN32
#include <errno.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
...@@ -43,21 +45,20 @@ ...@@ -43,21 +45,20 @@
#define mystrncasecmp strncasecmp #define mystrncasecmp strncasecmp
#endif #endif
#include <stdio.h> #include <cstdio>
#include <stdlib.h> #include <cstdlib>
#include <iostream> #include <iostream>
#include <algorithm> #include <algorithm>
#include <string> #include <string>
#include "bufferio.h" #include "bufferio.h"
#include "../ocgcore/ocgapi.h" #include "../ocgcore/ocgapi.h"
#include "../ocgcore/common.h"
template<size_t N, typename... TR> template<size_t N, typename... TR>
inline int myswprintf(wchar_t(&buf)[N], const wchar_t* fmt, TR... args) { inline int myswprintf(wchar_t(&buf)[N], const wchar_t* fmt, TR... args) {
return std::swprintf(buf, N, fmt, args...); return std::swprintf(buf, N, fmt, args...);
} }
inline FILE* myfopen(const wchar_t* filename, const char* mode) { inline FILE* mywfopen(const wchar_t* filename, const char* mode) {
FILE* fp{}; FILE* fp{};
#ifdef _WIN32 #ifdef _WIN32
wchar_t wmode[20]{}; wchar_t wmode[20]{};
...@@ -66,18 +67,12 @@ inline FILE* myfopen(const wchar_t* filename, const char* mode) { ...@@ -66,18 +67,12 @@ inline FILE* myfopen(const wchar_t* filename, const char* mode) {
#else #else
char fname[1024]{}; char fname[1024]{};
BufferIO::EncodeUTF8(filename, fname); BufferIO::EncodeUTF8(filename, fname);
fp = fopen(fname, mode); fp = std::fopen(fname, mode);
#endif #endif
return fp; return fp;
} }
#include <irrlicht.h> #include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
extern const unsigned short PRO_VERSION; extern const unsigned short PRO_VERSION;
extern unsigned int enable_log; extern unsigned int enable_log;
......
#include "data_manager.h" #include "data_manager.h"
#include "game.h" #include "game.h"
#include <stdio.h>
#include "spmemvfs/spmemvfs.h" #include "spmemvfs/spmemvfs.h"
namespace ygo { namespace ygo {
...@@ -14,23 +13,21 @@ DataManager::DataManager() : _datas(32768), _strings(32768) { ...@@ -14,23 +13,21 @@ DataManager::DataManager() : _datas(32768), _strings(32768) {
extra_setcode = { {8512558u, {0x8f, 0x54, 0x59, 0x82, 0x13a}}, }; extra_setcode = { {8512558u, {0x8f, 0x54, 0x59, 0x82, 0x13a}}, };
} }
bool DataManager::ReadDB(sqlite3* pDB) { bool DataManager::ReadDB(sqlite3* pDB) {
sqlite3_stmt* pStmt{}; sqlite3_stmt* pStmt = nullptr;
const char* sql = "select * from datas,texts where datas.id=texts.id"; const char* sql = "select * from datas,texts where datas.id=texts.id";
if (sqlite3_prepare_v2(pDB, sql, -1, &pStmt, 0) != SQLITE_OK) if (sqlite3_prepare_v2(pDB, sql, -1, &pStmt, 0) != SQLITE_OK)
return Error(pDB); return Error(pDB, pStmt);
wchar_t strBuffer[4096]; wchar_t strBuffer[4096];
int step = 0; int step = 0;
do { do {
CardDataC cd; CardDataC cd;
CardString cs; CardString cs;
step = sqlite3_step(pStmt); step = sqlite3_step(pStmt);
if (step == SQLITE_BUSY || step == SQLITE_ERROR || step == SQLITE_MISUSE) if (step == SQLITE_ROW) {
return Error(pDB, pStmt);
else if (step == SQLITE_ROW) {
cd.code = sqlite3_column_int(pStmt, 0); cd.code = sqlite3_column_int(pStmt, 0);
cd.ot = sqlite3_column_int(pStmt, 1); cd.ot = sqlite3_column_int(pStmt, 1);
cd.alias = sqlite3_column_int(pStmt, 2); cd.alias = sqlite3_column_int(pStmt, 2);
auto setcode = sqlite3_column_int64(pStmt, 3); uint64_t setcode = static_cast<uint64_t>(sqlite3_column_int64(pStmt, 3));
if (setcode) { if (setcode) {
auto it = extra_setcode.find(cd.code); auto it = extra_setcode.find(cd.code);
if (it != extra_setcode.end()) { if (it != extra_setcode.end()) {
...@@ -43,7 +40,7 @@ bool DataManager::ReadDB(sqlite3* pDB) { ...@@ -43,7 +40,7 @@ bool DataManager::ReadDB(sqlite3* pDB) {
else else
cd.set_setcode(setcode); cd.set_setcode(setcode);
} }
cd.type = sqlite3_column_int(pStmt, 4); cd.type = static_cast<decltype(cd.type)>(sqlite3_column_int64(pStmt, 4));
cd.attack = sqlite3_column_int(pStmt, 5); cd.attack = sqlite3_column_int(pStmt, 5);
cd.defense = sqlite3_column_int(pStmt, 6); cd.defense = sqlite3_column_int(pStmt, 6);
if (cd.type & TYPE_LINK) { if (cd.type & TYPE_LINK) {
...@@ -52,13 +49,13 @@ bool DataManager::ReadDB(sqlite3* pDB) { ...@@ -52,13 +49,13 @@ bool DataManager::ReadDB(sqlite3* pDB) {
} }
else else
cd.link_marker = 0; cd.link_marker = 0;
unsigned int level = sqlite3_column_int(pStmt, 7); uint32_t level = static_cast<uint32_t>(sqlite3_column_int(pStmt, 7));
cd.level = level & 0xff; cd.level = level & 0xff;
cd.lscale = (level >> 24) & 0xff; cd.lscale = (level >> 24) & 0xff;
cd.rscale = (level >> 16) & 0xff; cd.rscale = (level >> 16) & 0xff;
cd.race = sqlite3_column_int(pStmt, 8); cd.race = static_cast<decltype(cd.race)>(sqlite3_column_int64(pStmt, 8));
cd.attribute = sqlite3_column_int(pStmt, 9); cd.attribute = static_cast<decltype(cd.attribute)>(sqlite3_column_int64(pStmt, 9));
cd.category = sqlite3_column_int(pStmt, 10); cd.category = static_cast<decltype(cd.category)>(sqlite3_column_int64(pStmt, 10));
_datas[cd.code] = cd; _datas[cd.code] = cd;
if (const char* text = (const char*)sqlite3_column_text(pStmt, 12)) { if (const char* text = (const char*)sqlite3_column_text(pStmt, 12)) {
BufferIO::DecodeUTF8(text, strBuffer); BufferIO::DecodeUTF8(text, strBuffer);
...@@ -77,7 +74,9 @@ bool DataManager::ReadDB(sqlite3* pDB) { ...@@ -77,7 +74,9 @@ bool DataManager::ReadDB(sqlite3* pDB) {
} }
_strings[cd.code] = cs; _strings[cd.code] = cs;
} }
} while (step != SQLITE_DONE); else if (step != SQLITE_DONE)
return Error(pDB, pStmt);
} while (step == SQLITE_ROW);
sqlite3_finalize(pStmt); sqlite3_finalize(pStmt);
return true; return true;
} }
...@@ -85,17 +84,17 @@ bool DataManager::LoadDB(const wchar_t* wfile) { ...@@ -85,17 +84,17 @@ bool DataManager::LoadDB(const wchar_t* wfile) {
char file[256]; char file[256];
BufferIO::EncodeUTF8(wfile, file); BufferIO::EncodeUTF8(wfile, file);
#ifdef _WIN32 #ifdef _WIN32
IReadFile* reader = FileSystem->createAndOpenFile(wfile); auto reader = FileSystem->createAndOpenFile(wfile);
#else #else
IReadFile* reader = FileSystem->createAndOpenFile(file); auto reader = FileSystem->createAndOpenFile(file);
#endif #endif
if(reader == nullptr) if(reader == nullptr)
return false; return false;
spmemvfs_db_t db; spmemvfs_db_t db;
spmembuffer_t* mem = (spmembuffer_t*)calloc(sizeof(spmembuffer_t), 1); spmembuffer_t* mem = (spmembuffer_t*)std::calloc(sizeof(spmembuffer_t), 1);
spmemvfs_env_init(); spmemvfs_env_init();
mem->total = mem->used = reader->getSize(); mem->total = mem->used = reader->getSize();
mem->data = (char*)malloc(mem->total + 1); mem->data = (char*)std::malloc(mem->total + 1);
reader->read(mem->data, mem->total); reader->read(mem->data, mem->total);
reader->drop(); reader->drop();
(mem->data)[mem->total] = '\0'; (mem->data)[mem->total] = '\0';
...@@ -109,14 +108,14 @@ bool DataManager::LoadDB(const wchar_t* wfile) { ...@@ -109,14 +108,14 @@ bool DataManager::LoadDB(const wchar_t* wfile) {
return ret; return ret;
} }
bool DataManager::LoadStrings(const char* file) { bool DataManager::LoadStrings(const char* file) {
FILE* fp = fopen(file, "r"); FILE* fp = std::fopen(file, "r");
if(!fp) if(!fp)
return false; return false;
char linebuf[TEXT_LINE_SIZE]{}; char linebuf[TEXT_LINE_SIZE]{};
while(fgets(linebuf, sizeof linebuf, fp)) { while(std::fgets(linebuf, sizeof linebuf, fp)) {
ReadStringConfLine(linebuf); ReadStringConfLine(linebuf);
} }
fclose(fp); std::fclose(fp);
return true; return true;
} }
bool DataManager::LoadStrings(irr::io::IReadFile* reader) { bool DataManager::LoadStrings(irr::io::IReadFile* reader) {
...@@ -140,26 +139,26 @@ void DataManager::ReadStringConfLine(const char* linebuf) { ...@@ -140,26 +139,26 @@ void DataManager::ReadStringConfLine(const char* linebuf) {
char strbuf[TEXT_LINE_SIZE]{}; char strbuf[TEXT_LINE_SIZE]{};
int value{}; int value{};
wchar_t strBuffer[4096]{}; wchar_t strBuffer[4096]{};
if (sscanf(linebuf, "!%63s", strbuf) != 1) if (std::sscanf(linebuf, "!%63s", strbuf) != 1)
return; return;
if(!std::strcmp(strbuf, "system")) { if(!std::strcmp(strbuf, "system")) {
if (sscanf(&linebuf[7], "%d %240[^\n]", &value, strbuf) != 2) if (std::sscanf(&linebuf[7], "%d %240[^\n]", &value, strbuf) != 2)
return; return;
BufferIO::DecodeUTF8(strbuf, strBuffer); BufferIO::DecodeUTF8(strbuf, strBuffer);
_sysStrings[value] = strBuffer; _sysStrings[value] = strBuffer;
} else if(!std::strcmp(strbuf, "victory")) { } else if(!std::strcmp(strbuf, "victory")) {
if (sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf) != 2) if (std::sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf) != 2)
return; return;
BufferIO::DecodeUTF8(strbuf, strBuffer); BufferIO::DecodeUTF8(strbuf, strBuffer);
_victoryStrings[value] = strBuffer; _victoryStrings[value] = strBuffer;
} else if(!std::strcmp(strbuf, "counter")) { } else if(!std::strcmp(strbuf, "counter")) {
if (sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf) != 2) if (std::sscanf(&linebuf[8], "%x %240[^\n]", &value, strbuf) != 2)
return; return;
BufferIO::DecodeUTF8(strbuf, strBuffer); BufferIO::DecodeUTF8(strbuf, strBuffer);
_counterStrings[value] = strBuffer; _counterStrings[value] = strBuffer;
} else if(!std::strcmp(strbuf, "setname")) { } else if(!std::strcmp(strbuf, "setname")) {
//using tab for comment //using tab for comment
if (sscanf(&linebuf[8], "%x %240[^\t\n]", &value, strbuf) != 2) if (std::sscanf(&linebuf[8], "%x %240[^\t\n]", &value, strbuf) != 2)
return; return;
BufferIO::DecodeUTF8(strbuf, strBuffer); BufferIO::DecodeUTF8(strbuf, strBuffer);
_setnameStrings[value] = strBuffer; _setnameStrings[value] = strBuffer;
...@@ -418,9 +417,9 @@ unsigned char* DataManager::ReadScriptFromIrrFS(const char* script_name, int* sl ...@@ -418,9 +417,9 @@ unsigned char* DataManager::ReadScriptFromIrrFS(const char* script_name, int* sl
#ifdef _WIN32 #ifdef _WIN32
wchar_t fname[256]{}; wchar_t fname[256]{};
BufferIO::DecodeUTF8(script_name, fname); BufferIO::DecodeUTF8(script_name, fname);
IReadFile* reader = FileSystem->createAndOpenFile(fname); auto reader = FileSystem->createAndOpenFile(fname);
#else #else
IReadFile* reader = FileSystem->createAndOpenFile(script_name); auto reader = FileSystem->createAndOpenFile(script_name);
#endif #endif
if (!reader) if (!reader)
return nullptr; return nullptr;
...@@ -434,7 +433,7 @@ unsigned char* DataManager::ReadScriptFromIrrFS(const char* script_name, int* sl ...@@ -434,7 +433,7 @@ unsigned char* DataManager::ReadScriptFromIrrFS(const char* script_name, int* sl
unsigned char* DataManager::ReadScriptFromFile(const char* script_name, int* slen) { unsigned char* DataManager::ReadScriptFromFile(const char* script_name, int* slen) {
wchar_t fname[256]{}; wchar_t fname[256]{};
BufferIO::DecodeUTF8(script_name, fname); BufferIO::DecodeUTF8(script_name, fname);
FILE* fp = myfopen(fname, "rb"); FILE* fp = mywfopen(fname, "rb");
if (!fp) if (!fp)
return nullptr; return nullptr;
size_t len = std::fread(scriptBuffer, 1, sizeof scriptBuffer, fp); size_t len = std::fread(scriptBuffer, 1, sizeof scriptBuffer, fp);
......
...@@ -24,7 +24,7 @@ struct CardDataC : card_data { ...@@ -24,7 +24,7 @@ struct CardDataC : card_data {
uint32_t ot{}; uint32_t ot{};
uint32_t category{}; uint32_t category{};
bool is_setcodes(std::vector <uint32_t> values) const { bool is_setcodes(const std::vector<unsigned int>& values) const {
for (auto& value : values) { for (auto& value : values) {
if (is_setcode(value)) if (is_setcode(value))
return true; return true;
......
This diff is collapsed.
#ifndef DECK_CON_H #ifndef DECK_CON_H
#define DECK_CON_H #define DECK_CON_H
#include "config.h"
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include <irrlicht.h>
#include "data_manager.h" #include "data_manager.h"
#include "deck_manager.h"
#include "../ocgcore/mtrandom.h" #include "../ocgcore/mtrandom.h"
namespace ygo { namespace ygo {
class DeckBuilder: public irr::IEventReceiver { class DeckBuilder: public irr::IEventReceiver {
public: public:
virtual bool OnEvent(const irr::SEvent& event); bool OnEvent(const irr::SEvent& event) override;
void Initialize(); void Initialize();
void Terminate(); void Terminate();
void GetHoveredCard(); void GetHoveredCard();
...@@ -28,7 +29,7 @@ public: ...@@ -28,7 +29,7 @@ public:
void ChangeCategory(int catesel); void ChangeCategory(int catesel);
void ShowDeckManage(); void ShowDeckManage();
void ShowBigCard(int code, float zoom); void ShowBigCard(int code, float zoom);
void ZoomBigCard(s32 centerx = -1, s32 centery = -1); void ZoomBigCard(irr::s32 centerx = -1, irr::s32 centery = -1);
void CloseBigCard(); void CloseBigCard();
bool CardNameContains(const wchar_t *haystack, const wchar_t *needle); bool CardNameContains(const wchar_t *haystack, const wchar_t *needle);
...@@ -56,7 +57,7 @@ public: ...@@ -56,7 +57,7 @@ public:
unsigned int filter_scl{}; unsigned int filter_scl{};
unsigned int filter_marks{}; unsigned int filter_marks{};
int filter_lm{}; int filter_lm{};
position2di mouse_pos; irr::core::vector2di mouse_pos;
int hovered_code{}; int hovered_code{};
int hovered_pos{}; int hovered_pos{};
int hovered_seq{ -1 }; int hovered_seq{ -1 };
...@@ -74,14 +75,14 @@ public: ...@@ -74,14 +75,14 @@ public:
code_pointer draging_pointer; code_pointer draging_pointer;
int prev_category{}; int prev_category{};
int prev_deck{}; int prev_deck{};
s32 prev_operation{}; irr::s32 prev_operation{};
int prev_sel{ -1 }; int prev_sel{ -1 };
bool is_modified{}; bool is_modified{};
bool readonly{}; bool readonly{};
bool showing_pack{}; bool showing_pack{};
mt19937 rnd; mt19937 rnd;
const std::unordered_map<int, int>* filterList; const LFList* filterList{};
std::vector<code_pointer> results; std::vector<code_pointer> results;
wchar_t result_string[8]{}; wchar_t result_string[8]{};
std::vector<std::wstring> expansionPacks; std::vector<std::wstring> expansionPacks;
......
This diff is collapsed.
#ifndef DECKMANAGER_H #ifndef DECKMANAGER_H
#define DECKMANAGER_H #define DECKMANAGER_H
#include "config.h"
#include "data_manager.h"
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include <sstream> #include <sstream>
#include "data_manager.h"
namespace ygo { namespace ygo {
constexpr int DECK_MAX_SIZE = 60; constexpr int DECK_MAX_SIZE = 60;
...@@ -17,13 +16,13 @@ namespace ygo { ...@@ -17,13 +16,13 @@ namespace ygo {
struct LFList { struct LFList {
unsigned int hash{}; unsigned int hash{};
std::wstring listName; std::wstring listName;
std::unordered_map<int, int> content; std::unordered_map<unsigned int, int> content;
}; };
struct Deck { struct Deck {
std::vector<code_pointer> main; std::vector<code_pointer> main;
std::vector<code_pointer> extra; std::vector<code_pointer> extra;
std::vector<code_pointer> side; std::vector<code_pointer> side;
Deck() {} Deck() = default;
Deck(const Deck& ndeck) { Deck(const Deck& ndeck) {
main = ndeck.main; main = ndeck.main;
extra = ndeck.extra; extra = ndeck.extra;
...@@ -45,18 +44,18 @@ public: ...@@ -45,18 +44,18 @@ public:
void LoadLFListSingle(const char* path); void LoadLFListSingle(const char* path);
void LoadLFList(); void LoadLFList();
const wchar_t* GetLFListName(int lfhash); const wchar_t* GetLFListName(unsigned int lfhash);
const std::unordered_map<int, int>* GetLFListContent(int lfhash); const LFList* GetLFList(unsigned int lfhash);
unsigned int CheckDeck(Deck& deck, int lfhash, int rule); unsigned int CheckDeck(Deck& deck, int lfhash, int rule);
int LoadDeck(Deck& deck, int* dbuf, int mainc, int sidec, bool is_packlist = false); int LoadDeck(Deck& deck, int* dbuf, int mainc, int sidec, bool is_packlist = false);
int LoadDeck(Deck& deck, std::istringstream& deckStream, bool is_packlist = false); int LoadDeck(Deck& deck, std::istringstream& deckStream, bool is_packlist = false);
bool LoadSide(Deck& deck, int* dbuf, int mainc, int sidec); bool LoadSide(Deck& deck, int* dbuf, int mainc, int sidec);
void GetCategoryPath(wchar_t* ret, int index, const wchar_t* text); void GetCategoryPath(wchar_t* ret, int index, const wchar_t* text);
void GetDeckFile(wchar_t* ret, irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck); void GetDeckFile(wchar_t* ret, int category_index, const wchar_t* category_name, const wchar_t* deckname);
FILE* OpenDeckFile(const wchar_t* file, const char* mode); FILE* OpenDeckFile(const wchar_t* file, const char* mode);
IReadFile* OpenDeckReader(const wchar_t* file); irr::io::IReadFile* OpenDeckReader(const wchar_t* file);
bool LoadCurrentDeck(const wchar_t* file, bool is_packlist = false); bool LoadCurrentDeck(const wchar_t* file, bool is_packlist = false);
bool LoadCurrentDeck(irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck); bool LoadCurrentDeck(int category_index, const wchar_t* category_name, const wchar_t* deckname);
bool SaveDeck(Deck& deck, const wchar_t* file); bool SaveDeck(Deck& deck, const wchar_t* file);
bool DeleteDeck(const wchar_t* file); bool DeleteDeck(const wchar_t* file);
bool CreateCategory(const wchar_t* name); bool CreateCategory(const wchar_t* name);
......
This diff is collapsed.
...@@ -500,9 +500,9 @@ void DuelClient::HandleSTOCPacketLan(unsigned char* data, int len) { ...@@ -500,9 +500,9 @@ void DuelClient::HandleSTOCPacketLan(unsigned char* data, int len) {
mainGame->dInfo.time_limit = pkt->info.time_limit; mainGame->dInfo.time_limit = pkt->info.time_limit;
mainGame->dInfo.time_left[0] = 0; mainGame->dInfo.time_left[0] = 0;
mainGame->dInfo.time_left[1] = 0; mainGame->dInfo.time_left[1] = 0;
mainGame->deckBuilder.filterList = deckManager.GetLFListContent(pkt->info.lflist); mainGame->deckBuilder.filterList = deckManager.GetLFList(pkt->info.lflist);
if(mainGame->deckBuilder.filterList == nullptr) if(mainGame->deckBuilder.filterList == nullptr)
mainGame->deckBuilder.filterList = &deckManager._lfList[0].content; mainGame->deckBuilder.filterList = &deckManager._lfList[0];
mainGame->stHostPrepOB->setText(L""); mainGame->stHostPrepOB->setText(L"");
mainGame->SetStaticText(mainGame->stHostPrepRule, 180, mainGame->guiFont, str.c_str()); mainGame->SetStaticText(mainGame->stHostPrepRule, 180, mainGame->guiFont, str.c_str());
mainGame->RefreshCategoryDeck(mainGame->cbCategorySelect, mainGame->cbDeckSelect); mainGame->RefreshCategoryDeck(mainGame->cbCategorySelect, mainGame->cbDeckSelect);
...@@ -730,9 +730,8 @@ void DuelClient::HandleSTOCPacketLan(unsigned char* data, int len) { ...@@ -730,9 +730,8 @@ void DuelClient::HandleSTOCPacketLan(unsigned char* data, int len) {
else else
starttime = new_replay.pheader.seed; starttime = new_replay.pheader.seed;
tm* localedtime = localtime(&starttime);
wchar_t timetext[40]; wchar_t timetext[40];
std::wcsftime(timetext, 40, L"%Y-%m-%d %H-%M-%S", localedtime); std::wcsftime(timetext, sizeof timetext / sizeof timetext[0], L"%Y-%m-%d %H-%M-%S", std::localtime(&starttime));
mainGame->ebRSName->setText(timetext); mainGame->ebRSName->setText(timetext);
if(!mainGame->chkAutoSaveReplay->isChecked()) { if(!mainGame->chkAutoSaveReplay->isChecked()) {
mainGame->wReplaySave->setText(dataManager.GetSysString(1340)); mainGame->wReplaySave->setText(dataManager.GetSysString(1340));
...@@ -1901,23 +1900,23 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) { ...@@ -1901,23 +1900,23 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) {
else startpos = 155; else startpos = 155;
if(positions & 0x1) { if(positions & 0x1) {
mainGame->imageLoading.insert(std::make_pair(mainGame->btnPSAU, code)); mainGame->imageLoading.insert(std::make_pair(mainGame->btnPSAU, code));
mainGame->btnPSAU->setRelativePosition(rect<s32>(startpos, 45, startpos + 140, 185)); mainGame->btnPSAU->setRelativePosition(irr::core::rect<irr::s32>(startpos, 45, startpos + 140, 185));
mainGame->btnPSAU->setVisible(true); mainGame->btnPSAU->setVisible(true);
startpos += 145; startpos += 145;
} else mainGame->btnPSAU->setVisible(false); } else mainGame->btnPSAU->setVisible(false);
if(positions & 0x2) { if(positions & 0x2) {
mainGame->btnPSAD->setRelativePosition(rect<s32>(startpos, 45, startpos + 140, 185)); mainGame->btnPSAD->setRelativePosition(irr::core::rect<irr::s32>(startpos, 45, startpos + 140, 185));
mainGame->btnPSAD->setVisible(true); mainGame->btnPSAD->setVisible(true);
startpos += 145; startpos += 145;
} else mainGame->btnPSAD->setVisible(false); } else mainGame->btnPSAD->setVisible(false);
if(positions & 0x4) { if(positions & 0x4) {
mainGame->imageLoading.insert(std::make_pair(mainGame->btnPSDU, code)); mainGame->imageLoading.insert(std::make_pair(mainGame->btnPSDU, code));
mainGame->btnPSDU->setRelativePosition(rect<s32>(startpos, 45, startpos + 140, 185)); mainGame->btnPSDU->setRelativePosition(irr::core::rect<irr::s32>(startpos, 45, startpos + 140, 185));
mainGame->btnPSDU->setVisible(true); mainGame->btnPSDU->setVisible(true);
startpos += 145; startpos += 145;
} else mainGame->btnPSDU->setVisible(false); } else mainGame->btnPSDU->setVisible(false);
if(positions & 0x8) { if(positions & 0x8) {
mainGame->btnPSDD->setRelativePosition(rect<s32>(startpos, 45, startpos + 140, 185)); mainGame->btnPSDD->setRelativePosition(irr::core::rect<irr::s32>(startpos, 45, startpos + 140, 185));
mainGame->btnPSDD->setVisible(true); mainGame->btnPSDD->setVisible(true);
startpos += 145; startpos += 145;
} else mainGame->btnPSDD->setVisible(false); } else mainGame->btnPSDD->setVisible(false);
...@@ -3429,11 +3428,11 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) { ...@@ -3429,11 +3428,11 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) {
float xd = mainGame->dField.attack_target->curPos.X; float xd = mainGame->dField.attack_target->curPos.X;
float yd = mainGame->dField.attack_target->curPos.Y; float yd = mainGame->dField.attack_target->curPos.Y;
sy = (float)sqrt((xa - xd) * (xa - xd) + (ya - yd) * (ya - yd)) / 2; sy = (float)sqrt((xa - xd) * (xa - xd) + (ya - yd) * (ya - yd)) / 2;
mainGame->atk_t = vector3df((xa + xd) / 2, (ya + yd) / 2, 0); mainGame->atk_t = irr::core::vector3df((xa + xd) / 2, (ya + yd) / 2, 0);
if (ca == 0) if (ca == 0)
mainGame->atk_r = vector3df(0, 0, -atan((xd - xa) / (yd - ya))); mainGame->atk_r = irr::core::vector3df(0, 0, -atan((xd - xa) / (yd - ya)));
else else
mainGame->atk_r = vector3df(0, 0, 3.1415926 - atan((xd - xa) / (yd - ya))); mainGame->atk_r = irr::core::vector3df(0, 0, 3.1415926 - atan((xd - xa) / (yd - ya)));
} else { } else {
soundManager.PlaySoundEffect(SOUND_DIRECT_ATTACK); soundManager.PlaySoundEffect(SOUND_DIRECT_ATTACK);
myswprintf(event_string, dataManager.GetSysString(1620), dataManager.GetName(mainGame->dField.attacker->code)); myswprintf(event_string, dataManager.GetSysString(1620), dataManager.GetName(mainGame->dField.attacker->code));
...@@ -3444,11 +3443,11 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) { ...@@ -3444,11 +3443,11 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) {
if (ca == 0) if (ca == 0)
yd = -3.5f; yd = -3.5f;
sy = (float)sqrt((xa - xd) * (xa - xd) + (ya - yd) * (ya - yd)) / 2; sy = (float)sqrt((xa - xd) * (xa - xd) + (ya - yd) * (ya - yd)) / 2;
mainGame->atk_t = vector3df((xa + xd) / 2, (ya + yd) / 2, 0); mainGame->atk_t = irr::core::vector3df((xa + xd) / 2, (ya + yd) / 2, 0);
if (ca == 0) if (ca == 0)
mainGame->atk_r = vector3df(0, 0, -atan((xd - xa) / (yd - ya))); mainGame->atk_r = irr::core::vector3df(0, 0, -atan((xd - xa) / (yd - ya)));
else else
mainGame->atk_r = vector3df(0, 0, 3.1415926 - atan((xd - xa) / (yd - ya))); mainGame->atk_r = irr::core::vector3df(0, 0, 3.1415926 - atan((xd - xa) / (yd - ya)));
} }
matManager.GenArrow(sy); matManager.GenArrow(sy);
mainGame->attack_sv = 0; mainGame->attack_sv = 0;
...@@ -3673,9 +3672,9 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) { ...@@ -3673,9 +3672,9 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) {
mainGame->cbANNumber->setSelected(0); mainGame->cbANNumber->setSelected(0);
if(quickmode) { if(quickmode) {
mainGame->cbANNumber->setVisible(false); mainGame->cbANNumber->setVisible(false);
mainGame->btnANNumberOK->setRelativePosition(rect<s32>(20, 195, 210, 230)); mainGame->btnANNumberOK->setRelativePosition(irr::core::rect<irr::s32>(20, 195, 210, 230));
mainGame->btnANNumberOK->setEnabled(false); mainGame->btnANNumberOK->setEnabled(false);
recti pos = mainGame->wANNumber->getRelativePosition(); irr::core::recti pos = mainGame->wANNumber->getRelativePosition();
pos.LowerRightCorner.Y = pos.UpperLeftCorner.Y + 250; pos.LowerRightCorner.Y = pos.UpperLeftCorner.Y + 250;
mainGame->wANNumber->setRelativePosition(pos); mainGame->wANNumber->setRelativePosition(pos);
} else { } else {
...@@ -3683,8 +3682,8 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) { ...@@ -3683,8 +3682,8 @@ bool DuelClient::ClientAnalyze(unsigned char* msg, int len) {
mainGame->btnANNumber[i]->setVisible(false); mainGame->btnANNumber[i]->setVisible(false);
} }
mainGame->cbANNumber->setVisible(true); mainGame->cbANNumber->setVisible(true);
mainGame->btnANNumberOK->setRelativePosition(rect<s32>(80, 60, 150, 85)); mainGame->btnANNumberOK->setRelativePosition(irr::core::rect<irr::s32>(80, 60, 150, 85));
recti pos = mainGame->wANNumber->getRelativePosition(); irr::core::recti pos = mainGame->wANNumber->getRelativePosition();
pos.LowerRightCorner.Y = pos.UpperLeftCorner.Y + 95; pos.LowerRightCorner.Y = pos.UpperLeftCorner.Y + 95;
mainGame->wANNumber->setRelativePosition(pos); mainGame->wANNumber->setRelativePosition(pos);
} }
......
...@@ -53,7 +53,7 @@ public: ...@@ -53,7 +53,7 @@ public:
bufferevent_write(client_bev, duel_client_write, 3); bufferevent_write(client_bev, duel_client_write, 3);
} }
template<typename ST> template<typename ST>
static void SendPacketToServer(unsigned char proto, ST& st) { static void SendPacketToServer(unsigned char proto, const ST& st) {
auto p = duel_client_write; auto p = duel_client_write;
if (sizeof(ST) > MAX_DATA_SIZE) if (sizeof(ST) > MAX_DATA_SIZE)
return; return;
......
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "client_field.h" #include "client_field.h"
#include "deck_con.h" #include "deck_con.h"
#include "menu_handler.h" #include "menu_handler.h"
#include <time.h> #include <ctime>
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include <list> #include <list>
...@@ -29,6 +29,7 @@ constexpr int TEXT_LINE_SIZE = 256; ...@@ -29,6 +29,7 @@ constexpr int TEXT_LINE_SIZE = 256;
namespace ygo { namespace ygo {
bool IsExtension(const wchar_t* filename, const wchar_t* extension); bool IsExtension(const wchar_t* filename, const wchar_t* extension);
bool IsExtension(const char* filename, const char* extension);
struct Config { struct Config {
bool use_d3d{ false }; bool use_d3d{ false };
...@@ -143,9 +144,9 @@ class Game { ...@@ -143,9 +144,9 @@ class Game {
public: public:
bool Initialize(); bool Initialize();
void MainLoop(); void MainLoop();
void BuildProjectionMatrix(irr::core::matrix4& mProjection, f32 left, f32 right, f32 bottom, f32 top, f32 znear, f32 zfar); void BuildProjectionMatrix(irr::core::matrix4& mProjection, irr::f32 left, irr::f32 right, irr::f32 bottom, irr::f32 top, irr::f32 znear, irr::f32 zfar);
void InitStaticText(irr::gui::IGUIStaticText* pControl, u32 cWidth, u32 cHeight, irr::gui::CGUITTFont* font, const wchar_t* text); void InitStaticText(irr::gui::IGUIStaticText* pControl, irr::u32 cWidth, irr::u32 cHeight, irr::gui::CGUITTFont* font, const wchar_t* text);
std::wstring SetStaticText(irr::gui::IGUIStaticText* pControl, u32 cWidth, irr::gui::CGUITTFont* font, const wchar_t* text, u32 pos = 0); std::wstring SetStaticText(irr::gui::IGUIStaticText* pControl, irr::u32 cWidth, irr::gui::CGUITTFont* font, const wchar_t* text, irr::u32 pos = 0);
void LoadExpansions(); void LoadExpansions();
void RefreshCategoryDeck(irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck, bool selectlastused = true); void RefreshCategoryDeck(irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck, bool selectlastused = true);
void RefreshDeck(irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck); void RefreshDeck(irr::gui::IGUIComboBox* cbCategory, irr::gui::IGUIComboBox* cbDeck);
...@@ -169,7 +170,7 @@ public: ...@@ -169,7 +170,7 @@ public:
void HideElement(irr::gui::IGUIElement* element, bool set_action = false); void HideElement(irr::gui::IGUIElement* element, bool set_action = false);
void PopupElement(irr::gui::IGUIElement* element, int hideframe = 0); void PopupElement(irr::gui::IGUIElement* element, int hideframe = 0);
void WaitFrameSignal(int frame); void WaitFrameSignal(int frame);
void DrawThumb(code_pointer cp, position2di pos, const std::unordered_map<int,int>* lflist, bool drag = false); void DrawThumb(code_pointer cp, irr::core::vector2di pos, const LFList* lflist, bool drag = false);
void DrawDeckBd(); void DrawDeckBd();
void LoadConfig(); void LoadConfig();
void SaveConfig(); void SaveConfig();
...@@ -190,7 +191,7 @@ public: ...@@ -190,7 +191,7 @@ public:
int ChatLocalPlayer(int player); int ChatLocalPlayer(int player);
const wchar_t* LocalName(int local_player); const wchar_t* LocalName(int local_player);
bool HasFocus(EGUI_ELEMENT_TYPE type) const { bool HasFocus(irr::gui::EGUI_ELEMENT_TYPE type) const {
irr::gui::IGUIElement* focus = env->getFocus(); irr::gui::IGUIElement* focus = env->getFocus();
return focus && focus->hasType(type); return focus && focus->hasType(type);
} }
...@@ -203,26 +204,26 @@ public: ...@@ -203,26 +204,26 @@ public:
void OnResize(); void OnResize();
void ResizeChatInputWindow(); void ResizeChatInputWindow();
recti Resize(s32 x, s32 y, s32 x2, s32 y2); irr::core::recti Resize(irr::s32 x, irr::s32 y, irr::s32 x2, irr::s32 y2);
recti Resize(s32 x, s32 y, s32 x2, s32 y2, s32 dx, s32 dy, s32 dx2, s32 dy2); irr::core::recti Resize(irr::s32 x, irr::s32 y, irr::s32 x2, irr::s32 y2, irr::s32 dx, irr::s32 dy, irr::s32 dx2, irr::s32 dy2);
position2di Resize(s32 x, s32 y); irr::core::vector2di Resize(irr::s32 x, irr::s32 y);
position2di ResizeReverse(s32 x, s32 y); irr::core::vector2di ResizeReverse(irr::s32 x, irr::s32 y);
recti ResizePhaseHint(s32 x, s32 y, s32 x2, s32 y2, s32 width); irr::core::recti ResizePhaseHint(irr::s32 x, irr::s32 y, irr::s32 x2, irr::s32 y2, irr::s32 width);
recti ResizeWin(s32 x, s32 y, s32 x2, s32 y2); irr::core::recti ResizeWin(irr::s32 x, irr::s32 y, irr::s32 x2, irr::s32 y2);
recti ResizeCardImgWin(s32 x, s32 y, s32 mx, s32 my); irr::core::recti ResizeCardImgWin(irr::s32 x, irr::s32 y, irr::s32 mx, irr::s32 my);
recti ResizeCardHint(s32 x, s32 y, s32 x2, s32 y2); irr::core::recti ResizeCardHint(irr::s32 x, irr::s32 y, irr::s32 x2, irr::s32 y2);
position2di ResizeCardHint(s32 x, s32 y); irr::core::vector2di ResizeCardHint(irr::s32 x, irr::s32 y);
recti ResizeCardMid(s32 x, s32 y, s32 x2, s32 y2, s32 midx, s32 midy); irr::core::recti ResizeCardMid(irr::s32 x, irr::s32 y, irr::s32 x2, irr::s32 y2, irr::s32 midx, irr::s32 midy);
position2di ResizeCardMid(s32 x, s32 y, s32 midx, s32 midy); irr::core::vector2di ResizeCardMid(irr::s32 x, irr::s32 y, irr::s32 midx, irr::s32 midy);
recti ResizeFit(s32 x, s32 y, s32 x2, s32 y2); irr::core::recti ResizeFit(irr::s32 x, irr::s32 y, irr::s32 x2, irr::s32 y2);
void SetWindowsIcon(); void SetWindowsIcon();
void SetWindowsScale(float scale); void SetWindowsScale(float scale);
void FlashWindow(); void FlashWindow();
void SetCursor(ECURSOR_ICON icon); void SetCursor(irr::gui::ECURSOR_ICON icon);
template<typename T> template<typename T>
static void DrawShadowText(irr::gui::CGUITTFont* font, const T& text, const core::rect<s32>& position, const core::rect<s32>& padding, static void DrawShadowText(irr::gui::CGUITTFont* font, const T& text, const irr::core::rect<irr::s32>& position, const irr::core::rect<irr::s32>& padding,
video::SColor color = 0xffffffff, video::SColor shadowcolor = 0xff000000, bool hcenter = false, bool vcenter = false, const core::rect<s32>* clip = nullptr); irr::video::SColor color = 0xffffffff, irr::video::SColor shadowcolor = 0xff000000, bool hcenter = false, bool vcenter = false, const irr::core::rect<irr::s32>* clip = nullptr);
std::mutex gMutex; std::mutex gMutex;
Signal frameSignal; Signal frameSignal;
...@@ -239,41 +240,41 @@ public: ...@@ -239,41 +240,41 @@ public:
std::wstring chatMsg[8]; std::wstring chatMsg[8];
std::vector<BotInfo> botInfo; std::vector<BotInfo> botInfo;
int hideChatTimer; int hideChatTimer{};
bool hideChat; bool hideChat{};
int chatTiming[8]{}; int chatTiming[8]{};
int chatType[8]{}; int chatType[8]{};
unsigned short linePatternD3D; unsigned short linePatternD3D{};
unsigned short linePatternGL; unsigned short linePatternGL{ 0x0f0f };
int waitFrame; int waitFrame{};
int signalFrame; int signalFrame{};
int actionParam; int actionParam{};
int showingcode; int showingcode{};
const wchar_t* showingtext; const wchar_t* showingtext{};
int showcard; int showcard{};
int showcardcode; int showcardcode{};
int showcarddif; int showcarddif{};
int showcardp; int showcardp{};
int is_attacking; int is_attacking{};
int attack_sv; int attack_sv{};
irr::core::vector3df atk_r; irr::core::vector3df atk_r;
irr::core::vector3df atk_t; irr::core::vector3df atk_t;
float atkdy; float atkdy{};
int lpframe; int lpframe{};
int lpd; int lpd{};
int lpplayer; int lpplayer{};
int lpccolor; int lpccolor{};
std::wstring lpcstring; std::wstring lpcstring;
bool always_chain; bool always_chain{};
bool ignore_chain; bool ignore_chain{};
bool chain_when_avail; bool chain_when_avail{};
bool is_building; bool is_building{};
bool is_siding; bool is_siding{};
irr::core::dimension2d<irr::u32> window_size; irr::core::dimension2d<irr::u32> window_size;
float xScale; float xScale{ 1.0f };
float yScale; float yScale{ 1.0f };
ClientField dField; ClientField dField;
DeckBuilder deckBuilder; DeckBuilder deckBuilder;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include "game.h" #include "game.h"
#include "data_manager.h" #include "data_manager.h"
#include <event2/thread.h> #include <event2/thread.h>
#include <locale.h> #include <clocale>
#include <memory> #include <memory>
#ifdef __APPLE__ #ifdef __APPLE__
#import <CoreFoundation/CoreFoundation.h> #import <CoreFoundation/CoreFoundation.h>
...@@ -24,7 +24,7 @@ void ClickButton(irr::gui::IGUIElement* btn) { ...@@ -24,7 +24,7 @@ void ClickButton(irr::gui::IGUIElement* btn) {
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
#ifndef _WIN32 #ifndef _WIN32
setlocale(LC_CTYPE, "UTF-8"); std::setlocale(LC_CTYPE, "UTF-8");
#endif #endif
#ifdef __APPLE__ #ifdef __APPLE__
CFURLRef bundle_url = CFBundleCopyBundleURL(CFBundleGetMainBundle()); CFURLRef bundle_url = CFBundleCopyBundleURL(CFBundleGetMainBundle());
...@@ -36,17 +36,15 @@ int main(int argc, char* argv[]) { ...@@ -36,17 +36,15 @@ int main(int argc, char* argv[]) {
CFRelease(path); CFRelease(path);
#endif //__APPLE__ #endif //__APPLE__
#ifdef _WIN32 #ifdef _WIN32
#ifndef _DEBUG if (argc == 2 && (ygo::IsExtension(argv[1], ".ydk") || ygo::IsExtension(argv[1], ".yrp"))) { // open file from explorer
char* pstrext;
if(argc == 2 && (pstrext = std::strrchr(argv[1], '.'))
&& (!mystrncasecmp(pstrext, ".ydk", 4) || !mystrncasecmp(pstrext, ".yrp", 4))) {
wchar_t exepath[MAX_PATH]; wchar_t exepath[MAX_PATH];
GetModuleFileNameW(nullptr, exepath, MAX_PATH); GetModuleFileNameW(nullptr, exepath, MAX_PATH);
wchar_t* p = std::wcsrchr(exepath, '\\'); wchar_t* p = std::wcsrchr(exepath, L'\\');
*p = '\0'; if (p) {
SetCurrentDirectoryW(exepath); *p = 0;
SetCurrentDirectoryW(exepath);
}
} }
#endif //_DEBUG
#endif //_WIN32 #endif //_WIN32
#ifdef _WIN32 #ifdef _WIN32
WORD wVersionRequested; WORD wVersionRequested;
...@@ -63,7 +61,7 @@ int main(int argc, char* argv[]) { ...@@ -63,7 +61,7 @@ int main(int argc, char* argv[]) {
return 0; return 0;
#ifdef _WIN32 #ifdef _WIN32
int wargc; int wargc = 0;
std::unique_ptr<wchar_t*[], void(*)(wchar_t**)> wargv(CommandLineToArgvW(GetCommandLineW(), &wargc), [](wchar_t** wargv) { std::unique_ptr<wchar_t*[], void(*)(wchar_t**)> wargv(CommandLineToArgvW(GetCommandLineW(), &wargc), [](wchar_t** wargv) {
LocalFree(wargv); LocalFree(wargv);
}); });
...@@ -78,6 +76,24 @@ int main(int argc, char* argv[]) { ...@@ -78,6 +76,24 @@ int main(int argc, char* argv[]) {
bool keep_on_return = false; bool keep_on_return = false;
bool deckCategorySpecified = false; bool deckCategorySpecified = false;
for(int i = 1; i < wargc; ++i) { for(int i = 1; i < wargc; ++i) {
if (wargc == 2 && std::wcslen(wargv[1]) >= 4) {
wchar_t* pstrext = wargv[1] + std::wcslen(wargv[1]) - 4;
if (!mywcsncasecmp(pstrext, L".ydk", 4)) {
open_file = true;
BufferIO::CopyWideString(wargv[1], open_file_name);
exit_on_return = true;
ClickButton(ygo::mainGame->btnDeckEdit);
break;
}
if (!mywcsncasecmp(pstrext, L".yrp", 4)) {
open_file = true;
BufferIO::CopyWideString(wargv[1], open_file_name);
exit_on_return = true;
ClickButton(ygo::mainGame->btnReplayMode);
ClickButton(ygo::mainGame->btnLoadReplay);
break;
}
}
if(wargv[i][0] == L'-' && wargv[i][1] == L'e' && wargv[i][2] != L'\0') { if(wargv[i][0] == L'-' && wargv[i][1] == L'e' && wargv[i][2] != L'\0') {
ygo::dataManager.LoadDB(&wargv[i][2]); ygo::dataManager.LoadDB(&wargv[i][2]);
continue; continue;
...@@ -173,23 +189,6 @@ int main(int argc, char* argv[]) { ...@@ -173,23 +189,6 @@ int main(int argc, char* argv[]) {
if(open_file) if(open_file)
ClickButton(ygo::mainGame->btnLoadSinglePlay); ClickButton(ygo::mainGame->btnLoadSinglePlay);
break; break;
} else if(wargc == 2 && std::wcslen(wargv[1]) >= 4) {
wchar_t* pstrext = wargv[1] + std::wcslen(wargv[1]) - 4;
if(!mywcsncasecmp(pstrext, L".ydk", 4)) {
open_file = true;
BufferIO::CopyWideString(wargv[i], open_file_name);
exit_on_return = !keep_on_return;
ClickButton(ygo::mainGame->btnDeckEdit);
break;
}
if(!mywcsncasecmp(pstrext, L".yrp", 4)) {
open_file = true;
BufferIO::CopyWideString(wargv[i], open_file_name);
exit_on_return = !keep_on_return;
ClickButton(ygo::mainGame->btnReplayMode);
ClickButton(ygo::mainGame->btnLoadReplay);
break;
}
} }
} }
ygo::mainGame->MainLoop(); ygo::mainGame->MainLoop();
......
...@@ -129,7 +129,7 @@ void ImageManager::ResizeTexture() { ...@@ -129,7 +129,7 @@ void ImageManager::ResizeTexture() {
// function by Warr1024, from https://github.com/minetest/minetest/issues/2419 , modified // function by Warr1024, from https://github.com/minetest/minetest/issues/2419 , modified
void imageScaleNNAA(irr::video::IImage *src, irr::video::IImage *dest) { void imageScaleNNAA(irr::video::IImage *src, irr::video::IImage *dest) {
double sx, sy, minsx, maxsx, minsy, maxsy, area, ra, ga, ba, aa, pw, ph, pa; double sx, sy, minsx, maxsx, minsy, maxsy, area, ra, ga, ba, aa, pw, ph, pa;
u32 dy, dx; irr::u32 dy, dx;
irr::video::SColor pxl; irr::video::SColor pxl;
// Cache rectsngle boundaries. // Cache rectsngle boundaries.
...@@ -138,7 +138,7 @@ void imageScaleNNAA(irr::video::IImage *src, irr::video::IImage *dest) { ...@@ -138,7 +138,7 @@ void imageScaleNNAA(irr::video::IImage *src, irr::video::IImage *dest) {
// Walk each destination image pixel. // Walk each destination image pixel.
// Note: loop y around x for better cache locality. // Note: loop y around x for better cache locality.
irr::core::dimension2d<u32> dim = dest->getDimension(); irr::core::dimension2d<irr::u32> dim = dest->getDimension();
for(dy = 0; dy < dim.Height; dy++) for(dy = 0; dy < dim.Height; dy++)
for(dx = 0; dx < dim.Width; dx++) { for(dx = 0; dx < dim.Width; dx++) {
...@@ -176,7 +176,7 @@ void imageScaleNNAA(irr::video::IImage *src, irr::video::IImage *dest) { ...@@ -176,7 +176,7 @@ void imageScaleNNAA(irr::video::IImage *src, irr::video::IImage *dest) {
// Get source pixel and add it to totals, weighted // Get source pixel and add it to totals, weighted
// by covered area and alpha. // by covered area and alpha.
pxl = src->getPixel((u32)sx, (u32)sy); pxl = src->getPixel((irr::u32)sx, (irr::u32)sy);
area += pa; area += pa;
ra += pa * pxl.getRed(); ra += pa * pxl.getRed();
ga += pa * pxl.getGreen(); ga += pa * pxl.getGreen();
...@@ -199,16 +199,16 @@ void imageScaleNNAA(irr::video::IImage *src, irr::video::IImage *dest) { ...@@ -199,16 +199,16 @@ void imageScaleNNAA(irr::video::IImage *src, irr::video::IImage *dest) {
dest->setPixel(dx, dy, pxl); dest->setPixel(dx, dy, pxl);
} }
} }
irr::video::ITexture* ImageManager::GetTextureFromFile(const char* file, s32 width, s32 height) { irr::video::ITexture* ImageManager::GetTextureFromFile(const char* file, irr::s32 width, irr::s32 height) {
if(mainGame->gameConf.use_image_scale) { if(mainGame->gameConf.use_image_scale) {
irr::video::ITexture* texture; irr::video::ITexture* texture;
irr::video::IImage* srcimg = driver->createImageFromFile(file); irr::video::IImage* srcimg = driver->createImageFromFile(file);
if(srcimg == nullptr) if(srcimg == nullptr)
return nullptr; return nullptr;
if(srcimg->getDimension() == irr::core::dimension2d<u32>(width, height)) { if(srcimg->getDimension() == irr::core::dimension2d<irr::u32>(width, height)) {
texture = driver->addTexture(file, srcimg); texture = driver->addTexture(file, srcimg);
} else { } else {
video::IImage *destimg = driver->createImage(srcimg->getColorFormat(), irr::core::dimension2d<u32>(width, height)); irr::video::IImage *destimg = driver->createImage(srcimg->getColorFormat(), irr::core::dimension2d<irr::u32>(width, height));
imageScaleNNAA(srcimg, destimg); imageScaleNNAA(srcimg, destimg);
texture = driver->addTexture(file, destimg); texture = driver->addTexture(file, destimg);
destimg->drop(); destimg->drop();
...@@ -234,10 +234,10 @@ irr::video::ITexture* ImageManager::GetTexture(int code, bool fit) { ...@@ -234,10 +234,10 @@ irr::video::ITexture* ImageManager::GetTexture(int code, bool fit) {
auto tit = tMap[fit ? 1 : 0].find(code); auto tit = tMap[fit ? 1 : 0].find(code);
if(tit == tMap[fit ? 1 : 0].end()) { if(tit == tMap[fit ? 1 : 0].end()) {
char file[256]; char file[256];
snprintf(file, sizeof file, "expansions/pics/%d.jpg", code); std::snprintf(file, sizeof file, "expansions/pics/%d.jpg", code);
irr::video::ITexture* img = GetTextureFromFile(file, width, height); irr::video::ITexture* img = GetTextureFromFile(file, width, height);
if(img == nullptr) { if(img == nullptr) {
snprintf(file, sizeof file, "pics/%d.jpg", code); std::snprintf(file, sizeof file, "pics/%d.jpg", code);
img = GetTextureFromFile(file, width, height); img = GetTextureFromFile(file, width, height);
} }
if(img == nullptr && !mainGame->gameConf.use_image_scale) { if(img == nullptr && !mainGame->gameConf.use_image_scale) {
...@@ -261,10 +261,10 @@ irr::video::ITexture* ImageManager::GetBigPicture(int code, float zoom) { ...@@ -261,10 +261,10 @@ irr::video::ITexture* ImageManager::GetBigPicture(int code, float zoom) {
} }
irr::video::ITexture* texture; irr::video::ITexture* texture;
char file[256]; char file[256];
snprintf(file, sizeof file, "expansions/pics/%d.jpg", code); std::snprintf(file, sizeof file, "expansions/pics/%d.jpg", code);
irr::video::IImage* srcimg = driver->createImageFromFile(file); irr::video::IImage* srcimg = driver->createImageFromFile(file);
if(srcimg == nullptr) { if(srcimg == nullptr) {
snprintf(file, sizeof file, "pics/%d.jpg", code); std::snprintf(file, sizeof file, "pics/%d.jpg", code);
srcimg = driver->createImageFromFile(file); srcimg = driver->createImageFromFile(file);
} }
if(srcimg == nullptr) { if(srcimg == nullptr) {
...@@ -274,7 +274,7 @@ irr::video::ITexture* ImageManager::GetBigPicture(int code, float zoom) { ...@@ -274,7 +274,7 @@ irr::video::ITexture* ImageManager::GetBigPicture(int code, float zoom) {
texture = driver->addTexture(file, srcimg); texture = driver->addTexture(file, srcimg);
} else { } else {
auto origsize = srcimg->getDimension(); auto origsize = srcimg->getDimension();
video::IImage* destimg = driver->createImage(srcimg->getColorFormat(), irr::core::dimension2d<u32>(origsize.Width * zoom, origsize.Height * zoom)); irr::video::IImage* destimg = driver->createImage(srcimg->getColorFormat(), irr::core::dimension2d<irr::u32>(origsize.Width * zoom, origsize.Height * zoom));
imageScaleNNAA(srcimg, destimg); imageScaleNNAA(srcimg, destimg);
texture = driver->addTexture(file, destimg); texture = driver->addTexture(file, destimg);
destimg->drop(); destimg->drop();
...@@ -290,31 +290,31 @@ int ImageManager::LoadThumbThread() { ...@@ -290,31 +290,31 @@ int ImageManager::LoadThumbThread() {
imageManager.tThumbLoadingCodes.pop(); imageManager.tThumbLoadingCodes.pop();
imageManager.tThumbLoadingMutex.unlock(); imageManager.tThumbLoadingMutex.unlock();
char file[256]; char file[256];
snprintf(file, sizeof file, "expansions/pics/thumbnail/%d.jpg", code); std::snprintf(file, sizeof file, "expansions/pics/thumbnail/%d.jpg", code);
irr::video::IImage* img = imageManager.driver->createImageFromFile(file); irr::video::IImage* img = imageManager.driver->createImageFromFile(file);
if(img == nullptr) { if(img == nullptr) {
snprintf(file, sizeof file, "pics/thumbnail/%d.jpg", code); std::snprintf(file, sizeof file, "pics/thumbnail/%d.jpg", code);
img = imageManager.driver->createImageFromFile(file); img = imageManager.driver->createImageFromFile(file);
} }
if(img == nullptr && mainGame->gameConf.use_image_scale) { if(img == nullptr && mainGame->gameConf.use_image_scale) {
snprintf(file, sizeof file, "expansions/pics/%d.jpg", code); std::snprintf(file, sizeof file, "expansions/pics/%d.jpg", code);
img = imageManager.driver->createImageFromFile(file); img = imageManager.driver->createImageFromFile(file);
} }
if(img == nullptr && mainGame->gameConf.use_image_scale) { if(img == nullptr && mainGame->gameConf.use_image_scale) {
snprintf(file, sizeof file, "pics/%d.jpg", code); std::snprintf(file, sizeof file, "pics/%d.jpg", code);
img = imageManager.driver->createImageFromFile(file); img = imageManager.driver->createImageFromFile(file);
} }
if(img != nullptr) { if(img != nullptr) {
int width = CARD_THUMB_WIDTH * mainGame->xScale; int width = CARD_THUMB_WIDTH * mainGame->xScale;
int height = CARD_THUMB_HEIGHT * mainGame->yScale; int height = CARD_THUMB_HEIGHT * mainGame->yScale;
if(img->getDimension() == irr::core::dimension2d<u32>(width, height)) { if(img->getDimension() == irr::core::dimension2d<irr::u32>(width, height)) {
img->grab(); img->grab();
imageManager.tThumbLoadingMutex.lock(); imageManager.tThumbLoadingMutex.lock();
if(imageManager.tThumbLoadingThreadRunning) if(imageManager.tThumbLoadingThreadRunning)
imageManager.tThumbLoading[code] = img; imageManager.tThumbLoading[code] = img;
imageManager.tThumbLoadingMutex.unlock(); imageManager.tThumbLoadingMutex.unlock();
} else { } else {
irr::video::IImage *destimg = imageManager.driver->createImage(img->getColorFormat(), irr::core::dimension2d<u32>(width, height)); irr::video::IImage *destimg = imageManager.driver->createImage(img->getColorFormat(), irr::core::dimension2d<irr::u32>(width, height));
imageScaleNNAA(img, destimg); imageScaleNNAA(img, destimg);
img->drop(); img->drop();
destimg->grab(); destimg->grab();
...@@ -346,7 +346,7 @@ irr::video::ITexture* ImageManager::GetTextureThumb(int code) { ...@@ -346,7 +346,7 @@ irr::video::ITexture* ImageManager::GetTextureThumb(int code) {
if(lit != tThumbLoading.end()) { if(lit != tThumbLoading.end()) {
if(lit->second != nullptr) { if(lit->second != nullptr) {
char file[256]; char file[256];
snprintf(file, sizeof file, "pics/thumbnail/%d.jpg", code); std::snprintf(file, sizeof file, "pics/thumbnail/%d.jpg", code);
irr::video::ITexture* texture = driver->addTexture(file, lit->second); // textures must be added in the main thread due to OpenGL irr::video::ITexture* texture = driver->addTexture(file, lit->second); // textures must be added in the main thread due to OpenGL
lit->second->drop(); lit->second->drop();
tThumb[code] = texture; tThumb[code] = texture;
...@@ -379,18 +379,18 @@ irr::video::ITexture* ImageManager::GetTextureField(int code) { ...@@ -379,18 +379,18 @@ irr::video::ITexture* ImageManager::GetTextureField(int code) {
auto tit = tFields.find(code); auto tit = tFields.find(code);
if(tit == tFields.end()) { if(tit == tFields.end()) {
char file[256]; char file[256];
snprintf(file, sizeof file, "expansions/pics/field/%d.png", code); std::snprintf(file, sizeof file, "expansions/pics/field/%d.png", code);
irr::video::ITexture* img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale); irr::video::ITexture* img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
if(img == nullptr) { if(img == nullptr) {
snprintf(file, sizeof file, "expansions/pics/field/%d.jpg", code); std::snprintf(file, sizeof file, "expansions/pics/field/%d.jpg", code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale); img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
} }
if(img == nullptr) { if(img == nullptr) {
snprintf(file, sizeof file, "pics/field/%d.png", code); std::snprintf(file, sizeof file, "pics/field/%d.png", code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale); img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
} }
if(img == nullptr) { if(img == nullptr) {
snprintf(file, sizeof file, "pics/field/%d.jpg", code); std::snprintf(file, sizeof file, "pics/field/%d.jpg", code);
img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale); img = GetTextureFromFile(file, 512 * mainGame->xScale, 512 * mainGame->yScale);
if(img == nullptr) { if(img == nullptr) {
tFields[code] = nullptr; tFields[code] = nullptr;
......
...@@ -16,7 +16,7 @@ public: ...@@ -16,7 +16,7 @@ public:
void ClearTexture(); void ClearTexture();
void RemoveTexture(int code); void RemoveTexture(int code);
void ResizeTexture(); void ResizeTexture();
irr::video::ITexture* GetTextureFromFile(const char* file, s32 width, s32 height); irr::video::ITexture* GetTextureFromFile(const char* file, irr::s32 width, irr::s32 height);
irr::video::ITexture* GetTexture(int code, bool fit = false); irr::video::ITexture* GetTexture(int code, bool fit = false);
irr::video::ITexture* GetBigPicture(int code, float zoom); irr::video::ITexture* GetBigPicture(int code, float zoom);
irr::video::ITexture* GetTextureThumb(int code); irr::video::ITexture* GetTextureThumb(int code);
......
This diff is collapsed.
#include "config.h" #ifndef MATERIALS_H
#define MATERIALS_H
#include <irrlicht.h>
namespace ygo { namespace ygo {
...@@ -7,31 +10,31 @@ public: ...@@ -7,31 +10,31 @@ public:
Materials(); Materials();
void GenArrow(float y); void GenArrow(float y);
S3DVertex vCardFront[4]; irr::video::S3DVertex vCardFront[4];
S3DVertex vCardOutline[4]; irr::video::S3DVertex vCardOutline[4];
S3DVertex vCardOutliner[4]; irr::video::S3DVertex vCardOutliner[4];
S3DVertex vCardBack[4]; irr::video::S3DVertex vCardBack[4];
S3DVertex vSymbol[4]; irr::video::S3DVertex vSymbol[4];
S3DVertex vNegate[4]; irr::video::S3DVertex vNegate[4];
S3DVertex vChainNum[4]; irr::video::S3DVertex vChainNum[4];
S3DVertex vActivate[4]; irr::video::S3DVertex vActivate[4];
S3DVertex vField[4]; irr::video::S3DVertex vField[4];
S3DVertex vFieldSpell[4]; irr::video::S3DVertex vFieldSpell[4];
S3DVertex vFieldSpell1[4]; irr::video::S3DVertex vFieldSpell1[4];
S3DVertex vFieldSpell2[4]; irr::video::S3DVertex vFieldSpell2[4];
//S3DVertex vBackLine[76]; //irr::video::S3DVertex vBackLine[76];
S3DVertex vFieldDeck[2][4]; irr::video::S3DVertex vFieldDeck[2][4];
S3DVertex vFieldGrave[2][2][4]; //[player][rule], rule = 0: dule_rule <= 3, 1: dule_rule >= 4 irr::video::S3DVertex vFieldGrave[2][2][4]; //[player][rule], rule = 0: dule_rule <= 3, 1: dule_rule >= 4
S3DVertex vFieldExtra[2][4]; irr::video::S3DVertex vFieldExtra[2][4];
S3DVertex vFieldRemove[2][2][4]; //[player][rule] irr::video::S3DVertex vFieldRemove[2][2][4]; //[player][rule]
S3DVertex vFieldMzone[2][7][4]; //[player][sequence] irr::video::S3DVertex vFieldMzone[2][7][4]; //[player][sequence]
S3DVertex vFieldSzone[2][8][2][4]; //[player][sequence][rule] irr::video::S3DVertex vFieldSzone[2][8][2][4]; //[player][sequence][rule]
irr::core::vector3df vFieldContiAct[4]; irr::core::vector3df vFieldContiAct[4];
S3DVertex vArrow[40]; irr::video::S3DVertex vArrow[40];
SColor c2d[4]; irr::video::SColor c2d[4];
u16 iRectangle[6]; irr::u16 iRectangle[6];
//u16 iBackLine[116]; //irr::u16 iBackLine[116];
u16 iArrow[40]; irr::u16 iArrow[40];
irr::video::SMaterial mCard; irr::video::SMaterial mCard;
irr::video::SMaterial mTexture; irr::video::SMaterial mTexture;
irr::video::SMaterial mBackLine; irr::video::SMaterial mBackLine;
...@@ -44,3 +47,5 @@ public: ...@@ -44,3 +47,5 @@ public:
extern Materials matManager; extern Materials matManager;
} }
#endif //MATERIALS_H
...@@ -33,7 +33,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -33,7 +33,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
switch(event.EventType) { switch(event.EventType) {
case irr::EET_GUI_EVENT: { case irr::EET_GUI_EVENT: {
irr::gui::IGUIElement* caller = event.GUIEvent.Caller; irr::gui::IGUIElement* caller = event.GUIEvent.Caller;
s32 id = caller->getID(); irr::s32 id = caller->getID();
if(mainGame->wQuery->isVisible() && id != BUTTON_YES && id != BUTTON_NO) { if(mainGame->wQuery->isVisible() && id != BUTTON_YES && id != BUTTON_NO) {
mainGame->wQuery->getParent()->bringToFront(mainGame->wQuery); mainGame->wQuery->getParent()->bringToFront(mainGame->wQuery);
break; break;
...@@ -176,7 +176,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -176,7 +176,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
} }
case BUTTON_HP_READY: { case BUTTON_HP_READY: {
if(mainGame->cbCategorySelect->getSelected() == -1 || mainGame->cbDeckSelect->getSelected() == -1 || if(mainGame->cbCategorySelect->getSelected() == -1 || mainGame->cbDeckSelect->getSelected() == -1 ||
!deckManager.LoadCurrentDeck(mainGame->cbCategorySelect, mainGame->cbDeckSelect)) { !deckManager.LoadCurrentDeck(mainGame->cbCategorySelect->getSelected(), mainGame->cbCategorySelect->getText(), mainGame->cbDeckSelect->getText())) {
mainGame->gMutex.lock(); mainGame->gMutex.lock();
soundManager.PlaySoundEffect(SOUND_INFO); soundManager.PlaySoundEffect(SOUND_INFO);
mainGame->env->addMessageBox(L"", dataManager.GetSysString(1406)); mainGame->env->addMessageBox(L"", dataManager.GetSysString(1406));
...@@ -367,7 +367,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -367,7 +367,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
wchar_t arg1[512]; wchar_t arg1[512];
if(mainGame->botInfo[sel].select_deckfile) { if(mainGame->botInfo[sel].select_deckfile) {
wchar_t botdeck[256]; wchar_t botdeck[256];
deckManager.GetDeckFile(botdeck, mainGame->cbBotDeckCategory, mainGame->cbBotDeck); deckManager.GetDeckFile(botdeck, mainGame->cbBotDeckCategory->getSelected(), mainGame->cbBotDeckCategory->getText(), mainGame->cbBotDeck->getText());
myswprintf(arg1, L"%ls DeckFile='%ls'", mainGame->botInfo[sel].command, botdeck); myswprintf(arg1, L"%ls DeckFile='%ls'", mainGame->botInfo[sel].command, botdeck);
} }
else else
...@@ -386,7 +386,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -386,7 +386,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
wchar_t warg1[512]; wchar_t warg1[512];
if(mainGame->botInfo[sel].select_deckfile) { if(mainGame->botInfo[sel].select_deckfile) {
wchar_t botdeck[256]; wchar_t botdeck[256];
deckManager.GetDeckFile(botdeck, mainGame->cbBotDeckCategory, mainGame->cbBotDeck); deckManager.GetDeckFile(botdeck, mainGame->cbBotDeckCategory->getSelected(), mainGame->cbBotDeckCategory->getText(), mainGame->cbBotDeck->getText());
myswprintf(warg1, L"%ls DeckFile='%ls'", mainGame->botInfo[sel].command, botdeck); myswprintf(warg1, L"%ls DeckFile='%ls'", mainGame->botInfo[sel].command, botdeck);
} }
else else
...@@ -396,11 +396,11 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -396,11 +396,11 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
int flag = 0; int flag = 0;
flag += (mainGame->chkBotHand->isChecked() ? 0x1 : 0); flag += (mainGame->chkBotHand->isChecked() ? 0x1 : 0);
char arg2[8]; char arg2[8];
snprintf(arg2, sizeof arg2, "%d", flag); std::snprintf(arg2, sizeof arg2, "%d", flag);
char arg3[8]; char arg3[8];
snprintf(arg3, sizeof arg3, "%d", mainGame->gameConf.serverport); std::snprintf(arg3, sizeof arg3, "%d", mainGame->gameConf.serverport);
execl("./bot", "bot", arg1, arg2, arg3, nullptr); execl("./bot", "bot", arg1, arg2, arg3, nullptr);
exit(0); std::exit(0);
} else { } else {
if(!NetServer::StartServer(mainGame->gameConf.serverport)) { if(!NetServer::StartServer(mainGame->gameConf.serverport)) {
soundManager.PlaySoundEffect(SOUND_INFO); soundManager.PlaySoundEffect(SOUND_INFO);
...@@ -472,7 +472,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -472,7 +472,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
open_file = false; open_file = false;
} }
else if(mainGame->cbDBCategory->getSelected() != -1 && mainGame->cbDBDecks->getSelected() != -1) { else if(mainGame->cbDBCategory->getSelected() != -1 && mainGame->cbDBDecks->getSelected() != -1) {
deckManager.LoadCurrentDeck(mainGame->cbDBCategory, mainGame->cbDBDecks); deckManager.LoadCurrentDeck(mainGame->cbDBCategory->getSelected(), mainGame->cbDBCategory->getText(), mainGame->cbDBDecks->getText());
mainGame->ebDeckname->setText(L""); mainGame->ebDeckname->setText(L"");
} }
mainGame->HideElement(mainGame->wMainMenu); mainGame->HideElement(mainGame->wMainMenu);
...@@ -556,8 +556,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -556,8 +556,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
curtime = ReplayMode::cur_replay.pheader.start_time; curtime = ReplayMode::cur_replay.pheader.start_time;
else else
curtime = ReplayMode::cur_replay.pheader.seed; curtime = ReplayMode::cur_replay.pheader.seed;
tm* st = localtime(&curtime); std::wcsftime(infobuf, sizeof infobuf / sizeof infobuf[0], L"%Y/%m/%d %H:%M:%S\n", std::localtime(&curtime));
std::wcsftime(infobuf, 256, L"%Y/%m/%d %H:%M:%S\n", st);
repinfo.append(infobuf); repinfo.append(infobuf);
wchar_t namebuf[4][20]{}; wchar_t namebuf[4][20]{};
ReplayMode::cur_replay.ReadName(namebuf[0]); ReplayMode::cur_replay.ReadName(namebuf[0]);
...@@ -582,7 +581,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -582,7 +581,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
const wchar_t* name = mainGame->lstSinglePlayList->getListItem(sel); const wchar_t* name = mainGame->lstSinglePlayList->getListItem(sel);
wchar_t fname[256]; wchar_t fname[256];
myswprintf(fname, L"./single/%ls", name); myswprintf(fname, L"./single/%ls", name);
FILE* fp = myfopen(fname, "rb"); FILE* fp = mywfopen(fname, "rb");
if(!fp) { if(!fp) {
mainGame->stSinglePlayInfo->setText(L""); mainGame->stSinglePlayInfo->setText(L"");
break; break;
...@@ -591,7 +590,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -591,7 +590,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
wchar_t wlinebuf[1024]; wchar_t wlinebuf[1024];
std::wstring message = L""; std::wstring message = L"";
bool in_message = false; bool in_message = false;
while(fgets(linebuf, 1024, fp)) { while(std::fgets(linebuf, 1024, fp)) {
if(!std::strncmp(linebuf, "--[[message", 11)) { if(!std::strncmp(linebuf, "--[[message", 11)) {
size_t len = std::strlen(linebuf); size_t len = std::strlen(linebuf);
char* msgend = std::strrchr(linebuf, ']'); char* msgend = std::strrchr(linebuf, ']');
...@@ -614,7 +613,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -614,7 +613,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
message.append(wlinebuf); message.append(wlinebuf);
} }
} }
fclose(fp); std::fclose(fp);
mainGame->SetStaticText(mainGame->stSinglePlayInfo, 200, mainGame->guiFont, message.c_str()); mainGame->SetStaticText(mainGame->stSinglePlayInfo, 200, mainGame->guiFont, message.c_str());
break; break;
} }
...@@ -638,7 +637,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) { ...@@ -638,7 +637,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
mainGame->env->setFocus(mainGame->wHostPrepare); mainGame->env->setFocus(mainGame->wHostPrepare);
if(static_cast<irr::gui::IGUICheckBox*>(caller)->isChecked()) { if(static_cast<irr::gui::IGUICheckBox*>(caller)->isChecked()) {
if(mainGame->cbCategorySelect->getSelected() == -1 || mainGame->cbDeckSelect->getSelected() == -1 || if(mainGame->cbCategorySelect->getSelected() == -1 || mainGame->cbDeckSelect->getSelected() == -1 ||
!deckManager.LoadCurrentDeck(mainGame->cbCategorySelect, mainGame->cbDeckSelect)) { !deckManager.LoadCurrentDeck(mainGame->cbCategorySelect->getSelected(), mainGame->cbCategorySelect->getText(), mainGame->cbDeckSelect->getText())) {
mainGame->gMutex.lock(); mainGame->gMutex.lock();
static_cast<irr::gui::IGUICheckBox*>(caller)->setChecked(false); static_cast<irr::gui::IGUICheckBox*>(caller)->setChecked(false);
soundManager.PlaySoundEffect(SOUND_INFO); soundManager.PlaySoundEffect(SOUND_INFO);
......
#ifndef MENU_HANDLER_H #ifndef MENU_HANDLER_H
#define MENU_HANDLER_H #define MENU_HANDLER_H
#include "config.h" #include <irrlicht.h>
namespace ygo { namespace ygo {
class MenuHandler: public irr::IEventReceiver { class MenuHandler: public irr::IEventReceiver {
public: public:
virtual bool OnEvent(const irr::SEvent& event); bool OnEvent(const irr::SEvent& event) override;
s32 prev_operation; irr::s32 prev_operation{ 0 };
int prev_sel; int prev_sel{ -1 };
}; };
......
...@@ -88,13 +88,13 @@ public: ...@@ -88,13 +88,13 @@ public:
static void TraversalDir(const wchar_t* wpath, const std::function<void(const wchar_t*, bool)>& cb) { static void TraversalDir(const wchar_t* wpath, const std::function<void(const wchar_t*, bool)>& cb) {
wchar_t findstr[1024]; wchar_t findstr[1024];
std::swprintf(findstr, sizeof findstr / sizeof findstr[0], L"%s/*", wpath); std::swprintf(findstr, sizeof findstr / sizeof findstr[0], L"%ls/*", wpath);
WIN32_FIND_DATAW fdataw; WIN32_FIND_DATAW fdataw;
HANDLE fh = FindFirstFileW(findstr, &fdataw); HANDLE fh = FindFirstFileW(findstr, &fdataw);
if(fh == INVALID_HANDLE_VALUE) if(fh == INVALID_HANDLE_VALUE)
return; return;
do { do {
if(mywcsncasecmp(fdataw.cFileName, L".", 1) && mywcsncasecmp(fdataw.cFileName, L"..", 2)) if(std::wcscmp(fdataw.cFileName, L".") && std::wcscmp(fdataw.cFileName, L".."))
cb(fdataw.cFileName, (fdataw.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)); cb(fdataw.cFileName, (fdataw.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY));
} while(FindNextFileW(fh, &fdataw)); } while(FindNextFileW(fh, &fdataw));
FindClose(fh); FindClose(fh);
...@@ -119,7 +119,7 @@ public: ...@@ -119,7 +119,7 @@ public:
while((wfile = std::wcspbrk(wfile, L"/")) != nullptr) while((wfile = std::wcspbrk(wfile, L"/")) != nullptr)
*wfile++ = '_'; *wfile++ = '_';
} }
static bool IsFileExists(const char* file) { static bool IsFileExists(const char* file) {
struct stat fileStat; struct stat fileStat;
return (stat(file, &fileStat) == 0) && !S_ISDIR(fileStat.st_mode); return (stat(file, &fileStat) == 0) && !S_ISDIR(fileStat.st_mode);
...@@ -216,7 +216,7 @@ public: ...@@ -216,7 +216,7 @@ public:
stat(fname, &fileStat); stat(fname, &fileStat);
funit.filename = std::string(dirp->d_name); funit.filename = std::string(dirp->d_name);
funit.is_dir = S_ISDIR(fileStat.st_mode); funit.is_dir = S_ISDIR(fileStat.st_mode);
if(funit.is_dir && (strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0)) if(funit.is_dir && (std::strcmp(dirp->d_name, ".") == 0 || std::strcmp(dirp->d_name, "..") == 0))
continue; continue;
file_list.push_back(funit); file_list.push_back(funit);
} }
......
...@@ -41,7 +41,7 @@ public: ...@@ -41,7 +41,7 @@ public:
bufferevent_write(dp->bev, net_server_write, 3); bufferevent_write(dp->bev, net_server_write, 3);
} }
template<typename ST> template<typename ST>
static void SendPacketToPlayer(DuelPlayer* dp, unsigned char proto, ST& st) { static void SendPacketToPlayer(DuelPlayer* dp, unsigned char proto, const ST& st) {
auto p = net_server_write; auto p = net_server_write;
if (sizeof(ST) > MAX_DATA_SIZE) if (sizeof(ST) > MAX_DATA_SIZE)
return; return;
......
...@@ -23,8 +23,8 @@ void Replay::BeginRecord() { ...@@ -23,8 +23,8 @@ void Replay::BeginRecord() {
return; return;
#else #else
if(is_recording) if(is_recording)
fclose(fp); std::fclose(fp);
fp = fopen("./replay/_LastReplay.yrp", "wb"); fp = std::fopen("./replay/_LastReplay.yrp", "wb");
if(!fp) if(!fp)
return; return;
#endif #endif
...@@ -39,8 +39,8 @@ void Replay::WriteHeader(ReplayHeader& header) { ...@@ -39,8 +39,8 @@ void Replay::WriteHeader(ReplayHeader& header) {
DWORD size; DWORD size;
WriteFile(recording_fp, &header, sizeof(header), &size, nullptr); WriteFile(recording_fp, &header, sizeof(header), &size, nullptr);
#else #else
fwrite(&header, sizeof(header), 1, fp); std::fwrite(&header, sizeof(header), 1, fp);
fflush(fp); std::fflush(fp);
#endif #endif
} }
void Replay::WriteData(const void* data, size_t length, bool flush) { void Replay::WriteData(const void* data, size_t length, bool flush) {
...@@ -54,9 +54,9 @@ void Replay::WriteData(const void* data, size_t length, bool flush) { ...@@ -54,9 +54,9 @@ void Replay::WriteData(const void* data, size_t length, bool flush) {
DWORD size; DWORD size;
WriteFile(recording_fp, data, length, &size, nullptr); WriteFile(recording_fp, data, length, &size, nullptr);
#else #else
fwrite(data, length, 1, fp); std::fwrite(data, length, 1, fp);
if(flush) if(flush)
fflush(fp); std::fflush(fp);
#endif #endif
} }
void Replay::WriteInt32(int32_t data, bool flush) { void Replay::WriteInt32(int32_t data, bool flush) {
...@@ -67,7 +67,7 @@ void Replay::Flush() { ...@@ -67,7 +67,7 @@ void Replay::Flush() {
return; return;
#ifdef _WIN32 #ifdef _WIN32
#else #else
fflush(fp); std::fflush(fp);
#endif #endif
} }
void Replay::EndRecord() { void Replay::EndRecord() {
...@@ -76,7 +76,7 @@ void Replay::EndRecord() { ...@@ -76,7 +76,7 @@ void Replay::EndRecord() {
#ifdef _WIN32 #ifdef _WIN32
CloseHandle(recording_fp); CloseHandle(recording_fp);
#else #else
fclose(fp); std::fclose(fp);
#endif #endif
pheader.datasize = replay_size; pheader.datasize = replay_size;
pheader.flag |= REPLAY_COMPRESSED; pheader.flag |= REPLAY_COMPRESSED;
...@@ -94,19 +94,19 @@ void Replay::SaveReplay(const wchar_t* name) { ...@@ -94,19 +94,19 @@ void Replay::SaveReplay(const wchar_t* name) {
return; return;
wchar_t fname[256]; wchar_t fname[256];
myswprintf(fname, L"./replay/%ls.yrp", name); myswprintf(fname, L"./replay/%ls.yrp", name);
FILE* rfp = myfopen(fname, "wb"); FILE* rfp = mywfopen(fname, "wb");
if(!rfp) if(!rfp)
return; return;
fwrite(&pheader, sizeof pheader, 1, rfp); std::fwrite(&pheader, sizeof pheader, 1, rfp);
fwrite(comp_data, comp_size, 1, rfp); std::fwrite(comp_data, comp_size, 1, rfp);
fclose(rfp); std::fclose(rfp);
} }
bool Replay::OpenReplay(const wchar_t* name) { bool Replay::OpenReplay(const wchar_t* name) {
FILE* rfp = myfopen(name, "rb"); FILE* rfp = mywfopen(name, "rb");
if(!rfp) { if(!rfp) {
wchar_t fname[256]; wchar_t fname[256];
myswprintf(fname, L"./replay/%ls", name); myswprintf(fname, L"./replay/%ls", name);
rfp = myfopen(fname, "rb"); rfp = mywfopen(fname, "rb");
} }
if(!rfp) if(!rfp)
return false; return false;
...@@ -116,13 +116,13 @@ bool Replay::OpenReplay(const wchar_t* name) { ...@@ -116,13 +116,13 @@ bool Replay::OpenReplay(const wchar_t* name) {
is_replaying = false; is_replaying = false;
replay_size = 0; replay_size = 0;
comp_size = 0; comp_size = 0;
if(fread(&pheader, sizeof pheader, 1, rfp) < 1) { if(std::fread(&pheader, sizeof pheader, 1, rfp) < 1) {
fclose(rfp); std::fclose(rfp);
return false; return false;
} }
if(pheader.flag & REPLAY_COMPRESSED) { if(pheader.flag & REPLAY_COMPRESSED) {
comp_size = fread(comp_data, 1, MAX_COMP_SIZE, rfp); comp_size = std::fread(comp_data, 1, MAX_COMP_SIZE, rfp);
fclose(rfp); std::fclose(rfp);
if (pheader.datasize > MAX_REPLAY_SIZE) if (pheader.datasize > MAX_REPLAY_SIZE)
return false; return false;
replay_size = pheader.datasize; replay_size = pheader.datasize;
...@@ -133,8 +133,8 @@ bool Replay::OpenReplay(const wchar_t* name) { ...@@ -133,8 +133,8 @@ bool Replay::OpenReplay(const wchar_t* name) {
return false; return false;
} }
} else { } else {
replay_size = fread(replay_data, 1, MAX_REPLAY_SIZE, rfp); replay_size = std::fread(replay_data, 1, MAX_REPLAY_SIZE, rfp);
fclose(rfp); std::fclose(rfp);
comp_size = 0; comp_size = 0;
} }
is_replaying = true; is_replaying = true;
...@@ -143,12 +143,12 @@ bool Replay::OpenReplay(const wchar_t* name) { ...@@ -143,12 +143,12 @@ bool Replay::OpenReplay(const wchar_t* name) {
bool Replay::CheckReplay(const wchar_t* name) { bool Replay::CheckReplay(const wchar_t* name) {
wchar_t fname[256]; wchar_t fname[256];
myswprintf(fname, L"./replay/%ls", name); myswprintf(fname, L"./replay/%ls", name);
FILE* rfp = myfopen(fname, "rb"); FILE* rfp = mywfopen(fname, "rb");
if(!rfp) if(!rfp)
return false; return false;
ReplayHeader rheader; ReplayHeader rheader;
size_t count = fread(&rheader, sizeof rheader, 1, rfp); size_t count = std::fread(&rheader, sizeof rheader, 1, rfp);
fclose(rfp); std::fclose(rfp);
return count == 1 && rheader.id == 0x31707279 && rheader.version >= 0x12d0u && (rheader.version < 0x1353u || (rheader.flag & REPLAY_UNIFORM)); return count == 1 && rheader.id == 0x31707279 && rheader.version >= 0x12d0u && (rheader.version < 0x1353u || (rheader.flag & REPLAY_UNIFORM));
} }
bool Replay::DeleteReplay(const wchar_t* name) { bool Replay::DeleteReplay(const wchar_t* name) {
......
#ifndef REPLAY_MODE_H #ifndef REPLAY_MODE_H
#define REPLAY_MODE_H #define REPLAY_MODE_H
#include <stdint.h> #include <cstdint>
#include <vector> #include <vector>
#include "replay.h" #include "replay.h"
......
...@@ -419,7 +419,7 @@ void SingleDuel::TPResult(DuelPlayer* dp, unsigned char tp) { ...@@ -419,7 +419,7 @@ void SingleDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
rh.version = PRO_VERSION; rh.version = PRO_VERSION;
rh.flag = REPLAY_UNIFORM; rh.flag = REPLAY_UNIFORM;
rh.seed = seed; rh.seed = seed;
rh.start_time = (unsigned int)time(nullptr); rh.start_time = (unsigned int)std::time(nullptr);
last_replay.BeginRecord(); last_replay.BeginRecord();
last_replay.WriteHeader(rh); last_replay.WriteHeader(rh);
last_replay.WriteData(players[0]->name, 40, false); last_replay.WriteData(players[0]->name, 40, false);
......
...@@ -84,7 +84,7 @@ int SingleMode::SinglePlayThread() { ...@@ -84,7 +84,7 @@ int SingleMode::SinglePlayThread() {
rh.version = PRO_VERSION; rh.version = PRO_VERSION;
rh.flag = REPLAY_UNIFORM | REPLAY_SINGLE_MODE; rh.flag = REPLAY_UNIFORM | REPLAY_SINGLE_MODE;
rh.seed = seed; rh.seed = seed;
rh.start_time = (unsigned int)time(nullptr); rh.start_time = (unsigned int)std::time(nullptr);
mainGame->gMutex.lock(); mainGame->gMutex.lock();
mainGame->HideElement(mainGame->wSinglePlay); mainGame->HideElement(mainGame->wSinglePlay);
mainGame->ClearCardInfo(); mainGame->ClearCardInfo();
...@@ -135,10 +135,9 @@ int SingleMode::SinglePlayThread() { ...@@ -135,10 +135,9 @@ int SingleMode::SinglePlayThread() {
} }
last_replay.EndRecord(); last_replay.EndRecord();
mainGame->gMutex.lock(); mainGame->gMutex.lock();
time_t nowtime = time(nullptr); time_t nowtime = std::time(nullptr);
tm* localedtime = localtime(&nowtime);
wchar_t timetext[40]; wchar_t timetext[40];
std::wcsftime(timetext, 40, L"%Y-%m-%d %H-%M-%S", localedtime); std::wcsftime(timetext, sizeof timetext / sizeof timetext[0], L"%Y-%m-%d %H-%M-%S", std::localtime(&nowtime));
mainGame->ebRSName->setText(timetext); mainGame->ebRSName->setText(timetext);
if(!mainGame->chkAutoSaveReplay->isChecked()) { if(!mainGame->chkAutoSaveReplay->isChecked()) {
mainGame->wReplaySave->setText(dataManager.GetSysString(1340)); mainGame->wReplaySave->setText(dataManager.GetSysString(1340));
......
#ifndef SINGLE_MODE_H #ifndef SINGLE_MODE_H
#define SINGLE_MODE_H #define SINGLE_MODE_H
#include <stdint.h> #include <cstdint>
#include <vector> #include <vector>
#include "replay.h" #include "replay.h"
......
...@@ -12,7 +12,7 @@ bool SoundManager::Init() { ...@@ -12,7 +12,7 @@ bool SoundManager::Init() {
#ifdef YGOPRO_USE_IRRKLANG #ifdef YGOPRO_USE_IRRKLANG
bgm_scene = -1; bgm_scene = -1;
RefreshBGMList(); RefreshBGMList();
rnd.reset((unsigned int)time(nullptr)); rnd.reset((unsigned int)std::time(nullptr));
engineSound = irrklang::createIrrKlangDevice(); engineSound = irrklang::createIrrKlangDevice();
engineMusic = irrklang::createIrrKlangDevice(); engineMusic = irrklang::createIrrKlangDevice();
if(!engineSound || !engineMusic) { if(!engineSound || !engineMusic) {
......
...@@ -392,7 +392,7 @@ void TagDuel::TPResult(DuelPlayer* dp, unsigned char tp) { ...@@ -392,7 +392,7 @@ void TagDuel::TPResult(DuelPlayer* dp, unsigned char tp) {
rh.version = PRO_VERSION; rh.version = PRO_VERSION;
rh.flag = REPLAY_UNIFORM | REPLAY_TAG; rh.flag = REPLAY_UNIFORM | REPLAY_TAG;
rh.seed = seed; rh.seed = seed;
rh.start_time = (unsigned int)time(nullptr); rh.start_time = (unsigned int)std::time(nullptr);
last_replay.BeginRecord(); last_replay.BeginRecord();
last_replay.WriteHeader(rh); last_replay.WriteHeader(rh);
last_replay.WriteData(players[0]->name, 40, false); last_replay.WriteData(players[0]->name, 40, false);
......
...@@ -43,6 +43,10 @@ project "freetype" ...@@ -43,6 +43,10 @@ project "freetype"
"src/type42/type42.c", "src/type42/type42.c",
"src/winfonts/winfnt.c" } "src/winfonts/winfnt.c" }
if os.isfile("src/svg/svg.c") then
files { "src/svg/svg.c" }
end
filter "system:windows" filter "system:windows"
files { "builds/windows/ftsystem.c", files { "builds/windows/ftsystem.c",
"builds/windows/ftdebug.c" } "builds/windows/ftdebug.c" }
......
1 ICON "ygopro.ico" 1 ICON "ygopro.ico"
1 VERSIONINFO 1 VERSIONINFO
FILEVERSION 1, 0, 35, 3 FILEVERSION 1, 0, 36, 1
PRODUCTVERSION 1, 0, 35, 3 PRODUCTVERSION 1, 0, 36, 1
FILEOS 0x4 FILEOS 0x4
FILETYPE 0x1 FILETYPE 0x1
...@@ -13,11 +13,11 @@ BLOCK "080404b0" ...@@ -13,11 +13,11 @@ BLOCK "080404b0"
BEGIN BEGIN
VALUE "FileDescription", "YGOPro" VALUE "FileDescription", "YGOPro"
VALUE "InternalName", "YGOPro" VALUE "InternalName", "YGOPro"
VALUE "LegalCopyright", "Copyright (C) 2022 Fluorohydride" VALUE "LegalCopyright", "Copyright (C) 2025 Fluorohydride"
VALUE "OriginalFilename", "YGOPro.exe" VALUE "OriginalFilename", "YGOPro.exe"
VALUE "ProductName", "YGOPro" VALUE "ProductName", "YGOPro"
VALUE "FileVersion", "1.035.3" VALUE "FileVersion", "1.036.1"
VALUE "ProductVersion", "1.035.3" VALUE "ProductVersion", "1.036.1"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"
......
This diff is collapsed.
...@@ -1245,3 +1245,7 @@ ...@@ -1245,3 +1245,7 @@
!setname 0x1c0 龙华 竜華 !setname 0x1c0 龙华 竜華
!setname 0x1c1 阿尔戈☆群星 ARGS !setname 0x1c1 阿尔戈☆群星 ARGS
!setname 0x1c2 喷水引擎 アクア・ジェット !setname 0x1c2 喷水引擎 アクア・ジェット
!setname 0x1c3 御剑 Mitsurugi
!setname 0x1c4 征龙 征竜
!setname 0x1c5 再世 再世
!setname 0x1c6 统王 ドミナス
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment