Skip to content

Commit

Permalink
Merge branch 'master' into issue-9916
Browse files Browse the repository at this point in the history
  • Loading branch information
patrikjuvonen committed Jul 22, 2018
2 parents c511f43 + 7519b14 commit c166d6e
Show file tree
Hide file tree
Showing 19 changed files with 180 additions and 20 deletions.
32 changes: 32 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
@@ -0,0 +1,32 @@
---
name: Bug report
about: Create a report to help us improve

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**MTA Client (please complete the following information):**
- Version [e.g. 1.1, 1.5.4]
- Running in Wine? [e.g, No, Yes - Linux, Yes - macOS]

**MTA Server (please complete the following information):**
- OS: [e.g. Windows 7, Debian Stretch]
- Version [e.g. 1.1, 1.5.4]

**Additional context**
Add any other context about the problem here
17 changes: 17 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
@@ -0,0 +1,17 @@
---
name: Feature request
about: Suggest an idea for this project

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
9 changes: 9 additions & 0 deletions .github/ISSUE_TEMPLATE/security-report.md
@@ -0,0 +1,9 @@
---
name: Security report
about: Submit cheat or security vulnerability

---

Please submit your cheats or security vulnerabilities to @ccw on forum.mtasa.com. Please do not submit them here.

@ccw can be found here: https://forum.mtasa.com/profile/7264-ccw/
2 changes: 0 additions & 2 deletions PULL_REQUEST_TEMPLATE.md → .github/PULL_REQUEST_TEMPLATE.md
@@ -1,5 +1,3 @@
# Only use pull requests to submit patches! Use [the bug tracker](https://bugs.multitheftauto.com) to report bugs, or [the forum](https://forum.mtasa.com) to ask for help!

Before you go ahead and create a pull request, please make sure:

* [ ] [your code follows the coding guidelines](https://wiki.multitheftauto.com/index.php?title=Coding_guidelines)
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
@@ -1,7 +1,7 @@
Our project's code repository can be found on the [multitheftauto/mtasa-blue](https://github.com/multitheftauto/mtasa-blue/) Git repository at [GitHub](https://github.com/). We are always looking for new developers, so if you're interested, here are some useful links:

* [Nightly Builds](https://nightly.mtasa.com/)
* [Bugtracker Roadmap](https://bugs.mtasa.com/roadmap_page.php)
* [Issue Tracker](https://github.com/multitheftauto/mtasa-blue)
* [Wiki Roadmap](https://wiki.mtasa.com/wiki/Roadmap)

Before committing, please review the [coding guidelines](https://wiki.mtasa.com/index.php?title=Coding_guidelines).
5 changes: 5 additions & 0 deletions Client/gui/CGUIMemo_Impl.cpp
Expand Up @@ -111,6 +111,11 @@ void CGUIMemo_Impl::SetVerticalScrollPosition(float fPosition)
}
}

float CGUIMemo_Impl::GetMaxVerticalScrollPosition(void)
{
return GetScrollbarDocumentSize() - GetScrollbarPageSize();
}

float CGUIMemo_Impl::GetScrollbarDocumentSize(void)
{
CEGUI::Scrollbar* pScrollbar = reinterpret_cast<CEGUI::MultiLineEditbox*>(m_pWindow)->d_vertScrollbar;
Expand Down
1 change: 1 addition & 0 deletions Client/gui/CGUIMemo_Impl.h
Expand Up @@ -29,6 +29,7 @@ class CGUIMemo_Impl : public CGUIMemo, public CGUIElement_Impl, public CGUITabLi

float GetVerticalScrollPosition(void);
void SetVerticalScrollPosition(float fPosition);
float GetMaxVerticalScrollPosition(void);
float GetScrollbarDocumentSize(void);
float GetScrollbarPageSize(void);

Expand Down
8 changes: 4 additions & 4 deletions Client/mods/deathmatch/logic/CClientIFP.cpp
Expand Up @@ -24,22 +24,22 @@ CClientIFP::CClientIFP(class CClientManager* pManager, ElementID ID) : CClientEn
m_u32Hashkey = 0;
}

bool CClientIFP::LoadIFP(const SString& strFilePath, const SString& strBlockName)
bool CClientIFP::LoadIFP(const SString& strFile, const bool isRawData, const SString& strBlockName)
{
m_strBlockName = strBlockName;
m_pVecAnimations = &m_pIFPAnimations->vecAnimations;

if (LoadIFPFile(strFilePath))
if (LoadIFPFile(strFile, isRawData))
{
m_u32Hashkey = HashString(strBlockName.ToLower());
return true;
}
return false;
}

bool CClientIFP::LoadIFPFile(const SString& strFilePath)
bool CClientIFP::LoadIFPFile(const SString& strFile, const bool isRawData)
{
if (LoadFileToMemory(strFilePath))
if (isRawData ? LoadDataBufferToMemory(strFile) : LoadFileToMemory(strFile))
{
if (ReadIFPByVersion())
{
Expand Down
4 changes: 2 additions & 2 deletions Client/mods/deathmatch/logic/CClientIFP.h
Expand Up @@ -205,7 +205,7 @@ class CClientIFP : public CClientEntity, CFileReader
void MarkAsUnloading(void) { m_bUnloading = true; }
bool IsUnloading(void) { return m_bUnloading; }

bool LoadIFP(const SString& strFilePath, const SString& strBlockName);
bool LoadIFP(const SString& strFile, const bool isRawData, const SString& strBlockName);

const SString& GetBlockName(void) { return m_strBlockName; }
const unsigned int& GetBlockNameHash(void) { return m_u32Hashkey; }
Expand All @@ -219,7 +219,7 @@ class CClientIFP : public CClientEntity, CFileReader
void SetPosition(const CVector& vecPosition){};

private:
bool LoadIFPFile(const SString& strFilePath);
bool LoadIFPFile(const SString& strFile, const bool isRawData);
bool ReadIFPByVersion(void);
void ReadIFPVersion1(void);
void ReadIFPVersion2(bool bAnp3);
Expand Down
24 changes: 20 additions & 4 deletions Client/mods/deathmatch/logic/CFileReader.cpp
Expand Up @@ -45,15 +45,31 @@ void CFileReader::SkipBytes(const std::uint32_t u32BytesToSkip)
bool CFileReader::LoadFileToMemory(const SString& strFilePath)
{
std::ifstream fileStream(FromUTF8(strFilePath), std::ios::binary | std::ios::ate);
std::streamsize m_iFileSize = fileStream.tellg();
if (m_iFileSize == eIFSTREAM::SIZE_ERROR)
std::streamsize iFileSize = fileStream.tellg();
if (iFileSize == eIFSTREAM::SIZE_ERROR)
{
return false;
}

fileStream.seekg(0, std::ios::beg);
m_vecFileDataBuffer.reserve(static_cast<size_t>(m_iFileSize));
if (fileStream.read(m_vecFileDataBuffer.data(), m_iFileSize))
m_vecFileDataBuffer.reserve(static_cast<size_t>(iFileSize));
if (fileStream.read(m_vecFileDataBuffer.data(), iFileSize))
{
return true;
}
return false;
}

bool CFileReader::LoadDataBufferToMemory(const SString& buffer)
{
std::streamsize iBufferSize = buffer.size();
if (iBufferSize == eIFSTREAM::SIZE_ERROR)
{
return false;
}

m_vecFileDataBuffer.reserve(static_cast<size_t>(iBufferSize));
if (std::copy(buffer.begin(), buffer.end(), m_vecFileDataBuffer.data()))
{
return true;
}
Expand Down
1 change: 1 addition & 0 deletions Client/mods/deathmatch/logic/CFileReader.h
Expand Up @@ -24,6 +24,7 @@ class CFileReader

CFileReader(void);
bool LoadFileToMemory(const SString& strFilePath);
bool LoadDataBufferToMemory(const SString& buffer);
// Do not call any file reader functions after calling this function
void FreeFileReaderMemory(void);

Expand Down
10 changes: 8 additions & 2 deletions Client/mods/deathmatch/logic/CIFPEngine.cpp
Expand Up @@ -10,7 +10,7 @@

#include <StdInc.h>

std::shared_ptr<CClientIFP> CIFPEngine::EngineLoadIFP(CResource* pResource, CClientManager* pManager, const SString& strPath, const SString& strBlockName)
std::shared_ptr<CClientIFP> CIFPEngine::EngineLoadIFP(CResource* pResource, CClientManager* pManager, const SString& strFile, bool bIsRawData, const SString& strBlockName)
{
// Grab the resource root entity
CClientEntity* pRoot = pResource->GetResourceIFPRoot();
Expand All @@ -23,7 +23,7 @@ std::shared_ptr<CClientIFP> CIFPEngine::EngineLoadIFP(CResource* pResource, CCli
std::shared_ptr<CClientIFP> pIFP(new CClientIFP(pManager, INVALID_ELEMENT_ID));

// Try to load the IFP file
if (pIFP->LoadIFP(strPath, strBlockName))
if (pIFP->LoadIFP(strFile, bIsRawData, strBlockName))
{
// We can use the map to retrieve correct IFP by block name later
g_pClientGame->InsertIFPPointerToMap(u32BlockNameHash, pIFP);
Expand Down Expand Up @@ -99,3 +99,9 @@ bool CIFPEngine::EngineRestoreAnimation(CClientEntity* pEntity, const SString& s
}
return false;
}

// Return true if data looks like IFP file contents
bool CIFPEngine::IsIFPData(const SString& strData)
{
return strData.length() > 32 && memcmp(strData, "\x41\x4E\x50", 3) == 0;
}
3 changes: 2 additions & 1 deletion Client/mods/deathmatch/logic/CIFPEngine.h
Expand Up @@ -25,11 +25,12 @@ class CIFPEngine
ALL
};

static std::shared_ptr<CClientIFP> EngineLoadIFP(CResource* pResource, CClientManager* pManager, const SString& strPath, const SString& strBlockName);
static std::shared_ptr<CClientIFP> EngineLoadIFP(CResource* pResource, CClientManager* pManager, const SString& strFile, bool bIsRawData, const SString& strBlockName);
static bool EngineReplaceAnimation(CClientEntity* pEntity, const SString& strInternalBlockName, const SString& strInternalAnimName,
const SString& strCustomBlockName, const SString& strCustomAnimName);
static bool EngineRestoreAnimation(CClientEntity* pEntity, const SString& strInternalBlockName, const SString& strInternalAnimName,
const eRestoreAnimation& eRestoreType);
static bool IsIFPData(const SString& strData);
};

#endif
18 changes: 18 additions & 0 deletions Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp
Expand Up @@ -5569,6 +5569,24 @@ void CStaticFunctionDefinitions::GUIMemoSetCaretIndex(CClientEntity& Entity, uns
}
}

void CStaticFunctionDefinitions::GUIMemoSetVerticalScrollPosition(CClientEntity& Entity, float fPosition)
{
RUN_CHILDREN(GUIMemoSetVerticalScrollPosition(**iter, fPosition))

// Are we a GUI element?
if (IS_GUI(&Entity))
{
CClientGUIElement& GUIElement = static_cast<CClientGUIElement&>(Entity);

// Are we a gridlist?
if (IS_CGUIELEMENT_MEMO(&GUIElement))
{
CGUIMemo* guiMemo = static_cast<CGUIMemo*>(GUIElement.GetCGUIElement());
guiMemo->SetVerticalScrollPosition(fPosition / 100.0f * guiMemo->GetMaxVerticalScrollPosition());
}
}
}

void CStaticFunctionDefinitions::GUIGridListSetSortingEnabled(CClientEntity& Entity, bool bEnabled)
{
RUN_CHILDREN(GUIGridListSetSortingEnabled(**iter, bEnabled))
Expand Down
1 change: 1 addition & 0 deletions Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h
Expand Up @@ -460,6 +460,7 @@ class CStaticFunctionDefinitions

static void GUIMemoSetReadOnly(CClientEntity& Element, bool bFlag);
static void GUIMemoSetCaretIndex(CClientEntity& Element, unsigned int iCaret);
static void GUIMemoSetVerticalScrollPosition(CClientEntity& Element, float fPosition);

static void GUIGridListSetSortingEnabled(CClientEntity& Element, bool bEnabled);
static inline unsigned int GUIGridListAddColumn(CClientGUIElement& GUIElement, const char* szTitle, float fWidth)
Expand Down
9 changes: 5 additions & 4 deletions Client/mods/deathmatch/logic/luadefs/CLuaEngineDefs.cpp
Expand Up @@ -297,22 +297,23 @@ int CLuaEngineDefs::EngineLoadIFP(lua_State* luaVM)
CResource* pResource = pLuaMain->GetResource();
if (pResource)
{
bool bIsRawData = CIFPEngine::IsIFPData(strFile);
SString strPath;
// Is this a legal filepath?
if (CResourceManager::ParseResourcePathInput(strFile, pResource, &strPath))
if (bIsRawData || CResourceManager::ParseResourcePathInput(strFile, pResource, &strPath))
{
std::shared_ptr<CClientIFP> pIFP = CIFPEngine::EngineLoadIFP(pResource, m_pManager, strPath, strBlockName);
std::shared_ptr<CClientIFP> pIFP = CIFPEngine::EngineLoadIFP(pResource, m_pManager, bIsRawData ? strFile : strPath, bIsRawData, strBlockName);
if (pIFP != nullptr)
{
// Return the IFP element
lua_pushelement(luaVM, pIFP.get());
return 1;
}
else
argStream.SetCustomError(strFile, "Error loading IFP");
argStream.SetCustomError(bIsRawData ? "raw data" : strFile, "Error loading IFP");
}
else
argStream.SetCustomError(strFile, "Bad file path");
argStream.SetCustomError(bIsRawData ? "raw data" : strFile, "Bad file path");
}
}
}
Expand Down
51 changes: 51 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaGUIDefs.cpp
Expand Up @@ -134,6 +134,8 @@ void CLuaGUIDefs::LoadFunctions(void)
CLuaCFunctions::AddFunction("guiMemoGetCaretIndex", GUIMemoGetCaretIndex);
CLuaCFunctions::AddFunction("guiMemoSetReadOnly", GUIMemoSetReadOnly);
CLuaCFunctions::AddFunction("guiMemoIsReadOnly", GUIMemoIsReadOnly);
CLuaCFunctions::AddFunction("guiMemoSetVerticalScrollPosition", GUIMemoSetVerticalScrollPosition);
CLuaCFunctions::AddFunction("guiMemoGetVerticalScrollPosition", GUIMemoGetVerticalScrollPosition);

CLuaCFunctions::AddFunction("guiLabelSetColor", GUILabelSetColor);
CLuaCFunctions::AddFunction("guiLabelGetColor", GUILabelGetColor);
Expand Down Expand Up @@ -316,11 +318,14 @@ void CLuaGUIDefs::AddGuiMemoClass(lua_State* luaVM)
lua_classfunction(luaVM, "create", "guiCreateMemo");

lua_classfunction(luaVM, "getCaretIndex", "guiMemoGetCaretIndex");
lua_classfunction(luaVM, "getVerticalScrollPosition", "guiMemoGetVerticalScrollPosition");

lua_classfunction(luaVM, "setCaretIndex", "guiMemoSetCaretIndex");
lua_classfunction(luaVM, "setVerticalScrollPosition", "guiMemoSetVerticalScrollPosition");
lua_classfunction(luaVM, "setReadOnly", "guiMemoSetReadOnly");

lua_classvariable(luaVM, "caretIndex", "guiMemoSetCaretIndex", "guiMemoGetCaretIndex");
lua_classvariable(luaVM, "verticalScrollPosition", "guiMemoSetVerticalScrollPosition", "guiMemoGetVerticalScrollPosition");
lua_classvariable(luaVM, "readOnly", "guiMemoSetReadOnly", "guiMemoIsReadOnly");

lua_registerclass(luaVM, "GuiMemo", "GuiElement");
Expand Down Expand Up @@ -3132,6 +3137,29 @@ int CLuaGUIDefs::GUIMemoSetCaretIndex(lua_State* luaVM)
return 1;
}

int CLuaGUIDefs::GUIMemoSetVerticalScrollPosition(lua_State* luaVM)
{
// bool guiMemoSetVerticalScrollPosition ( gui-memo theMemo, float fPosition )
CClientGUIElement* theMemo;
float fPosition;

CScriptArgReader argStream(luaVM);
argStream.ReadUserData<CGUIMemo>(theMemo);
argStream.ReadNumber(fPosition);

if (!argStream.HasErrors())
{
CStaticFunctionDefinitions::GUIMemoSetVerticalScrollPosition(*theMemo, fPosition);
lua_pushboolean(luaVM, true);
return 1;
}
else
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());

lua_pushboolean(luaVM, false);
return 1;
}

int CLuaGUIDefs::GUIMemoGetCaretIndex(lua_State* luaVM)
{
// bool guiMemoGetCaretIndex ( gui-memo theMemo )
Expand All @@ -3153,6 +3181,29 @@ int CLuaGUIDefs::GUIMemoGetCaretIndex(lua_State* luaVM)
return 1;
}

int CLuaGUIDefs::GUIMemoGetVerticalScrollPosition(lua_State* luaVM)
{
// float guiMemoGetVerticalScrollPosition ( gui-memo theMemo )
CClientGUIElement* theMemo;

CScriptArgReader argStream(luaVM);
argStream.ReadUserData<CGUIMemo>(theMemo);

if (!argStream.HasErrors())
{
CGUIMemo* guiMemo = static_cast<CGUIMemo*>(theMemo->GetCGUIElement());
float fPos = guiMemo->GetVerticalScrollPosition() / guiMemo->GetMaxVerticalScrollPosition() * 100.0f;
lua_pushnumber(luaVM, fPos);
return 1;
}
else
m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage());

// error: bad arguments
lua_pushboolean(luaVM, false);
return 1;
}

int CLuaGUIDefs::GUIWindowSetMovable(lua_State* luaVM)
{
// bool guiWindowSetMovable ( element theElement, bool status )
Expand Down
2 changes: 2 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaGUIDefs.h
Expand Up @@ -123,6 +123,8 @@ class CLuaGUIDefs : public CLuaDefs
LUA_DECLARE(GUIMemoIsReadOnly);
LUA_DECLARE(GUIMemoSetCaretIndex);
LUA_DECLARE(GUIMemoGetCaretIndex);
LUA_DECLARE(GUIMemoGetVerticalScrollPosition);
LUA_DECLARE(GUIMemoSetVerticalScrollPosition);
LUA_DECLARE(GUIWindowSetMovable);
LUA_DECLARE(GUIWindowSetSizable);
LUA_DECLARE(GUIWindowGetMovable);
Expand Down
1 change: 1 addition & 0 deletions Client/sdk/gui/CGUIMemo.h
Expand Up @@ -28,6 +28,7 @@ class CGUIMemo : public CGUIElement

virtual float GetVerticalScrollPosition(void) = 0;
virtual void SetVerticalScrollPosition(float fPosition) = 0;
virtual float GetMaxVerticalScrollPosition(void) = 0;
virtual float GetScrollbarDocumentSize(void) = 0;
virtual float GetScrollbarPageSize(void) = 0;

Expand Down

0 comments on commit c166d6e

Please sign in to comment.