-
Notifications
You must be signed in to change notification settings - Fork 789
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
624 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
using GuiBaseUI; | ||
|
||
namespace Sth4nothing.UseStorageBook | ||
{ | ||
public class BookCell : ItemCell | ||
{ | ||
|
||
public ChildData[] childDatas; | ||
public override void Awake() | ||
{ | ||
base.Awake(); | ||
childDatas = new ChildData[NewBookView.columns]; | ||
for (int i = 0; i < NewBookView.columns; i++) | ||
{ | ||
Transform child = transform.GetChild(i); | ||
childDatas[i] = new ChildData(child); | ||
} | ||
//Main.Logger.Log("WarehouseItem Awake " + childDatas.Length); | ||
} | ||
} | ||
|
||
public class SetBook : MonoBehaviour | ||
{ | ||
public void SetBookId(int bookId) | ||
{ | ||
if (gameObject.name == "Item," + bookId) | ||
return; | ||
gameObject.name = "Item," + bookId; | ||
gameObject.GetComponent<Toggle>().group = HomeSystem.instance.bookHolder.GetComponent<ToggleGroup>(); | ||
Image component = gameObject.transform.Find("ItemBack").GetComponent<Image>(); | ||
component.sprite = GetSprites.instance.itemBackSprites[int.Parse(DateFile.instance.GetItemDate(bookId, 4, true))]; | ||
component.color = ActorMenu.instance.LevelColor(int.Parse(DateFile.instance.GetItemDate(bookId, 8, true))); | ||
GameObject gameObject2 = gameObject.transform.GetChild(2).gameObject; | ||
gameObject2.name = "ItemIcon," + bookId; | ||
gameObject2.GetComponent<Image>().sprite = GetSprites.instance.itemSprites[int.Parse(DateFile.instance.GetItemDate(bookId, 98, true))]; | ||
int num2 = int.Parse(DateFile.instance.GetItemDate(bookId, 901, true)); | ||
int num3 = int.Parse(DateFile.instance.GetItemDate(bookId, 902, true)); | ||
gameObject.transform.Find("ItemHpText").GetComponent<Text>().text = $"{ActorMenu.instance.Color3(num2, num3)}{num2}</color>/{num3}"; | ||
int[] bookPage = DateFile.instance.GetBookPage(bookId); | ||
Transform transform = gameObject.transform.Find("PageBack"); | ||
for (int j = 0; j < transform.childCount; j++) | ||
{ | ||
if (bookPage[j] == 1) | ||
{ | ||
transform.GetChild(j).GetComponent<Image>().color = new Color(100f / 255, 100f / 255, 0f, 1f); | ||
} | ||
} | ||
} | ||
static void Travel(Transform obj, int level) | ||
{ | ||
var indent = ""; | ||
for (int i = 0; i < level; i++) | ||
{ | ||
indent += '-'; | ||
} | ||
Debug.Log($"{indent}{obj.name}"); | ||
foreach (Transform child in obj) | ||
{ | ||
Travel(child, level + 1); | ||
} | ||
} | ||
} | ||
public struct ChildData | ||
{ | ||
public GameObject gameObject; | ||
public SetBook setBook; | ||
|
||
public ChildData(Transform child) | ||
{ | ||
gameObject = child.gameObject; | ||
setBook = gameObject.AddComponent<SetBook>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,236 @@ | ||
using Harmony12; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Xml.Serialization; | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
using UnityModManagerNet; | ||
|
||
namespace Sth4nothing.UseStorageBook | ||
{ | ||
class BookSetting : MonoBehaviour | ||
{ | ||
public static BookSetting Instance { get; private set; } | ||
private static GameObject canvas; | ||
private static GameObject go; | ||
private Rect windowRect; | ||
private bool cursorLock; | ||
public const float designWidth = 1600; | ||
public const float designHeight = 900; | ||
|
||
|
||
public bool Open {get; private set;} | ||
|
||
public static bool Load() | ||
{ | ||
try | ||
{ | ||
Main.Logger.Log("load"); | ||
if (Instance == null) | ||
{ | ||
go = new GameObject("", typeof(BookSetting)); | ||
DontDestroyOnLoad(go); | ||
} | ||
} | ||
catch (System.Exception) | ||
{ | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
private void Awake() | ||
{ | ||
Main.Logger.Log("awake"); | ||
Instance = this; | ||
DontDestroyOnLoad(this); | ||
} | ||
|
||
public void Start() | ||
{ | ||
Main.Logger.Log("start"); | ||
Open = false; | ||
windowRect = new Rect(0, 0, designWidth * 0.25f, designHeight); | ||
} | ||
|
||
public void OnGUI() | ||
{ | ||
if (Open) | ||
{ | ||
var bgColor = GUI.backgroundColor; | ||
var color = GUI.color; | ||
var svMat = GUI.matrix; | ||
|
||
Vector2 resizeRatio = new Vector2((float)Screen.width / designWidth, (float)Screen.height / designHeight); | ||
GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(resizeRatio.x, resizeRatio.y, 1.0f)); | ||
|
||
GUI.backgroundColor = Color.black; | ||
GUI.color = Color.white; | ||
|
||
windowRect = GUILayout.Window(667, windowRect, WindowFunc, ""); | ||
|
||
GUI.matrix = svMat; | ||
GUI.backgroundColor = bgColor; | ||
GUI.color = color; | ||
} | ||
} | ||
|
||
public void Update() | ||
{ | ||
if ((Input.GetKey(KeyCode.RightControl) || Input.GetKey(KeyCode.LeftControl)) | ||
&& Input.GetKeyUp(KeyCode.F6)) | ||
{ | ||
ToggleWindow(); | ||
} | ||
} | ||
|
||
private void WindowFunc(int windowId) | ||
{ | ||
var changed = false; | ||
GUILayout.BeginVertical(); | ||
GUILayout.Space(200); | ||
|
||
for (int i = 0; i < Main.repo.Length; i++) | ||
{ | ||
if (i % 5 == 0) | ||
GUILayout.BeginHorizontal(); | ||
var state = GUILayout.Toggle(Main.Setting.repo[i], Main.repo[i], GUILayout.Width(60)); | ||
if (Main.Setting.repo[i] != state) | ||
{ | ||
Main.Setting.repo[i] = state; | ||
changed = true; | ||
} | ||
if (i % 5 == 4 || i == Main.repo.Length - 1) | ||
GUILayout.EndHorizontal(); | ||
} | ||
GUILayout.Space(10); | ||
|
||
for (int i = 0; i < Main.tof.Length; i++) | ||
{ | ||
if (i % 5 == 0) | ||
GUILayout.BeginHorizontal(); | ||
var state = GUILayout.Toggle(Main.Setting.tof[i], Main.tof[i], GUILayout.Width(60)); | ||
if (Main.Setting.tof[i] != state) | ||
{ | ||
Main.Setting.tof[i] = state; | ||
changed = true; | ||
} | ||
if (i % 5 == 4 || i == Main.tof.Length - 1) | ||
GUILayout.EndHorizontal(); | ||
} | ||
GUILayout.Space(10); | ||
|
||
for (int i = 0; i < Main.pinji.Length; i++) | ||
{ | ||
if (i % 5 == 0) | ||
GUILayout.BeginHorizontal(); | ||
var state = GUILayout.Toggle(Main.Setting.pinji[i], Main.pinji[i], GUILayout.Width(60)); | ||
if (Main.Setting.pinji[i] != state) | ||
{ | ||
Main.Setting.pinji[i] = state; | ||
changed = true; | ||
} | ||
if (i % 5 == 4 || i == Main.pinji.Length - 1) | ||
GUILayout.EndHorizontal(); | ||
} | ||
GUILayout.Space(10); | ||
|
||
for (int i = 0; i < Main.gongfa.Length; i++) | ||
{ | ||
if (i % 5 == 0) | ||
GUILayout.BeginHorizontal(); | ||
var state = GUILayout.Toggle(Main.Setting.gongfa[i], Main.gongfa[i], GUILayout.Width(60)); | ||
if (Main.Setting.gongfa[i] != state) | ||
{ | ||
Main.Setting.gongfa[i] = state; | ||
changed = true; | ||
} | ||
if (i % 5 == 4 || i == Main.gongfa.Length - 1) | ||
GUILayout.EndHorizontal(); | ||
} | ||
GUILayout.Space(10); | ||
|
||
for (var i = 0; i < Main.gang.Length; i++) | ||
{ | ||
if (i % 5 == 0) | ||
GUILayout.BeginHorizontal(); | ||
var state = GUILayout.Toggle(Main.Setting.gang[i], Main.gang[i], GUILayout.Width(60)); | ||
if (Main.Setting.gang[i] != state) | ||
{ | ||
Main.Setting.gang[i] = state; | ||
changed = true; | ||
} | ||
if (i % 5 == 4 || i == Main.gang.Length - 1) | ||
GUILayout.EndHorizontal(); | ||
} | ||
GUILayout.Space(10); | ||
|
||
GUILayout.EndVertical(); | ||
|
||
if (changed) | ||
{ | ||
HomeSystem_SetBook_Patch.SetBookData(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// 切换窗体显示状态 | ||
/// </summary> | ||
public void ToggleWindow() | ||
{ | ||
if (!HomeSystem.instance.bookWindow.activeSelf && !Open) | ||
{ | ||
Main.Logger.Log("bookWindow未启动"); | ||
return; | ||
} | ||
Open = !Open; | ||
Main.Logger.Log($"toggle: {Open}"); | ||
BlockGameUI(Open); | ||
if (Open) | ||
{ | ||
cursorLock = Cursor.lockState == CursorLockMode.Locked || !Cursor.visible; | ||
if (cursorLock) | ||
{ | ||
Cursor.visible = true; | ||
Cursor.lockState = CursorLockMode.None; | ||
} | ||
} | ||
else | ||
{ | ||
if (cursorLock) | ||
{ | ||
Cursor.visible = false; | ||
Cursor.lockState = CursorLockMode.Locked; | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// 挡住游戏的UI | ||
/// </summary> | ||
/// <param name="open"></param> | ||
private void BlockGameUI(bool open) | ||
{ | ||
if (open) | ||
{ | ||
canvas = new GameObject("canvas667", typeof(Canvas), typeof(GraphicRaycaster)); | ||
canvas.GetComponent<Canvas>().renderMode = RenderMode.ScreenSpaceOverlay; | ||
canvas.GetComponent<Canvas>().sortingOrder = short.MaxValue; | ||
DontDestroyOnLoad(canvas); | ||
var panel = new GameObject("panel", typeof(Image)); | ||
panel.transform.SetParent(canvas.transform); | ||
panel.GetComponent<Image>().color = new Color(0f, 0f, 0f, 0.6f); | ||
panel.GetComponent<RectTransform>().anchorMin = new Vector2(0, 0); | ||
panel.GetComponent<RectTransform>().anchorMax = new Vector2(0.25f, 1); | ||
panel.GetComponent<RectTransform>().offsetMin = Vector2.zero; | ||
panel.GetComponent<RectTransform>().offsetMax = Vector2.zero; | ||
} | ||
else | ||
{ | ||
Destroy(canvas); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.