rendered paste bodyIndex: src/iconimagelist.cpp
===================================================================
--- src/iconimagelist.cpp (revisione 356)
+++ src/iconimagelist.cpp (copia locale)
@@ -10,8 +10,8 @@
#include "user.h"
#include "battle.h"
#include "utils.h"
+#include "iunitsync.h"
-
#include "images/bot.xpm"
#include "images/admin.xpm"
#include "images/admin_ingame.xpm"
@@ -188,6 +188,12 @@
sn = sn.Lower();
if ( sn == _T("arm") ) return ICON_ARM;
else if ( sn == _T("core") ) return ICON_CORE;
+ else if (ChachedSideIcons[side] == 0){
+ int IconPosition = Add(wxBitmap( usync()->GetSidePicture(side) ), wxNullBitmap);
+ ChachedSideIcons[side] = IconPosition;
+ return IconPosition;
+ }
+ else return ChachedSideIcons[side];
return -1;
}
Index: src/springunitsync.h
===================================================================
--- src/springunitsync.h (revisione 356)
+++ src/springunitsync.h (copia locale)
@@ -58,7 +58,14 @@
typedef int (USYNC_CALL_CONV *GetUnitCountPtr)();
typedef int (USYNC_CALL_CONV *ProcessUnitsNoChecksumPtr)();
+typedef int (USYNC_CALL_CONV *InitFindVFSPtr)(const char*);
+typedef int (USYNC_CALL_CONV *FindFilesVFSPtr)(int, char*, int);
+typedef int (USYNC_CALL_CONV *OpenFileVFSPtr)(const char*);
+typedef int (USYNC_CALL_CONV *FileSizeVFSPtr)(int);
+typedef int (USYNC_CALL_CONV *ReadFileVFSPtr)(int, void*, int);
+typedef void (USYNC_CALL_CONV *CloseFileVFSPtr)(int);
+
class SpringUnitSync : public IUnitSync
{
public:
@@ -79,6 +86,7 @@
int GetSideCount( const std::string& modname );
std::string GetSideName( const std::string& modname, int index );
+ wxImage GetSidePicture(const std::string& SideName);
bool LoadUnitSyncLib();
void FreeUnitSyncLib();
@@ -126,6 +134,13 @@
GetFullUnitNamePtr m_get_unit_full_name;
ProcessUnitsNoChecksumPtr m_proc_units_nocheck;
+ InitFindVFSPtr m_init_find_vfs;
+ FindFilesVFSPtr m_find_files_vfs;
+ OpenFileVFSPtr m_open_file_vfs;
+ FileSizeVFSPtr m_file_size_vfs;
+ ReadFileVFSPtr m_read_file_vfs;
+ CloseFileVFSPtr m_close_file_vfs;
+
void* _GetLibFuncPtr( const std::string& name );
};
Index: src/battleroomlistctrl.cpp
===================================================================
--- src/battleroomlistctrl.cpp (revisione 356)
+++ src/battleroomlistctrl.cpp (copia locale)
@@ -131,7 +131,7 @@
if ( !user.BattleStatus().spectator ) {
try {
- int sideimg = IconImageList::GetSideIcon( usync()->GetSideName( user.GetBattle()->opts().modname, user.BattleStatus().side ) );
+ int sideimg = icons().GetSideIcon( usync()->GetSideName( user.GetBattle()->opts().modname, user.BattleStatus().side ) );
if ( sideimg >= 0 ) SetItemColumnImage( index, 1, sideimg );
else SetItem( index, 1, WX_STRING(usync()->GetSideName( user.GetBattle()->opts().modname, user.BattleStatus().side )) );
} catch ( ... ) {
Index: src/springunitsync.cpp
===================================================================
--- src/springunitsync.cpp (revisione 356)
+++ src/springunitsync.cpp (copia locale)
@@ -2,6 +2,7 @@
#include <wx/msgdlg.h>
#include <wx/image.h>
#include <wx/string.h>
+#include <wx/mstream.h>
#include <wx/stdpaths.h>
#include <wx/filefn.h>
#include <wx/filename.h>
@@ -116,6 +117,13 @@
m_get_unit_full_name = (GetFullUnitNamePtr)_GetLibFuncPtr("GetFullUnitName");
m_proc_units_nocheck = (ProcessUnitsNoChecksumPtr)_GetLibFuncPtr("ProcessUnitsNoChecksum");
+ m_init_find_vfs = (InitFindVFSPtr)_GetLibFuncPtr("InitFindVFS");
+ m_find_files_vfs = (FindFilesVFSPtr)_GetLibFuncPtr("FindFilesVFS");
+ m_open_file_vfs = (OpenFileVFSPtr)_GetLibFuncPtr("OpenFileVFS");
+ m_file_size_vfs = (FileSizeVFSPtr)_GetLibFuncPtr("FileSizeVFS");
+ m_read_file_vfs = (ReadFileVFSPtr)_GetLibFuncPtr("ReadFileVFS");
+ m_close_file_vfs = (CloseFileVFSPtr)_GetLibFuncPtr("CloseFileVFS");
+
m_init( true, 1 );
}
catch ( std::runtime_error& e ) {
@@ -211,7 +219,7 @@
if ( getmapinfo ) {
char tmpdesc[245+1];
char tmpauth[200+1];
-
+
SpringMapInfo tm;
tm.description = &tmpdesc[0];
tm.author = &tmpauth[0];
@@ -260,6 +268,27 @@
return m_get_side_name( index );
}
+wxImage SpringUnitSync::GetSidePicture(const std::string& SideName )
+{
+ wxString ImgName = _("SidePics");
+ ImgName += _("/");
+ ImgName += WX_STRING( SideName ).Upper();
+ ImgName += _(".bmp");
+ int ini = m_open_file_vfs(ImgName.fn_str());
+ ASSERT_RUNTIME( ini != 0, "cannot find side image" );
+ int FileSize = m_file_size_vfs(ini);
+ if (FileSize == 0){
+ m_close_file_vfs(ini);
+ ASSERT_RUNTIME( FileSize != 0 , "side image has size 0" );
+ }
+ char* FileContent;
+ FileContent = new char [FileSize];
+ m_read_file_vfs(ini, FileContent, FileSize);
+ wxMemoryInputStream FileContentStream( FileContent, FileSize );
+ delete[] FileContent;
+ return wxImage( FileContentStream, wxBITMAP_TYPE_ANY, -1);
+}
+
int SpringUnitSync::GetNumUnits( const std::string& modname )
{
if ( !m_loaded ) return 0;
@@ -329,7 +358,7 @@
}
}
-
+
UnitSyncMap map = GetMap( mapname, true );
if ( map.info.width >= map.info.height ) {
Index: src/base64.cpp
===================================================================
--- src/base64.cpp (revisione 356)
+++ src/base64.cpp (copia locale)
@@ -95,4 +95,3 @@
return ret;
}
-
Index: src/iunitsync.h
===================================================================
--- src/iunitsync.h (revisione 356)
+++ src/iunitsync.h (copia locale)
@@ -64,6 +64,7 @@
virtual int GetSideCount( const std::string& modname ) = 0;
virtual std::string GetSideName( const std::string& modname, int index ) = 0;
+ virtual wxImage GetSidePicture(const std::string& SideName) =0;
virtual bool LoadUnitSyncLib() = 0;
virtual void FreeUnitSyncLib() = 0;
Index: src/iconimagelist.h
===================================================================
--- src/iconimagelist.h (revisione 356)
+++ src/iconimagelist.h (copia locale)
@@ -4,6 +4,8 @@
#include <wx/imaglist.h>
#include <wx/colour.h>
+#include <map>
+
#define ICON_ADMIN 0
#define ICON_ADMIN_AWAY 1
#define ICON_ADMIN_INGAME 2
@@ -66,10 +68,11 @@
static int GetColourIcon( const int& num );
void SetColourIcon( const int& num, const wxColour& colour );
- static int GetSideIcon( const std::string& side );
+ int GetSideIcon( const std::string& side );
static int GetReadyIcon( const bool& ready, const int& sync = 1 );
protected:
+ std::map<std::string, int> ChachedSideIcons;
};
IconImageList& icons();