import tkinter as tk
from tkinter import ttk, messagebox
import threading
import time

class MapleStoryTool:
    def __init__(self, root):
        self.root = root
        self.root.title("冒险岛079复古版 辅助工具 v6.0 ")
        self.root.geometry("900x600")
        self.root.resizable(False, False)
        self.root.configure(bg='#1a1a2e')

        # 设置样式
        style = ttk.Style()
        style.theme_use('clam')
        style.configure('Dark.TLabelframe', background='#16213e', foreground='#00ccff', bordercolor='#0f3460', lightcolor='#0f3460', darkcolor='#0f3460')
        style.configure('Dark.TLabelframe.Label', background='#16213e', foreground='#00ccff', font=('微软雅黑', 10, 'bold'))
        style.configure('Dark.TButton', background='#0f3460', foreground='white', font=('微软雅黑', 9), borderwidth=2, focusthickness=3)
        style.map('Dark.TButton', background=[('active', '#1a4d8c')])
        style.configure('Dark.TCheckbutton', background='#16213e', foreground='white', font=('微软雅黑', 9))
        style.configure('Dark.TScale', background='#16213e')

        # 左侧面板 - 物品复制
        left_frame = ttk.LabelFrame(root, text="📦 物品复制", style='Dark.TLabelframe', width=280, height=550)
        left_frame.place(x=10, y=10)

        items = [
            ("💰 金币", "gold"),
            ("⚔️ 装备", "equip"),
            ("🧪 药水", "potion"),
            ("📜 卷轴", "scroll"),
            ("🦴 怪物材料", "material"),
            ("💎 现金道具", "cash")
        ]

        self.item_entries = {}
        for i, (label, key) in enumerate(items):
            lbl = tk.Label(left_frame, text=label, bg='#16213e', fg='white', font=('微软雅黑', 9))
            lbl.grid(row=i, column=0, padx=10, pady=8, sticky='w')
            entry = tk.Entry(left_frame, width=10, bg='#0f3460', fg='#00ccff', insertbackground='#00ccff', bd=0, font=('微软雅黑', 9))
            entry.grid(row=i, column=1, padx=5, pady=8)
            entry.insert(0, "1")
            btn = ttk.Button(left_frame, text="复制", style='Dark.TButton', width=8,
                             command=lambda k=key, e=entry: self.duplicate_item(k, e))
            btn.grid(row=i, column=2, padx=5, pady=8)
            self.item_entries[key] = entry

        # 中央面板 - 装备强化保护
        mid_frame = ttk.LabelFrame(root, text="🛡️ 装备强化保护", style='Dark.TLabelframe', width=280, height=200)
        mid_frame.place(x=310, y=10)

        self.scroll_protect = tk.BooleanVar(value=True)
        self.break_protect = tk.BooleanVar(value=True)

        ttk.Checkbutton(mid_frame, text="🔒 砸卷不降低可砸次数", variable=self.scroll_protect,
                        style='Dark.TCheckbutton').pack(anchor='w', padx=20, pady=15)
        ttk.Checkbutton(mid_frame, text="🛡️ 强化失败不损坏装备", variable=self.break_protect,
                        style='Dark.TCheckbutton').pack(anchor='w', padx=20, pady=15)

        ttk.Button(mid_frame, text="应用保护设置", style='Dark.TButton',
                   command=self.apply_protection).pack(pady=10)

        # 右侧面板 - 权限与成长
        right_frame = ttk.LabelFrame(root, text="👑 权限与成长", style='Dark.TLabelframe', width=280, height=300)
        right_frame.place(x=610, y=10)

        # GM权限
        gm_frame = tk.Frame(right_frame, bg='#16213e')
        gm_frame.pack(pady=15)
        tk.Label(gm_frame, text="👤 GM权限", bg='#16213e', fg='white', font=('微软雅黑', 9)).pack(side='left', padx=5)
        self.gm_status = tk.Label(gm_frame, text="未激活", bg='#16213e', fg='red', font=('微软雅黑', 9, 'bold'))
        self.gm_status.pack(side='left', padx=5)
        ttk.Button(right_frame, text="激活GM权限", style='Dark.TButton',
                   command=self.activate_gm).pack(pady=5)

        # 经验倍率
        exp_frame = tk.Frame(right_frame, bg='#16213e')
        exp_frame.pack(pady=20)
        tk.Label(exp_frame, text="✨ 经验倍率", bg='#16213e', fg='white', font=('微软雅黑', 9)).pack(side='left', padx=5)
        self.exp_var = tk.IntVar(value=1)
        self.exp_label = tk.Label(exp_frame, text="1x", bg='#16213e', fg='#00ccff', font=('微软雅黑', 9, 'bold'))
        self.exp_label.pack(side='left', padx=5)

        self.exp_slider = ttk.Scale(right_frame, from_=1, to=1000, orient='horizontal',
                                     command=self.update_exp_label, style='Dark.TScale')
        self.exp_slider.set(1)
        self.exp_slider.pack(pady=5, padx=20, fill='x')

        ttk.Button(right_frame, text="应用倍率", style='Dark.TButton',
                   command=self.apply_exp_rate).pack(pady=10)

        # 底部信息栏
        footer = tk.Label(root, text="⚠️ ", 
                          bg='#0f3460', fg='#ffcc00', font=('微软雅黑', 9), height=2)
        footer.pack(side='bottom', fill='x')

        # 日志输出框
        log_frame = ttk.LabelFrame(root, text="📋 操作日志", style='Dark.TLabelframe', width=860, height=150)
        log_frame.place(x=10, y=430)

        self.log_text = tk.Text(log_frame, bg='#0f3460', fg='#00ffaa', font=('Consolas', 9), 
                                wrap='word', bd=0, height=6)
        self.log_text.pack(padx=5, pady=5, fill='both', expand=True)

        # 滚动条
        scrollbar = tk.Scrollbar(self.log_text)
        scrollbar.pack(side='right', fill='y')
        self.log_text.config(yscrollcommand=scrollbar.set)
        scrollbar.config(command=self.log_text.yview)

        self.log("系统初始化完成，欢迎使用冒险岛079辅助工具（演示版）")

    def log(self, message):
        """在日志框添加时间戳消息"""
        timestamp = time.strftime("%H:%M:%S")
        self.log_text.insert('end', f"[{timestamp}] {message}\n")
        self.log_text.see('end')
        self.root.update()

    def duplicate_item(self, key, entry):
        """模拟复制物品"""
        try:
            count = int(entry.get())
            if count <= 0:
                raise ValueError
            item_names = {
                'gold': '金币',
                'equip': '装备',
                'potion': '药水',
                'scroll': '卷轴',
                'material': '怪物材料',
                'cash': '现金道具'
            }
            self.log(f"[复制] 尝试复制 {item_names.get(key, key)} x{count} (模拟操作)")
            messagebox.showinfo("演示提示", f"已触发复制 {item_names.get(key, key)} x{count}\n（本工具为演示版，无实际效果）")
        except:
            messagebox.showerror("输入错误", "请输入有效的正整数")

    def apply_protection(self):
        """应用保护设置"""
        scroll = "开启" if self.scroll_protect.get() else "关闭"
        brk = "开启" if self.break_protect.get() else "关闭"
        self.log(f"[保护] 砸卷保护: {scroll} | 失败不损坏: {brk}")
        messagebox.showinfo("演示提示", f"保护设置已保存 (演示)\n砸卷保护: {scroll}\n失败不损坏: {brk}")

    def activate_gm(self):
        """激活GM权限"""
        self.gm_status.config(text="已激活", fg='#00ff00')
        self.log("[权限] GM权限已激活 (模拟)")
        messagebox.showinfo("演示提示", "GM权限激活成功 (演示)")

    def update_exp_label(self, val):
        """更新经验倍率显示"""
        val = int(float(val))
        self.exp_var.set(val)
        self.exp_label.config(text=f"{val}x")

    def apply_exp_rate(self):
        """应用经验倍率"""
        rate = self.exp_var.get()
        self.log(f"[经验] 经验倍率已设置为 {rate}x")
        messagebox.showinfo("演示提示", f"经验倍率已调整为 {rate}x (演示)")

if __name__ == "__main__":
    root = tk.Tk()
    app = MapleStoryTool(root)
    root.mainloop()