forked from qdsteam/sampmodmobile
-
Notifications
You must be signed in to change notification settings - Fork 7
/
skinchanger.cpp
106 lines (79 loc) · 2.34 KB
/
skinchanger.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <string.h>
#include <stdlib.h>
#include "main.h"
#include "game/game.h"
#include "net/netgame.h"
#include "gui/gui.h"
#include "vendor/imgui/imgui_internal.h"
#include "keyboard.h"
#include "skinchanger.h"
#include "chatwindow.h"
#include "modsa.h"
#include "vendor/inih/cpp/INIReader.h"
extern CGUI *pGUI;
extern CGame *pGame;
extern CNetGame *pNetGame;
extern CKeyBoard *pKeyBoard;
extern CChatWindow *pChatWindow;
extern CModSAWindow *pModSAWindow;
char szSkinIDInputBuffer[100];
char utf8SkinIDInputBuffer[100*3];
CSkinChanger::CSkinChanger()
{
m_bIsActive = false;
}
CSkinChanger::~CSkinChanger()
{
}
void CSkinChanger::Show(bool bShow)
{
if(pGame)
pGame->FindPlayerPed()->TogglePlayerControllable(!bShow);
m_bIsActive = bShow;
}
void CSkinChanger::Clear()
{
m_bIsActive = false;
memset(szSkinIDInputBuffer, 0, 100);
memset(utf8SkinIDInputBuffer, 0, 100*3);
}
void SkinIDWindowInputHandler(const char* str)
{
if(!str || *str == '\0') return;
strcpy(szSkinIDInputBuffer, str);
cp1251_to_utf8(utf8SkinIDInputBuffer, str);
}
void CSkinChanger::Render()
{
if(!m_bIsActive) return;
ImGuiIO &io = ImGui::GetIO();
ImGui::StyleColorsClassic();
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(8,8));
ImGui::Begin("> Skin Changer", nullptr,
ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoResize);
ImGui::Text("Enter the skin ID");
if( ImGui::Button(utf8SkinIDInputBuffer, ImVec2(555, 50) ))
{
if(!pKeyBoard->IsOpen())
pKeyBoard->Open(&SkinIDWindowInputHandler);
}
ImGui::ItemSize( ImVec2(0, pGUI->GetFontSize()/2 + 5) );
ImGui::SetCursorPosX((ImGui::GetWindowWidth() - 278 + ImGui::GetStyle().ItemSpacing.x) / 2);
if(ImGui::Button("Apply", ImVec2(125, 50)))
{
char *strskinid = szSkinIDInputBuffer;
unsigned int skinid = atoi(strskinid);
pGame->FindPlayerPed()->SetModelIndex(skinid);
Show(false);
}
ImGui::SameLine(0, pGUI->GetFontSize());
if(ImGui::Button("Cancel", ImVec2(125, 50)))
{
Show(false);
}
ImGui::SetWindowSize(ImVec2(-1, -1));
ImVec2 size = ImGui::GetWindowSize();
ImGui::SetWindowPos( ImVec2( ((io.DisplaySize.x - size.x)/2), ((io.DisplaySize.y - size.y)/2)) );
ImGui::End();
ImGui::PopStyleVar();
}